| | |
| | | import com.vincent.rsf.framework.common.R; |
| | | import com.vincent.rsf.framework.exception.CoolException; |
| | | import com.vincent.rsf.server.common.domain.PageResult; |
| | | import com.vincent.rsf.server.common.utils.CommonUtil; |
| | | import com.vincent.rsf.server.common.utils.ExcelUtil; |
| | | import com.vincent.rsf.server.common.annotation.OperationLog; |
| | | import com.vincent.rsf.server.common.domain.BaseParam; |
| | | 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.controller.BaseController; |
| | | 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 |
| | |
| | | public R page(@RequestBody Map<String, Object> 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)); |
| | | } |
| | | |
| | | @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("code"))) { |
| | | throw new CoolException("编码不能为空!!"); |
| | | } |
| | | if (Objects.isNull(matnr.get("groupId"))) { |
| | | throw new CoolException("物料分组不能为空!!"); |
| | | } |
| | | matnr.put("createBy", getLoginUserId()); |
| | | matnr.put("updateBy", getLoginUserId()); |
| | | return matnrService.saveMatnrs(matnr); |
| | | |
| | | /** |
| | | * 扩展字段存入库 |
| | | */ |
| | | if (!FieldsUtils.getFieldsSta().isEmpty()) { |
| | | String uuid16 = CommonUtil.randomUUID16(); |
| | | FieldsUtils.saveFields(matnr, uuid16); |
| | | } |
| | | |
| | | Matnr matnr1 = JSONObject.parseObject(JSONObject.toJSONString(matnr), Matnr.class); |
| | | 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") |
| | | public R update(@RequestBody Matnr matnr) { |
| | | @Transactional(rollbackFor = Exception.class) |
| | | 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("编码不能为空!!"); |
| | | } |
| | | if (Objects.isNull(matnr.getName())) { |
| | | throw new CoolException("名称不能为空!!"); |
| | | } |
| | | matnr.setUpdateBy(getLoginUserId()); |
| | | matnr.setUpdateTime(new Date()); |
| | | if (!matnrService.updateById(matnr)) { |
| | | return R.error("Update Fail"); |
| | | } |
| | | if (!FieldsUtils.getFieldsSta().isEmpty()) { |
| | | Matnr matnr1 = matnrService.getById(matnr.getId()); |
| | | params.put("fieldsIndex", matnr1.getFieldsIndex()); |
| | | 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") |