Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
潘荣晟
2025-11-06 16:07:23 +08:00
37 changed files with 1029 additions and 228 deletions

View File

@@ -1,13 +1,23 @@
FROM 172.16.46.66:10043/base-service/eclipse-temurin:21-jre
ARG BASE_IMAGE=172.16.46.66:10043/base-service/skywalking-agent-jre:9.7.0
FROM ${BASE_IMAGE}
# 设置应用目录
RUN mkdir -p /app
WORKDIR /app
# 复制应用文件
COPY target/base-server.jar /app/base-server.jar
COPY target/base-server.jar app.jar
# 设置环境变量
ENV TZ=Asia/Shanghai
ENV JAVA_OPTS="-Xms512m -Xmx512m"
ENV SW_AGENT_HOME=/opt/skywalking/agent
ENV SW_AGENT_NAME=base-server
ENV SW_AGENT_COLLECTOR_BACKEND_SERVICES=172.16.46.63:30201
ENV AGENT_JAVA_OPTS="-javaagent:${SW_AGENT_HOME}/skywalking-agent.jar -Dskywalking.agent.service_name=${SW_AGENT_NAME} -Dskywalking.collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES}"
# 暴露端口
EXPOSE 48200
# 运行应用
ENTRYPOINT ["java", "-jar", "/app/base-server.jar"]
CMD java ${AGENT_JAVA_OPTS} ${JAVA_OPTS} -Djava.security.egd=file:/dev/./urandom -jar app.jar

View File

@@ -53,6 +53,12 @@ public interface ErrorCodeConstants {
ErrorCode DEPARTMENT_MATERIAL_NOT_EXISTS = new ErrorCode(1_027_101_004, "组织物料不存在");
ErrorCode MATERIAL_HAS_CLASSES_NOT_EXISTS = new ErrorCode(1_027_101_004, "物料持有属性不存在");
ErrorCode MATERIAL_CLASSES_HIERARCHY_INVALID = new ErrorCode(1_027_101_101, "物料分类层级不符合 1-2-3 的层级规则");
ErrorCode MATERIAL_CLASSES_PARENT_NOT_EXISTS = new ErrorCode(1_027_101_102, "上级物料分类不存在");
ErrorCode MATERIAL_CLASSES_MAX_LEVEL_EXCEEDED = new ErrorCode(1_027_101_103, "物料分类最多支持三级");
ErrorCode MATERIAL_CLASSES_LEVEL_CONFLICT_WITH_CHILDREN = new ErrorCode(1_027_101_104, "存在下级分类,无法调整当前分类层级");
ErrorCode MATERIAL_CLASSES_LEVEL3_REQUIRED_FOR_MATERIAL = new ErrorCode(1_027_101_105, "仅允许三级物料分类关联物料");
// ========== 工艺信息属性 ==========
ErrorCode PROCESSING_INFOMATION_NOT_EXISTS = new ErrorCode(1_027_101_005, "工艺信息不存在");
ErrorCode PROCESSING_INFOMATION_OPERATION_NOT_EXISTS = new ErrorCode(1_027_101_006, "工艺工序不存在");

View File

@@ -5,12 +5,12 @@ import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.framework.common.pojo.PageParam;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.pojo.vo.BatchDeleteReqVO;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.framework.excel.core.util.ExcelUtils;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationPageReqVO;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationRespVO;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationSaveReqVO;
import com.zt.plat.module.base.dal.dataobject.base.MaterialInfomationDO;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationSimplePageReqVO;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationSimpleRespVO;
import com.zt.plat.module.base.service.base.MaterialInfomationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@@ -76,16 +76,23 @@ public class MaterialInfomationController {
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('base:material-infomation:query')")
public CommonResult<MaterialInfomationRespVO> getMaterialInfomation(@RequestParam("id") Long id) {
MaterialInfomationDO materialInfomation = materialInfomationService.getMaterialInfomation(id);
return success(BeanUtils.toBean(materialInfomation, MaterialInfomationRespVO.class));
MaterialInfomationRespVO materialInfomation = materialInfomationService.getMaterialInfomation(id);
return success(materialInfomation);
}
@GetMapping("/page")
@Operation(summary = "获得物料信息分页")
@PreAuthorize("@ss.hasPermission('base:material-infomation:query')")
public CommonResult<PageResult<MaterialInfomationRespVO>> getMaterialInfomationPage(@Valid MaterialInfomationPageReqVO pageReqVO) {
PageResult<MaterialInfomationDO> pageResult = materialInfomationService.getMaterialInfomationPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, MaterialInfomationRespVO.class));
PageResult<MaterialInfomationRespVO> pageResult = materialInfomationService.getMaterialInfomationPage(pageReqVO);
return success(pageResult);
}
@GetMapping("/simple-page")
@Operation(summary = "获得物料信息精简分页")
@PreAuthorize("@ss.hasPermission('base:material-infomation:query')")
public CommonResult<PageResult<MaterialInfomationSimpleRespVO>> getMaterialInfomationSimplePage(@Valid MaterialInfomationSimplePageReqVO pageReqVO) {
return success(materialInfomationService.getMaterialInfomationSimplePage(pageReqVO));
}
@GetMapping("/export-excel")
@@ -95,10 +102,10 @@ public class MaterialInfomationController {
public void exportMaterialInfomationExcel(@Valid MaterialInfomationPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<MaterialInfomationDO> list = materialInfomationService.getMaterialInfomationPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "物料信息.xls", "数据", MaterialInfomationRespVO.class,
BeanUtils.toBean(list, MaterialInfomationRespVO.class));
List<MaterialInfomationRespVO> list = materialInfomationService.getMaterialInfomationPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "物料信息.xls", "数据", MaterialInfomationRespVO.class,
list);
}
@GetMapping("/getOneTest")

View File

@@ -0,0 +1,22 @@
package com.zt.plat.module.base.controller.admin.base.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import com.zt.plat.framework.common.pojo.PageParam;
/**
* 物料信息精简分页 Request VO
*/
@Schema(description = "管理后台 - 物料信息精简分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
public class MaterialInfomationSimplePageReqVO extends PageParam {
@Schema(description = "关键字(编码/名称模糊匹配)")
private String keyword;
@Schema(description = "分类 ID")
private Long classesId;
}

View File

@@ -0,0 +1,26 @@
package com.zt.plat.module.base.controller.admin.base.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* 精简的物料信息 Response VO
*/
@Data
public class MaterialInfomationSimpleRespVO {
@Schema(description = "物料信息ID", example = "1024")
private Long id;
@Schema(description = "物料编码")
private String code;
@Schema(description = "物料名称")
private String name;
@Schema(description = "分类ID")
private Long classesId;
@Schema(description = "备注")
private String remark;
}

View File

@@ -116,4 +116,12 @@ public class BusinessDictionaryTypeController implements BusinessControllerMarke
return success(businessDictionaryTypeService.getBusinessDictionaryDataListByDictionaryTypeId(dictionaryTypeId));
}
@GetMapping("/business-dictionary-data/list-by-type")
@Operation(summary = "根据字典类型编码获取业务字典数据列表")
@PreAuthorize("@ss.hasPermission('base:business-dictionary-type:query')")
public CommonResult<List<BusinessDictionaryDataDO>> getBusinessDictionaryDataListByType(@RequestParam("type") String type) {
// 通过类型编码直接获取对应的业务字典项,避免前端重复查询字典类型 ID
return success(businessDictionaryTypeService.getBusinessDictionaryDataListByType(type));
}
}

View File

