plp
chenyuan 2 years ago
parent b722c53492
commit 42eb696cc9

@ -77,8 +77,8 @@ public class MoldBrandController {
@Operation(summary = "获得模具型号分页") @Operation(summary = "获得模具型号分页")
@PreAuthorize("@ss.hasPermission('erp:mold-brand:query')") @PreAuthorize("@ss.hasPermission('erp:mold-brand:query')")
public CommonResult<PageResult<MoldBrandRespVO>> getMoldBrandPage(@Valid MoldBrandPageReqVO pageReqVO) { public CommonResult<PageResult<MoldBrandRespVO>> getMoldBrandPage(@Valid MoldBrandPageReqVO pageReqVO) {
PageResult<MoldBrandDO> pageResult = moldBrandService.getMoldBrandPage(pageReqVO); PageResult<MoldBrandRespVO> pageResult = moldBrandService.getMoldBrandPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, MoldBrandRespVO.class)); return success(pageResult);
} }
@GetMapping("/export-excel") @GetMapping("/export-excel")
@ -88,10 +88,9 @@ public class MoldBrandController {
public void exportMoldBrandExcel(@Valid MoldBrandPageReqVO pageReqVO, public void exportMoldBrandExcel(@Valid MoldBrandPageReqVO pageReqVO,
HttpServletResponse response) throws IOException { HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<MoldBrandDO> list = moldBrandService.getMoldBrandPage(pageReqVO).getList(); List<MoldBrandRespVO> list = moldBrandService.getMoldBrandPage(pageReqVO).getList();
// 导出 Excel // 导出 Excel
ExcelUtils.write(response, "模具型号.xls", "数据", MoldBrandRespVO.class, ExcelUtils.write(response, "模具型号.xls", "数据", MoldBrandRespVO.class, list);
BeanUtils.toBean(list, MoldBrandRespVO.class));
} }
// ==================== 子表(模具) ==================== // ==================== 子表(模具) ====================
@ -100,8 +99,7 @@ public class MoldBrandController {
@Operation(summary = "获得模具分页") @Operation(summary = "获得模具分页")
@Parameter(name = "brandId", description = "型号id") @Parameter(name = "brandId", description = "型号id")
@PreAuthorize("@ss.hasPermission('erp:mold-brand:query')") @PreAuthorize("@ss.hasPermission('erp:mold-brand:query')")
public CommonResult<PageResult<MoldDO>> getMoldPage(PageParam pageReqVO, public CommonResult<PageResult<MoldRespVO>> getMoldPage(PageParam pageReqVO, @RequestParam("brandId") Long brandId) {
@RequestParam("brandId") Long brandId) {
return success(moldBrandService.getMoldPage(pageReqVO, brandId)); return success(moldBrandService.getMoldPage(pageReqVO, brandId));
} }

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

@ -29,8 +29,10 @@ public class MoldRespVO {
private String name; private String name;
@Schema(description = "单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "19527") @Schema(description = "单位ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "19527")
@ExcelProperty("单位ID")
private Long unitId; private Long unitId;
@Schema(description = "单位", requiredMode = Schema.RequiredMode.REQUIRED, example = "个")
@ExcelProperty("单位")
private String unitName;
@Schema(description = "机台ID", example = "24428") @Schema(description = "机台ID", example = "24428")
@ExcelProperty("机台ID") @ExcelProperty("机台ID")

@ -52,7 +52,7 @@ public interface MoldBrandService {
* @param pageReqVO * @param pageReqVO
* @return * @return
*/ */
PageResult<MoldBrandDO> getMoldBrandPage(MoldBrandPageReqVO pageReqVO); PageResult<MoldBrandRespVO> getMoldBrandPage(MoldBrandPageReqVO pageReqVO);
// ==================== 子表(模具) ==================== // ==================== 子表(模具) ====================
@ -63,7 +63,7 @@ public interface MoldBrandService {
* @param brandId id * @param brandId id
* @return * @return
*/ */
PageResult<MoldDO> getMoldPage(PageParam pageReqVO, Long brandId); PageResult<MoldRespVO> getMoldPage(PageParam pageReqVO, Long brandId);
/** /**
* *

@ -1,5 +1,14 @@
package cn.iocoder.yudao.module.erp.service.mold; package cn.iocoder.yudao.module.erp.service.mold;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductCategoryDO;
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.stereotype.Service;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -18,6 +27,7 @@ import cn.iocoder.yudao.module.erp.dal.mysql.mold.MoldMapper;
import javax.annotation.Resource; import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; 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.erp.enums.ErrorCodeConstants.*; import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.*;
/** /**
@ -33,7 +43,10 @@ public class MoldBrandServiceImpl implements MoldBrandService {
private MoldBrandMapper moldBrandMapper; private MoldBrandMapper moldBrandMapper;
@Resource @Resource
private MoldMapper moldMapper; private MoldMapper moldMapper;
@Resource
private ErpProductUnitService productUnitService;
@Resource
private ErpProductService productService;
@Override @Override
public Long createMoldBrand(MoldBrandSaveReqVO createReqVO) { public Long createMoldBrand(MoldBrandSaveReqVO createReqVO) {
// 插入 // 插入
@ -76,17 +89,40 @@ public class MoldBrandServiceImpl implements MoldBrandService {
} }
@Override @Override
public PageResult<MoldBrandDO> getMoldBrandPage(MoldBrandPageReqVO pageReqVO) { public PageResult<MoldBrandRespVO> getMoldBrandPage(MoldBrandPageReqVO pageReqVO) {
return moldBrandMapper.selectPage(pageReqVO); PageResult<MoldBrandDO> pageResult = moldBrandMapper.selectPage(pageReqVO);
return new PageResult<>(buildMoldBrandVOList(pageResult.getList()),pageResult.getTotal());
}
private List<MoldBrandRespVO> buildMoldBrandVOList(List<MoldBrandDO> list) {
if (CollUtil.isEmpty(list)) {
return Collections.emptyList();
}
Map<Long, ErpProductDO> map = productService.getProductMap(
convertSet(list, MoldBrandDO::getProductId));
return BeanUtils.toBean(list, MoldBrandRespVO.class, item -> {
MapUtils.findAndThen(map, item.getProductId(),
product -> item.setProductName(product.getName()));
});
} }
// ==================== 子表(模具) ==================== // ==================== 子表(模具) ====================
@Override @Override
public PageResult<MoldDO> getMoldPage(PageParam pageReqVO, Long brandId) { public PageResult<MoldRespVO> getMoldPage(PageParam pageReqVO, Long brandId) {
return moldMapper.selectPage(pageReqVO, brandId); PageResult<MoldDO> pageResult = moldMapper.selectPage(pageReqVO, brandId);
return new PageResult<>(buildMoldVOList(pageResult.getList()), pageResult.getTotal());
} }
private List<MoldRespVO> buildMoldVOList(List<MoldDO> list) {
if (CollUtil.isEmpty(list)) {
return Collections.emptyList();
}
Map<Long, ErpProductUnitDO> unitMap = productUnitService.getProductUnitMap(
convertSet(list, MoldDO::getUnitId));
return BeanUtils.toBean(list, MoldRespVO.class, product -> {
MapUtils.findAndThen(unitMap, product.getUnitId(),
unit -> product.setUnitName(unit.getName()));
});
}
@Override @Override
public Long createMold(MoldDO mold) { public Long createMold(MoldDO mold) {
moldMapper.insert(mold); moldMapper.insert(mold);

@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProduc
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO; import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductSaveReqVO; import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductSaveReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO; import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO;
import javax.validation.Valid; import javax.validation.Valid;
import java.util.Collection; import java.util.Collection;
@ -107,5 +108,14 @@ public interface ErpProductService {
* @return * @return
*/ */
Long getProductCountByUnitId(Long unitId); Long getProductCountByUnitId(Long unitId);
/**
*
*
* @param ids
* @return
*/
List<ErpProductDO> getProductList(Collection<Long> ids);
default Map<Long, ErpProductDO> getProductMap(Collection<Long> ids) {
return convertMap(getProductList(ids), ErpProductDO::getId);
}
} }

@ -148,5 +148,8 @@ public class ErpProductServiceImpl implements ErpProductService {
public Long getProductCountByUnitId(Long unitId) { public Long getProductCountByUnitId(Long unitId) {
return productMapper.selectCountByUnitId(unitId); return productMapper.selectCountByUnitId(unitId);
} }
@Override
public List<ErpProductDO> getProductList(Collection<Long> ids) {
return productMapper.selectBatchIds(ids);
}
} }
Loading…
Cancel
Save