pref_mail@163.com
9 months ago
6 changed files with 254 additions and 29 deletions
@ -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; |
||||
|
||||
} |
@ -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…
Reference in new issue