张晓波
2023-09-19 164694c47c35d6654df69b533e8dbf8b5423efc5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
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);
    }
}