@@ -19,7 +19,6 @@ import com.zt.plat.framework.common.pojo.vo.BatchDeleteReqVO;
import com.zt.plat.framework.common.pojo.PageParam;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.framework.common.util.object.BeanUtils;
import static com.zt.plat.framework.common.pojo.CommonResult.success;
import com.zt.plat.framework.excel.core.util.ExcelUtils;
@@ -79,8 +78,8 @@ public class DepartmentMaterialController {
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('base:department-material:query')")
public CommonResult<DepartmentMaterialRespVO> getDepartmentMaterial(@RequestParam("id") Long id) {
DepartmentMaterialDO departmentMaterial = departmentMaterialService.getDepartmentMaterial(id);
return success(BeanUtils.toBean(departmentMaterial, DepartmentMaterialRespVO.class));
DepartmentMaterialRespVO departmentMaterial = departmentMaterialService.getDepartmentMaterial(id);
return success(departmentMaterial);
}
@GetMapping("/page")

View File

@@ -29,7 +29,8 @@ public class DepartmentMaterialPageReqVO extends PageParam {
private String dictionaryDataValue;
@Schema(description = "状态编码", example = "1")
private String isEnable;
// 对应系统字典 base_material_status用于前端筛选
private String status;
@Schema(description = "物料编码")
private String materialNumber;

View File

@@ -74,10 +74,7 @@ public class DepartmentMaterialRespVO {
@Schema(description = "状态编码")
@ExcelProperty("状态编码")
private String isEnable;
@Schema(description = "状态名称")
@ExcelProperty("状态")
private String statusLabel;
// base_material_status 系统字典取值
private String status;
}

View File

@@ -12,6 +12,10 @@ public class DepartmentMaterialSaveReqVO {
@Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "5674")
private Long id;
@Schema(description = "部门ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "1001")
@NotNull(message = "部门ID不能为空")
private Long deptId;
@Schema(description = "物料信息ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "3923")
@NotNull(message = "物料信息ID不能为空")
private Long infomationId;
@@ -23,6 +27,11 @@ public class DepartmentMaterialSaveReqVO {
@NotEmpty(message = "字典数据值-物料类型不能为空")
private String dictionaryDataValue;
@Schema(description = "状态编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
// 对应系统字典 base_material_status
@NotEmpty(message = "状态不能为空")
private String status;
@Schema(description = "备注", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "备注不能为空")
private String remark;

View File

@@ -1,5 +1,7 @@
package com.zt.plat.module.base.controller.admin.materialproperties;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.module.base.dal.dataobject.materialproperties.MaterialPropertiesDO;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
@@ -19,7 +21,6 @@ import com.zt.plat.framework.common.pojo.vo.BatchDeleteReqVO;
import com.zt.plat.framework.common.pojo.PageParam;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.framework.common.util.object.BeanUtils;
import static com.zt.plat.framework.common.pojo.CommonResult.success;
import com.zt.plat.framework.excel.core.util.ExcelUtils;
@@ -28,7 +29,6 @@ import com.zt.plat.framework.apilog.core.annotation.ApiAccessLog;
import static com.zt.plat.framework.apilog.core.enums.OperateTypeEnum.*;
import com.zt.plat.module.base.controller.admin.materialproperties.vo.*;
import com.zt.plat.module.base.dal.dataobject.materialproperties.MaterialPropertiesDO;
import com.zt.plat.module.base.service.materialproperties.MaterialPropertiesService;
@Tag(name = "管理后台 - 物料属性")
@@ -79,16 +79,23 @@ public class MaterialPropertiesController {
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('base:material-properties:query')")
public CommonResult<MaterialPropertiesRespVO> getMaterialProperties(@RequestParam("id") Long id) {
MaterialPropertiesDO materialProperties = materialPropertiesService.getMaterialProperties(id);
return success(BeanUtils.toBean(materialProperties, MaterialPropertiesRespVO.class));
MaterialPropertiesRespVO materialProperties = materialPropertiesService.getMaterialProperties(id);
return success(materialProperties);
}
@GetMapping("/page")
@Operation(summary = "获得物料属性分页")
@PreAuthorize("@ss.hasPermission('base:material-properties:query')")
public CommonResult<PageResult<MaterialPropertiesRespVO>> getMaterialPropertiesPage(@Valid MaterialPropertiesPageReqVO pageReqVO) {
PageResult<MaterialPropertiesDO> pageResult = materialPropertiesService.getMaterialPropertiesPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, MaterialPropertiesRespVO.class));
PageResult<MaterialPropertiesRespVO> pageResult = materialPropertiesService.getMaterialPropertiesPage(pageReqVO);
return success(pageResult);
}
@GetMapping("/simple-page")
@Operation(summary = "获得物料属性精简分页")
@PreAuthorize("@ss.hasPermission('base:material-properties:query')")
public CommonResult<PageResult<MaterialPropertiesSimpleRespVO>> getMaterialPropertiesSimplePage(@Valid MaterialPropertiesSimplePageReqVO pageReqVO) {
return success(materialPropertiesService.getMaterialPropertiesSimplePage(pageReqVO));
}
@GetMapping("/export-excel")
@@ -98,10 +105,10 @@ public class MaterialPropertiesController {
public void exportMaterialPropertiesExcel(@Valid MaterialPropertiesPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<MaterialPropertiesDO> list = materialPropertiesService.getMaterialPropertiesPage(pageReqVO).getList();
List<MaterialPropertiesRespVO> list = materialPropertiesService.getMaterialPropertiesPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "物料属性.xls", "数据", MaterialPropertiesRespVO.class,
BeanUtils.toBean(list, MaterialPropertiesRespVO.class));
list);
}
}

View File

@@ -19,10 +19,13 @@ public class MaterialPropertiesPageReqVO extends PageParam {
@Schema(description = "属性名称", example = "芋艿")
private String name;
@Schema(description = "关键字(编码/名称模糊匹配)")
private String keyword;
@Schema(description = "计量单位量ID", example = "30468")
private Long unitQuantityId;
@Schema(description = "业务字典数据值")
@Schema(description = "属性类型")
private String dictionaryDataValue;
@Schema(description = "数据类型", example = "1")

View File

@@ -28,10 +28,14 @@ public class MaterialPropertiesRespVO {
@ExcelProperty("计量单位量ID")
private Long unitQuantityId;
@Schema(description = "业务字典数据值", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("业务字典数据值")
@Schema(description = "属性类型", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("属性类型")
private String dictionaryDataValue;
@Schema(description = "属性类型名称")
@ExcelProperty("属性类型名称")
private String dictionaryDataLabel;
@Schema(description = "数据类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
@ExcelProperty("数据类型")
private String dataType;
@@ -40,6 +44,18 @@ public class MaterialPropertiesRespVO {
@ExcelProperty("备注")
private String remark;
@Schema(description = "量纲名称")
@ExcelProperty("量纲名称")
private String unitQuantityName;
@Schema(description = "计量单位名称")
@ExcelProperty("计量单位")
private String unitName;
@Schema(description = "计量单位符号")
@ExcelProperty("计量单位符号")
private String unitSymbol;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;

View File

@@ -20,11 +20,11 @@ public class MaterialPropertiesSaveReqVO {
@NotEmpty(message = "属性名称不能为空")
private String name;
@Schema(description = "计量单位量ID", example = "30468")
@Schema(description = "计量单位量ID", requiredMode = Schema.RequiredMode.NOT_REQUIRED, example = "30468")
private Long unitQuantityId;
@Schema(description = "业务字典数据值", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "业务字典数据值不能为空")
@Schema(description = "属性类型(业务字典数据值)", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "属性类型不能为空")
private String dictionaryDataValue;
@Schema(description = "数据类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")

View File

@@ -0,0 +1,16 @@
package com.zt.plat.module.base.controller.admin.materialproperties.vo;
import com.zt.plat.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - 物料属性精简分页 Request VO")
@Data
public class MaterialPropertiesSimplePageReqVO extends PageParam {
@Schema(description = "关键字(编码/名称模糊匹配)")
private String keyword;
@Schema(description = "属性类型")
private String dictionaryDataValue;
}

View File

@@ -0,0 +1,35 @@
package com.zt.plat.module.base.controller.admin.materialproperties.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* 精简的物料属性 Response VO
*/
@Data
public class MaterialPropertiesSimpleRespVO {
@Schema(description = "物料属性ID", example = "1001")
private Long id;
@Schema(description = "属性编码")
private String code;
@Schema(description = "属性名称")
private String name;
@Schema(description = "数据类型")
private String dataType;
@Schema(description = "单位名称")
private String unitName;
@Schema(description = "单位符号")
private String unitSymbol;
@Schema(description = "属性类型")
private String dictionaryDataValue;
@Schema(description = "属性类型名称")
private String dictionaryDataLabel;
}

View File

@@ -91,6 +91,13 @@ public class QuantityUnitRelationController implements BusinessControllerMarker
return success(BeanUtils.toBean(pageResult, QuantityUnitRelationRespVO.class));
}
@GetMapping("/simple-page")
@Operation(summary = "获得计量单位量与单位关联精简分页")
@PreAuthorize("@ss.hasPermission('unitmanagement:quantity-unit-relation:query')")
public CommonResult<PageResult<QuantityUnitRelationSimpleRespVO>> getQuantityUnitRelationSimplePage(@Valid QuantityUnitRelationSimplePageReqVO pageReqVO) {
return success(quantityUnitRelationService.getQuantityUnitRelationSimplePage(pageReqVO));
}
@GetMapping("/export-excel")
@Operation(summary = "导出计量单位量与单位关联 Excel")
@PreAuthorize("@ss.hasPermission('unitmanagement:quantity-unit-relation:export')")

View File

@@ -0,0 +1,22 @@
package com.zt.plat.module.base.controller.admin.quantityUnitRelation.vo;
import com.zt.plat.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
/**
* 计量单位量与单位关联精简分页 Request VO
*/
@Schema(description = "管理后台 - 计量单位量与单位关联精简分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
public class QuantityUnitRelationSimplePageReqVO extends PageParam {
@Schema(description = "量纲ID")
private Long untQtyId;
@Schema(description = "关键字(量纲/单位名称、符号模糊匹配)")
private String keyword;
}

View File

@@ -0,0 +1,33 @@
package com.zt.plat.module.base.controller.admin.quantityUnitRelation.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
/**
* 精简的量纲-单位关联响应
*/
@Data
public class QuantityUnitRelationSimpleRespVO {
@Schema(description = "关联关系ID", example = "1001")
private Long id;
@Schema(description = "量纲ID", example = "2001")
private Long untQtyId;
@Schema(description = "量纲名称")
private String untQtyName;
@Schema(description = "计量单位ID", example = "3001")
private Long untId;
@Schema(description = "计量单位名称")
private String untName;
@Schema(description = "计量单位符号")
private String untSymbol;
@Schema(description = "是否基准单位1表示是0表示否")
private Integer isBse;
}

View File

@@ -2,7 +2,9 @@ package com.zt.plat.module.base.dal.dao.businessdictionarytype;
import java.util.*;
import cn.hutool.core.collection.CollUtil;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.module.base.dal.dataobject.businessdictionarytype.BusinessDictionaryDataDO;
import org.apache.ibatis.annotations.Mapper;
@@ -26,4 +28,16 @@ public interface BusinessDictionaryDataMapper extends BaseMapperX<BusinessDictio
return deleteBatch(BusinessDictionaryDataDO::getDictionaryTypeId, dictionaryTypeIds);
}
default List<BusinessDictionaryDataDO> selectListByValues(Iterable<String> values) {
if (values == null || !values.iterator().hasNext()) {
return CollUtil.newArrayList();
}
List<String> valueList = CollUtil.newArrayList(values);
if (CollUtil.isEmpty(valueList)) {
return CollUtil.newArrayList();
}
return selectList(new LambdaQueryWrapperX<BusinessDictionaryDataDO>()
.in(BusinessDictionaryDataDO::getValue, valueList));
}
}

View File

@@ -23,4 +23,8 @@ public interface BusinessDictionaryTypeMapper extends BaseMapperX<BusinessDictio
.orderByDesc(BusinessDictionaryTypeDO::getId));
}
default BusinessDictionaryTypeDO selectByType(String type) {
return selectOne(BusinessDictionaryTypeDO::getType, type);
}
}

View File

@@ -24,6 +24,7 @@ public interface DepartmentMaterialMapper extends BaseMapperX<DepartmentMaterial
.eqIfPresent(DepartmentMaterialDO::getClassesId, reqVO.getClassesId())
.eqIfPresent(DepartmentMaterialDO::getDeptId, reqVO.getDeptId())
.eqIfPresent(DepartmentMaterialDO::getDictionaryDataValue, reqVO.getDictionaryDataValue())
.eqIfPresent(DepartmentMaterialDO::getStatus, reqVO.getStatus())
.eqIfPresent(DepartmentMaterialDO::getRemark, reqVO.getRemark())
.betweenIfPresent(DepartmentMaterialDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(DepartmentMaterialDO::getId));

View File

@@ -1,13 +1,13 @@
package com.zt.plat.module.base.dal.dao.materialproperties;
import java.util.*;
import cn.hutool.core.util.StrUtil;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.module.base.controller.admin.materialproperties.vo.MaterialPropertiesPageReqVO;
import com.zt.plat.module.base.controller.admin.materialproperties.vo.MaterialPropertiesSimplePageReqVO;
import com.zt.plat.module.base.dal.dataobject.materialproperties.MaterialPropertiesDO;
import org.apache.ibatis.annotations.Mapper;
import com.zt.plat.module.base.controller.admin.materialproperties.vo.*;
/**
* 物料属性 Mapper
@@ -18,15 +18,33 @@ import com.zt.plat.module.base.controller.admin.materialproperties.vo.*;
public interface MaterialPropertiesMapper extends BaseMapperX<MaterialPropertiesDO> {
default PageResult<MaterialPropertiesDO> selectPage(MaterialPropertiesPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<MaterialPropertiesDO>()
.eqIfPresent(MaterialPropertiesDO::getCode, reqVO.getCode())
.likeIfPresent(MaterialPropertiesDO::getName, reqVO.getName())
.eqIfPresent(MaterialPropertiesDO::getUnitQuantityId, reqVO.getUnitQuantityId())
.eqIfPresent(MaterialPropertiesDO::getDictionaryDataValue, reqVO.getDictionaryDataValue())
.eqIfPresent(MaterialPropertiesDO::getDataType, reqVO.getDataType())
.eqIfPresent(MaterialPropertiesDO::getRemark, reqVO.getRemark())
.betweenIfPresent(MaterialPropertiesDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(MaterialPropertiesDO::getId));
LambdaQueryWrapperX<MaterialPropertiesDO> query = new LambdaQueryWrapperX<MaterialPropertiesDO>()
.eqIfPresent(MaterialPropertiesDO::getCode, reqVO.getCode())
.likeIfPresent(MaterialPropertiesDO::getName, reqVO.getName())
.eqIfPresent(MaterialPropertiesDO::getUnitQuantityId, reqVO.getUnitQuantityId())
.eqIfPresent(MaterialPropertiesDO::getDictionaryDataValue, reqVO.getDictionaryDataValue())
.eqIfPresent(MaterialPropertiesDO::getDataType, reqVO.getDataType())
.eqIfPresent(MaterialPropertiesDO::getRemark, reqVO.getRemark())
.betweenIfPresent(MaterialPropertiesDO::getCreateTime, reqVO.getCreateTime());
if (StrUtil.isNotBlank(reqVO.getKeyword())) {
query.and(w -> w.like(MaterialPropertiesDO::getCode, reqVO.getKeyword())
.or()
.like(MaterialPropertiesDO::getName, reqVO.getKeyword()));
}
query.orderByDesc(MaterialPropertiesDO::getId);
return selectPage(reqVO, query);
}
default PageResult<MaterialPropertiesDO> selectSimplePage(MaterialPropertiesSimplePageReqVO reqVO) {
LambdaQueryWrapperX<MaterialPropertiesDO> query = new LambdaQueryWrapperX<MaterialPropertiesDO>()
.eqIfPresent(MaterialPropertiesDO::getDictionaryDataValue, reqVO.getDictionaryDataValue());
if (StrUtil.isNotBlank(reqVO.getKeyword())) {
query.and(w -> w.like(MaterialPropertiesDO::getCode, reqVO.getKeyword())
.or()
.like(MaterialPropertiesDO::getName, reqVO.getKeyword()));
}
query.orderByAsc(MaterialPropertiesDO::getCode);
return selectPage(reqVO, query);
}
}

View File

@@ -1,13 +1,14 @@
package com.zt.plat.module.base.dal.dao.quantityUnitRelation;
import java.util.*;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.module.base.controller.admin.quantityUnitRelation.vo.QuantityUnitRelationPageReqVO;
import com.zt.plat.module.base.controller.admin.quantityUnitRelation.vo.QuantityUnitRelationSimplePageReqVO;
import com.zt.plat.module.base.dal.dataobject.quantityUnitRelation.QuantityUnitRelationDO;
import org.apache.ibatis.annotations.Mapper;
import com.zt.plat.module.base.controller.admin.quantityUnitRelation.vo.*;
import java.util.List;
/**
* 计量单位量与单位关联 Mapper
@@ -24,6 +25,10 @@ public interface QuantityUnitRelationMapper extends BaseMapperX<QuantityUnitRela
.orderByDesc(QuantityUnitRelationDO::getUntQtyId));
}
default PageResult<QuantityUnitRelationDO> selectSimplePage(QuantityUnitRelationSimplePageReqVO reqVO, LambdaQueryWrapperX<QuantityUnitRelationDO> wrapper) {
return BaseMapperX.super.selectPage(reqVO, wrapper);
}
/**
* 根据量纲ID查询所有关联关系
*

View File

@@ -52,6 +52,11 @@ public class DepartmentMaterialDO extends BaseDO {
@TableField("DIC_DAT_VAL")
private String dictionaryDataValue;
/**
* 状态编码,对应系统字典 base_material_status
*/
@TableField("STS")
private String status;
/**
* 备注
*/
@TableField("RMK")

View File

@@ -4,6 +4,7 @@ import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.mybatis.core.mapper.BaseMapperX;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationPageReqVO;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationSimplePageReqVO;
import com.zt.plat.module.base.dal.dataobject.base.MaterialInfomationDO;
import org.apache.ibatis.annotations.Mapper;
@@ -31,4 +32,8 @@ public interface MaterialInfomationMapper extends BaseMapperX<MaterialInfomation
.orderByDesc(MaterialInfomationDO::getId));
}
default PageResult<MaterialInfomationDO> selectSimplePage(MaterialInfomationSimplePageReqVO reqVO, LambdaQueryWrapperX<MaterialInfomationDO> wrapper) {
return BaseMapperX.super.selectPage(reqVO, wrapper);
}
}

View File

@@ -4,6 +4,8 @@ import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationPageReqVO;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationRespVO;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationSaveReqVO;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationSimplePageReqVO;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationSimpleRespVO;
import com.zt.plat.module.base.dal.dataobject.base.MaterialInfomationDO;
import jakarta.validation.Valid;
@@ -51,7 +53,7 @@ public interface MaterialInfomationService {
* @param id 编号
* @return 物料信息
*/
MaterialInfomationDO getMaterialInfomation(Long id);
MaterialInfomationRespVO getMaterialInfomation(Long id);
/**
* 获得物料信息分页
@@ -59,7 +61,15 @@ public interface MaterialInfomationService {
* @param pageReqVO 分页查询
* @return 物料信息分页
*/
PageResult<MaterialInfomationDO> getMaterialInfomationPage(MaterialInfomationPageReqVO pageReqVO);
PageResult<MaterialInfomationRespVO> getMaterialInfomationPage(MaterialInfomationPageReqVO pageReqVO);
String getOneTest();
/**
* 获得精简的物料信息分页
*
* @param pageReqVO 分页参数
* @return 精简分页列表
*/
PageResult<MaterialInfomationSimpleRespVO> getMaterialInfomationSimplePage(MaterialInfomationSimplePageReqVO pageReqVO);
}

View File

@@ -1,15 +1,21 @@
package com.zt.plat.module.base.service.base;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.zt.plat.framework.common.pojo.CommonResult;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationPageReqVO;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationRespVO;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationSaveReqVO;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationSimplePageReqVO;
import com.zt.plat.module.base.controller.admin.base.vo.MaterialInfomationSimpleRespVO;
import com.zt.plat.module.base.dal.dao.materialclasses.MaterialClassesMapper;
import com.zt.plat.module.base.dal.dao.materialhasclasses.MaterialHasClassesMapper;
import com.zt.plat.module.base.dal.dataobject.base.MaterialInfomationDO;
import com.zt.plat.module.base.dal.dataobject.materialclasses.MaterialClassesDO;
import com.zt.plat.module.base.dal.dataobject.materialhasclasses.MaterialHasClassesDO;
import com.zt.plat.module.base.dal.mysql.base.MaterialInfomationMapper;
import com.zt.plat.module.erp.api.ErpExternalApi;
@@ -20,12 +26,16 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.zt.plat.module.base.enums.ErrorCodeConstants.MATERIAL_CLASSES_LEVEL3_REQUIRED_FOR_MATERIAL;
import static com.zt.plat.module.base.enums.ErrorCodeConstants.MATERIAL_CLASSES_NOT_EXISTS;
import static com.zt.plat.module.base.enums.ErrorCodeConstants.MATERIAL_INFOMATION_NOT_EXISTS;
/**
@@ -37,143 +47,254 @@ import static com.zt.plat.module.base.enums.ErrorCodeConstants.MATERIAL_INFOMATI
@Validated
public class MaterialInfomationServiceImpl implements MaterialInfomationService {
@Resource
private MaterialInfomationMapper materialInfomationMapper;
@Resource
private MaterialInfomationMapper materialInfomationMapper;
@Resource
private ErpExternalApi erpExternalApi;
@Resource
private ErpExternalApi erpExternalApi;
@Resource
private MaterialHasClassesMapper materialHasClassesMapper;
@Resource
private MaterialHasClassesMapper materialHasClassesMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public MaterialInfomationRespVO createMaterialInfomation(MaterialInfomationSaveReqVO createReqVO) {
// 插入
MaterialInfomationDO materialInfomation = BeanUtils.toBean(createReqVO, MaterialInfomationDO.class);
materialInfomationMapper.insert(materialInfomation);
// 维护分类关联
if (createReqVO.getClassesId() != null) {
MaterialHasClassesDO relation = MaterialHasClassesDO.builder()
.classesId(createReqVO.getClassesId())
.infomationId(materialInfomation.getId())
.build();
materialHasClassesMapper.insert(relation);
materialInfomation.setClassesId(createReqVO.getClassesId());
}
// 返回
return BeanUtils.toBean(materialInfomation, MaterialInfomationRespVO.class);
}
@Resource
private MaterialClassesMapper materialClassesMapper;
@Override
@Transactional(rollbackFor = Exception.class)
public void updateMaterialInfomation(MaterialInfomationSaveReqVO updateReqVO) {
// 校验存在
validateMaterialInfomationExists(updateReqVO.getId());
// 更新
MaterialInfomationDO updateObj = BeanUtils.toBean(updateReqVO, MaterialInfomationDO.class);
materialInfomationMapper.updateById(updateObj);
// 更新分类关联
materialHasClassesMapper.delete(new LambdaUpdateWrapper<MaterialHasClassesDO>()
.eq(MaterialHasClassesDO::getInfomationId, updateReqVO.getId()));
if (updateReqVO.getClassesId() != null) {
MaterialHasClassesDO relation = MaterialHasClassesDO.builder()
.classesId(updateReqVO.getClassesId())
.infomationId(updateReqVO.getId())
.build();
materialHasClassesMapper.insert(relation);
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public MaterialInfomationRespVO createMaterialInfomation(MaterialInfomationSaveReqVO createReqVO) {
validateMaterialClassForBinding(createReqVO.getClassesId());
MaterialInfomationDO materialInfomation = BeanUtils.toBean(createReqVO, MaterialInfomationDO.class);
materialInfomationMapper.insert(materialInfomation);
if (createReqVO.getClassesId() != null) {
MaterialHasClassesDO relation = MaterialHasClassesDO.builder()
.classesId(createReqVO.getClassesId())
.infomationId(materialInfomation.getId())
.build();
materialHasClassesMapper.insert(relation);
materialInfomation.setClassesId(createReqVO.getClassesId());
}
return CollUtil.getFirst(buildRespList(Collections.singletonList(materialInfomation)));
}
@Override
public void deleteMaterialInfomation(Long id) {
// 校验存在
validateMaterialInfomationExists(id);
// 删除
materialInfomationMapper.deleteById(id);
materialHasClassesMapper.delete(new LambdaUpdateWrapper<MaterialHasClassesDO>()
.eq(MaterialHasClassesDO::getInfomationId, id));
}
@Override
@Transactional(rollbackFor = Exception.class)
public void updateMaterialInfomation(MaterialInfomationSaveReqVO updateReqVO) {
validateMaterialInfomationExists(updateReqVO.getId());
validateMaterialClassForBinding(updateReqVO.getClassesId());
MaterialInfomationDO updateObj = BeanUtils.toBean(updateReqVO, MaterialInfomationDO.class);
materialInfomationMapper.updateById(updateObj);
materialHasClassesMapper.delete(new LambdaUpdateWrapper<MaterialHasClassesDO>()
.eq(MaterialHasClassesDO::getInfomationId, updateReqVO.getId()));
if (updateReqVO.getClassesId() != null) {
MaterialHasClassesDO relation = MaterialHasClassesDO.builder()
.classesId(updateReqVO.getClassesId())
.infomationId(updateReqVO.getId())
.build();
materialHasClassesMapper.insert(relation);
}
}
@Override
public void deleteMaterialInfomationListByIds(List<Long> ids) {
// 校验存在
validateMaterialInfomationExists(ids);
// 删除
materialInfomationMapper.deleteByIds(ids);
}
@Override
public void deleteMaterialInfomation(Long id) {
validateMaterialInfomationExists(id);
materialInfomationMapper.deleteById(id);
materialHasClassesMapper.delete(new LambdaUpdateWrapper<MaterialHasClassesDO>()
.eq(MaterialHasClassesDO::getInfomationId, id));
}
private void validateMaterialInfomationExists(List<Long> ids) {
List<MaterialInfomationDO> list = materialInfomationMapper.selectByIds(ids);
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
throw exception(MATERIAL_INFOMATION_NOT_EXISTS);
}
}
@Override
public void deleteMaterialInfomationListByIds(List<Long> ids) {
validateMaterialInfomationExists(ids);
materialInfomationMapper.deleteByIds(ids);
}
private void validateMaterialInfomationExists(Long id) {
if (materialInfomationMapper.selectById(id) == null) {
throw exception(MATERIAL_INFOMATION_NOT_EXISTS);
}
}
private void validateMaterialInfomationExists(List<Long> ids) {
List<MaterialInfomationDO> list = materialInfomationMapper.selectByIds(ids);
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
throw exception(MATERIAL_INFOMATION_NOT_EXISTS);
}
}
@Override
public MaterialInfomationDO getMaterialInfomation(Long id) {
MaterialInfomationDO info = materialInfomationMapper.selectById(id);
if (info == null) {
return null;
}
MaterialHasClassesDO relation = materialHasClassesMapper.selectFirstOne(MaterialHasClassesDO::getInfomationId, id);
if (relation != null) {
info.setClassesId(relation.getClassesId());
}
return info;
}
private void validateMaterialInfomationExists(Long id) {
if (materialInfomationMapper.selectById(id) == null) {
throw exception(MATERIAL_INFOMATION_NOT_EXISTS);
}
}
@Override
public PageResult<MaterialInfomationDO> getMaterialInfomationPage(MaterialInfomationPageReqVO pageReqVO) {
List<Long> infomationIds = null;
List<MaterialHasClassesDO> relationList = Collections.emptyList();
if (pageReqVO.getClassesId() != null) {
relationList = materialHasClassesMapper.selectList(MaterialHasClassesDO::getClassesId, pageReqVO.getClassesId());
if (CollUtil.isEmpty(relationList)) {
return PageResult.empty();
}
infomationIds = relationList.stream()
.map(MaterialHasClassesDO::getInfomationId)
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList());
}
private void validateMaterialClassForBinding(Long classesId) {
if (classesId == null) {
throw exception(MATERIAL_CLASSES_LEVEL3_REQUIRED_FOR_MATERIAL);
}
MaterialClassesDO materialClasses = materialClassesMapper.selectById(classesId);
if (materialClasses == null) {
throw exception(MATERIAL_CLASSES_NOT_EXISTS);
}
if (!isThirdLevelClass(materialClasses)) {
throw exception(MATERIAL_CLASSES_LEVEL3_REQUIRED_FOR_MATERIAL);
}
}
PageResult<MaterialInfomationDO> pageResult = materialInfomationMapper.selectPage(pageReqVO, infomationIds);
if (CollUtil.isEmpty(pageResult.getList())) {
return pageResult;
}
private boolean isThirdLevelClass(MaterialClassesDO materialClasses) {
Long level = materialClasses.getLevel();
if (Objects.equals(level, 3L)) {
return true;
}
if (level != null && level > 3L) {
return false;
}
Long depth = resolveClassDepth(materialClasses);
return depth != null && depth == 3L;
}
List<Long> currentInfoIds = pageResult.getList().stream()
.map(MaterialInfomationDO::getId)
.collect(Collectors.toList());
private Long resolveClassDepth(MaterialClassesDO materialClasses) {
long depth = 1L;
Set<Long> visited = new HashSet<>();
if (materialClasses.getId() != null) {
visited.add(materialClasses.getId());
}
Long parentId = materialClasses.getParentId();
while (parentId != null) {
if (!visited.add(parentId)) {
return null;
}
MaterialClassesDO parent = materialClassesMapper.selectById(parentId);
if (parent == null) {
return null;
}
depth++;
if (depth > 3L) {
return depth;
}
parentId = parent.getParentId();
}
return depth;
}
if (pageReqVO.getClassesId() == null) {
relationList = materialHasClassesMapper.selectList(MaterialHasClassesDO::getInfomationId, currentInfoIds);
}
@Override
public MaterialInfomationRespVO getMaterialInfomation(Long id) {
MaterialInfomationDO info = materialInfomationMapper.selectById(id);
if (info == null) {
return null;
}
MaterialHasClassesDO relation = materialHasClassesMapper.selectFirstOne(MaterialHasClassesDO::getInfomationId, id);
if (relation != null) {
info.setClassesId(relation.getClassesId());
}
return CollUtil.getFirst(buildRespList(Collections.singletonList(info)));
}
Map<Long, Long> infoClassMap = relationList.stream()
.filter(item -> item.getInfomationId() != null)
.collect(Collectors.toMap(MaterialHasClassesDO::getInfomationId, MaterialHasClassesDO::getClassesId, (existing, replacement) -> existing));
@Override
public PageResult<MaterialInfomationRespVO> getMaterialInfomationPage(MaterialInfomationPageReqVO pageReqVO) {
List<Long> infomationIds = null;
List<MaterialHasClassesDO> relationList = Collections.emptyList();
if (pageReqVO.getClassesId() != null) {
relationList = materialHasClassesMapper.selectList(MaterialHasClassesDO::getClassesId, pageReqVO.getClassesId());
if (CollUtil.isEmpty(relationList)) {
return PageResult.empty();
}
infomationIds = relationList.stream()
.map(MaterialHasClassesDO::getInfomationId)
.filter(Objects::nonNull)
.distinct()
.collect(Collectors.toList());
}
pageResult.getList().forEach(item -> item.setClassesId(infoClassMap.get(item.getId())));
return pageResult;
}
PageResult<MaterialInfomationDO> pageResult = materialInfomationMapper.selectPage(pageReqVO, infomationIds);
if (CollUtil.isEmpty(pageResult.getList())) {
return PageResult.empty(pageResult.getTotal());
}
@Override
public String getOneTest() {
ErpProductiveVersionReqDTO reqDTO = new ErpProductiveVersionReqDTO();
reqDTO.setFactoryNumber("5020");
reqDTO.setMaterialNumber("224814");
CommonResult<String> erpProductiveVersion = erpExternalApi.getErpProductiveVersionByFM(reqDTO);
return erpProductiveVersion.getData();
}
List<Long> currentInfoIds = pageResult.getList().stream()
.map(MaterialInfomationDO::getId)
.collect(Collectors.toList());
if (pageReqVO.getClassesId() == null) {
relationList = materialHasClassesMapper.selectList(MaterialHasClassesDO::getInfomationId, currentInfoIds);
}
Map<Long, Long> infoClassMap = relationList.stream()
.filter(item -> item.getInfomationId() != null)
.collect(Collectors.toMap(MaterialHasClassesDO::getInfomationId, MaterialHasClassesDO::getClassesId, (existing, replacement) -> existing));
pageResult.getList().forEach(item -> item.setClassesId(infoClassMap.get(item.getId())));
List<MaterialInfomationRespVO> respList = buildRespList(pageResult.getList());
return new PageResult<>(respList, pageResult.getTotal());
}
@Override
public String getOneTest() {
ErpProductiveVersionReqDTO reqDTO = new ErpProductiveVersionReqDTO();
reqDTO.setFactoryNumber("5020");
reqDTO.setMaterialNumber("224814");
CommonResult<String> erpProductiveVersion = erpExternalApi.getErpProductiveVersionByFM(reqDTO);
return erpProductiveVersion.getData();
}
@Override
public PageResult<MaterialInfomationSimpleRespVO> getMaterialInfomationSimplePage(MaterialInfomationSimplePageReqVO pageReqVO) {
LambdaQueryWrapperX<MaterialInfomationDO> wrapper = new LambdaQueryWrapperX<>();
if (StrUtil.isNotBlank(pageReqVO.getKeyword())) {
wrapper.and(w -> w.like(MaterialInfomationDO::getCode, pageReqVO.getKeyword())
.or().like(MaterialInfomationDO::getName, pageReqVO.getKeyword()));
}
Map<Long, Long> infoClassMap = Collections.emptyMap();
if (pageReqVO.getClassesId() != null) {
List<MaterialHasClassesDO> relations = materialHasClassesMapper.selectList(MaterialHasClassesDO::getClassesId, pageReqVO.getClassesId());
if (CollUtil.isEmpty(relations)) {
return new PageResult<>(Collections.emptyList(), 0L);
}
List<Long> infoIds = relations.stream()
.map(MaterialHasClassesDO::getInfomationId)
.filter(Objects::nonNull)
.distinct()
.toList();
if (CollUtil.isEmpty(infoIds)) {
return new PageResult<>(Collections.emptyList(), 0L);
}
wrapper.in(MaterialInfomationDO::getId, infoIds);
infoClassMap = relations.stream()
.filter(item -> item.getInfomationId() != null)
.collect(Collectors.toMap(MaterialHasClassesDO::getInfomationId,
MaterialHasClassesDO::getClassesId, (existing, replacement) -> existing));
}
wrapper.orderByAsc(MaterialInfomationDO::getCode);
PageResult<MaterialInfomationDO> pageResult = materialInfomationMapper.selectSimplePage(pageReqVO, wrapper);
if (CollUtil.isEmpty(pageResult.getList())) {
return new PageResult<>(Collections.emptyList(), pageResult.getTotal());
}
if (pageReqVO.getClassesId() == null) {
List<Long> infoIds = pageResult.getList().stream().map(MaterialInfomationDO::getId).toList();
List<MaterialHasClassesDO> relations = materialHasClassesMapper.selectList(MaterialHasClassesDO::getInfomationId, infoIds);
infoClassMap = relations.stream()
.filter(item -> item.getInfomationId() != null)
.collect(Collectors.toMap(MaterialHasClassesDO::getInfomationId,
MaterialHasClassesDO::getClassesId, (existing, replacement) -> existing));
}
Map<Long, Long> finalInfoClassMap = infoClassMap;
List<MaterialInfomationSimpleRespVO> respList = pageResult.getList().stream().map(item -> {
MaterialInfomationSimpleRespVO vo = new MaterialInfomationSimpleRespVO();
vo.setId(item.getId());
vo.setCode(item.getCode());
vo.setName(item.getName());
vo.setRemark(item.getRemark());
vo.setClassesId(finalInfoClassMap.get(item.getId()));
return vo;
}).collect(Collectors.toList());
return new PageResult<>(respList, pageResult.getTotal());
}
private List<MaterialInfomationRespVO> buildRespList(List<MaterialInfomationDO> list) {
if (CollUtil.isEmpty(list)) {
return Collections.emptyList();
}
return list.stream()
.map(item -> BeanUtils.toBean(item, MaterialInfomationRespVO.class))
.collect(Collectors.toList());
}
}

View File

@@ -69,4 +69,12 @@ public interface BusinessDictionaryTypeService {
*/
List<BusinessDictionaryDataDO> getBusinessDictionaryDataListByDictionaryTypeId(Long dictionaryTypeId);
/**
* 根据字典类型编码获取业务字典数据列表
*
* @param type 字典类型编码
* @return 字典数据列表
*/
List<BusinessDictionaryDataDO> getBusinessDictionaryDataListByType(String type);
}

View File

@@ -2,6 +2,7 @@ package com.zt.plat.module.base.service.businessdictionarytype;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
@@ -116,6 +117,19 @@ public class BusinessDictionaryTypeServiceImpl implements BusinessDictionaryType
return businessDictionaryDataMapper.selectListByDictionaryTypeId(dictionaryTypeId);
}
@Override
public List<BusinessDictionaryDataDO> getBusinessDictionaryDataListByType(String type) {
if (StrUtil.isBlank(type)) {
return Collections.emptyList();
}
BusinessDictionaryTypeDO dictionaryType = businessDictionaryTypeMapper.selectByType(type);
if (dictionaryType == null) {
return Collections.emptyList();
}
// 直接根据类型编码定位字典类型,简化前端查询流程
return businessDictionaryDataMapper.selectListByDictionaryTypeId(dictionaryType.getId());
}
private void createBusinessDictionaryDataList(Long dictionaryTypeId, List<BusinessDictionaryDataDO> list) {
list.forEach(o -> o.setDictionaryTypeId(dictionaryTypeId).clean());
businessDictionaryDataMapper.insertBatch(list);

View File

@@ -49,7 +49,7 @@ public interface DepartmentMaterialService {
* @param id 编号
* @return 组织架构物料
*/
DepartmentMaterialDO getDepartmentMaterial(Long id);
DepartmentMaterialRespVO getDepartmentMaterial(Long id);
/**
* 获得组织架构物料分页

View File

@@ -13,7 +13,6 @@ import java.util.stream.Collectors;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.util.collection.CollectionUtils;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.module.base.controller.admin.departmentmaterial.vo.*;
import com.zt.plat.module.base.dal.dao.departmentmaterial.DepartmentMaterialMapper;
import com.zt.plat.module.base.dal.dao.materialclasses.MaterialClassesMapper;
@@ -21,6 +20,9 @@ import com.zt.plat.module.base.dal.dataobject.base.MaterialInfomationDO;
import com.zt.plat.module.base.dal.dataobject.departmentmaterial.DepartmentMaterialDO;
import com.zt.plat.module.base.dal.dataobject.materialclasses.MaterialClassesDO;
import com.zt.plat.module.base.dal.mysql.base.MaterialInfomationMapper;
import com.zt.plat.module.base.dal.dao.businessdictionarytype.BusinessDictionaryDataMapper;
import com.zt.plat.module.base.dal.dataobject.businessdictionarytype.BusinessDictionaryDataDO;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.module.system.api.dept.DeptApi;
import com.zt.plat.module.system.api.dept.dto.DeptRespDTO;
@@ -45,6 +47,9 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
@Resource
private MaterialClassesMapper materialClassesMapper;
@Resource
private BusinessDictionaryDataMapper businessDictionaryDataMapper;
@Resource
private DeptApi deptApi;
@@ -53,8 +58,8 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
// 插入
DepartmentMaterialDO departmentMaterial = BeanUtils.toBean(createReqVO, DepartmentMaterialDO.class);
departmentMaterialMapper.insert(departmentMaterial);
// 返回
return BeanUtils.toBean(departmentMaterial, DepartmentMaterialRespVO.class);
// 构造完整响应,方便前端直接刷新数据
return CollUtil.getFirst(decorateDepartmentMaterials(Collections.singletonList(departmentMaterial)));
}
@Override
@@ -96,8 +101,12 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
}
@Override
public DepartmentMaterialDO getDepartmentMaterial(Long id) {
return departmentMaterialMapper.selectById(id);
public DepartmentMaterialRespVO getDepartmentMaterial(Long id) {
DepartmentMaterialDO data = departmentMaterialMapper.selectById(id);
if (data == null) {
return null;
}
return CollUtil.getFirst(decorateDepartmentMaterials(Collections.singletonList(data)));
}
@Override
@@ -124,8 +133,17 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
return PageResult.empty(pageResult.getTotal());
}
List<DepartmentMaterialRespVO> respList = decorateDepartmentMaterials(pageResult.getList());
return new PageResult<>(respList, pageResult.getTotal());
}
private List<DepartmentMaterialRespVO> decorateDepartmentMaterials(List<DepartmentMaterialDO> sourceList) {
if (CollUtil.isEmpty(sourceList)) {
return Collections.emptyList();
}
// 关联数据准备
Set<Long> infoIds = pageResult.getList().stream()
Set<Long> infoIds = sourceList.stream()
.map(DepartmentMaterialDO::getInfomationId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
@@ -136,7 +154,7 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
.collect(Collectors.toMap(MaterialInfomationDO::getId, Function.identity()));
Set<Long> classIds = new HashSet<>();
pageResult.getList().forEach(item -> {
sourceList.forEach(item -> {
if (item.getClassesId() != null) {
classIds.add(item.getClassesId());
}
@@ -148,13 +166,13 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
Map<Long, MaterialClassesDO> classCache = loadClassHierarchy(classIds);
Set<Long> deptIds = pageResult.getList().stream()
Set<Long> deptIds = sourceList.stream()
.map(DepartmentMaterialDO::getDeptId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
Map<Long, DeptRespDTO> deptMap = Collections.emptyMap();
if (!deptIds.isEmpty()) {
if (CollUtil.isNotEmpty(deptIds)) {
try {
deptMap = CollectionUtils.convertMap(deptApi.getDeptList(deptIds).getCheckedData(), DeptRespDTO::getId);
} catch (Exception ignore) {
@@ -162,8 +180,18 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
}
}
List<DepartmentMaterialRespVO> respList = new ArrayList<>(pageResult.getList().size());
for (DepartmentMaterialDO item : pageResult.getList()) {
Set<String> dictionaryValues = sourceList.stream()
.map(DepartmentMaterialDO::getDictionaryDataValue)
.filter(StrUtil::isNotBlank)
.collect(Collectors.toSet());
Map<String, BusinessDictionaryDataDO> dictionaryMap = dictionaryValues.isEmpty()
? Collections.emptyMap()
: businessDictionaryDataMapper.selectListByValues(dictionaryValues).stream()
.filter(Objects::nonNull)
.collect(Collectors.toMap(BusinessDictionaryDataDO::getValue, Function.identity(), (exist, replace) -> exist));
List<DepartmentMaterialRespVO> respList = new ArrayList<>(sourceList.size());
for (DepartmentMaterialDO item : sourceList) {
DepartmentMaterialRespVO respVO = BeanUtils.toBean(item, DepartmentMaterialRespVO.class);
MaterialInfomationDO info = infoMap.get(item.getInfomationId());
@@ -195,13 +223,16 @@ public class DepartmentMaterialServiceImpl implements DepartmentMaterialService
respVO.setDeptName(deptRespDTO.getName());
}
respVO.setStatusLabel(StrUtil.isNotBlank(respVO.getStatusLabel()) ? respVO.getStatusLabel() : "未配置");
BusinessDictionaryDataDO dictionaryData = dictionaryMap.get(respVO.getDictionaryDataValue());
if (dictionaryData != null) {
respVO.setDictionaryDataLabel(dictionaryData.getLabel());
} else {
respVO.setDictionaryDataLabel(respVO.getDictionaryDataValue());
}
respVO.setDictionaryDataLabel(respVO.getDictionaryDataValue());
respList.add(respVO);
}
return new PageResult<>(respList, pageResult.getTotal());
return respList;
}
private Map<Long, MaterialClassesDO> loadClassHierarchy(Set<Long> initialIds) {

View File

@@ -10,14 +10,11 @@ import java.util.*;
import com.zt.plat.module.base.controller.admin.materialclasses.vo.*;
import com.zt.plat.module.base.dal.dataobject.materialclasses.MaterialClassesDO;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.pojo.PageParam;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.module.base.dal.dao.materialclasses.MaterialClassesMapper;
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.zt.plat.framework.common.util.collection.CollectionUtils.convertList;
import static com.zt.plat.framework.common.util.collection.CollectionUtils.diffList;
import static com.zt.plat.module.base.enums.ErrorCodeConstants.*;
/**
@@ -32,10 +29,21 @@ public class MaterialClassesServiceImpl implements MaterialClassesService {
@Resource
private MaterialClassesMapper materialClassesMapper;
private static final int MAX_LEVEL = 3;
@Override
public MaterialClassesRespVO createMaterialClasses(MaterialClassesSaveReqVO createReqVO) {
Long normalizedParentId = normalizeParentId(createReqVO.getParentId());
MaterialClassesDO parent = validateAndGetParent(null, normalizedParentId);
long resolvedLevel = resolveLevel(parent);
validateLevel(resolvedLevel);
if (createReqVO.getLevel() != null && !Objects.equals(createReqVO.getLevel(), resolvedLevel)) {
throw exception(MATERIAL_CLASSES_HIERARCHY_INVALID);
}
// 插入
MaterialClassesDO materialClasses = BeanUtils.toBean(createReqVO, MaterialClassesDO.class);
materialClasses.setParentId(normalizedParentId);
materialClasses.setLevel(resolvedLevel);
materialClassesMapper.insert(materialClasses);
// 返回
return BeanUtils.toBean(materialClasses, MaterialClassesRespVO.class);
@@ -45,8 +53,18 @@ public class MaterialClassesServiceImpl implements MaterialClassesService {
public void updateMaterialClasses(MaterialClassesSaveReqVO updateReqVO) {
// 校验存在
validateMaterialClassesExists(updateReqVO.getId());
Long normalizedParentId = normalizeParentId(updateReqVO.getParentId());
MaterialClassesDO parent = validateAndGetParent(updateReqVO.getId(), normalizedParentId);
long resolvedLevel = resolveLevel(parent);
validateLevel(resolvedLevel);
if (updateReqVO.getLevel() != null && !Objects.equals(updateReqVO.getLevel(), resolvedLevel)) {
throw exception(MATERIAL_CLASSES_HIERARCHY_INVALID);
}
ensureChildrenCompatible(updateReqVO.getId(), resolvedLevel);
// 更新
MaterialClassesDO updateObj = BeanUtils.toBean(updateReqVO, MaterialClassesDO.class);
updateObj.setParentId(normalizedParentId);
updateObj.setLevel(resolvedLevel);
materialClassesMapper.updateById(updateObj);
}
@@ -94,4 +112,80 @@ public class MaterialClassesServiceImpl implements MaterialClassesService {
return materialClassesMapper.selectList();
}
private Long normalizeParentId(Long parentId) {
if (parentId == null || parentId <= 0) {
return null;
}
return parentId;
}
private MaterialClassesDO validateAndGetParent(Long currentId, Long parentId) {
if (parentId == null) {
return null;
}
if (currentId != null && Objects.equals(currentId, parentId)) {
throw exception(MATERIAL_CLASSES_HIERARCHY_INVALID);
}
MaterialClassesDO parent = materialClassesMapper.selectById(parentId);
if (parent == null) {
throw exception(MATERIAL_CLASSES_PARENT_NOT_EXISTS);
}
if (parent.getLevel() == null) {
throw exception(MATERIAL_CLASSES_HIERARCHY_INVALID);
}
if (parent.getLevel() >= MAX_LEVEL) {
throw exception(MATERIAL_CLASSES_MAX_LEVEL_EXCEEDED);
}
if (currentId != null) {
Long cursorId = parent.getParentId();
while (cursorId != null && cursorId > 0) {
if (Objects.equals(cursorId, currentId)) {
throw exception(MATERIAL_CLASSES_HIERARCHY_INVALID);
}
MaterialClassesDO cursor = materialClassesMapper.selectById(cursorId);
if (cursor == null) {
break;
}
cursorId = cursor.getParentId();
}
}
return parent;
}
private long resolveLevel(MaterialClassesDO parent) {
if (parent == null) {
return 1L;
}
Long parentLevel = parent.getLevel();
if (parentLevel == null) {
throw exception(MATERIAL_CLASSES_HIERARCHY_INVALID);
}
return parentLevel + 1;
}
private void validateLevel(long level) {
if (level < 1L) {
throw exception(MATERIAL_CLASSES_HIERARCHY_INVALID);
}
if (level > MAX_LEVEL) {
throw exception(MATERIAL_CLASSES_MAX_LEVEL_EXCEEDED);
}
}
private void ensureChildrenCompatible(Long currentId, long level) {
List<MaterialClassesDO> children = materialClassesMapper.selectList(MaterialClassesDO::getParentId, currentId);
if (CollUtil.isEmpty(children)) {
return;
}
long expectedChildLevel = level + 1;
if (expectedChildLevel > MAX_LEVEL) {
throw exception(MATERIAL_CLASSES_LEVEL_CONFLICT_WITH_CHILDREN);
}
boolean mismatch = children.stream()
.anyMatch(child -> child.getLevel() == null || !Objects.equals(child.getLevel(), expectedChildLevel));
if (mismatch) {
throw exception(MATERIAL_CLASSES_HIERARCHY_INVALID);
}
}
}

View File

@@ -2,10 +2,12 @@ package com.zt.plat.module.base.service.materialproperties;
import java.util.*;
import jakarta.validation.*;
import com.zt.plat.module.base.controller.admin.materialproperties.vo.*;
import com.zt.plat.module.base.dal.dataobject.materialproperties.MaterialPropertiesDO;
import com.zt.plat.module.base.controller.admin.materialproperties.vo.MaterialPropertiesPageReqVO;
import com.zt.plat.module.base.controller.admin.materialproperties.vo.MaterialPropertiesRespVO;
import com.zt.plat.module.base.controller.admin.materialproperties.vo.MaterialPropertiesSaveReqVO;
import com.zt.plat.module.base.controller.admin.materialproperties.vo.MaterialPropertiesSimplePageReqVO;
import com.zt.plat.module.base.controller.admin.materialproperties.vo.MaterialPropertiesSimpleRespVO;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.pojo.PageParam;
/**
* 物料属性 Service 接口
@@ -49,7 +51,7 @@ public interface MaterialPropertiesService {
* @param id 编号
* @return 物料属性
*/
MaterialPropertiesDO getMaterialProperties(Long id);
MaterialPropertiesRespVO getMaterialProperties(Long id);
/**
* 获得物料属性分页
@@ -57,6 +59,14 @@ public interface MaterialPropertiesService {
* @param pageReqVO 分页查询
* @return 物料属性分页
*/
PageResult<MaterialPropertiesDO> getMaterialPropertiesPage(MaterialPropertiesPageReqVO pageReqVO);
PageResult<MaterialPropertiesRespVO> getMaterialPropertiesPage(MaterialPropertiesPageReqVO pageReqVO);
/**
* 获得精简的物料属性分页
*
* @param pageReqVO 分页查询
* @return 精简分页结果
*/
PageResult<MaterialPropertiesSimpleRespVO> getMaterialPropertiesSimplePage(MaterialPropertiesSimplePageReqVO pageReqVO);
}

View File

@@ -1,29 +1,43 @@
package com.zt.plat.module.base.service.materialproperties;
import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import cn.hutool.core.util.StrUtil;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.*;
import com.zt.plat.module.base.controller.admin.materialproperties.vo.*;
import com.zt.plat.module.base.dal.dataobject.materialproperties.MaterialPropertiesDO;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.pojo.PageParam;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.module.base.controller.admin.materialproperties.vo.MaterialPropertiesPageReqVO;
import com.zt.plat.module.base.controller.admin.materialproperties.vo.MaterialPropertiesRespVO;
import com.zt.plat.module.base.controller.admin.materialproperties.vo.MaterialPropertiesSaveReqVO;
import com.zt.plat.module.base.controller.admin.materialproperties.vo.MaterialPropertiesSimplePageReqVO;
import com.zt.plat.module.base.controller.admin.materialproperties.vo.MaterialPropertiesSimpleRespVO;
import com.zt.plat.module.base.dal.dao.materialproperties.MaterialPropertiesMapper;
import com.zt.plat.module.base.dal.dao.quantityUnitRelation.QuantityUnitRelationMapper;
import com.zt.plat.module.base.dal.dao.unitQuantity.UnitQuantityMapper;
import com.zt.plat.module.base.dal.dao.untInfo.UntInfoMapper;
import com.zt.plat.module.base.dal.dao.businessdictionarytype.BusinessDictionaryDataMapper;
import com.zt.plat.module.base.dal.dataobject.materialproperties.MaterialPropertiesDO;
import com.zt.plat.module.base.dal.dataobject.quantityUnitRelation.QuantityUnitRelationDO;
import com.zt.plat.module.base.dal.dataobject.unitQuantity.UnitQuantityDO;
import com.zt.plat.module.base.dal.dataobject.untInfo.UntInfoDO;
import com.zt.plat.module.base.dal.dataobject.businessdictionarytype.BusinessDictionaryDataDO;
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.zt.plat.framework.common.util.collection.CollectionUtils.convertList;
import static com.zt.plat.framework.common.util.collection.CollectionUtils.diffList;
import static com.zt.plat.module.base.enums.ErrorCodeConstants.*;
import static com.zt.plat.module.base.enums.ErrorCodeConstants.MATERIAL_PROPERTIES_NOT_EXISTS;
/**
* 物料属性 Service 实现类
*
* @author 后台管理-1
*/
@Service
@Validated
@@ -32,39 +46,43 @@ public class MaterialPropertiesServiceImpl implements MaterialPropertiesService
@Resource
private MaterialPropertiesMapper materialPropertiesMapper;
@Resource
private QuantityUnitRelationMapper quantityUnitRelationMapper;
@Resource
private UnitQuantityMapper unitQuantityMapper;
@Resource
private UntInfoMapper untInfoMapper;
@Resource
private BusinessDictionaryDataMapper businessDictionaryDataMapper;
@Override
public MaterialPropertiesRespVO createMaterialProperties(MaterialPropertiesSaveReqVO createReqVO) {
// 插入
MaterialPropertiesDO materialProperties = BeanUtils.toBean(createReqVO, MaterialPropertiesDO.class);
materialPropertiesMapper.insert(materialProperties);
// 返回
return BeanUtils.toBean(materialProperties, MaterialPropertiesRespVO.class);
return CollUtil.getFirst(buildRespList(Collections.singletonList(materialProperties)));
}
@Override
public void updateMaterialProperties(MaterialPropertiesSaveReqVO updateReqVO) {
// 校验存在
validateMaterialPropertiesExists(updateReqVO.getId());
// 更新
MaterialPropertiesDO updateObj = BeanUtils.toBean(updateReqVO, MaterialPropertiesDO.class);
materialPropertiesMapper.updateById(updateObj);
}
@Override
public void deleteMaterialProperties(Long id) {
// 校验存在
validateMaterialPropertiesExists(id);
// 删除
materialPropertiesMapper.deleteById(id);
}
@Override
public void deleteMaterialPropertiesListByIds(List<Long> ids) {
// 校验存在
public void deleteMaterialPropertiesListByIds(List<Long> ids) {
validateMaterialPropertiesExists(ids);
// 删除
materialPropertiesMapper.deleteByIds(ids);
}
}
private void validateMaterialPropertiesExists(List<Long> ids) {
List<MaterialPropertiesDO> list = materialPropertiesMapper.selectByIds(ids);
@@ -80,13 +98,122 @@ public class MaterialPropertiesServiceImpl implements MaterialPropertiesService
}
@Override
public MaterialPropertiesDO getMaterialProperties(Long id) {
return materialPropertiesMapper.selectById(id);
public MaterialPropertiesRespVO getMaterialProperties(Long id) {
MaterialPropertiesDO entity = materialPropertiesMapper.selectById(id);
if (entity == null) {
return null;
}
return CollUtil.getFirst(buildRespList(Collections.singletonList(entity)));
}
@Override
public PageResult<MaterialPropertiesDO> getMaterialPropertiesPage(MaterialPropertiesPageReqVO pageReqVO) {
return materialPropertiesMapper.selectPage(pageReqVO);
public PageResult<MaterialPropertiesRespVO> getMaterialPropertiesPage(MaterialPropertiesPageReqVO pageReqVO) {
PageResult<MaterialPropertiesDO> pageResult = materialPropertiesMapper.selectPage(pageReqVO);
List<MaterialPropertiesRespVO> respList = buildRespList(pageResult.getList());
return new PageResult<>(respList, pageResult.getTotal());
}
@Override
public PageResult<MaterialPropertiesSimpleRespVO> getMaterialPropertiesSimplePage(MaterialPropertiesSimplePageReqVO pageReqVO) {
PageResult<MaterialPropertiesDO> pageResult = materialPropertiesMapper.selectSimplePage(pageReqVO);
if (CollUtil.isEmpty(pageResult.getList())) {
return new PageResult<>(Collections.emptyList(), pageResult.getTotal());
}
List<MaterialPropertiesRespVO> respList = buildRespList(pageResult.getList());
List<MaterialPropertiesSimpleRespVO> simpleList = buildSimpleList(respList);
return new PageResult<>(simpleList, pageResult.getTotal());
}
private List<MaterialPropertiesSimpleRespVO> buildSimpleList(List<MaterialPropertiesRespVO> respList) {
if (CollUtil.isEmpty(respList)) {
return Collections.emptyList();
}
return respList.stream().map(item -> {
MaterialPropertiesSimpleRespVO vo = new MaterialPropertiesSimpleRespVO();
vo.setId(item.getId());
vo.setCode(item.getCode());
vo.setName(item.getName());
vo.setDataType(item.getDataType());
vo.setUnitName(item.getUnitName());
vo.setUnitSymbol(item.getUnitSymbol());
vo.setDictionaryDataValue(item.getDictionaryDataValue());
vo.setDictionaryDataLabel(item.getDictionaryDataLabel());
return vo;
}).collect(Collectors.toList());
}
private List<MaterialPropertiesRespVO> buildRespList(List<MaterialPropertiesDO> list) {
if (CollUtil.isEmpty(list)) {
return Collections.emptyList();
}
Set<Long> relationIds = list.stream()
.map(MaterialPropertiesDO::getUnitQuantityId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
Map<Long, QuantityUnitRelationDO> relationMap = relationIds.isEmpty()
? Collections.emptyMap()
: quantityUnitRelationMapper.selectBatchIds(relationIds).stream()
.filter(Objects::nonNull)
.collect(Collectors.toMap(QuantityUnitRelationDO::getId, Function.identity()));
Set<Long> quantityIds = relationMap.values().stream()
.map(QuantityUnitRelationDO::getUntQtyId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
Set<Long> unitIds = relationMap.values().stream()
.map(QuantityUnitRelationDO::getUntId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
Map<Long, UnitQuantityDO> quantityMap = quantityIds.isEmpty()
? Collections.emptyMap()
: unitQuantityMapper.selectBatchIds(quantityIds).stream()
.filter(Objects::nonNull)
.collect(Collectors.toMap(UnitQuantityDO::getId, Function.identity()));
Map<Long, UntInfoDO> unitMap = unitIds.isEmpty()
? Collections.emptyMap()
: untInfoMapper.selectBatchIds(unitIds).stream()
.filter(Objects::nonNull)
.collect(Collectors.toMap(UntInfoDO::getId, Function.identity()));
Set<String> dictionaryValues = list.stream()
.map(MaterialPropertiesDO::getDictionaryDataValue)
.filter(StrUtil::isNotBlank)
.collect(Collectors.toSet());
Map<String, BusinessDictionaryDataDO> dictionaryMap = dictionaryValues.isEmpty()
? Collections.emptyMap()
: businessDictionaryDataMapper.selectListByValues(dictionaryValues).stream()
.filter(Objects::nonNull)
.collect(Collectors.toMap(BusinessDictionaryDataDO::getValue, Function.identity(), (existing, replacement) -> existing));
return list.stream().map(item -> {
MaterialPropertiesRespVO respVO = BeanUtils.toBean(item, MaterialPropertiesRespVO.class);
QuantityUnitRelationDO relation = relationMap.get(item.getUnitQuantityId());
if (relation != null) {
UnitQuantityDO quantity = quantityMap.get(relation.getUntQtyId());
if (quantity != null) {
respVO.setUnitQuantityName(quantity.getName());
}
UntInfoDO unit = unitMap.get(relation.getUntId());
if (unit != null) {
respVO.setUnitName(unit.getName());
respVO.setUnitSymbol(unit.getSmb());
}
}
BusinessDictionaryDataDO dictionaryDataDO = dictionaryMap.get(item.getDictionaryDataValue());
if (dictionaryDataDO != null) {
respVO.setDictionaryDataLabel(dictionaryDataDO.getLabel());
} else {
respVO.setDictionaryDataLabel(respVO.getDictionaryDataValue());
}
return respVO;
}).collect(Collectors.toList());
}
}

View File

@@ -5,6 +5,7 @@ import jakarta.validation.*;
import com.zt.plat.module.base.controller.admin.quantityUnitRelation.vo.*;
import com.zt.plat.module.base.dal.dataobject.quantityUnitRelation.QuantityUnitRelationDO;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.module.base.controller.admin.quantityUnitRelation.vo.QuantityUnitRelationSimplePageReqVO;
/**
* 计量单位量与单位关联 Service 接口
@@ -85,4 +86,12 @@ public interface QuantityUnitRelationService {
*/
void deleteUnitWithRelation(@Valid DeleteUnitWithRelationReqVO deleteReqVO);
/**
* 查询精简的量纲-单位关联分页,用于下拉框
*
* @param pageReqVO 分页查询条件
* @return 关联关系列表
*/
PageResult<QuantityUnitRelationSimpleRespVO> getQuantityUnitRelationSimplePage(QuantityUnitRelationSimplePageReqVO pageReqVO);
}

View File

@@ -1,6 +1,7 @@
package com.zt.plat.module.base.service.quantityUnitRelation;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
@@ -11,11 +12,19 @@ import com.zt.plat.module.base.controller.admin.quantityUnitRelation.vo.*;
import com.zt.plat.module.base.dal.dataobject.quantityUnitRelation.QuantityUnitRelationDO;
import com.zt.plat.framework.common.pojo.PageResult;
import com.zt.plat.framework.common.util.object.BeanUtils;
import com.zt.plat.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.zt.plat.module.base.dal.dao.quantityUnitRelation.QuantityUnitRelationMapper;
import com.zt.plat.module.base.dal.dao.unitQuantity.UnitQuantityMapper;
import com.zt.plat.module.base.dal.dao.untInfo.UntInfoMapper;
import com.zt.plat.module.base.service.untInfo.UntInfoService;
import com.zt.plat.module.base.controller.admin.untInfo.vo.UntInfoSaveReqVO;
import com.zt.plat.module.base.controller.admin.untInfo.vo.UntInfoRespVO;
import com.zt.plat.module.base.dal.dataobject.unitQuantity.UnitQuantityDO;
import com.zt.plat.module.base.dal.dataobject.untInfo.UntInfoDO;
import java.util.function.Function;
import java.util.stream.Collectors;
import static com.zt.plat.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.zt.plat.framework.common.util.collection.CollectionUtils.convertList;
@@ -36,6 +45,12 @@ public class QuantityUnitRelationServiceImpl implements QuantityUnitRelationServ
@Resource
private UntInfoService untInfoService;
@Resource
private UnitQuantityMapper unitQuantityMapper;
@Resource
private UntInfoMapper untInfoMapper;
@Override
public QuantityUnitRelationRespVO createQuantityUnitRelation(QuantityUnitRelationSaveReqVO createReqVO) {
// 插入
@@ -170,4 +185,90 @@ public class QuantityUnitRelationServiceImpl implements QuantityUnitRelationServ
untInfoService.deleteUntInfo(deleteReqVO.getUntId());
}
@Override
public PageResult<QuantityUnitRelationSimpleRespVO> getQuantityUnitRelationSimplePage(QuantityUnitRelationSimplePageReqVO pageReqVO) {
LambdaQueryWrapperX<QuantityUnitRelationDO> wrapper = new LambdaQueryWrapperX<>();
wrapper.eqIfPresent(QuantityUnitRelationDO::getUntQtyId, pageReqVO.getUntQtyId());
if (StrUtil.isNotBlank(pageReqVO.getKeyword())) {
String keyword = pageReqVO.getKeyword();
List<Long> matchedQtyIds = unitQuantityMapper.selectList(new LambdaQueryWrapperX<UnitQuantityDO>()
.like(UnitQuantityDO::getName, keyword))
.stream()
.map(UnitQuantityDO::getId)
.filter(Objects::nonNull)
.toList();
List<Long> matchedUntIds = untInfoMapper.selectList(new LambdaQueryWrapperX<UntInfoDO>()
.like(UntInfoDO::getName, keyword)
.or()
.like(UntInfoDO::getSmb, keyword))
.stream()
.map(UntInfoDO::getId)
.filter(Objects::nonNull)
.toList();
if (CollUtil.isEmpty(matchedQtyIds) && CollUtil.isEmpty(matchedUntIds)) {
return new PageResult<>(Collections.emptyList(), 0L);
}
wrapper.and(w -> {
boolean hasCondition = false;
if (CollUtil.isNotEmpty(matchedQtyIds)) {
w.in(QuantityUnitRelationDO::getUntQtyId, matchedQtyIds);
hasCondition = true;
}
if (CollUtil.isNotEmpty(matchedUntIds)) {
if (hasCondition) {
w.or();
}
w.in(QuantityUnitRelationDO::getUntId, matchedUntIds);
}
});
}
wrapper.orderByAsc(QuantityUnitRelationDO::getUntQtyId).orderByAsc(QuantityUnitRelationDO::getId);
PageResult<QuantityUnitRelationDO> pageResult = quantityUnitRelationMapper.selectSimplePage(pageReqVO, wrapper);
if (CollUtil.isEmpty(pageResult.getList())) {
return new PageResult<>(Collections.emptyList(), pageResult.getTotal());
}
Set<Long> qtyIds = pageResult.getList().stream()
.map(QuantityUnitRelationDO::getUntQtyId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
Set<Long> unitIds = pageResult.getList().stream()
.map(QuantityUnitRelationDO::getUntId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
Map<Long, UnitQuantityDO> qtyMap = qtyIds.isEmpty() ? Collections.emptyMap()
: unitQuantityMapper.selectBatchIds(qtyIds).stream()
.filter(Objects::nonNull)
.collect(Collectors.toMap(UnitQuantityDO::getId, Function.identity()));
Map<Long, UntInfoDO> unitMap = unitIds.isEmpty() ? Collections.emptyMap()
: untInfoMapper.selectBatchIds(unitIds).stream()
.filter(Objects::nonNull)
.collect(Collectors.toMap(UntInfoDO::getId, Function.identity()));
List<QuantityUnitRelationSimpleRespVO> respList = pageResult.getList().stream().map(item -> {
QuantityUnitRelationSimpleRespVO vo = new QuantityUnitRelationSimpleRespVO();
vo.setId(item.getId());
vo.setUntQtyId(item.getUntQtyId());
UnitQuantityDO quantityDO = qtyMap.get(item.getUntQtyId());
if (quantityDO != null) {
vo.setUntQtyName(quantityDO.getName());
}
vo.setUntId(item.getUntId());
UntInfoDO untInfoDO = unitMap.get(item.getUntId());
if (untInfoDO != null) {
vo.setUntName(untInfoDO.getName());
vo.setUntSymbol(untInfoDO.getSmb());
}
vo.setIsBse(item.getIsBse());
return vo;
}).collect(Collectors.toList());
return new PageResult<>(respList, pageResult.getTotal());
}
}