新火炬后端单体项目初始化代码
houshuai
2025-07-04 e40e3e8cd0c19a38458a5804d570361302bf2acd
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
package org.jeecg.modules.qms.controller;
 
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.qms.entity.Defect;
import org.jeecg.modules.qms.entity.InspectionItem;
import org.jeecg.modules.qms.entity.InspectionPlan;
import org.jeecg.modules.qms.entity.InspectionPlanItem;
import org.jeecg.modules.qms.service.IInspectionPlanItemService;
import org.jeecg.modules.qms.service.IInspectionPlanService;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
 
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
 
 /**
 * @Description: 检验方案
 * @Author: jeecg-boot
 * @Date:   2025-07-02
 * @Version: V1.0
 */
@Api(tags="检验方案")
@RestController
@RequestMapping("/qms/inspectionPlan")
@Slf4j
public class InspectionPlanController extends JeecgController<InspectionPlan, IInspectionPlanService> {
    @Autowired
    private IInspectionPlanService inspectionPlanService;
 
     @Autowired
     private IInspectionPlanItemService inspectionPlanItemService;
    
    /**
     * 分页列表查询
     *
     * @param inspectionPlan
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    //@AutoLog(value = "检验方案-分页列表查询")
    @ApiOperation(value="检验方案-分页列表查询", notes="检验方案-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<InspectionPlan>> queryPageList(InspectionPlan inspectionPlan,
                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                   HttpServletRequest req) {
        QueryWrapper<InspectionPlan> queryWrapper = QueryGenerator.initQueryWrapper(inspectionPlan, req.getParameterMap());
        Page<InspectionPlan> page = new Page<InspectionPlan>(pageNo, pageSize);
        IPage<InspectionPlan> pageList = inspectionPlanService.page(page, queryWrapper);
        return Result.OK(pageList);
    }
    
    /**
     *   添加
     *
     * @param jSONObject
     * @return
     */
    @AutoLog(value = "检验方案-添加")
    @ApiOperation(value="检验方案-添加", notes="检验方案-添加")
    @PostMapping(value = "/add")
    public Result<?> add(@RequestBody JSONObject jSONObject) {
        InspectionPlan inspectionPlan = jSONObject.toJavaObject(InspectionPlan.class);
        inspectionPlan.setPlanStatus(CommonConstant.STATUS_1);
        inspectionPlan.setPublishStatus(CommonConstant.STATUS_0);
        inspectionPlan.setIsNewVersion("1");
        inspectionPlan.setVersion("V1");
        inspectionPlanService.save(inspectionPlan);
        //保存检验方案检验项目关联关系
        JSONArray jsonArray = jSONObject.getJSONArray("detailData");
        List<InspectionPlanItem> inspectionPlanItemList = jsonArray.toJavaList(InspectionPlanItem.class);
        for(int i = 0;i<inspectionPlanItemList.size();i++){
            InspectionPlanItem inspectionPlanItem = inspectionPlanItemList.get(i);
            inspectionPlanItem.setItemId(inspectionPlanItem.getId());
            inspectionPlanItem.setId(null);
            inspectionPlanItem.setPlanId(inspectionPlan.getId());
        }
        inspectionPlanItemService.saveBatch(inspectionPlanItemList);
        return Result.OK("添加成功!");
    }
    
    /**
     *  编辑
     *
     * @param jSONObject
     * @return
     */
    @AutoLog(value = "检验方案-编辑")
    @ApiOperation(value="检验方案-编辑", notes="检验方案-编辑")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
    public Result<?> edit(@RequestBody JSONObject jSONObject) {
        InspectionPlan inspectionPlan = jSONObject.toJavaObject(InspectionPlan.class);
        inspectionPlan.setPlanStatus(CommonConstant.STATUS_1);
        inspectionPlanService.updateById(inspectionPlan);
        //删除原关联关系
        inspectionPlanItemService.removeBatchByIds(inspectionPlanItemService.lambdaQuery().eq(InspectionPlanItem::getPlanId,inspectionPlan.getId()).list());
        //保存检验方案检验项目关联关系
        JSONArray jsonArray = jSONObject.getJSONArray("detailData");
        List<InspectionPlanItem> inspectionPlanItemList = jsonArray.toJavaList(InspectionPlanItem.class);
        for(int i = 0;i<inspectionPlanItemList.size();i++){
            InspectionPlanItem inspectionPlanItem = inspectionPlanItemList.get(i);
            inspectionPlanItem.setPlanId(inspectionPlan.getId());
            inspectionPlanItem.setItemId(inspectionPlanItem.getId());
            inspectionPlanItem.setId(null);
        }
        inspectionPlanItemService.saveBatch(inspectionPlanItemList);
        return Result.OK("编辑成功!");
    }
    
