zhanghl
2025-05-09 35df7283579ab155e32ecf3299c52fc9b7e5bdef
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
package com.aps.core.service.impl;
 
import cn.hutool.core.util.IdUtil;
import com.aps.common.core.utils.DateUtils;
import com.aps.common.core.utils.uuid.IdUtils;
import com.aps.common.security.utils.DictUtils;
import com.aps.core.domain.ApsPlatePlan;
import com.aps.core.domain.ApsPlatePlanTemp;
import com.aps.core.mapper.ApsPartPlanTempMapper;
import com.aps.core.mapper.ApsPlatePlanMapper;
import com.aps.core.mapper.ApsPlatePlanTempMapper;
import com.aps.core.service.IApsPlatePlanService;
import com.aps.system.api.domain.SysDictData;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.List;
import java.util.Optional;
 
/**
 * 钣金计划管理Service业务层处理
 *
 * @author ruoyi
 * @date 2025-04-08
 */
@Service
public class ApsPlatePlanServiceImpl implements IApsPlatePlanService
{
    @Autowired
    private ApsPlatePlanMapper apsPlatePlanMapper;
 
    @Autowired
    private ApsPartPlanTempMapper apsPartPlanTempMapper;
    @Autowired
    private ApsPlatePlanTempMapper apsPlatePlanTempMapper;
 
    /**
     * 查询钣金计划管理
     *
     * @param id 钣金计划管理主键
     * @return 钣金计划管理
     */
    @Override
    public ApsPlatePlan selectApsPlatePlanById(String id)
    {
        return apsPlatePlanMapper.selectApsPlatePlanById(id);
    }
 
    /**
     * 查询钣金计划管理列表
     *
     * @param apsPlatePlan 钣金计划管理
     * @return 钣金计划管理
     */
    @Override
    public List<ApsPlatePlan> selectApsPlatePlanList(ApsPlatePlan apsPlatePlan)
    {
        return apsPlatePlanMapper.selectApsPlatePlanList(apsPlatePlan);
    }
 
    /**
     * 新增钣金计划管理
     *
     * @param apsPlatePlan 钣金计划管理
     * @return 结果
     */
    @Override
    public int insertApsPlatePlan(ApsPlatePlan apsPlatePlan)
    {
        apsPlatePlan.setId(IdUtil.getSnowflakeNextId());
        apsPlatePlan.setCreateTime(DateUtils.getNowDate());
        return apsPlatePlanMapper.insertApsPlatePlan(apsPlatePlan);
    }
 
    /**
     * 修改钣金计划管理
     *
     * @param apsPlatePlan 钣金计划管理
     * @return 结果
     */
    @Override
    public int updateApsPlatePlan(ApsPlatePlan apsPlatePlan)
    {
        return apsPlatePlanMapper.updateApsPlatePlan(apsPlatePlan);
    }
 
    /**
     * 批量删除钣金计划管理
     *
     * @param ids 需要删除的钣金计划管理主键
     * @return 结果
     */
    @Override
    public int deleteApsPlatePlanByIds(String[] ids)
    {
        return apsPlatePlanMapper.deleteApsPlatePlanByIds(ids);
    }
 
    /**
     * 删除钣金计划管理信息
     *
     * @param id 钣金计划管理主键
     * @return 结果
     */
    @Override
    public int deleteApsPlatePlanById(String id)
    {
        return apsPlatePlanMapper.deleteApsPlatePlanById(id);
    }
 
    @Override
    public int confirmPlan(ApsPlatePlanTemp tempPlan) {
        //先删除所有
        apsPlatePlanMapper.removeAllPlatePlans();
        //查询临时表数据
        List<ApsPlatePlanTemp> apsPartPlanTemps=apsPlatePlanTempMapper.selectApsPlatePlanTempList(tempPlan);
        int count=0;
        String[] ids=new String[apsPartPlanTemps.size()];
        for (int i = 0; i <apsPartPlanTemps.size() ; i++) {
            //记录临时表id
            ids[i]=apsPartPlanTemps.get(i).getId();
            ApsPlatePlan platePlan=new ApsPlatePlan();
            BeanUtils.copyProperties(apsPartPlanTemps.get(i), platePlan);
            platePlan.setId(IdUtil.getSnowflakeNextId());
            platePlan.setCreateTime(DateUtils.getNowDate());
            //插入正式表,并记录
            apsPlatePlanMapper.insertApsPlatePlan(platePlan);
            count++;
        }
        //插入数量与临时表查询一直则删除临时表数据
        if (count==apsPartPlanTemps.size()) {
            apsPlatePlanTempMapper.deleteApsPlatePlanTempByIds(ids);
        }
        return 1;
    }
   @Override
   public String importData(List<ApsPlatePlanTemp> tempList) throws Exception {
 
        String batchNum= IdUtils.fastUUID();
        //判断导入数据是否为空
        if (tempList.size() > 0) {
            /*
            * aps_business_type aps_document_status aps_is_suspended aps_account
            * */
 
            List<SysDictData> suspendedDic = DictUtils.getDictCache("aps_is_suspended");
            List<SysDictData> businessTypeDic = DictUtils.getDictCache("aps_business_type");
            List<SysDictData> documentStatusDic = DictUtils.getDictCache("aps_document_status");
            List<SysDictData> accountDic = DictUtils.getDictCache("aps_account");
            for (int i = 0; i < tempList.size(); i++) {
 
                ApsPlatePlanTemp planTemp = tempList.get(i);
 
                String isSuspendedTxt = planTemp.getIsSuspended().trim();
                String businessType = planTemp.getBusinessType().trim();
                String documentStatusText = planTemp.getDocumentStatus().trim();
                String account = planTemp.getAccount().trim();
 
                Optional<SysDictData> documentStatusFirst = documentStatusDic.stream().filter(x -> x.getDictLabel().equals(documentStatusText)).findFirst();
                documentStatusFirst.ifPresent(sysDictData -> planTemp.setDocumentStatus(sysDictData.getDictValue()));
 
                Optional<SysDictData> accountFirst = accountDic.stream().filter(x -> x.getDictLabel().equals(account)).findFirst();
                accountFirst.ifPresent(sysDictData -> planTemp.setAccount(sysDictData.getDictValue()));
 
                Optional<SysDictData> businessTypeFirst = businessTypeDic.stream().filter(x -> x.getDictLabel().equals(businessType)).findFirst();
                businessTypeFirst.ifPresent(sysDictData -> planTemp.setBusinessType(sysDictData.getDictValue()));
 
 
                Optional<SysDictData> isSuspendedFirst = suspendedDic.stream().filter(x -> x.getDictLabel().equals(isSuspendedTxt)).findFirst();
                isSuspendedFirst.ifPresent(sysDictData -> planTemp.setIsSuspended(sysDictData.getDictValue()));
 
                planTemp.setId(IdUtils.fastUUID());
                //插入版本号
                planTemp.setBatchNumber(batchNum);
                //插入临时表
                apsPlatePlanTempMapper.insertApsPlatePlanTemp(planTemp);
            }
           return batchNum ;
        } else {
           return Strings.EMPTY;
        }
    }
 
    /**
     * 钣金冗余工单报表
     * @param apsPlatePlan
     * @return
     */
    @Override
    public List<ApsPlatePlan> selectPlateRedundantOrderList(ApsPlatePlan apsPlatePlan) {
        return apsPlatePlanMapper.selectPlateRedundantOrderList(apsPlatePlan);
    }
}