6
jinlin
2023-12-05 dc352ea3b9ec925320784592f29ca640b3a7b2ea
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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
package com.zt.life.modules.itemCirculatOrder.service;
 
import cn.hutool.core.convert.Convert;
import com.zt.common.service.BaseService;
import com.zt.life.export.dto.WordFile;
import com.zt.life.export.service.WordFileService;
import com.zt.life.modules.itemCirculatOrder.dao.ItemCirculatOrderDao;
import com.zt.life.modules.itemCirculatOrder.dto.ItemCirculatOrderDto;
import com.zt.life.modules.itemCirculatOrder.model.ItemCirculatOrder;
import com.zt.life.modules.itemCirculatOrder.model.ItemCirculatOrderTechnical;
import com.zt.life.modules.mainPart.utils.GetShowDictList;
import com.zt.life.modules.mainPart.utils.GetFilesPath;
import com.zt.life.modules.project.model.*;
import com.zt.life.modules.project.service.ProjectService;
import com.zt.life.modules.sysBaseInfo.service.TestAgencyInfoService;
import com.zt.life.sys.dto.OssDto;
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 com.zt.common.db.query.QueryFilter;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
 
/**
 * item_circulat_order
 *
 * @author zt generator
 * @since 1.0.0 2023-11-22
 */
@Service
public class ItemCirculatOrderService extends BaseService<ItemCirculatOrderDao, ItemCirculatOrder> {
    @Autowired
    private SysOssConfigService sysOssConfigService;
 
    @Autowired
    private SysOssService sysOssService;
 
    @Autowired
    private TestAgencyInfoService testAgencyInfoService;
 
    @Autowired
    private SysCodeRuleService sysCodeRuleService;
 
    @Autowired
    private ProjectService projectService;
 
    @Autowired
    private ItemCirculatOrderTechnicalService technicalService;
 
    @Autowired
    private WorkflowService workflowService;
 
    @Autowired
    private GetShowDictList getShowDictList;
 
    @Autowired
    private WordFileService wordFileService;
 
    @Autowired
    private GetFilesPath getFilesPath;
 
 
    /**
     * 分页查询
     *
     * @param queryFilter
     * @return
     */
    public List<ItemCirculatOrder> page(QueryFilter queryFilter) {
        return baseDao.getList(queryFilter.getQueryParams());
    }
 
    /**
     * 删除
     *
     * @param ids
     */
    public void delete(Long[] ids) {
        super.deleteLogic(ids);
    }
 
