feat: 电气专用bom添加分页查询和获取子节点接口

This commit is contained in:
曹鹏飞 2024-04-08 17:33:38 +08:00
parent e3a25f1ddc
commit 25a9e64f74
11 changed files with 344 additions and 52 deletions

View File

@ -1,17 +1,18 @@
package com.nflg.product.bomnew.api.user;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzt.logapi.context.LogRecordContext;
import com.mzt.logapi.starter.annotation.LogRecord;
import com.nflg.product.base.core.api.BaseApi;
import com.nflg.product.bomnew.pojo.query.BomNewDQbomPageQuery;
import com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO;
import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO;
import com.nflg.product.bomnew.service.DQBomImportService;
import com.nflg.product.bomnew.service.DQBomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import nflg.product.common.vo.ResultVO;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
@ -30,7 +31,16 @@ public class DQBomApi extends BaseApi {
@Resource
DQBomImportService dqBomImportService;
@ApiOperation("导入")
@Resource
DQBomService dQBomService;
/**
* 导入
* @param file 导入的excel文件
* @return
* @throws IOException
*/
@ApiOperation("从excel导入数据")
@PostMapping("importBom")
@LogRecord(success = "电气BOM-导入:文件名:{{#fileNme}},操作结果:{{#_ret}}", bizNo = "", type = "电气BOM导入")
public ResultVO<List<OperationErrorMsgVO>> importBom(@RequestParam(value = "file") MultipartFile file) throws IOException {
@ -42,4 +52,21 @@ public class DQBomApi extends BaseApi {
return ResultVO.success(dqBomImportService.importBom(file));
}
/**
* 分页查询数据
* @param query 查询条件
* @return
*/
@PostMapping("getPageList")
@ApiOperation("分页查询数据")
public ResultVO<Page<BomNewDQbomVO>> getPageList(@RequestBody BomNewDQbomPageQuery query) {
return ResultVO.success(dQBomService.getPageList(query));
}
@GetMapping("getChild")
@ApiOperation("获取子级数据")
public ResultVO<List<BomNewDQbomVO>> getChild(@RequestParam("bomRowId") Long bomRowId) {
return ResultVO.success(dQBomService.getChild(bomRowId));
}
}

View File

@ -0,0 +1,28 @@
package com.nflg.product.bomnew.constant;
import lombok.AllArgsConstructor;
import lombok.Getter;
/**
* @author 曹鹏飞
* @date 2024/4/8 10:22:59
*/
@AllArgsConstructor
@Getter
public enum DQBomStatusEnum implements ValueEnum<Integer> {
WAIT_CONVERT(1, "待转换"),
PUBLISHED(2, "定版已发布PBOM");
private final Integer value;
private final String description;
public static DQBomStatusEnum findByValue(Integer value) {
for (DQBomStatusEnum statusEnum : DQBomStatusEnum.values()) {
if (statusEnum.getValue().equals(value)) {
return statusEnum;
}
}
throw new IllegalArgumentException("无效的值");
}
}

View File

@ -1,8 +1,10 @@
package com.nflg.product.bomnew.mapper.master;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomParentEntity;
import org.apache.ibatis.annotations.Select;
import com.nflg.product.bomnew.pojo.query.BomNewDQbomPageQuery;
import com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO;
import java.util.List;
@ -12,6 +14,7 @@ import java.util.List;
*/
public interface BomNewDQbomParentMapper extends BaseMapper<BomNewDQbomParentEntity> {
@Select("SELECT p.* FROM t_bom_new_dqbom_parent p INNER JOIN t_bom_new_dqbom_child c ON p.material_no = c.material_no WHERE c.status=1 AND p.material_no='#{materialNo}' ORDER BY p.row_id DESC")
List<BomNewDQbomParentEntity> getWorkSheet(String materialNo);
Page<BomNewDQbomVO> getPageList(Page<Object> objectPage, BomNewDQbomPageQuery query, String userCode);
List<BomNewDQbomVO> getChild(Long bomRowId);
}

View File

@ -106,34 +106,6 @@ public class BomNewDQbomChildEntity implements Serializable {
@ApiModelProperty(value = "修改时间")
private LocalDateTime modifyTime;
/**
* 处理状态1=待处理2=已处理
*/
@TableField(value = "edit_status")
@ApiModelProperty(value = "处理状态")
private Integer editStatus = 1;
/**
* 转换状态1=待转换2=已转换已发布PBOM
*/
@TableField(value = "status")
@ApiModelProperty(value = "转换状态")
private Integer status = 1;
/**
* 异常状态
*/
@TableField(value = "exception_status")
@ApiModelProperty(value = "异常状态")
private Integer exceptionStatus = -1;
/**
* 异常标记
*/
@TableField(value = "exception_tag")
@ApiModelProperty(value = "异常标记")
private String exceptionTag;
/**
* 来源 1-EXCE导入 2-MDM创建
*/

View File

@ -121,6 +121,34 @@ public class BomNewDQbomParentEntity implements Serializable {
@ApiModelProperty(value = "是否最新版")
private Integer lastVersionIs = 1;
/**
* 处理状态1=待处理2=已处理
*/
@TableField(value = "edit_status")
@ApiModelProperty(value = "处理状态")
private Integer editStatus = 1;
/**
* 转换状态1=待转换2=已转换已发布PBOM
*/
@TableField(value = "status")
@ApiModelProperty(value = "转换状态")
private Integer status = 1;
/**
* 异常状态
*/
@TableField(value = "exception_status")
@ApiModelProperty(value = "异常状态")
private Integer exceptionStatus = -1;
/**
* 异常标记
*/
@TableField(value = "exception_tag")
@ApiModelProperty(value = "异常标记")
private String exceptionTag;
/**
* 创建人名称
*/

View File

@ -0,0 +1,60 @@
package com.nflg.product.bomnew.pojo.query;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* @author 曹鹏飞
* @date 2024/4/8 10:19:27
*/
@Data
@Accessors(chain = true)
@ApiModel(value = "com-nflg-product-bomnew-pojo-new-query-BomNewDQbomPageQuery")
public class BomNewDQbomPageQuery extends BasePageQuery implements Serializable {
/**
* 图号
*/
@ApiModelProperty(value = "图号")
private String drawingNo;
/**
* 物料编码
*/
@ApiModelProperty(value = "物料编码")
private String materialNo;
/**
* 物料名称
*/
@ApiModelProperty(value = "物料名称")
private String materialName;
/*
* 开始时间
*/
@ApiModelProperty(value = "开始时间")
private String startDate;
/*
* 结束时间
*/
@ApiModelProperty(value = "结束时间")
private String endDate;
/*
* 是否仅显示自己的数据0=所有人的数据1=仅自己的数据默认为0
*/
@ApiModelProperty(value = "是否仅显示自己的数据0=所有人的数据1=仅自己的数据默认为0")
private Integer showMySelfOnly = 0;
/**
* 状态 1=待转换2=已转换已发布PBOM
*/
@ApiModelProperty("状态 1=待转换、2=已转换已发布PBOM")
private Integer status;
}

View File

@ -0,0 +1,45 @@
package com.nflg.product.bomnew.pojo.vo;
import com.baomidou.mybatisplus.annotation.TableField;
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomParentEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* @author 曹鹏飞
* @date 2024/4/8 10:36:42
*/
@Data
@Accessors(chain = true)
@ApiModel(value = "com-nflg-product-bomnew-pojo-new-vo-BomNewDQbomVO")
public class BomNewDQbomVO extends BomNewDQbomParentEntity implements Serializable {
/**
* 物料信息表中的物料名称
*/
@ApiModelProperty(value = "物料名称(系统)")
private String systemMaterialName;
/**
* 物料类别
*/
@ApiModelProperty(value = "物料类别")
private String systemMaterialCategoryName;
/**
* 物料状态 1:激活 2:禁止采购 3:售后专用 4:冻结 5:完全弃用
*/
@ApiModelProperty(value = "物料状态")
private Integer systemMaterialState;
/**
* 排序号
*/
@TableField(value = "order_number")
@ApiModelProperty(value = "排序号")
private String orderNumber;
}

View File

@ -104,34 +104,37 @@ public class DQBomImportService {
private void checkExceptionStatus(List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children) {
List<String> materialNos = children.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toList());
List<BaseMaterialVO> materialVOS = materialMainService.getMaterialBaseInfo(materialNos);
checkChildExceptionStatus(children.get(0), parents, children, materialVOS);
checkChildExceptionStatus(parents.get(0), parents, children, materialVOS);
}
private void checkChildExceptionStatus(BomNewDQbomChildEntity child, List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children, List<BaseMaterialVO> materialVOS) {
BomNewDQbomParentEntity parent = parents.stream().filter(p -> p.getMaterialNo().equals(child.getMaterialNo())).findFirst().get();
private void checkChildExceptionStatus(BomNewDQbomParentEntity parent, List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children, List<BaseMaterialVO> materialVOS) {
//BomNewDQbomParentEntity parent = parents.stream().filter(p -> p.getMaterialNo().equals(child.getMaterialNo())).findFirst().get();
if (parent.getProjectType().equals("T")) {
child.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue());
parent.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue());
} else {
BaseMaterialVO materialVO = materialVOS.stream().filter(v -> v.getMaterialNo().equals(child.getMaterialNo())).findFirst().orElse(null);
BaseMaterialVO materialVO = materialVOS.stream().filter(v -> v.getMaterialNo().equals(parent.getMaterialNo())).findFirst().orElse(null);
if (materialVO == null) {
child.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_7.getValue());
parent.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_7.getValue());
} else if (materialVO.getMaterialState().equals(MaterialGetEnum.MaterialStateEnum.STATE_NO_4.getValue())) {
child.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_2.getValue());
parent.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_2.getValue());
} else if (!materialVO.getMaterialName().equals(parent.getMaterialName())) {
child.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_15.getValue());
parent.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_15.getValue());
} else {
child.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue());
parent.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue());
}
}
List<BomNewDQbomChildEntity> cc = children.stream().filter(c -> c.getParentRowId().equals(parent.getRowId())).collect(Collectors.toList());
for (BomNewDQbomChildEntity c : cc) {
checkChildExceptionStatus(c, parents, children, materialVOS);
List<String> cc = children.stream().filter(c -> c.getParentRowId().equals(parent.getRowId()))
.map(BomNewDQbomChildEntity::getMaterialNo)
.collect(Collectors.toList());
List<BomNewDQbomParentEntity> pp = parents.stream().filter(p -> cc.contains(p.getMaterialNo())).collect(Collectors.toList());
for (BomNewDQbomParentEntity p : pp) {
checkChildExceptionStatus(p, parents, children, materialVOS);
}
}
private void checkInconsistentData(BomNewDQbomParentEntity parent, List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children) throws JsonProcessingException {
log.debug("checkInconsistentDataparent" + JsonUtil.toJson(parent));
BomNewDQbomParentEntity oldParent = dQBomParentService.getWorkSheet(parent.getMaterialNo()).stream().findFirst().orElse(null);
BomNewDQbomParentEntity oldParent = dQBomParentService.getLastVersion(parent.getMaterialNo());
if (oldParent != null) {
if (!parent.getMaterialUnit().equals(oldParent.getMaterialUnit())
|| !parent.getMaterialTexture().equals(oldParent.getMaterialTexture())) {
@ -256,7 +259,7 @@ public class DQBomImportService {
private void handlerExcelRow(DQbomExcelVO dQbomExcelVO) {
rowNum.set(rowNum.get() + 1);
log.debug("电气bom导入excel" + rowNum.get() + "行,处理前:" + JSON.toJSONString(dQbomExcelVO));
log.debug("电气bom导入excel{}行,处理前:{}", rowNum.get(), JSON.toJSONString(dQbomExcelVO));
dQbomExcelVO.setRowNum(rowNum.get());
if (StrUtil.isBlank(dQbomExcelVO.getMaterialNo())) {

View File

@ -15,8 +15,11 @@ import java.util.List;
@Service
public class DQBomParentService extends ServiceImpl<BomNewDQbomParentMapper, BomNewDQbomParentEntity> {
public List<BomNewDQbomParentEntity> getWorkSheet(String materialNo) {
return this.getBaseMapper().getWorkSheet(materialNo);
public BomNewDQbomParentEntity getLastVersion(String materialNo) {
return this.lambdaQuery().eq(BomNewDQbomParentEntity::getLastVersionIs, 1)
.eq(BomNewDQbomParentEntity::getMaterialNo, materialNo)
.list()
.stream().findFirst().orElse(null);
}
public void setLastVersionIs0(List<String> materialNo) {

View File

@ -0,0 +1,56 @@
package com.nflg.product.bomnew.service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nflg.product.base.core.conmon.util.SessionUtil;
import com.nflg.product.bomnew.pojo.query.BomNewDQbomPageQuery;
import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO;
import com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author 曹鹏飞
* @date 2024/4/8 11:26:04
*/
@Service
@Slf4j
public class DQBomService {
@Resource
DQBomParentService dQBomParentService;
@Resource
DQBomChildService dQBomChildService;
@Resource
MaterialMainService materialMainService;
public Page<BomNewDQbomVO> getPageList(BomNewDQbomPageQuery query) {
Page<BomNewDQbomVO> ret = dQBomParentService.getBaseMapper().getPageList(new Page<>(query.getPage(), query.getPageSize()), query, SessionUtil.getUserCode());
initMaterialInfo(ret.getRecords());
return ret;
}
public List<BomNewDQbomVO> getChild(Long bomRowId) {
List<BomNewDQbomVO> data = dQBomParentService.getBaseMapper().getChild(bomRowId);
initMaterialInfo(data);
return data;
}
private void initMaterialInfo(List<BomNewDQbomVO> data) {
List<String> materialNos = data.stream().map(BomNewDQbomVO::getMaterialNo).collect(Collectors.toList());
List<BaseMaterialVO> materialBaseInfos = materialMainService.getMaterialBaseInfo(materialNos);
data.forEach(d -> {
BaseMaterialVO bm = materialBaseInfos.stream().filter(m -> m.getMaterialNo().equals(d.getMaterialNo())).findFirst().orElse(null);
if (bm != null) {
d.setSystemMaterialState(bm.getMaterialState());
d.setSystemMaterialName(bm.getMaterialName());
d.setSystemMaterialCategoryName(bm.getCategoryName());
}
});
}
}

View File

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nflg.product.bomnew.mapper.master.BomNewDQbomParentMapper">
<resultMap id="BaseResultMap" type="com.nflg.product.bomnew.pojo.entity.BomNewDQbomParentEntity">
<id column="row_id" jdbcType="BIGINT" property="rowId"/>
<result column="material_no" jdbcType="VARCHAR" property="materialNo"/>
<result column="material_name" jdbcType="VARCHAR" property="materialName"/>
<result column="unit_weight" jdbcType="DECIMAL" property="unitWeight"/>
<result column="material_unit" jdbcType="VARCHAR" property="materialUnit"/>
<result column="material_texture" jdbcType="VARCHAR" property="materialTexture"/>
<result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
<result column="created_name" jdbcType="VARCHAR" property="createdName"/>
<result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
<result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime"/>
<result column="created_job" jdbcType="INTEGER" property="createdJob"/>
<result column="remark" jdbcType="VARCHAR" property="remark"/>
<result column="root_is" jdbcType="INTEGER" property="rootIs"/>
<result column="status" jdbcType="INTEGER" property="status"/>
<result column="drawing_no" jdbcType="VARCHAR" property="drawingNo"/>
<result column="project_type" jdbcType="VARCHAR" property="projectType"/>
<result column="current_version" jdbcType="VARCHAR" property="currentVersion"/>
<result column="user_root_is" jdbcType="INTEGER" property="userRootIs"/>
<result column="exception_status" jdbcType="INTEGER" property="exceptionStatus"/>
<result column="last_version_is" jdbcType="INTEGER" property="lastVersionIs"/>
<result column="bom_exist" jdbcType="INTEGER" property="bomExist"/>
<result column="convert_to_pbom_time" jdbcType="TIMESTAMP" property="convertToPbomTime"/>
<result column="level" jdbcType="INTEGER" property="level"/>
<result column="exception_tag" jdbcType="VARCHAR" property="exceptionTag"/>
<result column="edit_status" jdbcType="INTEGER" property="editStatus"/>
<result column="expire_end_time" jdbcType="TIMESTAMP" property="expireEndTime"/>
</resultMap>
<!--分页获取数据-->
<select id="getPageList" resultType="com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO">
SELECT p.*
FROM t_bom_new_dqbom_parent p
INNER JOIN t_bom_new_dqbom_child c ON p.material_no = c.material_no
WHERE (root_is | user_root_is = 1) AND p.status = #{query.status}
<if test="query.showMySelfOnly == 1">
AND p.created_by = '#{userCode}'
</if>
<if test="query.drawingNo != null">
AND p.drawing_no = '#{query.drawingNo}'
</if>
<if test="query.materialNo != null">
AND p.material_no = '#{query.materialNo}'
</if>
<if test="query.materialName != null">
AND p.material_name like concat('%', '${query.materialName}', '%')
</if>
<if test="query.startDate != null">
AND p.created_time <![CDATA[ >= ]]> #{query.startDate}
</if>
<if test="query.endDate != null">
AND p.created_time <![CDATA[ <= ]]> #{query.endDate}
</if>
ORDER BY user_root_is DESC, row_id DESC
</select>
<!--获取子级数据-->
<select id="getChild" resultType="com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO">
SELECT p.*, c.order_number
FROM t_bom_new_dqbom_parent p
INNER JOIN t_bom_new_dqbom_child c ON p.material_no = c.material_no
WHERE c.parent_row_id = #{bomRowId}
ORDER BY c.order_number
</select>
</mapper>