| | |
| | | package com.vincent.rsf.server.manager.controller; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.vincent.rsf.framework.common.Cools; |
| | | 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.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; |
| | | |
| | |
| | | @PreAuthorize("hasAuthority('manager:matnr:save')") |
| | | @OperationLog("Create 物料信息表") |
| | | @PostMapping("/matnr/save") |
| | | public R save(@RequestBody Matnr matnr) { |
| | | if (Objects.isNull(matnr.getName())) { |
| | | public R save(@RequestBody Map<String, Object> matnr) { |
| | | if (Objects.isNull(matnr)) { |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | if (Objects.isNull(matnr.get("matnr"))) { |
| | | throw new CoolException("名称不能为空!!"); |
| | | } |
| | | if (Objects.isNull(matnr.getCode())) { |
| | | throw new CoolException("编码不能为空!!"); |
| | | } |
| | | if (Objects.isNull(matnr.getGroupId())) { |
| | | if (Objects.isNull(matnr.get("groupId"))) { |
| | | throw new CoolException("物料分组不能为空!!"); |
| | | } |
| | | |
| | | matnr.setCreateBy(getLoginUserId()); |
| | | matnr.setUpdateBy(getLoginUserId()); |
| | | if (!matnrService.save(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") |
| | | public R update(@RequestBody Matnr matnr) { |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public R update(@RequestBody Map<String, Object> params) { |
| | | 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 (!Objects.isNull(params.get("fieldsIndex"))) { |
| | | FieldsUtils.updateFieldsValue(params); |
| | | } |
| | | return R.ok("Update Success").add(matnr); |
| | | } |
| | | |