|  |  | 
 |  |  | import com.vincent.rsf.server.common.domain.KeyValVo; | 
 |  |  | import com.vincent.rsf.server.common.domain.PageParam; | 
 |  |  | import com.vincent.rsf.server.common.utils.FieldsUtils; | 
 |  |  | import com.vincent.rsf.server.manager.controller.params.MatnrToGroupParams; | 
 |  |  | import com.vincent.rsf.server.manager.entity.Matnr; | 
 |  |  | import com.vincent.rsf.server.manager.entity.excel.MatnrsTemplate; | 
 |  |  | import com.vincent.rsf.server.manager.service.MatnrService; | 
 |  |  | import com.vincent.rsf.server.system.constant.SerialRuleCode; | 
 |  |  | import com.vincent.rsf.server.system.controller.BaseController; | 
 |  |  | import com.vincent.rsf.server.system.utils.SerialRuleUtils; | 
 |  |  | import io.swagger.annotations.Api; | 
 |  |  | import io.swagger.annotations.ApiOperation; | 
 |  |  | import io.swagger.v3.oas.annotations.security.SecurityRequirement; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.http.HttpHeaders; | 
 |  |  | import org.springframework.security.access.prepost.PreAuthorize; | 
 |  |  | import org.springframework.transaction.annotation.Transactional; | 
 |  |  | import org.springframework.web.bind.annotation.*; | 
 |  |  | import org.springframework.web.multipart.MultipartFile; | 
 |  |  |  | 
 |  |  | import javax.servlet.http.HttpServletResponse; | 
 |  |  | import javax.validation.Valid; | 
 |  |  | import javax.validation.constraints.NotNull; | 
 |  |  | import java.util.*; | 
 |  |  |  | 
 |  |  | @RestController | 
 |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('manager:matnr:list')") | 
 |  |  |     @PostMapping("/matnr/page") | 
 |  |  |     public R page(@RequestBody Map<String, Object> map) { | 
 |  |  | //        if (!Objects.isNull(map.get("groupId"))) { | 
 |  |  | //            return R.ok(matnrService.getPages(map)); | 
 |  |  | //        } else { | 
 |  |  | //            BaseParam baseParam = buildParam(map, BaseParam.class); | 
 |  |  | //            PageParam<Matnr, BaseParam> pageParam = new PageParam<>(baseParam, Matnr.class); | 
 |  |  | //            return R.ok().add(matnrService.getMatnrPage(pageParam, map)); | 
 |  |  | //        } | 
 |  |  |         BaseParam baseParam = buildParam(map, BaseParam.class); | 
 |  |  |         PageParam<Matnr, BaseParam> pageParam = new PageParam<>(baseParam, Matnr.class); | 
 |  |  |         return R.ok().add( matnrService.getMatnrPage(pageParam)); | 
 |  |  |         return R.ok().add(matnrService.getMatnrPage(pageParam, map)); | 
 |  |  |  | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('manager:matnr:list')") | 
 |  |  | 
 |  |  |         return R.ok().add(matnrService.listByIds(Arrays.asList(ids))); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('manager:matnr:list')") | 
 |  |  |     @GetMapping("/matnr/{id}") | 
 |  |  |     public R get(@PathVariable("id") Long id) { | 
 |  |  |         return R.ok().add(matnrService.getById(id)); | 
 |  |  |         return R.ok(matnrService.selectMatnrById(id)); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('manager:matnr:save')") | 
 |  |  | 
 |  |  |         if (Objects.isNull(matnr)) { | 
 |  |  |             throw new CoolException("参数不能为空!!"); | 
 |  |  |         } | 
 |  |  |         if (Objects.isNull(matnr.get("matnr"))) { | 
 |  |  |         if (Objects.isNull(matnr.get("name"))) { | 
 |  |  |             throw new CoolException("名称不能为空!!"); | 
 |  |  |         } | 
 |  |  |         if (Objects.isNull(matnr.get("groupId"))) { | 
 |  |  |             throw new CoolException("物料分组不能为空!!"); | 
 |  |  |         } | 
 |  |  |         matnr.put("createBy", getLoginUserId()); | 
 |  |  |         matnr.put("updateBy", getLoginUserId()); | 
 |  |  |         return matnrService.saveMatnrs(matnr); | 
 |  |  |  | 
 |  |  |         Matnr matnr1 = JSONObject.parseObject(JSONObject.toJSONString(matnr), Matnr.class); | 
 |  |  |         if (Objects.isNull(matnr1.getCode())) { | 
 |  |  |             String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_MATNR_CODE, null); | 
 |  |  |             System.out.println("=========>"); | 
 |  |  |             System.out.println(ruleCode); | 
 |  |  |             matnr1.setCode(ruleCode); | 
 |  |  |         } | 
 |  |  |         /** | 
 |  |  |          * 扩展字段存入库 | 
 |  |  |          */ | 
 |  |  |         String uuid16 = CommonUtil.randomUUID16(); | 
 |  |  |         if (!FieldsUtils.getFieldsSta().isEmpty()) { | 
 |  |  |             FieldsUtils.saveFields(matnr, uuid16); | 
 |  |  |             matnr1.setFieldsIndex(uuid16); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         matnr1.setCreateBy(getLoginUserId()); | 
 |  |  |         matnr1.setUpdateBy(getLoginUserId()); | 
 |  |  |  | 
 |  |  |         if (!matnrService.save(matnr1)) { | 
 |  |  |             return R.error("Save Fail"); | 
 |  |  |         } | 
 |  |  |         return R.ok("Save Success").add(matnr); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('manager:matnr:update')") | 
 |  |  |     @OperationLog("Update 物料信息表") | 
 |  |  |     @PostMapping("/matnr/update") | 
 |  |  |     @Transactional(rollbackFor = Exception.class) | 
 |  |  |     public R update(@RequestBody Map<String, Object> params) { | 
 |  |  |     public R update(@RequestBody Map<String, Object> params) throws Exception { | 
 |  |  |         Matnr matnr = JSONObject.parseObject(JSONObject.toJSONString(params), Matnr.class); | 
 |  |  |         if (Objects.isNull(matnr.getCode())) { | 
 |  |  |             throw new CoolException("编码不能为空!!"); | 
 |  |  | 
 |  |  |             throw new CoolException("名称不能为空!!"); | 
 |  |  |         } | 
 |  |  |         matnr.setUpdateBy(getLoginUserId()); | 
 |  |  |  | 
 |  |  |         if (!FieldsUtils.getFieldsSta().isEmpty()) { | 
 |  |  |             Matnr matnr1 = matnrService.getById(matnr.getId()); | 
 |  |  |             if (!Objects.isNull(matnr1.getFieldsIndex())) { | 
 |  |  |                 params.put("fieldsIndex", matnr1.getFieldsIndex()); | 
 |  |  |             } else { | 
 |  |  |                 String uuid16 = CommonUtil.randomUUID16(); | 
 |  |  |                 params.put("index", uuid16); | 
 |  |  |                 matnr.setFieldsIndex(uuid16); | 
 |  |  |             } | 
 |  |  |             FieldsUtils.updateFieldsValue(params); | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         if (!matnrService.updateById(matnr)) { | 
 |  |  |             return R.error("Update Fail"); | 
 |  |  |         } | 
 |  |  |         if (!Objects.isNull(params.get("fieldsIndex"))) { | 
 |  |  |             FieldsUtils.updateFieldsValue(params); | 
 |  |  |         } | 
 |  |  |         return R.ok("Update Success").add(matnr); | 
 |  |  |     } | 
 |  |  | 
 |  |  |         return R.ok(new PageResult().setRecords(matnrPage.getRecords()).setTotal(matnrPage.getTotal())); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('manager:matnr:list')") | 
 |  |  |     @ApiOperation("绑定物料分组") | 
 |  |  |     @PostMapping("/matnr/group/bind") | 
 |  |  |     public R bindMatnrToGroup(@RequestBody MatnrToGroupParams params) { | 
 |  |  |         if (Objects.isNull(params)) { | 
 |  |  |             return  R.error("参数不能为空!!"); | 
 |  |  |         } | 
 |  |  |         if (matnrService.bindMatnrs(params)) { | 
 |  |  |             return R.ok(); | 
 |  |  |         } else { | 
 |  |  |             return R.error("操作失败!!"); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('manager:matnr:update')") | 
 |  |  |     @ApiOperation("批量修改") | 
 |  |  |     @PostMapping("/matnr/batch/update") | 
 |  |  |     public R batchUpdate(@RequestBody MatnrToGroupParams params) { | 
 |  |  |         if (Objects.isNull(params)) { | 
 |  |  |             return  R.error("参数不能为空!!"); | 
 |  |  |         } | 
 |  |  |         if (Objects.isNull(params.getMatnr())) { | 
 |  |  |             return R.error("物料属性不能为空!!"); | 
 |  |  |         } | 
 |  |  |         if (matnrService.batchUpdate(params)) { | 
 |  |  |             return R.ok(); | 
 |  |  |         }else { | 
 |  |  |             return R.error("操作失败!!"); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('manager:matnr:list')") | 
 |  |  |     @ApiOperation("导出物料信息") | 
 |  |  |     @PostMapping("/matnr/export") | 
 |  |  | 
 |  |  |         if (!Objects.isNull(map.get("ids"))) { | 
 |  |  |             matnrs = matnrService.list(new LambdaQueryWrapper<Matnr>().in(Matnr::getId, map.get("ids")).eq(Matnr::getStatus, 1)); | 
 |  |  |         } else { | 
 |  |  |             matnrs = matnrService.list(new LambdaQueryWrapper<Matnr>().last("limit 1")); | 
 |  |  |             matnrs = matnrService.list(); | 
 |  |  |         } | 
 |  |  |         ExcelUtil.build(ExcelUtil.create(null, MatnrsTemplate.class, true), response); | 
 |  |  |         ExcelUtil.build(ExcelUtil.create(matnrs, Matnr.class, false), response); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @PreAuthorize("hasAuthority('manager:matnr:list')") | 
 |  |  |     @ApiOperation("下载物料模板") | 
 |  |  |     @PostMapping("/matnr/template/download") | 
 |  |  |     public void download(@RequestBody Map<String, Object> map, HttpServletResponse response) throws Exception { | 
 |  |  |         ExcelUtil.build(ExcelUtil.create(null, MatnrsTemplate.class, true), response); | 
 |  |  |         ExcelUtil.build(ExcelUtil.create(null, MatnrsTemplate.class), response); | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |  |