yangyang
2025-03-20 9e27b1b292872bd83b761091554fbd8db72b595e
#优化
物料扩展字段修改优化
2个文件已修改
49 ■■■■■ 已修改文件
rsf-server/src/main/java/com/vincent/rsf/server/common/utils/FieldsUtils.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
rsf-server/src/main/java/com/vincent/rsf/server/manager/controller/MatnrController.java 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
rsf-server/src/main/java/com/vincent/rsf/server/common/utils/FieldsUtils.java
@@ -87,4 +87,37 @@
        FieldsService fieldsService = SpringUtils.getBean(FieldsService.class);
        return fieldsService.list(new LambdaQueryWrapper<Fields>().eq(Fields::getStatus, 1).eq(Fields::getFlagEnable, 1));
    }
    public static void updateFieldsValue(Map<String, Object> params) {
        List<Fields> fields = getFieldsSta();
        if (fields.isEmpty()) { return; }
        Object fieldsIndex = params.get("fieldsIndex");
        if (!Objects.isNull(fieldsIndex)) {
            String index = fieldsIndex.toString();
            FieldsItemService fieldsItemService = SpringUtils.getBean(FieldsItemService.class);
            for (Fields field : fields) {
                if (!Objects.isNull(params.get(field.getFields()))) {
                    FieldsItem indexItem = fieldsItemService.getOne(new LambdaQueryWrapper<FieldsItem>()
                            .eq(FieldsItem::getUuid, index)
                            .eq(FieldsItem::getFieldsId, field.getId()));
                    //如果子表为空,执行插入操作,否则就执行修改操作
                    if (Objects.isNull(indexItem)) {
                        FieldsItem item = new FieldsItem();
                        item.setUuid(index)
                                .setFieldsId(field.getId())
                                .setValue(params.get(field.getFields()).toString());
                        if (fieldsItemService.save(item)) {
                            throw new CoolException("扩展字段修改失败!!");
                        }
                    } else {
                        indexItem.setValue(params.get(field.getFields()).toString());
                        if (fieldsItemService.updateById(indexItem)) {
                            throw new CoolException("扩展字段修改失败!!");
                        }
                    }
                }
            }
        }
    }
}
rsf-server/src/main/java/com/vincent/rsf/server/manager/controller/MatnrController.java
@@ -24,6 +24,7 @@
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;
@@ -83,15 +84,17 @@
            throw new CoolException("物料分组不能为空!!");
        }
        Matnr matnr1 = JSONObject.parseObject(JSONObject.toJSONString(matnr), Matnr.class);
        /**
         * 扩展字段存入库
         */
        String uuid16 = CommonUtil.randomUUID16();
        if (!FieldsUtils.getFieldsSta().isEmpty()) {
            String uuid16 = CommonUtil.randomUUID16();
            FieldsUtils.saveFields(matnr, uuid16);
            matnr1.setFieldsIndex(uuid16);
        }
        Matnr matnr1 = JSONObject.parseObject(JSONObject.toJSONString(matnr), Matnr.class);
        matnr1.setCreateBy(getLoginUserId());
        matnr1.setUpdateBy(getLoginUserId());
@@ -104,12 +107,17 @@
    @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);
        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);
    }