skyouc
2025-03-25 2e7e4493e133b9b646da9cd2d635287f14509e4c
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/MatnrServiceImpl.java
@@ -6,6 +6,7 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.vincent.rsf.framework.common.R;
import com.vincent.rsf.framework.exception.CoolException;
@@ -14,6 +15,7 @@
import com.vincent.rsf.server.common.utils.CommonUtil;
import com.vincent.rsf.server.common.utils.ExcelUtil;
import com.vincent.rsf.server.common.utils.FieldsUtils;
import com.vincent.rsf.server.manager.controller.params.MatnrToGroupParams;
import com.vincent.rsf.server.manager.entity.MatnrGroup;
import com.vincent.rsf.server.manager.entity.excel.MatnrsTemplate;
import com.vincent.rsf.server.manager.mapper.MatnrMapper;
@@ -99,7 +101,7 @@
    }
    @Override
    public IPage<Map<String, Object>> getMatnrPage(PageParam<Matnr, BaseParam> pageParam) {
    public PageParam<Matnr, BaseParam> getMatnrPage(PageParam<Matnr, BaseParam> pageParam) {
        IPage<Map<String, Object>> reulst = this.baseMapper.selectMatnrs(pageParam, pageParam.buildWrapper(true));
        /**获取物料分页信息 */
        List<Map<String, Object>> mapList = reulst.getRecords();
@@ -110,17 +112,56 @@
                }
            });
        }
        List<Matnr> matnrs = JSONArray.parseArray(JSON.toJSONString(mapList), Matnr.class);
//        PageParam<Matnr, BaseParam> page = this.page(pageParam, pageParam.buildWrapper(true));
//        List<Matnr> records = page.getRecords();
//        for (Matnr record : records) {
//            if (!Objects.isNull(record.getFieldsIndex())) {
//                Map<String, String> fields = FieldsUtils.getFields(record.getFieldsIndex());
//                record.setExtendFields(fields);
//            }
//        }
//        page.setRecords(records);
        return reulst;
        PageParam<Matnr, BaseParam> page = this.page(pageParam, pageParam.buildWrapper(true));
        List<Matnr> records = page.getRecords();
        for (Matnr record : records) {
            if (!Objects.isNull(record.getFieldsIndex())) {
                Map<String, String> fields = FieldsUtils.getFields(record.getFieldsIndex());
                record.setExtendFields(fields);
            }
        }
        page.setRecords(records);
        return page;
    }
    @Override
    public Matnr selectMatnrById(Long id) {
        Matnr matnr = this.baseMapper.selectById(id);
        if (Objects.isNull(matnr)) {
            throw new CoolException("当前物料不存在!!");
        }
        if (!Objects.isNull(matnr.getFieldsIndex())) {
            Map<String, String> fields = FieldsUtils.getFields(matnr.getFieldsIndex());
            matnr.setExtendFields(fields);
        }
        return matnr;
    }
    /**
     * 物料绑定
     * @param params
     * @return
     */
    @Override
    public boolean bindMatnrs(MatnrToGroupParams params) {
        if (Objects.isNull(params) && params.getIds().isEmpty()) {
            throw new CoolException("物料不能为空!!");
        }
        if (Objects.isNull(params.getGroupId())) {
            throw new CoolException("分组不能为空!!");
        }
        MatnrGroup groups = matnrGroupService.getOne(new LambdaQueryWrapper<MatnrGroup>().eq(MatnrGroup::getId, params.getGroupId()));
        if (Objects.isNull(groups)) {
            throw new CoolException("物料分组不存在!!");
        }
        if (!this.update(new LambdaUpdateWrapper<Matnr>()
                .in(Matnr::getId, params.getIds())
                .set(Matnr::getGroupId, groups.getId())
                .set(Matnr::getGroupCode, groups.getCode()))) {
            throw new CoolException("绑定失败!!");
        }
        return true;
    }
    /**
@@ -134,8 +175,6 @@
        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);
        }
        /**
@@ -146,9 +185,9 @@
            FieldsUtils.saveFields(matnr, uuid16);
            matnr1.setFieldsIndex(uuid16);
        }
        if (!this.save(matnr1)) {
        if (!this.saveOrUpdate(matnr1)) {
            return R.error("Save Fail");
        }
        return R.ok("保存成功!!");
        return R.ok(matnr1);
    }
}