package com.thhy.materials.modules.biz.pipeplan.service.impl;
|
|
import com.thhy.general.common.BasicStatus;
|
import com.thhy.general.config.SysUserInfo;
|
import com.thhy.general.exception.BasicException;
|
import com.thhy.general.utils.DeepCopyUtils;
|
import com.thhy.general.utils.UserInfoUtils;
|
import com.thhy.materials.modules.biz.pipeplan.entity.PipePlan;
|
import com.thhy.materials.modules.biz.pipeplan.entity.PipePlanDto;
|
import com.thhy.materials.modules.biz.pipeplan.entity.PipePlanListVo;
|
import com.thhy.materials.modules.biz.pipeplan.entity.PlanMonthCal;
|
import com.thhy.materials.modules.biz.pipeplan.mapper.PipePlanMapper;
|
import com.thhy.materials.modules.biz.pipeplan.service.PipePlanService;
|
import com.thhy.materials.modules.biz.pipeplanmonth.entity.PipePlanMonth;
|
import com.thhy.materials.modules.biz.pipeplanmonth.mapper.PipePlanMonthMapper;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.io.Serializable;
|
import java.util.Date;
|
import java.util.List;
|
|
/**
|
* 服务实现类
|
* @author zhang_xiao_bo
|
* @since 2023-04-18 09:08:51
|
*/
|
@Service
|
public class PipePlanServiceImpl implements PipePlanService {
|
|
|
|
@Autowired
|
private PipePlanMapper pipePlanMapper;
|
|
@Autowired
|
private PipePlanMonthMapper monthMapper;
|
|
public PipePlan get(Serializable id){
|
return pipePlanMapper.queryById(id);
|
}
|
|
public List<PipePlanListVo> findList(PipePlan pipePlan){
|
SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
|
List<PipePlanListVo> pipePlanListVos = pipePlanMapper.findList(pipePlan.setCompanyId(sysUserInfo.getCompanyId()));
|
for(PipePlanListVo planListVo : pipePlanListVos){
|
PlanMonthCal planp = pipePlanMapper.queryPlanProductByPlan(planListVo.getPlanId());
|
PlanMonthCal producted = pipePlanMapper.queryProductedByPlan(planListVo);
|
planListVo.setPlan(planp);
|
producted.setResultStr(producted.getResultStr()+",0");
|
planListVo.setProducted(producted);
|
}
|
return pipePlanListVos;
|
}
|
|
/**
|
* 增加和修改
|
* @param pipePlanDto
|
*/
|
@Transactional
|
public void addPipePlan(PipePlanDto pipePlanDto){
|
SysUserInfo sysUserInfo = UserInfoUtils.getInstance().getUserInfo();
|
List<String> planIds = pipePlanMapper.queryByPYS(pipePlanDto);
|
if(planIds.size()>1){
|
throw new BasicException(BasicStatus.UNQUE_IS_ERROR);
|
}
|
List<PipePlanMonth> pipePlanMonths = pipePlanDto.getMonthList();
|
PipePlan pipePlan = new PipePlan();
|
DeepCopyUtils.copy(pipePlanDto,pipePlan);
|
if(pipePlan.getPlanId() == null){
|
if(planIds.size()>0){
|
throw new BasicException(BasicStatus.PIPE_PLAN_PRO_SIZE_YEAR);
|
}
|
//增加操作
|
pipePlan.setCreateUser(sysUserInfo.getUserId());
|
pipePlan.setCreateTime(new Date());
|
pipePlanMapper.insert(pipePlan);
|
}else{
|
//修改操作
|
if (planIds.size()>0) {
|
if(!pipePlan.getPlanId().equals(planIds.get(0))){
|
throw new BasicException(BasicStatus.PIPE_PLAN_PRO_SIZE_YEAR);
|
}
|
}
|
pipePlan.setUpdateUser(sysUserInfo.getUserId());
|
pipePlan.setUpdateTime(new Date());
|
pipePlanMapper.update(pipePlan);
|
monthMapper.deleteByPlan(pipePlanDto.getPlanId());
|
}
|
|
for(PipePlanMonth month : pipePlanMonths){
|
month.setPipePlanId(pipePlan.getPlanId());
|
monthMapper.insert(month);
|
}
|
|
}
|
|
/**
|
* 修改
|
* @param pipePlan
|
*/
|
public void update(PipePlan pipePlan){
|
pipePlanMapper.update(pipePlan);
|
}
|
|
/**
|
* 删除
|
* @param planId
|
*/
|
public void delete(Serializable planId){
|
pipePlanMapper.deletelogic(planId);
|
}
|
|
@Override
|
public List<PipePlanMonth> queryMonthList(String pipePlanId) {
|
return pipePlanMapper.queryMonthList(pipePlanId);
|
}
|
|
@Override
|
public double sumProduct(String pipePlanId) {
|
return pipePlanMapper.sumProduct(pipePlanId);
|
}
|
}
|