Browse Source

更新项目日志新增修改时回写项目档案轮天

jihs 4 years ago
parent
commit
b8a1666882

+ 75 - 15
src/main/java/org/jeecg/modules/prowork/service/impl/ProWorkLogicServiceImpl.java

@@ -2,7 +2,7 @@ package org.jeecg.modules.prowork.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.google.common.collect.Lists;
-import io.swagger.annotations.ApiModel;
+import org.apache.commons.lang3.StringUtils;
 import org.jeecg.common.dto.prowork.ProWorkLogicAddReqDTO;
 import org.jeecg.common.dto.prowork.ProWorkLogicContentAddReqDTO;
 import org.jeecg.common.dto.prowork.ProWorkLogicContentListRespDTO;
@@ -21,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.util.CollectionUtils;
-
 import java.util.List;
 
 /**
@@ -44,28 +43,41 @@ public class ProWorkLogicServiceImpl extends ServiceImpl<ProWorkLogicMapper, Pro
      */
     @Override
     public void add(ProWorkLogicAddReqDTO reqDTO) throws Exception {
-        if(CollectionUtils.isEmpty(reqDTO.getDetailList())){
+        if(CollectionUtils.isEmpty(reqDTO.getDetailList())) {
             throw new JeecgBootException("子表不能为空");
         }
         ProWorkLogic proWorkLogic = new ProWorkLogic(reqDTO);
         // 设置编码
         CallResult<String> nextSerial = sysSerialPatternService.getNextSerial(proWorkLogic, "pro_work_logic", "billcode", true);
-        if(!nextSerial.isSucceed()){
+        if(!nextSerial.isSucceed()) {
             throw new RuntimeException("获取编号失败");
         }
         proWorkLogic.setBillcode(nextSerial.getContent());
         save(proWorkLogic);
         //添加子表
         int sort = 1;
-        for(ProWorkLogicContentAddReqDTO detail : reqDTO.getDetailList()){
+        for(ProWorkLogicContentAddReqDTO detail : reqDTO.getDetailList()) {
             detail.setLogicId(proWorkLogic.getId());
-            ProWorkLogicContent proWorkLogicContent =  new ProWorkLogicContent(detail);
+            ProWorkLogicContent proWorkLogicContent = new ProWorkLogicContent(detail);
             proWorkLogicContent.setSort(sort++);
             proWorkLogicContentService.save(proWorkLogicContent);
 
             //回写项目档案计划列表的实际人天
-            projectManageBusinessOtherService.updateById(new ProjectManageBusinessOther(proWorkLogicContent.getProPlanId(),
-            proWorkLogicContent.getId(), proWorkLogicContent.getDuration().toString()));
+            QueryWrapper<ProjectManageBusinessOther> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("del_flag", "0");
+            queryWrapper.eq("id", proWorkLogicContent.getProPlanId());
+            ProjectManageBusinessOther other = projectManageBusinessOtherService.getById(proWorkLogicContent.getProPlanId());
+            if(other != null) {
+                String otherRealTime = other.getRealTime();
+                double orgRealTime = 0;   //初始值
+                if(StringUtils.isNotBlank(otherRealTime)) {
+                    orgRealTime = Double.parseDouble(otherRealTime);
+                }
+                //计算后的轮天
+                Double realTime = proWorkLogicContent.getDuration() / 8 + orgRealTime;
+                projectManageBusinessOtherService.updateById(new ProjectManageBusinessOther(proWorkLogicContent.getProPlanId(),
+                        proWorkLogicContent.getId(), realTime.toString()));
+            }
 
         }
     }
@@ -77,18 +89,35 @@ public class ProWorkLogicServiceImpl extends ServiceImpl<ProWorkLogicMapper, Pro
     public boolean edit(ProWorkLogicAddReqDTO reqDTO) {
         ProWorkLogic proWorkLogic = new ProWorkLogic(reqDTO);
         updateById(proWorkLogic);
+        //回写轮天之前,先前去新增时添加的轮天
+        dropOrgRealTime(reqDTO.getId());
+
         //删除子表
         deletChildren(reqDTO.getId());
         //添加子表
         int sort = 1;
-        for(ProWorkLogicContentAddReqDTO detail : reqDTO.getDetailList()){
+        for(ProWorkLogicContentAddReqDTO detail : reqDTO.getDetailList()) {
             detail.setLogicId(proWorkLogic.getId());
-            ProWorkLogicContent proWorkLogicContent =  new ProWorkLogicContent(detail);
+            ProWorkLogicContent proWorkLogicContent = new ProWorkLogicContent(detail);
             proWorkLogicContent.setSort(sort++);
             proWorkLogicContentService.save(proWorkLogicContent);
             //回写项目档案计划列表的实际人天
-            projectManageBusinessOtherService.updateById(new ProjectManageBusinessOther(proWorkLogicContent.getProPlanId(),
-                    proWorkLogicContent.getId(), proWorkLogicContent.getDuration().toString()));
+            QueryWrapper<ProjectManageBusinessOther> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("del_flag", "0");
+            queryWrapper.eq("id", proWorkLogicContent.getProPlanId());
+            ProjectManageBusinessOther other = projectManageBusinessOtherService.getById(proWorkLogicContent.getProPlanId());
+            if(other != null) {
+                String otherRealTime = other.getRealTime();
+                double orgRealTime = 0;   //初始值
+                if(StringUtils.isNotBlank(otherRealTime)) {
+                    orgRealTime = Double.parseDouble(otherRealTime);
+                }
+                //计算后的轮天
+                Double realTime = proWorkLogicContent.getDuration() / 8 + orgRealTime;
+                projectManageBusinessOtherService.updateById(new ProjectManageBusinessOther(proWorkLogicContent.getProPlanId(),
+                        proWorkLogicContent.getId(), realTime.toString()));
+            }
+
         }
         return true;
     }
@@ -100,6 +129,9 @@ public class ProWorkLogicServiceImpl extends ServiceImpl<ProWorkLogicMapper, Pro
     public boolean dropById(ProWorkLogic proWorkLogic) {
         proWorkLogic.setDelFlag("1");
         updateById(proWorkLogic);
+        //减去批次档案里的轮天
+        //回写轮天之前,先前去新增时添加的轮天
+        dropOrgRealTime(proWorkLogic.getId());
         //删除子表
         deletChildren(proWorkLogic.getId());
         return true;
@@ -119,15 +151,13 @@ public class ProWorkLogicServiceImpl extends ServiceImpl<ProWorkLogicMapper, Pro
         queryWrapper.orderByAsc("sort");
         List<ProWorkLogicContent> list = proWorkLogicContentService.list(queryWrapper);
         List<ProWorkLogicContentListRespDTO> contentListRespDTOS = Lists.newArrayList();
-        for(ProWorkLogicContent proWorkLogicContent : list){
+        for(ProWorkLogicContent proWorkLogicContent : list) {
             contentListRespDTOS.add(new ProWorkLogicContentListRespDTO(proWorkLogicContent));
         }
         respDTO.setDetailList(contentListRespDTOS);
         return respDTO;
     }
 
-
-
     /**
      * @desc 删除子表
      */
@@ -137,4 +167,34 @@ public class ProWorkLogicServiceImpl extends ServiceImpl<ProWorkLogicMapper, Pro
         queryWrapper.eq("logic_id", id);
         proWorkLogicContentService.update(new ProWorkLogicContent("1"), queryWrapper);
     }
+
+    /**
+     * @desc 回写轮天之前,先前减去新增时添加的轮天
+     */
+    private void dropOrgRealTime(String id) {
+        QueryWrapper<ProWorkLogicContent> contentQueryWrapper = new QueryWrapper<>();
+        contentQueryWrapper.eq("del_flag", "0");
+        contentQueryWrapper.eq("logic_id", id);
+        List<ProWorkLogicContent> contents = proWorkLogicContentService.list(contentQueryWrapper);
+
+        for(ProWorkLogicContent proWorkLogicContent : contents) {
+            QueryWrapper<ProjectManageBusinessOther> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("del_flag", "0");
+            queryWrapper.eq("id", proWorkLogicContent.getProPlanId());
+            ProjectManageBusinessOther other = projectManageBusinessOtherService.getById(proWorkLogicContent.getProPlanId());
+            if(other != null) {
+                String otherRealTime = other.getRealTime();
+                double orgRealTime = 0;   //初始值
+                if(StringUtils.isNotBlank(otherRealTime)) {
+                    orgRealTime = Double.parseDouble(otherRealTime);
+                }
+
+                //计算后的轮天
+                Double realTime = orgRealTime - (proWorkLogicContent.getDuration() / 8);
+                projectManageBusinessOtherService.updateById(new ProjectManageBusinessOther(proWorkLogicContent.getProPlanId(),
+                        proWorkLogicContent.getId(), realTime.toString()));
+            }
+
+        }
+    }
 }

+ 1 - 1
src/main/java/org/jeecg/modules/system/controller/CdPrintTemplateController.java

@@ -122,7 +122,7 @@ public class CdPrintTemplateController {
 		return result;
 	}
 
-	@ApiOperation(value = "新增和编辑", notes = "新增打印模板和修改打印模板")
+	@ApiOperation(value = "根据id查询", notes = "根据id查询")
 	@ApiImplicitParams({
 			@ApiImplicitParam(name="id", value="id",required=true, dataType="String"),
 	})