    public Boolean save(ItemCirculatOrderDto itemCirculatOrderDto) {
        Long circulatOrderid = itemCirculatOrderDto.getCirculatOrder().getId();
        if (circulatOrderid != null)
            baseDao.updateById(itemCirculatOrderDto.getCirculatOrder());
        else {
            Map<String, String> map = new HashMap<>();
            map.put("funCode", "item_circulat_order");
            map.put("projectId", itemCirculatOrderDto.getProjectId().toString());
            itemCirculatOrderDto.getCirculatOrder().setProjectId(itemCirculatOrderDto.getProjectId());
            itemCirculatOrderDto.getCirculatOrder().setCode(sysCodeRuleService.getNewCode(map));
            baseDao.insert(itemCirculatOrderDto.getCirculatOrder());
            circulatOrderid = itemCirculatOrderDto.getCirculatOrder().getId();
        }
 
        for (ItemCirculatOrderTechnical circulatOrderTechnical : itemCirculatOrderDto.getTechnicalList()) {
            circulatOrderTechnical.setCirculatOrderId(circulatOrderid);
            if (circulatOrderTechnical.getId() != null) {
                technicalService.update(circulatOrderTechnical);
            } else {
                circulatOrderTechnical.setCirculatOrderId(circulatOrderid);
                technicalService.insert(circulatOrderTechnical);
            }
            sysOssConfigService.updateOss(circulatOrderTechnical.getId(), circulatOrderTechnical.getFiles());// 保存附件
        }
 
        if (itemCirculatOrderDto.getTestAgencyInfo().getId() == 10000) {
            itemCirculatOrderDto.getTestAgencyInfo().setId(circulatOrderid);
            testAgencyInfoService.insert(itemCirculatOrderDto.getTestAgencyInfo());
        } else {
            testAgencyInfoService.update(itemCirculatOrderDto.getTestAgencyInfo());
        }
 
        Long bizId = itemCirculatOrderDto.getCirculatOrder().getId();
        FlowInfoDto flowInfoDto = itemCirculatOrderDto.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 ItemCirculatOrderDto getDto(Long projectId, Long circulatOrderid) {
        ItemCirculatOrderDto data = new ItemCirculatOrderDto();
        if (circulatOrderid != null) {
            data.setId(circulatOrderid);
            ItemCirculatOrder itemCirculatOrder = this.get(circulatOrderid);
            data.setCirculatOrder(itemCirculatOrder);
            if (projectId == null) {
                projectId = itemCirculatOrder.getProjectId();
            }
 
            data.setTestAgencyInfo(testAgencyInfoService.get(circulatOrderid));
 
            List<ItemCirculatOrderTechnical> technicalList = technicalService.getList(circulatOrderid);
            data.setTechnicalList(technicalList);
 
        } else {
            ItemCirculatOrder itemCirculatOrder = new ItemCirculatOrder();
            data.setCirculatOrder(itemCirculatOrder);
            List<?> resultList = technicalService.itemList(projectId);
            List<?> technicalList = resultList;
            data.setTechnicalList((List<ItemCirculatOrderTechnical>) technicalList);
        }
 
        if (projectId != null) {
            data.setProjectId(projectId);
            Project project = projectService.get(projectId);
            String type = project.getSoftwareType();
            if (type == "3") {
                type = "2";
            } else {
                type = "1";
            }
            project.setSoftwareType(type);
            data.setProject(project);
        }
        if (data.getTestAgencyInfo() == null)
            data.setTestAgencyInfo(testAgencyInfoService.get(10000L));
        if (circulatOrderid != null) {
            for (ItemCirculatOrderTechnical technical : data.getTechnicalList()) {
                Long technicalId = technical.getId();
                OssDto ossDto = sysOssConfigService.getOssByBusiType(technicalId, "circulat_order");
                if (ossDto != null) {
                    technical.setFiles(ossDto);
                }
            }
        }
        return data;
    }
 
    public void exportCirculatOrder(Long id, HttpServletRequest request, HttpServletResponse response) {
        try {
            ItemCirculatOrderDto dataObj = this.getDto(null, id);
 
            String acceptorPath = "文件图片:"+ getFilesPath.getSignPath(Convert.toLong(dataObj.getCirculatOrder().getItemAcceptorId()));
            dataObj.getCirculatOrder().setItemAcceptor(acceptorPath);
            String detectorPath = "文件图片:"+getFilesPath.getSignPath(Convert.toLong(dataObj.getCirculatOrder().getCalibratDetectorId()));
            dataObj.getCirculatOrder().setCalibratDetector(detectorPath);
            String issuerPath = "文件图片:"+getFilesPath.getSignPath(Convert.toLong(dataObj.getCirculatOrder().getItemIssuerId()));
            dataObj.getCirculatOrder().setItemIssuer(issuerPath);
            //通用字典列表字符串生成
            String itemRequireStr = getShowDictList.getShowDictList(dataObj.getCirculatOrder().getItemRequire(), "is_or_not", false);
            dataObj.getCirculatOrder().setItemRequireStr(itemRequireStr);
 
            String acceptSituationStr = getShowDictList.getShowDictList(dataObj.getCirculatOrder().getAcceptSituation(), "is_or_not", false);
            dataObj.getCirculatOrder().setAcceptSituationStr(acceptSituationStr);
 
            String detectSituationStr = getShowDictList.getShowDictList(dataObj.getCirculatOrder().getDetectSituation(), "is_or_not", false);
            dataObj.getCirculatOrder().setDetectSituationStr(detectSituationStr);
 
            String issueSituationStr = getShowDictList.getShowDictList(dataObj.getCirculatOrder().getIssueSituation(), "is_or_not", false);
            dataObj.getCirculatOrder().setIssueSituationStr(issueSituationStr);
 
            for (ItemCirculatOrderTechnical technical : dataObj.getTechnicalList()) {
                String value = technical.getSecretClass();
                String secretClassStr = getShowDictList.getShowDictList(value, "secret_class", false);
                technical.setSecretClass(secretClassStr);
            }
 
 
            WordFile wordFile = new WordFile();
            wordFile.setModulePath("物品流转单.docx");
            wordFile.setWordName(dataObj.getProject().getSoftwareName() + "_物品流转单.docx");
            wordFileService.exportWordFile(request, dataObj, wordFile, response);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
 
}