jinlin
2023-12-08 7cfb3068b1d2ff6ac549bb6775ce2be0e0d6ec49
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
package com.zt.life.modules.configItemChange.service;
 
import com.zt.common.db.query.QueryFilter;
import com.zt.common.service.BaseService;
import com.zt.life.modules.configItemChange.dao.ConfigItemChangeDao;
import com.zt.life.modules.configItemChange.dto.ConfigItemChangeDto;
import com.zt.life.modules.configItemChange.model.ConfigItemChange;
import com.zt.life.modules.configItemWarehouse.model.WarehouseCmAudit;
import com.zt.life.modules.configItemWarehouse.model.WarehouseConfigItem;
import com.zt.life.modules.configItemWarehouse.model.WarehouseQaAudit;
import com.zt.life.modules.configItemWarehouse.service.WarehouseCmAuditService;
import com.zt.life.modules.configItemWarehouse.service.WarehouseConfigItemService;
import com.zt.life.modules.configItemWarehouse.service.WarehouseQaAuditService;
import com.zt.life.modules.project.service.ProjectService;
import com.zt.life.modules.testCheckOrder.model.TestCheckOrder;
import com.zt.life.modules.testCheckOrder.service.TestCheckOrderService;
import com.zt.life.sys.service.SysOssConfigService;
import com.zt.modules.coderule.service.SysCodeRuleService;
import com.zt.modules.oss.service.SysOssService;
import com.zt.modules.workflow.dto.FlowInfoDto;
import com.zt.modules.workflow.service.WorkflowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
 
/**
 * config_item_warehouse
 *
 * @author zt generator
 * @since 1.0.0 2023-11-27
 */
@Service
public class ConfigItemChangeService extends BaseService<ConfigItemChangeDao, ConfigItemChange> {
    @Autowired
    private SysOssConfigService sysOssConfigService;
 
    @Autowired
    private SysOssService sysOssService;
 
    @Autowired
    private WorkflowService workflowService;
 
    @Autowired
    private SysCodeRuleService sysCodeRuleService;
 
    @Autowired
    private ProjectService projectService;
 
    @Autowired
    private WarehouseCmAuditService cmAuditService;
 
    @Autowired
    private WarehouseQaAuditService qaAuditService;
 
    @Autowired
    private WarehouseConfigItemService configItemService;
 
    @Autowired
    private TestCheckOrderService testCheckOrderService;
 
    /**
     * 分页查询
     *
     * @param queryFilter
     * @return
     */
    public List<ConfigItemChange> page(QueryFilter queryFilter) {
        return baseDao.getList(queryFilter.getQueryParams());
    }
 
    /**
     * 删除
     *
     * @param ids
     */
    public void delete(Long[] ids) {
        super.deleteLogic(ids);
    }
 
    public Boolean save(ConfigItemChangeDto configItemDto) {
        Long changeId = configItemDto.getConfigItemChange().getId();
        if (changeId != null)
            baseDao.updateById(configItemDto.getConfigItemChange());
        else {
            Map<String, String> map = new HashMap<>();
            map.put("funCode", "config_item_change");
            map.put("projectId", configItemDto.getProjectId().toString());
            configItemDto.getConfigItemChange().setProjectId(configItemDto.getProjectId());
            configItemDto.getConfigItemChange().setCode(sysCodeRuleService.getNewCode(map));
            baseDao.insert(configItemDto.getConfigItemChange());
            changeId = configItemDto.getConfigItemChange().getId();
        }
 
        for (WarehouseConfigItem configItem : configItemDto.getConfigChangeList()) {
            configItem.setWarehouseId(changeId);
            if (configItem.getId() != null) {
                configItemService.update(configItem);
            } else {
                configItem.setWarehouseId(changeId);
                configItem.setProjectId(configItemDto.getConfigItemChange().getProjectId());
                configItemService.insert(configItem);
            }
            Long checkId = configItem.getCheckId();
            if (checkId != null) {
                TestCheckOrder testCheckOrder = testCheckOrderService.get(checkId);
                if (testCheckOrder.getConfigItemId() == null) {
                    Long configItemId = configItem.getId();
                    testCheckOrder.setConfigItemId(configItemId);
                    testCheckOrderService.update(testCheckOrder);
                }
            }
            sysOssConfigService.updateOss(configItem.getId(), configItem.getFiles());// 保存附件
        }
 
        for (WarehouseCmAudit cmAudit : configItemDto.getCmAuditList()) {
            cmAudit.setWarehouseId(changeId);
            if (cmAudit.getId() != null) {
                cmAuditService.update(cmAudit);
            } else {
                cmAudit.setWarehouseId(changeId);
                cmAuditService.insert(cmAudit);
            }
        }
 
        for (WarehouseQaAudit qaAudit : configItemDto.getQaAuditList()) {
            qaAudit.setWarehouseId(changeId);
            if (qaAudit.getId() != null) {
                qaAuditService.update(qaAudit);
            } else {
                qaAudit.setWarehouseId(changeId);
                qaAuditService.insert(qaAudit);
            }
        }
 
        Long bizId = configItemDto.getConfigItemChange().getId();
        FlowInfoDto flowInfoDto = configItemDto.getFlowInfoDto();
 
        if (flowInfoDto != null && flowInfoDto.getSubmitType() != null && "tj,bl".contains(flowInfoDto.getSubmitType())) {
            if ("tj".equals(flowInfoDto.getSubmitType())) {
                workflowService.startFlow(flowInfoDto.getFlowCode(), bizId);
            }
            workflowService.approvePass(flowInfoDto.getFlowCode(), bizId, flowInfoDto.getStepIdMark());
        }
        return true;
    }
 
    public ConfigItemChangeDto getDto(Long projectId, Long changeId) {
        ConfigItemChangeDto data = new ConfigItemChangeDto();
        if (changeId != null) {
            data.setId(changeId);
            ConfigItemChange configItemChange = this.get(changeId);
            data.setConfigItemChange(configItemChange);
 
            if (projectId == null) {
                projectId = configItemChange.getProjectId();
            }
            List<WarehouseCmAudit> CmAuditList = cmAuditService.getList(changeId);
            data.setCmAuditList(CmAuditList);
            List<WarehouseQaAudit> QaAuditList = qaAuditService.getList(changeId);
            data.setQaAuditList(QaAuditList);
            List<WarehouseConfigItem> configChangeList = configItemService.getList(changeId);
            data.setConfigChangeList(configChangeList);
 
        } else {
            ConfigItemChange configItemChange = new ConfigItemChange();
            data.setConfigItemChange(configItemChange);
            List<?> cmList = baseDao.itemList("change_cm_audit");
            List<?> CmAuditList = cmList;
            data.setCmAuditList((List<WarehouseCmAudit>) CmAuditList);
            List<?> qaList = baseDao.itemList("change_qa_audit");
            List<?> QaAuditList = qaList;
            data.setQaAuditList((List<WarehouseQaAudit>) QaAuditList);
        }
 
        if (projectId != null) {
            data.setProjectId(projectId);
            data.setProject(projectService.get(projectId));
        }
 
        return data;
    }
 
}