| | |
| | | import com.ruoyi.common.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.common.utils.uuid.IdUtils; |
| | | import com.ruoyi.other.mapper.TempFileMapper; |
| | | import com.ruoyi.other.service.impl.TempFileServiceImpl; |
| | | import com.ruoyi.sales.mapper.CommonFileMapper; |
| | | import com.ruoyi.sales.mapper.SalesLedgerProductMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedgerProduct; |
| | | import com.ruoyi.sales.service.impl.CommonFileServiceImpl; |
| | | import lombok.AllArgsConstructor; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.AbstractMap; |
| | |
| | | private final ProductMapper productMapper; |
| | | private final SalesLedgerProductMapper salesLedgerProductMapper; |
| | | private ProductModelMapper productModelMapper; |
| | | private final CommonFileServiceImpl commonFileService; |
| | | |
| | | private final TempFileServiceImpl tempFileService; |
| | | |
| | | @Override |
| | | public int addOrEditProductModel(ProductModelDto productModelDto) { |
| | | public int addOrEditProductModel(ProductModelDto productModelDto) throws IOException { |
| | | if(StringUtils.isEmpty(productModelDto.getProductName())){ |
| | | throw new RuntimeException("产品名称不能为空"); |
| | | } |
| | |
| | | ProductModel productModel = new ProductModel(); |
| | | BeanUtils.copyProperties(productModelDto,productModel); |
| | | productModel.setProductId(product.getId()); |
| | | return productModelMapper.insert(productModel); |
| | | productModelMapper.insert(productModel); |
| | | if(CollectionUtils.isNotEmpty(productModelDto.getTempFileIds())){ |
| | | commonFileService.migrateTempFilesToFormal(productModel.getId(), productModelDto.getTempFileIds()); |
| | | } |
| | | return 1; |
| | | } else { |
| | | Product product1 = productMapper.selectById(productModelDto.getProductId()); |
| | | if(product1 != null){ |
| | | product1.setProductName(productModelDto.getProductName()); |
| | | productMapper.updateById(product1); |
| | | } |
| | | |
| | | if(CollectionUtils.isNotEmpty(productModelDto.getTempFileIds())){ |
| | | commonFileService.migrateTempFilesToFormal(productModelDto.getId(), productModelDto.getTempFileIds()); |
| | | } |
| | | return productModelMapper.updateById(productModelDto); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | try { |
| | | ExcelUtil<ProductModelExcelCopyDto> productModelExcelUtil = new ExcelUtil<>(ProductModelExcelCopyDto.class); |
| | | List<ProductModelExcelCopyDto> productModelList = productModelExcelUtil.importExcel(file.getInputStream()); |
| | | // List<Product> productList = productMapper.selectList(new LambdaQueryWrapper<Product>() |
| | | // .isNull(Product::getParentId)); |
| | | // if(CollectionUtils.isEmpty(productList)) { |
| | | // throw new RuntimeException("请先添加父级产品"); |
| | | // } |
| | | if(CollectionUtils.isNotEmpty(productModelList)){ |
| | | // 2. 按产品名称,图纸编号分组 |
| | | Map<Map.Entry<String, String>, List<ProductModelExcelCopyDto>> groupedByProductNameAndDrawingNumber = |