feat: 电气专用bom功能

This commit is contained in:
曹鹏飞 2024-04-18 21:22:34 +08:00
parent 2154ac2599
commit acbd76a8bf
9 changed files with 149 additions and 50 deletions

View File

@ -1,6 +1,7 @@
package com.nflg.product.bomnew.api.user;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.ImmutableList;
import com.mzt.logapi.context.LogRecordContext;
import com.mzt.logapi.starter.annotation.LogRecord;
import com.nflg.product.base.core.api.BaseApi;
@ -17,8 +18,11 @@ import io.swagger.annotations.ApiOperation;
import nflg.product.common.vo.ResultVO;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.ttzero.excel.entity.ListSheet;
import org.ttzero.excel.entity.Workbook;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.io.IOException;
@ -39,6 +43,20 @@ public class DQBomApi extends BaseApi {
@Resource
DQBomService dQBomService;
/**
* 模板下载
* @param response
* @throws IOException
*/
@GetMapping("getExcelTemplate")
@ApiOperation("模板下载")
public void getExcelTemplate(HttpServletResponse response) throws IOException {
EecExcelUtil.setResponseExcelHeader(response, "电气专用bom导入模版");
new Workbook("物料导入模板")
.addSheet(new ListSheet<>("sheet1", ImmutableList.of(new DQbomExcelVO())))
.writeTo(response.getOutputStream());
}
/**
* 导入
* @param file 导入的excel文件
@ -177,10 +195,15 @@ public class DQBomApi extends BaseApi {
return ResultVO.error("暂未实现");
}
@PostMapping("convertToSAP")
@ApiOperation("导入SAP")
public ResultVO convertToSAP(@Valid @RequestBody @NotNull Long rootBomRowId) {
//TODO 导入SAP
return ResultVO.error("暂未实现");
/**
* 导入到SAP
* @param rootBomRowId 顶级bom的rowId
* @return
*/
@PostMapping("importToSAP")
@ApiOperation("导入到SAP")
public ResultVO importToSAP(@Valid @RequestBody @NotNull Long rootBomRowId) {
dQBomService.importToSAP(rootBomRowId);
return ResultVO.success();
}
}

View File

@ -5,7 +5,6 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomParentEntity;
import com.nflg.product.bomnew.pojo.query.BomNewDQbomPageQuery;
import com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO;
import com.nflg.product.bomnew.pojo.vo.DQbomExcelVO;
import java.util.List;
@ -21,7 +20,7 @@ public interface BomNewDQbomParentMapper extends BaseMapper<BomNewDQbomParentEnt
void resetBomExist(Long rowId);
DQbomExcelVO getRootBomByRowId(Long rootBomRowId);
BomNewDQbomVO getRootBomByRowId(Long rootBomRowId);
List<DQbomExcelVO> getChildren(Long bomRowId);
List<BomNewDQbomVO> getChildren(Long bomRowId);
}

View File

