fix product

plp
chenshuichuan 2 years ago
parent 6d9be1cd27
commit cf9f50266f

@ -29,15 +29,13 @@ public class MoldBrandPageReqVO extends PageParam {
private Long productId;
@Schema(description = "预期寿命(小时)")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private BigDecimal[] useTime;
private BigDecimal useTime;
@Schema(description = "维保模式", example = "2")
private Integer maintainType;
@Schema(description = "维保周期")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private BigDecimal[] maintainTime;
private BigDecimal maintainTime;
@Schema(description = "模具系数")
private Long moldSize;

@ -35,7 +35,7 @@ public class MoldBrandRespVO {
@Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "2336")
private Long productId;
@Schema(description = "产品", requiredMode = Schema.RequiredMode.REQUIRED, example = "2336")
@ExcelProperty("产品ID")
@ExcelProperty("产品")
private String productName;
@Schema(description = "预期寿命(小时)")

@ -29,8 +29,7 @@ public class MoldPageReqVO extends PageParam {
private Long machineId;
@Schema(description = "使用时间(小时)")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private BigDecimal[] useTime;
private BigDecimal useTime;
@Schema(description = "入库时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)

@ -11,6 +11,9 @@ import com.alibaba.excel.annotation.*;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 模具 Response VO")
@Data
@ExcelIgnoreUnannotated
@ -44,6 +47,7 @@ public class MoldRespVO {
@Schema(description = "入库时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("入库时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY)
private LocalDateTime inTime;
@Schema(description = "状态", example = "1")

@ -23,9 +23,9 @@ public interface MoldBrandMapper extends BaseMapperX<MoldBrandDO> {
.likeIfPresent(MoldBrandDO::getName, reqVO.getName())
.eqIfPresent(MoldBrandDO::getMoldType, reqVO.getMoldType())
.eqIfPresent(MoldBrandDO::getProductId, reqVO.getProductId())
.betweenIfPresent(MoldBrandDO::getUseTime, reqVO.getUseTime())
.eqIfPresent(MoldBrandDO::getUseTime, reqVO.getUseTime())
.eqIfPresent(MoldBrandDO::getMaintainType, reqVO.getMaintainType())
.betweenIfPresent(MoldBrandDO::getMaintainTime, reqVO.getMaintainTime())
.eqIfPresent(MoldBrandDO::getMaintainTime, reqVO.getMaintainTime())
.eqIfPresent(MoldBrandDO::getMoldSize, reqVO.getMoldSize())
.eqIfPresent(MoldBrandDO::getRemark, reqVO.getRemark())
.eqIfPresent(MoldBrandDO::getIsEnable, reqVO.getIsEnable())

@ -29,7 +29,11 @@
<artifactId>yudao-module-system-api</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-erp-biz</artifactId>
<version>${revision}</version>
</dependency>
<!-- 业务组件 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>

@ -75,8 +75,8 @@ public class BomController {
@Operation(summary = "获得产品BOM分页")
@PreAuthorize("@ss.hasPermission('mes:bom:query')")
public CommonResult<PageResult<BomRespVO>> getBomPage(@Valid BomPageReqVO pageReqVO) {
PageResult<BomDO> pageResult = bomService.getBomPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, BomRespVO.class));
PageResult<BomRespVO> pageResult = bomService.getBomPage(pageReqVO);
return success(pageResult);
}
@GetMapping("/export-excel")
@ -86,10 +86,10 @@ public class BomController {
public void exportBomExcel(@Valid BomPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<BomDO> list = bomService.getBomPage(pageReqVO).getList();
List<BomRespVO> list = bomService.getBomPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "产品BOM.xls", "数据", BomRespVO.class,
BeanUtils.toBean(list, BomRespVO.class));
list);
}
// ==================== 子表产品BOM明细 ====================
@ -98,7 +98,7 @@ public class BomController {
@Operation(summary = "获得产品BOM明细列表")
@Parameter(name = "bomId", description = "BOM ID")
@PreAuthorize("@ss.hasPermission('mes:bom:query')")
public CommonResult<List<BomDetailDO>> getBomDetailListByBomId(@RequestParam("bomId") Long bomId) {
public CommonResult<List<BomDetailRespVO>> getBomDetailListByBomId(@RequestParam("bomId") Long bomId) {
return success(bomService.getBomDetailListByBomId(bomId));
}

@ -0,0 +1,61 @@
package cn.iocoder.yudao.module.mes.controller.admin.bom.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import java.util.*;
import java.math.BigDecimal;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
import cn.iocoder.yudao.framework.excel.core.annotations.DictFormat;
import cn.iocoder.yudao.framework.excel.core.convert.DictConvert;
@Schema(description = "管理后台 - 产品BOM明细 Response VO")
@Data
@ExcelIgnoreUnannotated
public class BomDetailRespVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "22516")
@ExcelProperty("ID")
private Long id;
@Schema(description = "原料ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "17312")
@ExcelProperty("原料ID")
private Long productId;
@Schema(description = "原料", requiredMode = Schema.RequiredMode.REQUIRED, example = "2336")
@ExcelProperty("原料")
private String productName;
@Schema(description = "单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "24169")
@ExcelProperty("单位ID")
private Long unitId;
@Schema(description = "单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "个")
@ExcelProperty("单位")
private String unitName;
@Schema(description = "BOM ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "30665")
@ExcelProperty("BOM ID")
private Long bomId;
@Schema(description = "用量", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("用量")
private BigDecimal usage;
@Schema(description = "损耗率%")
@ExcelProperty("损耗率%")
private BigDecimal yieldRate;
@Schema(description = "备注", example = "你说的对")
@ExcelProperty("备注")
private String remark;
@Schema(description = "是否启用")
@ExcelProperty(value = "是否启用", converter = DictConvert.class)
@DictFormat("infra_boolean_string") // TODO 代码优化:建议设置到对应的 DictTypeConstants 枚举类中
private Boolean isEnable;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

@ -31,10 +31,16 @@ public class BomRespVO {
@Schema(description = "产品ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "5633")
@ExcelProperty("产品ID")
private Long productId;
@Schema(description = "产品", requiredMode = Schema.RequiredMode.REQUIRED, example = "2336")
@ExcelProperty("产品")
private String productName;
@Schema(description = "单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "24261")
@ExcelProperty("单位ID")
private Long unitId;
@Schema(description = "单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "个")
@ExcelProperty("单位")
private String unitName;
@Schema(description = "成品率%")
@ExcelProperty("成品率%")

@ -52,7 +52,7 @@ public interface BomService {
* @param pageReqVO
* @return BOM
*/
PageResult<BomDO> getBomPage(BomPageReqVO pageReqVO);
PageResult<BomRespVO> getBomPage(BomPageReqVO pageReqVO);
// ==================== 子表产品BOM明细 ====================
@ -62,6 +62,6 @@ public interface BomService {
* @param bomId BOM ID
* @return BOM
*/
List<BomDetailDO> getBomDetailListByBomId(Long bomId);
List<BomDetailRespVO> getBomDetailListByBomId(Long bomId);
}

@ -1,5 +1,12 @@
package cn.iocoder.yudao.module.mes.service.bom;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.module.erp.dal.dataobject.mold.MoldDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO;
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
import cn.iocoder.yudao.module.erp.service.product.ErpProductUnitService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
@ -18,6 +25,7 @@ import cn.iocoder.yudao.module.mes.dal.mysql.bom.BomDetailMapper;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
/**
@ -33,7 +41,10 @@ public class BomServiceImpl implements BomService {
private BomMapper bomMapper;
@Resource
private BomDetailMapper bomDetailMapper;
@Resource
private ErpProductService productService;
@Resource
private ErpProductUnitService productUnitService;
@Override
@Transactional(rollbackFor = Exception.class)
public Long createBom(BomSaveReqVO createReqVO) {
@ -84,17 +95,49 @@ public class BomServiceImpl implements BomService {
}
@Override
public PageResult<BomDO> getBomPage(BomPageReqVO pageReqVO) {
return bomMapper.selectPage(pageReqVO);
public PageResult<BomRespVO> getBomPage(BomPageReqVO pageReqVO) {
PageResult<BomDO> pageResult = bomMapper.selectPage(pageReqVO);
return new PageResult<>(buildVOList(pageResult.getList()), pageResult.getTotal());
}
private List<BomRespVO> buildVOList(List<BomDO> list) {
if (CollUtil.isEmpty(list)) {
return Collections.emptyList();
}
Map<Long, ErpProductDO> map = productService.getProductMap(
convertSet(list, BomDO::getProductId));
Map<Long, ErpProductUnitDO> unitMap = productUnitService.getProductUnitMap(
convertSet(list, BomDO::getUnitId));
return BeanUtils.toBean(list, BomRespVO.class, item -> {
MapUtils.findAndThen(map, item.getProductId(),
product -> item.setProductName(product.getName()));
MapUtils.findAndThen(unitMap, item.getUnitId(),
unit -> item.setUnitName(unit.getName()));
});
}
// ==================== 子表产品BOM明细 ====================
@Override
public List<BomDetailDO> getBomDetailListByBomId(Long bomId) {
return bomDetailMapper.selectListByBomId(bomId);
public List<BomDetailRespVO> getBomDetailListByBomId(Long bomId) {
List<BomDetailDO> list = bomDetailMapper.selectListByBomId(bomId);
return buildDetailVOList(list);
}
private List<BomDetailRespVO> buildDetailVOList(List<BomDetailDO> list) {
if (CollUtil.isEmpty(list)) {
return Collections.emptyList();
}
Map<Long, ErpProductDO> map = productService.getProductMap(
convertSet(list, BomDetailDO::getProductId));
Map<Long, ErpProductUnitDO> unitMap = productUnitService.getProductUnitMap(
convertSet(list, BomDetailDO::getUnitId));
return BeanUtils.toBean(list, BomDetailRespVO.class, item -> {
MapUtils.findAndThen(map, item.getProductId(),
product -> item.setProductName(product.getName()));
MapUtils.findAndThen(unitMap, item.getUnitId(),
unit -> item.setUnitName(unit.getName()));
});
}
private void createBomDetailList(Long bomId, List<BomDetailDO> list) {
list.forEach(o -> o.setBomId(bomId));
bomDetailMapper.insertBatch(list);

@ -146,7 +146,7 @@ public class BomServiceImplTest extends BaseDbUnitTest {
reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28));
// 调用
PageResult<BomDO> pageResult = bomService.getBomPage(reqVO);
PageResult<BomRespVO> pageResult = bomService.getBomPage(reqVO);
// 断言
assertEquals(1, pageResult.getTotal());
assertEquals(1, pageResult.getList().size());

@ -64,7 +64,7 @@ spring:
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
redis:
host: 47.106.185.127 # 地址
host: 127.0.0.1 # 地址
port: 6379 # 端口
database: 0 # 数据库索引
#password: bkcaydy8ydhZZnS2 # 密码,建议生产环境开启

Loading…
Cancel
Save