    /**
     *   通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "检验方案-通过id删除")
    @ApiOperation(value="检验方案-通过id删除", notes="检验方案-通过id删除")
    //@RequiresPermissions("org.jeecg.modules:qms_inspection_plan:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name="id",required=true) String id) {
        inspectionPlanService.removeById(id);
        //删除关联关系
        inspectionPlanItemService.removeBatchByIds(inspectionPlanItemService.lambdaQuery().eq(InspectionPlanItem::getPlanId,id).list());
        return Result.OK("删除成功!");
    }
    
    /**
     *  批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "检验方案-批量删除")
    @ApiOperation(value="检验方案-批量删除", notes="检验方案-批量删除")
    //@RequiresPermissions("org.jeecg.modules:qms_inspection_plan:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
        this.inspectionPlanService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }
    
    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    //@AutoLog(value = "检验方案-通过id查询")
    @ApiOperation(value="检验方案-通过id查询", notes="检验方案-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<InspectionPlan> queryById(@RequestParam(name="id",required=true) String id) {
        InspectionPlan inspectionPlan = inspectionPlanService.getById(id);
        if(inspectionPlan==null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(inspectionPlan);
    }
 
    /**
    * 导出excel
    *
    * @param request
    * @param inspectionPlan
    */
    //@RequiresPermissions("org.jeecg.modules:qms_inspection_plan:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, InspectionPlan inspectionPlan) {
        return super.exportXls(request, inspectionPlan, InspectionPlan.class, "检验方案");
    }
 
    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    //@RequiresPermissions("qms_inspection_plan:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, InspectionPlan.class);
    }
 
     @AutoLog(value = "检验方案-启用&禁用")
     @ApiOperation(value = "检验方案-启用&禁用", notes = "检验方案-启用&禁用")
     @PutMapping(value = "/active")
     public Result<?> active(@RequestParam(name = "id", required = true) String id) {
         InspectionPlan inspectionPlan = inspectionPlanService.getById(id);
         if (CommonConstant.STATUS_1.equals(inspectionPlan.getPlanStatus())) {
             inspectionPlan.setPlanStatus(CommonConstant.STATUS_0);
         } else {
             inspectionPlan.setPlanStatus(CommonConstant.STATUS_1);
         }
         inspectionPlanService.updateById(inspectionPlan);
         return Result.ok("操作成功!");
     }
 
     @AutoLog(value = "检验方案-发布")
     @ApiOperation(value = "检验方案-发布", notes = "检验方案-发布")
     @PutMapping(value = "/publish")
     public Result<?> publish(@RequestParam(name = "id", required = true) String id) {
         InspectionPlan inspectionPlan = inspectionPlanService.getById(id);
         if (CommonConstant.STATUS_1.equals(inspectionPlan.getPublishStatus())) {
             inspectionPlan.setPublishStatus(CommonConstant.STATUS_0);
         } else {
             inspectionPlan.setPublishStatus(CommonConstant.STATUS_1);
         }
         inspectionPlanService.updateById(inspectionPlan);
         return Result.ok("操作成功!");
     }
 
     @AutoLog(value = "检验方案-升版")
     @ApiOperation(value = "检验方案-升版", notes = "检验方案-升版")
     @PutMapping(value = "/version")
     public Result<?> version(@RequestParam(name = "id", required = true) String id) {
         InspectionPlan inspectionPlan = inspectionPlanService.getById(id);
         //复制当前检验方案
         InspectionPlan newInspectionPlan = new InspectionPlan();
         BeanUtil.copyProperties(inspectionPlan,newInspectionPlan);
         newInspectionPlan.setId(null);
         newInspectionPlan.setPlanStatus(CommonConstant.STATUS_1);
         newInspectionPlan.setPublishStatus(CommonConstant.STATUS_0);
         newInspectionPlan.setCreateTime(new Date());
         LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
         newInspectionPlan.setCreateBy(user.getUsername());
         //计算版本,版本+1
         String number = inspectionPlan.getVersion().substring(1);
         BigDecimal newNumber = new BigDecimal(number).add(BigDecimal.ONE);
         newInspectionPlan.setVersion("V"+newNumber);
         newInspectionPlan.setIsNewVersion("1");
         inspectionPlanService.save(newInspectionPlan);
         //复制检验方案检验项目
         List<InspectionPlanItem> inspectionPlanItemList = inspectionPlanItemService.lambdaQuery().eq(InspectionPlanItem::getPlanId,inspectionPlan.getId()).list();
         List<InspectionPlanItem> newInspectionPlanItemList = new ArrayList<>();
         newInspectionPlanItemList.addAll(inspectionPlanItemList);
         for(InspectionPlanItem inspectionPlanItem : inspectionPlanItemList){
             inspectionPlanItem.setId(null);
             inspectionPlanItem.setPlanId(newInspectionPlan.getId());
         }
         inspectionPlanItemService.saveBatch(newInspectionPlanItemList);
         //更新原检验方案为禁用
         inspectionPlan.setPlanStatus(CommonConstant.STATUS_0);
         inspectionPlan.setIsNewVersion("0");
         inspectionPlanService.updateById(inspectionPlan);
         return Result.ok("升版成功!");
     }
 
}