ludc
2024-10-15 aecacfb404d19749260189ab1d4ee90efc92ae24
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
228
229
package com.vci.web.controller;
 
import com.vci.constant.FrameWorkLangCodeConstant;
import com.vci.dto.OsAttributeDTO;
import com.vci.starter.web.annotation.controller.VciUnCheckRight;
import com.vci.starter.web.annotation.log.VciBusinessLog;
import com.vci.starter.web.exception.VciBaseException;
import com.vci.starter.web.pagemodel.BaseQueryObject;
import com.vci.starter.web.pagemodel.BaseResult;
import com.vci.dto.OsStatusDTO;
import com.vci.pagemodel.OsLifeCycleVO;
import com.vci.pagemodel.OsStatusVO;
import com.vci.starter.web.util.ControllerUtil;
import com.vci.starter.web.util.LocalFileUtil;
import com.vci.starter.web.util.VciBaseUtil;
import com.vci.web.service.OsLifeCycleServiceI;
import com.vci.web.service.OsStatusServiceI;
import com.vci.web.util.Func;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
 
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
 
/**
 * 状态的控制器
 * @author weidy
 * @date 2022-2-15
 */
@RestController
@RequestMapping("/statusController")
@VciBusinessLog(modelName = "对象建模-状态池")
public class VciOsStatusController {
 
    /**
     * 状态的服务
     */
    @Autowired
    private OsStatusServiceI statusService;
 
    /**
     * 生命周期的服务
     */
    @Autowired
    private OsLifeCycleServiceI lifeCycleService;
 
    /**
     * 日志
     */
    private Logger logger = LoggerFactory.getLogger(getClass());
 
    /**
     * 状态的列表
     * @param queryObject 查询对象
     * @return 显示对象
     */
    @GetMapping("/gridStatus")
    @VciBusinessLog(operateName = "查看状态列表")
    @VciUnCheckRight
    public BaseResult<OsStatusVO> gridStatus(BaseQueryObject queryObject){
        try {
            return BaseResult.dataGrid(statusService.gridStatus(queryObject.getConditionMap(),queryObject.getPageHelper()));
        }catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "属性管理列表查询时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
 
    /**
     * 查询状态池的应用范围
     * @param oid 状态的主键
     * @return 使用的生命周期的对象
     */
    @GetMapping("/listUsed")
    @VciBusinessLog(operateName = "查询状态池的应用范围")
    @VciUnCheckRight
    public BaseResult<OsLifeCycleVO> listUsed(String oid){
        try {
            return BaseResult.dataGrid(lifeCycleService.listStatusUsed(oid));
        }catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "属性管理列表查询时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
 
    /**
     * 添加状态
     * @param statusDTO 状态的数据传输对象
     * @return 执行结果
     */
    @PostMapping("/addSave")
    public BaseResult addSave(@RequestBody OsStatusDTO statusDTO){
        try {
            return statusService.addSave(statusDTO) ? BaseResult.success("添加状态成功!"):BaseResult.fail("添加状态失败!");
        }catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "添加状态时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
 
    /**
     * 修改状态
     * @param statusDTO 状态的数据传输对象
     * @return 执行结果
     */
    @PutMapping("/editSave")
    public BaseResult editSave(@RequestBody OsStatusDTO statusDTO){
        try {
            return statusService.editSave(statusDTO) ? BaseResult.success("修改状态成功!"):BaseResult.fail("修改状态失败!");
        }catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "修改状态时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
 
    /**
     * 删除状态
     * @param osStatusDTOS 状态的DTO对象
     * @return 执行结果
     */
    @DeleteMapping("/deleteStatus")
    public BaseResult deleteStatus(@RequestBody List<OsStatusDTO> osStatusDTOS){
        try {
            return statusService.deleteStatus(osStatusDTOS) ? BaseResult.success("删除状态成功!"):BaseResult.fail("删除状态失败!");
        }catch (Exception e) {
            e.printStackTrace();
            String exceptionMessage = "删除状态时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            logger.error(exceptionMessage);
            return BaseResult.fail(exceptionMessage);
        }
    }
 
    /**
     * 使用主键来获取对象
     * @param oid 主键
     * @return 对象的信息
     */
    @GetMapping("/getObjectByOid")
    public BaseResult<OsStatusVO> getObjectByOid(String oid){
        return BaseResult.success(statusService.getObjectByOid(oid));
    }
 
    /**
     * 导出状态
     * @param exportFileName
     * @param statusOids
     * @param response
     */
    @GetMapping( "/exportStatus")
    @VciBusinessLog(operateName = "导出状态")
    public void exportStatus(String exportFileName,String statusOids, HttpServletResponse response){
        try {
            String excelPath = statusService.exportStatus(exportFileName,statusOids,true);
            ControllerUtil.writeFileToResponse(response,excelPath);
        } catch (Exception e) {
            String msg = "导出状态时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            try {
                //出错时
                e.printStackTrace();
                ControllerUtil.writeDataToResponse(response,"error_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss") + ".txt", StringUtils.isNotBlank(msg)?msg.getBytes():new byte[0],null);
            } catch (IOException ioException) {
                ioException.printStackTrace();
            }
        }
    }
 
    /**
     * 下载状态导入模板
     * @param exportFileName
     * @param response
     */
    @GetMapping( "/downloadStatusTemplate")
    @VciBusinessLog(operateName = "导出状态")
    public void downloadStatusTemplate(String exportFileName, HttpServletResponse response){
        try {
            String excelPath = statusService.downloadStatusTemplate(exportFileName);
            ControllerUtil.writeFileToResponse(response,excelPath);
        } catch (Exception e) {
            String msg = "下载枚举导入模板时出现错误,原因:" + VciBaseUtil.getExceptionMessage(e);
            try {
                //出错时
                e.printStackTrace();
                ControllerUtil.writeDataToResponse(response,"error_" + Func.format(new Date(),"yyyy-MM-dd HHmmss.sss") + ".txt", StringUtils.isNotBlank(msg)?msg.getBytes():new byte[0],null);
            } catch (IOException ioException) {
                ioException.printStackTrace();
            }
        }
    }
 
    /**
     * 导入状态
     * @param file
     * @return
     */
    @PostMapping("/importStatus")
    @VciBusinessLog(operateName = "导入状态")
    public BaseResult importStatus(MultipartFile file){
        String excelFileName = LocalFileUtil.getDefaultTempFolder() + File.separator + LocalFileUtil.getFileNameForIE(file.getOriginalFilename());
        File file1 = new File(excelFileName);
        try {
            file.transferTo(new File(excelFileName));
            if (file != null) {
                return statusService.importStatus(file1);
            } else {
                return BaseResult.fail(FrameWorkLangCodeConstant.IMPORT_FAIL, new String[]{"无导入的文件"});
            }
        }catch (Throwable e) {
            throw new VciBaseException(VciBaseUtil.getExceptionMessage(e),new String[0],e);
        }finally {
            file1.delete();
        }
    }
 
}