|
@@ -0,0 +1,180 @@
|
|
|
|
+package com.rongwei.bscommon.sys.service.impl;
|
|
|
|
+
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
+import com.rongwei.bscommon.sys.service.ZhcxCommissionCheckDetailService;
|
|
|
|
+import com.rongwei.bscommon.sys.service.ZhcxCommissionCheckParameterSetDetalService;
|
|
|
|
+import com.rongwei.bscommon.sys.service.ZhcxCommissionCheckParameterSetService;
|
|
|
|
+import com.rongwei.bsentity.domain.ZhcxCommissionCheckDetailDo;
|
|
|
|
+import com.rongwei.bsentity.domain.ZhcxCommissionCheckDo;
|
|
|
|
+import com.rongwei.bscommon.sys.dao.ZhcxCommissionCheckDao;
|
|
|
|
+import com.rongwei.bscommon.sys.service.ZhcxCommissionCheckService;
|
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.rongwei.bsentity.domain.ZhcxCommissionCheckParameterSetDetalDo;
|
|
|
|
+import com.rongwei.bsentity.domain.ZhcxCommissionCheckParameterSetDo;
|
|
|
|
+import com.rongwei.bsentity.dto.CommissionCheckDTO;
|
|
|
|
+import com.rongwei.rwcommon.base.R;
|
|
|
|
+import com.rongwei.rwcommon.utils.SecurityUtil;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
+
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Objects;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * <p>
|
|
|
|
+ * 试车检查表 服务实现类
|
|
|
|
+ * </p>
|
|
|
|
+ *
|
|
|
|
+ * @author xuan
|
|
|
|
+ * @since 2024-09-24
|
|
|
|
+ */
|
|
|
|
+@Service
|
|
|
|
+public class ZhcxCommissionCheckServiceImpl extends ServiceImpl<ZhcxCommissionCheckDao, ZhcxCommissionCheckDo> implements ZhcxCommissionCheckService {
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ZhcxCommissionCheckParameterSetService checkParameterSetService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ZhcxCommissionCheckDetailService commissionCheckDetailService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private ZhcxCommissionCheckParameterSetDetalService commissionCheckParameterSetDetalService;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @Transactional(rollbackFor = {java. lang. Exception.class})
|
|
|
|
+ @Override
|
|
|
|
+ public R commissionCheckAdd(CommissionCheckDTO checkDTO) {
|
|
|
|
+ // 试车主表
|
|
|
|
+ ZhcxCommissionCheckDo check = checkDTO.getCheck();
|
|
|
|
+ List<ZhcxCommissionCheckParameterSetDetalDo> setDetails = checkDTO.getSetDetails();
|
|
|
|
+ if(Objects.isNull(check) || Objects.isNull(check.getProjectid()) || Objects.isNull(check.getProjectEname())){
|
|
|
|
+ return R.error("项目不能为空");
|
|
|
|
+ }
|
|
|
|
+ if(setDetails.isEmpty()){
|
|
|
|
+ return R.error("项目不能为空");
|
|
|
|
+ }
|
|
|
|
+ // 试车子表
|
|
|
|
+ List<ZhcxCommissionCheckDetailDo> checkDetails = checkDTO.getCheckDetails();
|
|
|
|
+ // 查询已保存过的子表数据(平台bug,已保存的数据只能去数据库中查)
|
|
|
|
+ List<ZhcxCommissionCheckDetailDo> savedcheckDetails = getSavedDataByPid(check.getId());
|
|
|
|
+ if(!savedcheckDetails.isEmpty()){
|
|
|
|
+ checkDetails.addAll(savedcheckDetails);
|
|
|
|
+ }
|
|
|
|
+ // 创建新增集合
|
|
|
|
+ // 试车主子表
|
|
|
|
+ List<ZhcxCommissionCheckDo> resultCheckDo = new ArrayList<>();
|
|
|
|
+ List<ZhcxCommissionCheckDetailDo> resultCheckDetailDo = new ArrayList<>();
|
|
|
|
+ // 试车参数设置子表
|
|
|
|
+ List<ZhcxCommissionCheckParameterSetDetalDo> resultCheckParameterSetDetail = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ // 试车参数主表
|
|
|
|
+ ZhcxCommissionCheckParameterSetDo parameterSetDo = checkParameterSetData(check);
|
|
|
|
+ // 正片开始
|
|
|
|
+ for (ZhcxCommissionCheckParameterSetDetalDo setDetail : setDetails) {
|
|
|
|
+ // 试车检查主表机号判断 如果该机已存在就返回
|
|
|
|
+ LambdaQueryWrapper<ZhcxCommissionCheckDo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.eq(ZhcxCommissionCheckDo::getDeleted,"0")
|
|
|
|
+ .eq(ZhcxCommissionCheckDo::getMachineid,setDetail.getMachineid());
|
|
|
|
+ List<ZhcxCommissionCheckDo> checkDos = this.list(queryWrapper);
|
|
|
|
+ if (!checkDos.isEmpty()){
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ // 防止机号重复
|
|
|
|
+ checkParameterSetDetalDo(setDetail.getMachineid());
|
|
|
|
+
|
|
|
|
+ ZhcxCommissionCheckDo zhcxCommissionCheckDo = new ZhcxCommissionCheckDo();
|
|
|
|
+ BeanUtil.copyProperties(check,zhcxCommissionCheckDo);
|
|
|
|
+ // 机号id
|
|
|
|
+ String machineid = setDetail.getMachineid();
|
|
|
|
+ // 机号
|
|
|
|
+ String machineno = setDetail.getMachineno();
|
|
|
|
+ // 新的试车检查主表id
|
|
|
|
+ String newCheckId = zhcxCommissionCheckDo.getId()+machineno.replace("#","");
|
|
|
|
+ // 构件试车主表
|
|
|
|
+ zhcxCommissionCheckDo.setId(newCheckId).setMachineid(machineid).setMachineno(machineno);
|
|
|
|
+ resultCheckDo.add(zhcxCommissionCheckDo);
|
|
|
|
+ // 试车子表
|
|
|
|
+ if(!checkDetails.isEmpty()){
|
|
|
|
+ for (ZhcxCommissionCheckDetailDo checkDetail : checkDetails) {
|
|
|
|
+ ZhcxCommissionCheckDetailDo detailDo = new ZhcxCommissionCheckDetailDo();
|
|
|
|
+ BeanUtil.copyProperties(checkDetail,detailDo);
|
|
|
|
+ detailDo.setId(SecurityUtil.getUUID());
|
|
|
|
+ detailDo.setPid(zhcxCommissionCheckDo.getId());
|
|
|
|
+ resultCheckDetailDo.add(detailDo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //试车参数子表
|
|
|
|
+ setDetail.setPid(parameterSetDo.getId());
|
|
|
|
+ setDetail.setCheckid(newCheckId);
|
|
|
|
+ setDetail.setProjectid(check.getProjectid());
|
|
|
|
+ resultCheckParameterSetDetail.add(setDetail);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 保存操作
|
|
|
|
+ if(!resultCheckDo.isEmpty()){
|
|
|
|
+ this.saveBatch(resultCheckDo);
|
|
|
|
+ }
|
|
|
|
+ if(!resultCheckDetailDo.isEmpty()){
|
|
|
|
+ commissionCheckDetailService.saveBatch(resultCheckDetailDo);
|
|
|
|
+ }
|
|
|
|
+ if(!resultCheckParameterSetDetail.isEmpty()){
|
|
|
|
+ commissionCheckParameterSetDetalService.saveBatch(resultCheckParameterSetDetail);
|
|
|
|
+ }
|
|
|
|
+ return R.ok("保存成功");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 构建/查找返回 试车参数主表
|
|
|
|
+ * @param check 伪试车主表
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private ZhcxCommissionCheckParameterSetDo checkParameterSetData(ZhcxCommissionCheckDo check){
|
|
|
|
+ LambdaQueryWrapper<ZhcxCommissionCheckParameterSetDo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.eq(ZhcxCommissionCheckParameterSetDo::getDeleted,"0")
|
|
|
|
+ .eq(ZhcxCommissionCheckParameterSetDo::getProjectid,check.getProjectid());
|
|
|
|
+ List<ZhcxCommissionCheckParameterSetDo> list = checkParameterSetService.list(queryWrapper);
|
|
|
|
+ if (list.isEmpty()){
|
|
|
|
+ ZhcxCommissionCheckParameterSetDo parameterSetDo = new ZhcxCommissionCheckParameterSetDo();
|
|
|
|
+ parameterSetDo.setId(SecurityUtil.getUUID());
|
|
|
|
+ parameterSetDo.setProjectid(check.getProjectid());
|
|
|
|
+ parameterSetDo.setProjectcode(check.getProjectcode());
|
|
|
|
+ parameterSetDo.setProjectname(check.getProjectname());
|
|
|
|
+ checkParameterSetService.save(parameterSetDo);
|
|
|
|
+ return parameterSetDo;
|
|
|
|
+ }else {
|
|
|
|
+ return list.get(0);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 平台bug之一 返回已保存在试车子表
|
|
|
|
+ * @param pid 伪主表id
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private List<ZhcxCommissionCheckDetailDo> getSavedDataByPid(String pid){
|
|
|
|
+ LambdaQueryWrapper<ZhcxCommissionCheckDetailDo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.eq(ZhcxCommissionCheckDetailDo::getDeleted,"0")
|
|
|
|
+ .eq(ZhcxCommissionCheckDetailDo::getPid,pid);
|
|
|
|
+ return commissionCheckDetailService.list(queryWrapper);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 参数数据子表伪删除
|
|
|
|
+ * @param machineid 机号id
|
|
|
|
+ */
|
|
|
|
+ private void checkParameterSetDetalDo(String machineid){
|
|
|
|
+ // 可能原因 没有把参数子表数据删了 重新建数据 id跟机号是相同的 可能导致机号数据doule
|
|
|
|
+ LambdaQueryWrapper<ZhcxCommissionCheckParameterSetDetalDo> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
|
+ queryWrapper.eq(ZhcxCommissionCheckParameterSetDetalDo::getDeleted,"0")
|
|
|
|
+ .eq(ZhcxCommissionCheckParameterSetDetalDo::getMachineid,machineid);
|
|
|
|
+ List<ZhcxCommissionCheckParameterSetDetalDo> list = commissionCheckParameterSetDetalService.list(queryWrapper);
|
|
|
|
+ if (!list.isEmpty()){
|
|
|
|
+ ZhcxCommissionCheckParameterSetDetalDo detalDo = list.get(0);
|
|
|
|
+ detalDo.setDeleted("1");
|
|
|
|
+ commissionCheckParameterSetDetalService.updateById(detalDo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|