@ -30,6 +30,13 @@ public class BomNewDQbomParentEntity implements Serializable {
@ApiModelProperty(value = "主键-雪花")
private Long rowId;
/**
* 层次
*/
@TableField(value = "level")
@ApiModelProperty(value = "层次")
private Integer level;
/**
* 图号
*/
@ -176,4 +183,18 @@ public class BomNewDQbomParentEntity implements Serializable {
@TableField(value = "modify_time")
@ApiModelProperty(value = "修改时间")
private LocalDateTime modifyTime;
/**
* 导入SAP状态1-未导入3-已导入
*/
@TableField(value = "sap_state")
@ApiModelProperty(value = "导入SAP状态1-未导入3-已导入")
private Integer sapState;
/**
* 导入SAP时间
*/
@TableField(value = "sap_time")
@ApiModelProperty(value = "导入SAP时间")
private LocalDateTime sapTime;
}

View File

@ -1,6 +1,5 @@
package com.nflg.product.bomnew.pojo.query;
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomParentEntity;
import com.nflg.product.bomnew.pojo.vo.BomNewDQbomSaveVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ -25,7 +24,7 @@ public class BomNewDQbomSaveQuery implements Serializable {
*/
@ApiModelProperty(value = "父级")
@NotNull
private BomNewDQbomParentEntity parent;
private BomNewDQbomSaveVO parent;
/**
* 子级数据

View File

@ -1,12 +1,11 @@
package com.nflg.product.bomnew.pojo.vo;
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity;
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 javax.validation.constraints.NotNull;
import java.io.Serializable;
/**
@ -16,12 +15,8 @@ import java.io.Serializable;
@Data
@Accessors(chain = true)
@ApiModel(value = "com-nflg-product-bomnew-pojo-new-vo-BomNewDQbomSaveVO")
public class BomNewDQbomSaveVO extends BomNewDQbomChildEntity implements Serializable {
public class BomNewDQbomSaveVO extends BomNewDQbomParentEntity implements Serializable {
@ApiModelProperty("物料BOM版本ID")
private Long bomRowId = 0L;
@NotNull
@ApiModelProperty("物料bom行ID")
private Long childBomRowId;
@ApiModelProperty("物料BOM关系rowId")
private Long bomChildRowId;
}

View File

@ -46,4 +46,9 @@ public class BomNewDQbomVO extends BomNewDQbomChildEntity implements Serializabl
*/
@ApiModelProperty(value = "物料状态")
private Integer systemMaterialState;
/**
* 父级物料编码
*/
private String parentMaterialNo;
}

View File

@ -1,15 +1,20 @@
package com.nflg.product.bomnew.service;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nflg.product.base.core.conmon.util.SessionUtil;
import com.nflg.product.bomnew.constant.DQBomStatusEnum;
import com.nflg.product.bomnew.constant.EbomEditStatusEnum;
import com.nflg.product.bomnew.constant.UserJobEnum;
import com.nflg.product.bomnew.constant.*;
import com.nflg.product.bomnew.pojo.dto.sap.impart2.ImportSapParamDTO;
import com.nflg.product.bomnew.pojo.dto.sap.impart2.T1DTO;
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomParentEntity;
import com.nflg.product.bomnew.pojo.query.BomNewDQbomPageQuery;
@ -21,12 +26,15 @@ import com.nflg.product.bomnew.pojo.vo.DQbomExcelVO;
import com.nflg.product.bomnew.util.BomUtil;
import com.nflg.product.bomnew.util.VUtils;
import lombok.extern.slf4j.Slf4j;
import nflg.product.common.constant.STATE;
import nflg.product.common.vo.ResultVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
@ -92,11 +100,11 @@ public class DQBomService {
*/
@Transactional(rollbackFor = Exception.class)
public void save(BomNewDQbomSaveQuery query) {
BomNewDQbomParentEntity parent = query.getParent();
BomNewDQbomParentEntity parent = new BomNewDQbomParentEntity();
BeanUtil.copyProperties(query.getParent(), parent);
BomNewDQbomChildEntity child;
List<BomNewDQbomParentEntity> liParents = new ArrayList<>();
List<BomNewDQbomChildEntity> liChildren = new ArrayList<>();
if (Objects.isNull(parent.getRowId())) {
//新增父级节点
@ -108,6 +116,7 @@ public class DQBomService {
VUtils.isTure(CollUtil.isEmpty(query.getChildren())).throwMessage("新添加的bom必须有子级");
parent.setRowId(IdWorker.getId());
parent.setLevel(1);
parent.setBomExist(1);
parent.setCreatedBy(SessionUtil.getUserCode());
parent.setStatus(DQBomStatusEnum.WAIT_CONVERT.getValue());
@ -133,7 +142,7 @@ public class DQBomService {
parent.setBomExist(1);
parent.setModifyTime(LocalDateTime.now());
child =
child = dQBomChildService.getById(query.getParent().getBomChildRowId());
}
//处理child
List<BomNewDQbomChildEntity> children = Convert.toList(BomNewDQbomChildEntity.class, query.getChildren());
@ -148,8 +157,7 @@ public class DQBomService {
c.setCreatedBy(SessionUtil.getUserCode());
c.setCreatedName(SessionUtil.getRealName());
}
liChildren.addAll(children);
dQBomChildService.saveBatch(liChildren);
dQBomChildService.saveBatch(children);
//处理parent
List<BomNewDQbomParentEntity> parents = Convert.toList(BomNewDQbomParentEntity.class, query.getChildren());
List<String> materialNos = dQBomParentService.lambdaQuery()
@ -217,13 +225,56 @@ public class DQBomService {
}
public List<DQbomExcelVO> exportBom(Long rootBomRowId) {
DQbomExcelVO root = dQBomParentService.getBaseMapper().getRootBomByRowId(rootBomRowId);
return Convert.toList(DQbomExcelVO.class, getAll(rootBomRowId));
}
private List<BomNewDQbomVO> getAll(Long rootBomRowId) {
BomNewDQbomVO root = dQBomParentService.getBaseMapper().getRootBomByRowId(rootBomRowId);
VUtils.isTure(Objects.isNull(root)).throwMessage("数据不存在");
List<DQbomExcelVO> datas = new ArrayList<>();
List<BomNewDQbomVO> datas = new ArrayList<>();
datas.add(root);
List<DQbomExcelVO> children = dQBomParentService.getBaseMapper().getChildren(rootBomRowId);
getChildren(datas, root);
return datas;
}
private void getChildren(List<BomNewDQbomVO> datas, BomNewDQbomVO parent) {
if (parent.getBomRowId() == 0) return;
List<BomNewDQbomVO> cc = dQBomParentService.getBaseMapper().getChildren(parent.getBomRowId());
if (CollUtil.isNotEmpty(cc)) {
cc.forEach(c -> {
c.setParentMaterialNo(parent.getMaterialNo());
datas.add(c);
getChildren(datas, c);
});
}
}
public void importToSAP(Long rootBomRowId) {
List<BomNewDQbomVO> datas = getAll(rootBomRowId);
ImportSapParamDTO sapDto = new ImportSapParamDTO();
sapDto.setZID(RandomUtil.randomNumbers(5));
sapDto.setI_WERKS(FactoryCodeEnum.FACTORY_1010.getValue());
sapDto.setI_STLAN("2");
String dateYMD = DateUtil.format(new Date(), "yyyyMMdd");
datas.forEach(d -> {
T1DTO t1 = new T1DTO();
t1.setID(RandomUtil.randomNumbers(5));
t1.setMATNR(d.getParentMaterialNo());
t1.setIDNRK(d.getMaterialNo());
t1.setMEINS(d.getMaterialUnit());
t1.setMENGE("1");
t1.setPOSTP(d.getProjectType());
t1.setDATUM(dateYMD);
sapDto.getT1().add(t1);
});
ResultVO<Boolean> resultVO = SpringUtil.getBean(SapOpUtilService.class).importToSapV2(sapDto, null);
if (resultVO.getState().equals(STATE.Success.getState())) {
BomNewDQbomParentEntity parentEntity = new BomNewDQbomParentEntity();
parentEntity.setRowId(rootBomRowId);
parentEntity.setSapState(MBomConstantEnum.MBomStatusEnum.PUB_SAP.getValue());
parentEntity.setSapTime(LocalDateTimeUtil.now());
dQBomParentService.updateById(parentEntity);
}
}
}

View File

@ -343,6 +343,8 @@ public class OriginalBomToEBomConvert extends BaseConvert {
ebom.setExpireEndTime(LocalDateTime.now());
this.eBomParentResult.add(ebom);
}
eBomParent.setRootIs(parentEnt.getRootIs());
eBomParent.setUserRootIs(parentEnt.getUserRootIs());
this.eBomParentResult.add(eBomParent);
return eBomParent.getRowId();

View File

@ -24,6 +24,8 @@
<result column="level" jdbcType="INTEGER" property="level"/>
<result column="edit_status" jdbcType="INTEGER" property="editStatus"/>
<result column="expire_end_time" jdbcType="TIMESTAMP" property="expireEndTime"/>
<result column="sap_state" jdbcType="INTEGER" property="sapState"/>
<result column="sap_time" jdbcType="TIMESTAMP" property="sapTime"/>
</resultMap>
<!--分页获取数据-->
<select id="getPageList" resultType="com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO">
@ -67,25 +69,26 @@
WHERE p.row_id = #{rowId};
</select>
<select id="getRootBomByRowId" resultType="com.nflg.product.bomnew.pojo.vo.DQbomExcelVO">
SELECT p.level,
p.material_no,
p.drawing_no,
p.material_name,
p.material_texture,
c.num,
p.material_unit,
c.project_type,
p.current_version,
p.unit_weight,
c.remark
FROM t_bom_new_dqbom_child c
JOIN t_bom_new_dqbom_parent p ON c.material_no = p.material_no AND c.parent_row_id = 0
WHERE p.row_id = #{rootBomRowId}
<select id="getRootBomByRowId" resultType="com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO">
SELECT level,
material_no,
drawing_no,
material_name,
material_texture,
num,
material_unit,
project_type,
current_version,
unit_weight,
remark
FROM t_bom_new_dqbom_parent
WHERE row_id = #{rootBomRowId}
</select>
<select id="getChildren" resultType="com.nflg.product.bomnew.pojo.vo.DQbomExcelVO">
SELECT c.level,
<select id="getChildren" resultType="com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO">
SELECT ifnull(p.row_id, 0) AS bomRowId,
c.row_id,
c.level,
c.material_no,
c.drawing_no,
c.material_name,
@ -97,7 +100,8 @@
ifnull(p.unit_weight, c.unit_weight) unit_weight,
c.remark
FROM t_bom_new_dqbom_child c
LEFT JOIN t_bom_new_dqbom_parent p ON c.material_no = p.material_no AND c.parent_row_id = 0
WHERE p.row_id = #{rootBomRowId}
LEFT JOIN t_bom_new_dqbom_parent p ON c.material_no = p.material_no AND p.last_version_is = 1
WHERE c.parent_row_id = #{rootBomRowId}
order by c.level
</select>
</mapper>