李旭东
2023-11-03 a07b4b6ff1c98dcf81338bb45d59308db7c058a9
hd/pipe/materialsManage/src/main/java/com/thhy/materials/modules/biz/pipeoutplan/service/impl/PipeOutPlanServiceImpl.java
对比新文件
@@ -0,0 +1,112 @@
package com.thhy.materials.modules.biz.pipeoutplan.service.impl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.thhy.general.common.BasicResult;
import com.thhy.general.config.SysUserInfo;
import com.thhy.general.utils.UUIDUtils;
import com.thhy.general.utils.UserInfoUtils;
import com.thhy.materials.modules.biz.pipeoutplan.entity.PipeOutPlanEntity;
import com.thhy.materials.modules.biz.pipeoutplan.entity.PipeOutPlanMothEntity;
import com.thhy.materials.modules.biz.pipeoutplan.mapper.PipeOutPlanMapper;
import com.thhy.materials.modules.biz.pipeoutplan.service.PipeOutPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
/**
 * @Author QiuYuHao
 * @CreateDate 2023-11-03 9:42:41
 * 发运管理逻辑实现层
 */
@Service
public class PipeOutPlanServiceImpl implements PipeOutPlanService {
   @Autowired
   private PipeOutPlanMapper pipeOutPlanMapper;
   @Override
   @Transactional(rollbackFor = Exception.class)
   public BasicResult insert(PipeOutPlanEntity pipeOutPlanEntity) {
      PipeOutPlanEntity isExit = pipeOutPlanMapper.selectInfoByProIdAndYear(pipeOutPlanEntity.getProId(), pipeOutPlanEntity.getPlanYear());
      if (isExit != null){
         return BasicResult.faild("500","同一项目、年份有且只有一个计划",null);
      }
      String planOutId = UUIDUtils.create();
      pipeOutPlanEntity.setPlanOutId(planOutId);
      pipeOutPlanMapper.insert(pipeOutPlanEntity);
      List<PipeOutPlanMothEntity> monthList = pipeOutPlanEntity.getMonthList();
      for (PipeOutPlanMothEntity vo : monthList) {
         vo.setPipeOutPlanId(planOutId);
         vo.setId(UUIDUtils.create());
         pipeOutPlanMapper.insertMoth(vo);
      }
      return BasicResult.success();
   }
   @Override
   @Transactional(rollbackFor = Exception.class)
   public BasicResult delete(String pipeNeedId) {
      pipeOutPlanMapper.delete(pipeNeedId);
      pipeOutPlanMapper.deleteMoth(pipeNeedId);
      return BasicResult.success();
   }
   @Override
   @Transactional(rollbackFor = Exception.class)
   public BasicResult update(PipeOutPlanEntity pipeOutPlanEntity) {
      PipeOutPlanEntity isExit = pipeOutPlanMapper.selectInfoByProIdAndYear(pipeOutPlanEntity.getProId(), pipeOutPlanEntity.getPlanYear());
      if (!pipeOutPlanEntity.getPlanOutId().equals(isExit.getPlanOutId()) && isExit != null){
         return BasicResult.faild("500","同一项目、年份有且只有一个计划",null);
      }
      pipeOutPlanMapper.update(pipeOutPlanEntity);
      String planOutId = pipeOutPlanEntity.getPlanOutId();
      pipeOutPlanMapper.deleteMoth(planOutId);
      List<PipeOutPlanMothEntity> monthList = pipeOutPlanEntity.getMonthList();
      for (PipeOutPlanMothEntity vo : monthList) {
         vo.setPipeOutPlanId(planOutId);
         vo.setId(UUIDUtils.create());
         pipeOutPlanMapper.insertMoth(vo);
      }
      return BasicResult.success();
   }
   @Override
   public BasicResult selectInfo(String pipeNeedId) {
      PipeOutPlanEntity pipeOutPlanEntity = pipeOutPlanMapper.selectInfo(pipeNeedId);
      List<PipeOutPlanMothEntity> mothList = pipeOutPlanMapper.findMothList(pipeNeedId);
      pipeOutPlanEntity.setMonthList(mothList);
      return BasicResult.success(pipeOutPlanEntity);
   }
   @Override
   public BasicResult findAll(Map<String, Object> map) {
      Integer pageNum = (Integer) map.get("pageNum");
      Integer pageSize = (Integer) map.get("pageSize");
      PageHelper.startPage(pageNum,pageSize);
      SysUserInfo userInfo = UserInfoUtils.getInstance().getUserInfo();
      map.put("companyId",userInfo.getCompanyId());
      List<PipeOutPlanEntity> all = pipeOutPlanMapper.findAll(map);
      all.forEach(obj->{
         String proId = obj.getProId();
         Integer planYear = obj.getPlanYear();
         String planOutId = obj.getPlanOutId();
         List<PipeOutPlanMothEntity> mothListByProIdAndYear = pipeOutPlanMapper.findMothListByProIdAndYear(proId, planYear.toString(), planOutId);
         Integer completePlanProductNum = 0;
         for (PipeOutPlanMothEntity pipeOutPlanMothEntity : mothListByProIdAndYear) {
            Integer completePlanProduct = pipeOutPlanMothEntity.getCompletePlanProduct();
            completePlanProductNum+=completePlanProduct;
         }
         obj.setMonthList(mothListByProIdAndYear);
         obj.setCompletePipeNum(completePlanProductNum);
      });
      return BasicResult.success(new PageInfo<>(all));
   }
}