skyouc
2025-04-18 4a2408cf21e1c60196d798ab971f00328d9ca249
rsf-server/src/main/java/com/vincent/rsf/server/manager/controller/MatnrGroupController.java
@@ -17,12 +17,14 @@
import com.vincent.rsf.server.manager.service.MatnrGroupService;
import com.vincent.rsf.server.system.controller.BaseController;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
import java.util.stream.Collectors;
@Api(tags = "物料分组")
@RestController
@@ -63,25 +65,32 @@
    @PostMapping("/matnrGroup/save")
    public R save(@RequestBody MatnrGroup matnrGroup) {
        if (Objects.isNull(matnrGroup)) {
            throw new CoolException("参数不能为空!!");
            return R.error("参数不能为空!!");
        }
        if (Objects.isNull(matnrGroup.getName())) {
            throw new CoolException("分组名称不能为空!!");
            return R.error("分组名称不能为空!!");
        }
        if (Objects.isNull(matnrGroup.getCode())) {
            throw new CoolException("分组编码不能为空!!");
            return R.error("分组编码不能为空!!");
        }
        matnrGroup.setCreateBy(getLoginUserId());
        matnrGroup.setUpdateBy(getLoginUserId());
        List<MatnrGroup> list = matnrGroupService.list(new LambdaQueryWrapper<MatnrGroup>()
                .eq(!Objects.isNull(matnrGroup.getParCode()), MatnrGroup::getParCode, matnrGroup.getParCode())
                .eq(MatnrGroup::getCode, matnrGroup.getCode()));
        if (!list.isEmpty()) {
            throw new CoolException("物料分组编码不能重复!!");
            return R.error("物料分组编码不能重复!!");
        }
        List<MatnrGroup> groups = matnrGroupService.list(new LambdaQueryWrapper<MatnrGroup>()
                .eq(MatnrGroup::getName, matnrGroup.getName()));
        if (!groups.isEmpty()) {
            throw new CoolException("分组已存在,请勿重复添加!!");
            return R.error("分组已存在,请勿重复添加!!");
        }
        //判断上级编码是否为空
        if (!Objects.isNull(matnrGroup.getParCode()) && !StringUtils.isBlank(matnrGroup.getParCode())) {
            matnrGroup.setParCode(matnrGroup.getParCode() + matnrGroup.getCode());
        }
        if (!matnrGroupService.save(matnrGroup)) {
            return R.error("Save Fail");
@@ -93,18 +102,24 @@
    @OperationLog("Update 物料分类表")
    @PostMapping("/matnrGroup/update")
    public R update(@RequestBody MatnrGroup matnrGroup) {
        matnrGroup.setUpdateBy(getLoginUserId());
        MatnrGroup matGroup = matnrGroupService.getById(matnrGroup.getId());
        if (Objects.isNull(matGroup)) {
            return R.error("物料分组不存在!!");
        }
        if (!matnrGroup.getName().equals(matGroup.getName())) {
            List<MatnrGroup> areasList = matnrGroupService.list(new LambdaQueryWrapper<MatnrGroup>().eq(MatnrGroup::getName, matnrGroup.getName()));
            if (!areasList.isEmpty()) {
                throw new CoolException("仓库名已存在!!");
                return R.error("仓库名已存在!!");
            }
        }
        if (!matnrGroup.getCode().equals(matGroup.getCode())) {
            List<MatnrGroup> areasList = matnrGroupService.list(new LambdaQueryWrapper<MatnrGroup>().eq(MatnrGroup::getCode, matnrGroup.getCode()));
        if (!Objects.isNull(matnrGroup.getCode()) && !matnrGroup.getCode().equals(matGroup.getCode())) {
            List<MatnrGroup> areasList = matnrGroupService.list(new LambdaQueryWrapper<MatnrGroup>()
                            .eq(!Objects.isNull(matnrGroup.getParCode()), MatnrGroup::getParCode, matnrGroup.getParCode())
                    .eq(MatnrGroup::getCode, matnrGroup.getCode()));
            if (!areasList.isEmpty()) {
                throw new CoolException("仓库编码已存在!!");
                return R.error("仓库编码已存在!!");
            }
        }
@@ -141,18 +156,12 @@
    @PreAuthorize("hasAuthority('manager:matnrGroup:list')")
    @PostMapping("/matnrGroup/tree")
    public R tree(@RequestBody(required = false) Map<String, Object> map) {
        List<MatnrGroup> matnrs = new ArrayList<>();
        if (Objects.isNull(map)) {
            matnrs = matnrGroupService.list(new LambdaQueryWrapper<MatnrGroup>().orderByAsc(MatnrGroup::getCode));
        } else {
            if (Objects.isNull(map.get("condition"))) {
                return R.ok("condition参数不能为空!!");
            }
            matnrs = matnrGroupService.list(new LambdaQueryWrapper<MatnrGroup>()
                    .like(MatnrGroup::getName, map.get("condition")).orderByAsc(MatnrGroup::getCode));
            return R.error("参数不能为空!!");
        }
        List<MatnrGroup> treeData = Utils.toTreeData(matnrs, 0L, MatnrGroup::getParentId, MatnrGroup::getId, MatnrGroup::setChildren);
        return R.ok().add(treeData);
        List<MatnrGroup> matnrs = matnrGroupService.getTreeData(map);
        return R.ok().add(matnrs);
    }