|
@@ -0,0 +1,190 @@
|
|
|
+/*
|
|
|
+ * Copyright [2022] [https://www.xiaonuo.vip]
|
|
|
+ *
|
|
|
+ * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
|
|
+ *
|
|
|
+ * 1.请不要删除和修改根目录下的LICENSE文件。
|
|
|
+ * 2.请不要删除和修改Snowy源码头部的版权声明。
|
|
|
+ * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
|
|
|
+ * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
|
|
|
+ * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
|
|
|
+ * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
|
|
|
+ */
|
|
|
+package vip.xiaonuo.biz.modular.bizpipeappoint.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollStreamUtil;
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import jakarta.annotation.Resource;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import vip.xiaonuo.biz.modular.bizpipeplan.entity.BizPipePlan;
|
|
|
+import vip.xiaonuo.biz.modular.bizpipeplan.service.BizPipePlanService;
|
|
|
+import vip.xiaonuo.common.enums.CommonSortOrderEnum;
|
|
|
+import vip.xiaonuo.common.exception.CommonException;
|
|
|
+import vip.xiaonuo.common.page.CommonPageRequest;
|
|
|
+import vip.xiaonuo.biz.modular.bizpipeappoint.entity.BizPipeAppoint;
|
|
|
+import vip.xiaonuo.biz.modular.bizpipeappoint.mapper.BizPipeAppointMapper;
|
|
|
+import vip.xiaonuo.biz.modular.bizpipeappoint.param.BizPipeAppointAddParam;
|
|
|
+import vip.xiaonuo.biz.modular.bizpipeappoint.param.BizPipeAppointEditParam;
|
|
|
+import vip.xiaonuo.biz.modular.bizpipeappoint.param.BizPipeAppointIdParam;
|
|
|
+import vip.xiaonuo.biz.modular.bizpipeappoint.param.BizPipeAppointPageParam;
|
|
|
+import vip.xiaonuo.biz.modular.bizpipeappoint.service.BizPipeAppointService;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.concurrent.locks.ReentrantLock;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 管桩预约Service接口实现类
|
|
|
+ *
|
|
|
+ * @author fanzherong
|
|
|
+ * @date 2025/06/30 15:49
|
|
|
+ **/
|
|
|
+@Service
|
|
|
+public class BizPipeAppointServiceImpl extends ServiceImpl<BizPipeAppointMapper, BizPipeAppoint> implements BizPipeAppointService {
|
|
|
+
|
|
|
+ private final ReentrantLock lock = new ReentrantLock();
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private BizPipePlanService bizPipePlanService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Page<BizPipeAppoint> page(BizPipeAppointPageParam bizPipeAppointPageParam) {
|
|
|
+ QueryWrapper<BizPipeAppoint> queryWrapper = new QueryWrapper<BizPipeAppoint>().checkSqlInjection();
|
|
|
+
|
|
|
+ return this.page(CommonPageRequest.defaultPage(), queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void add(BizPipeAppointAddParam bizPipeAppointAddParam) {
|
|
|
+ checkCount(bizPipeAppointAddParam);
|
|
|
+ checkParam(bizPipeAppointAddParam);
|
|
|
+ BizPipeAppoint bizPipeAppoint = BeanUtil.toBean(bizPipeAppointAddParam, BizPipeAppoint.class);
|
|
|
+ this.save(bizPipeAppoint);
|
|
|
+
|
|
|
+ //查询管桩计划
|
|
|
+ BizPipePlan pipePlan = bizPipePlanService.getById(bizPipeAppointAddParam.getPlanId());
|
|
|
+ if(ObjectUtil.isNotNull(pipePlan)){
|
|
|
+ pipePlan.setPlanAlreadyCount(pipePlan.getPlanAlreadyCount()+1);
|
|
|
+ bizPipePlanService.updateById(pipePlan);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //校验剩余可约次数
|
|
|
+ public void checkCount(BizPipeAppointAddParam bizPipeAppointAddParam){
|
|
|
+ lock.lock();
|
|
|
+ try{
|
|
|
+ BizPipePlan pipePlan = bizPipePlanService.getById(bizPipeAppointAddParam.getPlanId());
|
|
|
+ if(ObjectUtil.isNotNull(pipePlan)){
|
|
|
+ //判断剩余可约次数是否小于0
|
|
|
+ if(pipePlan.getPlanCount()-pipePlan.getPlanAlreadyCount() <=0){
|
|
|
+ throw new CommonException("管桩计划单已预约满!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }finally {
|
|
|
+ lock.unlock(); // 释放锁
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //校验参数
|
|
|
+ public void checkParam(BizPipeAppointAddParam bizPipeAppointAddParam){
|
|
|
+ if(ObjectUtil.isNotEmpty(bizPipeAppointAddParam.getLicensePlate())){
|
|
|
+ bizPipeAppointAddParam.setLicensePlate(bizPipeAppointAddParam.getLicensePlate().toUpperCase().trim());
|
|
|
+ //根据车牌号查询是否有正在执行中的管桩预约
|
|
|
+ long count = this.count(new QueryWrapper<BizPipeAppoint>().lambda().
|
|
|
+ ne(BizPipeAppoint::getStatus, "5").
|
|
|
+ eq(BizPipeAppoint::getLicensePlate, bizPipeAppointAddParam.getLicensePlate()));
|
|
|
+ if(count>0){
|
|
|
+ throw new CommonException("车辆存在正在执行的管桩预约!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void edit(BizPipeAppointEditParam bizPipeAppointEditParam) {
|
|
|
+ BizPipeAppoint bizPipeAppoint = this.queryEntity(bizPipeAppointEditParam.getId());
|
|
|
+ checkCount(bizPipeAppointEditParam,bizPipeAppoint);
|
|
|
+ checkParam(bizPipeAppointEditParam,bizPipeAppoint);
|
|
|
+ if(!StringUtils.equals(bizPipeAppointEditParam.getPlanId(),bizPipeAppoint.getPlanId())){
|
|
|
+ //修改老管桩订单已约次数
|
|
|
+ BizPipePlan oldPlan = bizPipePlanService.getById(bizPipeAppoint.getPlanId());
|
|
|
+ if(ObjectUtil.isNotNull(oldPlan)){
|
|
|
+ oldPlan.setPlanAlreadyCount(oldPlan.getPlanAlreadyCount()-1);
|
|
|
+ bizPipePlanService.updateById(oldPlan);
|
|
|
+ }
|
|
|
+
|
|
|
+ //修改新管桩订单预约次数
|
|
|
+ BizPipePlan newPlan = bizPipePlanService.getById(bizPipeAppointEditParam.getPlanId());
|
|
|
+ if(ObjectUtil.isNotNull(newPlan)){
|
|
|
+ newPlan.setPlanAlreadyCount(newPlan.getPlanAlreadyCount()+1);
|
|
|
+ bizPipePlanService.updateById(newPlan);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BeanUtil.copyProperties(bizPipeAppointEditParam, bizPipeAppoint);
|
|
|
+ this.updateById(bizPipeAppoint);
|
|
|
+ }
|
|
|
+
|
|
|
+ //校验剩余可约次数
|
|
|
+ public void checkCount(BizPipeAppointEditParam bizPipeAppointEditParam,BizPipeAppoint bizPipeAppoint){
|
|
|
+ if(!StringUtils.equals(bizPipeAppointEditParam.getPlanId(),bizPipeAppoint.getPlanId())){
|
|
|
+ lock.lock();
|
|
|
+ try{
|
|
|
+ BizPipePlan pipePlan = bizPipePlanService.getById(bizPipeAppointEditParam.getPlanId());
|
|
|
+ if(ObjectUtil.isNotNull(pipePlan)){
|
|
|
+ //判断剩余可约次数是否小于0
|
|
|
+ if(pipePlan.getPlanCount()-pipePlan.getPlanAlreadyCount() <=0){
|
|
|
+ throw new CommonException("管桩计划单已预约满!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }finally {
|
|
|
+ lock.unlock(); // 释放锁
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public void checkParam(BizPipeAppointEditParam bizPipeAppointEditParam,BizPipeAppoint bizPipeAppoint){
|
|
|
+ if(ObjectUtil.isNotEmpty(bizPipeAppointEditParam.getLicensePlate())){
|
|
|
+ bizPipeAppointEditParam.setLicensePlate(bizPipeAppointEditParam.getLicensePlate().toUpperCase().trim());
|
|
|
+ if(!StringUtils.equals(bizPipeAppointEditParam.getLicensePlate(),bizPipeAppoint.getLicensePlate())){
|
|
|
+ //根据车牌号查询是否有正在执行中的管桩预约
|
|
|
+ long count = this.count(new QueryWrapper<BizPipeAppoint>().lambda().
|
|
|
+ ne(BizPipeAppoint::getStatus, "5").
|
|
|
+ eq(BizPipeAppoint::getLicensePlate, bizPipeAppointEditParam.getLicensePlate()));
|
|
|
+ if(count>0){
|
|
|
+ throw new CommonException("车辆存在正在执行的管桩预约!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void delete(List<BizPipeAppointIdParam> bizPipeAppointIdParamList) {
|
|
|
+ // 执行删除
|
|
|
+ this.removeByIds(CollStreamUtil.toList(bizPipeAppointIdParamList, BizPipeAppointIdParam::getId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BizPipeAppoint detail(BizPipeAppointIdParam bizPipeAppointIdParam) {
|
|
|
+ return this.queryEntity(bizPipeAppointIdParam.getId());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BizPipeAppoint queryEntity(String id) {
|
|
|
+ BizPipeAppoint bizPipeAppoint = this.getById(id);
|
|
|
+ if(ObjectUtil.isEmpty(bizPipeAppoint)) {
|
|
|
+ throw new CommonException("管桩预约不存在,id值为:{}", id);
|
|
|
+ }
|
|
|
+ return bizPipeAppoint;
|
|
|
+ }
|
|
|
+}
|