Browse Source

fix:增加三方物料的导入

dist.1.3.0
pref_mail@163.com 9 months ago
parent
commit
db5da08375
  1. 13
      blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/entity/BasicdataFactoryCategoryEntity.java
  2. 2
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/controller/BasicdataCategoryController.java
  3. 39
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/controller/BasicdataFactoryCategoryController.java
  4. 4
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/excel/BasicdataCategoryExcel.java
  5. 65
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/excel/BasicdataFactoryCategoryExcel.java
  6. 112
      blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/excel/BasicdataFactoryCategoryImporter.java

13
blade-service-api/logpm-basicdata-api/src/main/java/com/logpm/basicdata/entity/BasicdataFactoryCategoryEntity.java

@ -40,12 +40,25 @@ public class BasicdataFactoryCategoryEntity extends TenantEntity {
private String reserve5;
@ApiModelProperty(value = "结算品类id")
private Long categoryId;
@ApiModelProperty(value = "结算品类名称")
private String category;
@ApiModelProperty(value = "一级品")
private String firsts;
@ApiModelProperty(value = "二级品")
private String seconds;
@ApiModelProperty(value = "三级品")
private String thirds;
@ApiModelProperty(value = "品牌名称")
private String brand;
@ApiModelProperty(value = "品牌id")
private Long brandId;

2
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/controller/BasicdataCategoryController.java

@ -177,7 +177,7 @@ public class BasicdataCategoryController extends BladeController {
ExcelUtil.export(response, "品类数据" + DateUtil.time(), "品类数据表", list, BasicdataCategoryExcel.class);
}
/**
* 导出数据
* 下载模板
*/
@GetMapping("/downTemplate")
@ApiOperationSupport(order = 9)

39
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/controller/BasicdataFactoryCategoryController.java

@ -4,6 +4,12 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.logpm.basicdata.dto.BasicdataFactoryCategoryDTO;
import com.logpm.basicdata.entity.BasicdataFactoryCategoryEntity;
import com.logpm.basicdata.excel.BasicdataCategoryExcel;
import com.logpm.basicdata.excel.BasicdataCategoryImporter;
import com.logpm.basicdata.excel.BasicdataFactoryCategoryExcel;
import com.logpm.basicdata.excel.BasicdataFactoryCategoryImporter;
import com.logpm.basicdata.service.IBasicdataBrandService;
import com.logpm.basicdata.service.IBasicdataCategoryService;
import com.logpm.basicdata.service.IBasicdataFactoryCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -11,8 +17,15 @@ import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.common.exception.CustomerException;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.excel.util.ExcelUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.DateUtil;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
@Slf4j
@RestController
@ -22,8 +35,8 @@ import org.springframework.web.bind.annotation.*;
public class BasicdataFactoryCategoryController extends BladeController {
private final IBasicdataFactoryCategoryService basicdataFactoryCategoryService;
private final IBasicdataBrandService basicdataBrandService;
private final IBasicdataCategoryService basicdataCategoryService;
@ResponseBody
@PostMapping("/pageList")
@ -85,5 +98,27 @@ public class BasicdataFactoryCategoryController extends BladeController {
}
/**
* 下载模板
*/
@GetMapping("/downTemplate")
@ApiOperationSupport(order = 9)
@ApiOperation(value = "下载导出模板", notes = "下载导出模板")
public void downTemplate(HttpServletResponse response) {
List<BasicdataFactoryCategoryExcel> list = new ArrayList<>();
ExcelUtil.export(response, "工厂品类数据" + DateUtil.time(), "工厂品类数据", list, BasicdataFactoryCategoryExcel.class);
}
@PostMapping("/import")
@ApiOperationSupport(order = 12)
@ApiOperation(value = "导入品类", notes = "传入excel")
public R importCategory(MultipartFile file) {
BasicdataFactoryCategoryImporter basicdataFactoryCategoryImporter = new BasicdataFactoryCategoryImporter(basicdataFactoryCategoryService,basicdataBrandService,basicdataCategoryService);
ExcelUtil.save(file, basicdataFactoryCategoryImporter, BasicdataFactoryCategoryExcel.class);
return R.success("操作成功");
}
}

4
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/excel/BasicdataCategoryExcel.java

@ -29,8 +29,8 @@ import java.io.Serializable;
/**
* 品类 Excel实体类
*
* @author cyz
* @since 2023-06-02
* @author chao
* @since 2024-04-19
*/
@Data
@ColumnWidth(25)

65
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/excel/BasicdataFactoryCategoryExcel.java

@ -0,0 +1,65 @@
/*
* Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* Neither the name of the dreamlu.net developer nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* Author: Chill 庄骞 (smallchill@163.com)
*/
package com.logpm.basicdata.excel;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
/**
* 工厂品类导入
*
* @author chao
* @date 2024/04/19
*/
@Data
@ColumnWidth(25)
@HeadRowHeight(20)
@ContentRowHeight(18)
public class BasicdataFactoryCategoryExcel implements Serializable {
private static final long serialVersionUID = 1L;
@ColumnWidth(20)
@ExcelProperty("品牌")
private String brand;
@ColumnWidth(20)
@ExcelProperty("结算品类")
private String category;
@ColumnWidth(20)
@ExcelProperty("一级品")
private String firsts;
@ColumnWidth(20)
@ExcelProperty("二级品")
private String seconds;
@ColumnWidth(20)
@ExcelProperty("三级品")
private String thirds;
}

112
blade-service/logpm-basicdata/src/main/java/com/logpm/basicdata/excel/BasicdataFactoryCategoryImporter.java

@ -0,0 +1,112 @@
package com.logpm.basicdata.excel;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.logpm.basicdata.entity.BasicdataBrandEntity;
import com.logpm.basicdata.entity.BasicdataCategoryEntity;
import com.logpm.basicdata.entity.BasicdataFactoryCategoryEntity;
import com.logpm.basicdata.service.IBasicdataBrandService;
import com.logpm.basicdata.service.IBasicdataCategoryService;
import com.logpm.basicdata.service.IBasicdataFactoryCategoryService;
import lombok.AllArgsConstructor;
import org.springblade.core.excel.support.ExcelImporter;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
@AllArgsConstructor
public class BasicdataFactoryCategoryImporter implements ExcelImporter<BasicdataFactoryCategoryExcel> {
private final IBasicdataFactoryCategoryService basicdataFactoryCategoryService;
private final IBasicdataBrandService basicdataBrandService;
private final IBasicdataCategoryService basicdataCategoryService;
@Transactional(rollbackFor = RuntimeException.class)
@Override
public void save(List<BasicdataFactoryCategoryExcel> data) {
LambdaQueryWrapper<BasicdataBrandEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(BasicdataBrandEntity::getIsDeleted, 0);
List<BasicdataBrandEntity> list = basicdataBrandService.list(queryWrapper);
LambdaQueryWrapper<BasicdataCategoryEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(BasicdataCategoryEntity::getIsDeleted, 0);
List<BasicdataCategoryEntity> basicdataCategoryEntities = basicdataCategoryService.list(lambdaQueryWrapper);
LambdaQueryWrapper<BasicdataFactoryCategoryEntity> lambdaQueryWrapper1 = new LambdaQueryWrapper<>();
lambdaQueryWrapper1.eq(BasicdataFactoryCategoryEntity::getIsDeleted, 0);
List<BasicdataFactoryCategoryEntity> allBasicdataFactoryCategoryEntities = basicdataFactoryCategoryService.list(lambdaQueryWrapper1);
List<BasicdataFactoryCategoryEntity> basicdataFactoryCategoryEntities = new ArrayList<>();
for (BasicdataFactoryCategoryExcel datum : data) {
boolean isBrandFound = list.stream()
.anyMatch(entity -> entity.getBrandName().equals(datum.getBrand()));
// 根据 isBrandFound 的值进行相应的处理
if (!isBrandFound) {
// 或者执行其他逻辑,如记录到日志、抛出异常等
throw new ServiceException(datum.getBrand() + "品牌在系统中不存在!");
}
isBrandFound = basicdataCategoryEntities.stream().anyMatch(entity -> entity.getName().equals(datum.getCategory()));
if (!isBrandFound) {
// 或者执行其他逻辑,如记录到日志、抛出异常等
throw new ServiceException(datum.getCategory() + "结算品类在系统中不存在!");
}
// 需要判断目前增加的三方物料在系统中是否已经存在
checkAllBasicdataFactoryCategoryEntities(allBasicdataFactoryCategoryEntities, datum);
BasicdataFactoryCategoryEntity basicdataFactoryCategoryEntity = BeanUtil.copy(datum, BasicdataFactoryCategoryEntity.class);
if (ObjectUtil.isNotEmpty(basicdataFactoryCategoryEntity)) {
assert basicdataFactoryCategoryEntity != null;
basicdataFactoryCategoryEntity.setBrandId(list.stream().filter(entity -> entity.getBrandName().equals(basicdataFactoryCategoryEntity.getBrand())).findFirst().get().getId());
basicdataFactoryCategoryEntity.setCategoryId(basicdataCategoryEntities.stream().filter(entity -> entity.getName().equals(basicdataFactoryCategoryEntity.getCategory())).findFirst().get().getId());
}
basicdataFactoryCategoryEntities.add(basicdataFactoryCategoryEntity);
}
basicdataFactoryCategoryService.saveBatch(basicdataFactoryCategoryEntities);
}
/**
* 验证三方物料是否已经存在
* @param allBasicdataFactoryCategoryEntities
* @param datum
*/
private void checkAllBasicdataFactoryCategoryEntities(List<BasicdataFactoryCategoryEntity> allBasicdataFactoryCategoryEntities, BasicdataFactoryCategoryExcel datum) {
for (BasicdataFactoryCategoryEntity allBasicdataFactoryCategoryEntity : allBasicdataFactoryCategoryEntities) {
if (allBasicdataFactoryCategoryEntity.getBrand().equals(datum.getBrand()) && allBasicdataFactoryCategoryEntity.getCategory().equals(datum.getCategory()) ){
if(ObjectUtil.isNotEmpty(allBasicdataFactoryCategoryEntity.getFirsts())&& ObjectUtil.isNotEmpty(allBasicdataFactoryCategoryEntity.getSeconds())&& ObjectUtil.isNotEmpty(allBasicdataFactoryCategoryEntity.getThirds())){
if(allBasicdataFactoryCategoryEntity.getFirsts().equals(datum.getFirsts()) && allBasicdataFactoryCategoryEntity.getSeconds().equals(datum.getSeconds()) && allBasicdataFactoryCategoryEntity.getThirds().equals(datum.getThirds())){
throw new ServiceException("品牌:" + datum.getBrand() + " 品类:" + datum.getCategory() + "一级品:"+datum.getFirsts()+" 二级品:"+datum.getSeconds()+" 三级品:"+datum.getThirds()+"已存在相同的配置内容");
}
}else if(ObjectUtil.isNotEmpty(allBasicdataFactoryCategoryEntity.getFirsts())&& ObjectUtil.isNotEmpty(allBasicdataFactoryCategoryEntity.getSeconds())){
if (allBasicdataFactoryCategoryEntity.getFirsts().equals(datum.getFirsts()) && allBasicdataFactoryCategoryEntity.getSeconds().equals(datum.getSeconds())){
throw new ServiceException("品牌:" + datum.getBrand() + " 品类:" + datum.getCategory() + "一级品:"+datum.getFirsts()+" 二级品:"+datum.getSeconds()+"已存在相同的配置内容");
}
} else if (ObjectUtil.isNotEmpty(allBasicdataFactoryCategoryEntity.getFirsts())) {
if (allBasicdataFactoryCategoryEntity.getFirsts().equals(datum.getFirsts())){
throw new ServiceException("品牌:" + datum.getBrand() + " 品类:" + datum.getCategory() + "一级品:"+datum.getFirsts()+"已存在相同的配置内容");
}
}
}
}
}
}
Loading…
Cancel
Save