| | |
| | | package org.jeecg.modules.qms.controller; |
| | | |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | 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; |
| | |
| | | public class InspectionPlanController extends JeecgController<InspectionPlan, IInspectionPlanService> { |
| | | @Autowired |
| | | private IInspectionPlanService inspectionPlanService; |
| | | |
| | | @Autowired |
| | | private IInspectionPlanItemService inspectionPlanItemService; |
| | | |
| | | /** |
| | | * 分页列表查询 |
| | |
| | | /** |
| | | * 添加 |
| | | * |
| | | * @param inspectionPlan |
| | | * @param jSONObject |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "检验方案-添加") |
| | | @ApiOperation(value="检验方案-添加", notes="检验方案-添加") |
| | | //@RequiresPermissions("org.jeecg.modules:qms_inspection_plan:add") |
| | | @PostMapping(value = "/add") |
| | | public Result<String> add(@RequestBody InspectionPlan inspectionPlan) { |
| | | 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 inspectionPlan |
| | | * @param jSONObject |
| | | * @return |
| | | */ |
| | | @AutoLog(value = "检验方案-编辑") |
| | | @ApiOperation(value="检验方案-编辑", notes="检验方案-编辑") |
| | | //@RequiresPermissions("org.jeecg.modules:qms_inspection_plan:edit") |
| | | @RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST}) |
| | | public Result<String> edit(@RequestBody InspectionPlan inspectionPlan) { |
| | | 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("编辑成功!"); |
| | | } |
| | | |
| | |
| | | @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("删除成功!"); |
| | | } |
| | | |
| | |
| | | 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("升版成功!"); |
| | | } |
| | | |
| | | } |