4097 lines
220 KiB
Java
4097 lines
220 KiB
Java
package com.vverp.service;
|
||
|
||
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
||
import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
|
||
import cn.hutool.core.comparator.CompareUtil;
|
||
import com.vverp.base.exception.ImportExcelException;
|
||
import com.vverp.constant.MaterialOrderItemConsts;
|
||
import com.vverp.dao.MaterialOrderDao;
|
||
import com.vverp.dto.CellDto;
|
||
import com.vverp.dto.CompanyQuery;
|
||
import com.vverp.dto.OrderInfo;
|
||
import com.vverp.dto.OrderQuery;
|
||
import com.vverp.entity.*;
|
||
import com.vverp.enums.OrderStatus;
|
||
import com.vverp.moli.util.DateUtil;
|
||
import com.vverp.moli.util.Filter;
|
||
import com.vverp.moli.util.Page;
|
||
import com.vverp.moli.util.Pageable;
|
||
import com.vverp.util.*;
|
||
import org.apache.commons.io.IOUtils;
|
||
import org.apache.commons.lang.StringUtils;
|
||
import org.apache.commons.lang3.BooleanUtils;
|
||
import org.apache.poi.hssf.usermodel.*;
|
||
import org.apache.poi.ss.usermodel.*;
|
||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||
import org.glassfish.jersey.internal.jsr166.Flow;
|
||
import org.slf4j.Logger;
|
||
import org.slf4j.LoggerFactory;
|
||
import org.springframework.beans.BeanUtils;
|
||
import org.springframework.context.annotation.Lazy;
|
||
import org.springframework.mock.web.MockMultipartFile;
|
||
import org.springframework.stereotype.Service;
|
||
import org.springframework.transaction.annotation.Propagation;
|
||
import org.springframework.transaction.annotation.Transactional;
|
||
import org.springframework.web.multipart.MultipartFile;
|
||
|
||
import javax.annotation.Resource;
|
||
import javax.servlet.ServletOutputStream;
|
||
import javax.servlet.http.HttpServletResponse;
|
||
import java.io.*;
|
||
import java.math.BigDecimal;
|
||
import java.net.URLEncoder;
|
||
import java.util.*;
|
||
import java.util.zip.ZipEntry;
|
||
import java.util.zip.ZipOutputStream;
|
||
|
||
@Service
|
||
public class MaterialOrderService extends BaseOrderService<MaterialOrder, Long> {
|
||
private final Logger logger = LoggerFactory.getLogger(MaterialOrderService.class);
|
||
|
||
@Resource
|
||
private AdminService adminService;
|
||
|
||
@Resource
|
||
private ProductService productService;
|
||
|
||
@Resource
|
||
private MaterialOrderItemService materialOrderItemService;
|
||
|
||
@Resource
|
||
private MaterialOrderDao materialOrderDao;
|
||
|
||
@Resource
|
||
private OrderTool orderTool;
|
||
|
||
@Resource
|
||
private PaymentMethodService paymentMethodService;
|
||
|
||
@Resource
|
||
private CompanyService companyService;
|
||
|
||
@Resource
|
||
private ProductTypeService productTypeService;
|
||
|
||
@Resource
|
||
private SupplierService supplierService;
|
||
|
||
@Resource
|
||
private ExtraFieldService extraFieldService;
|
||
|
||
@Resource
|
||
private FlowSnService flowSnService;
|
||
|
||
@Resource
|
||
private SupplierProductService supplierProductService;
|
||
|
||
@Resource
|
||
private DiameterService diameterService;
|
||
|
||
@Resource
|
||
private WallThicknessService wallThicknessService;
|
||
|
||
@Resource
|
||
private PurchaseApplyOrderService purchaseApplyOrderService;
|
||
|
||
@Resource
|
||
private MaterialOrderItemPriceService materialOrderItemPriceService;
|
||
|
||
@Resource
|
||
private MaterialOrderStageService materialOrderStageService;
|
||
|
||
@Resource
|
||
private UploadFileService uploadFileService;
|
||
@Resource
|
||
private AttachFileService attachFileService;
|
||
@Resource
|
||
private NoticeEntityService noticeEntityService;
|
||
|
||
@Lazy
|
||
@Resource
|
||
private PurchaseOrderItemService purchaseOrderItemService;
|
||
@Resource
|
||
private PurchaseStockItemService purchaseStockItemService;
|
||
@Resource
|
||
private ProgressStockService progressStockService;
|
||
@Resource
|
||
private ProgressService progressService;
|
||
|
||
private List<Map<String,Object>> specialList = new ArrayList<>();
|
||
|
||
|
||
public Page<MaterialOrder> findPageByParams(Pageable pageable, String key, String value) {
|
||
return materialOrderDao.findPageByParams(pageable, key, value);
|
||
}
|
||
|
||
public Page<MaterialOrder> findPageByProduct(Pageable pageable,String productCode){
|
||
return materialOrderDao.findPageByProduct(pageable,productCode);
|
||
}
|
||
|
||
public List<MaterialOrder> findByStageNum(String preTitle,Integer stageNum,Long progressId){
|
||
return materialOrderDao.findByStageNum(preTitle,stageNum,progressId);
|
||
}
|
||
|
||
public List<MaterialOrder> findByStageNumUp(String preTitle,Integer stageNum,Long progressId){
|
||
return materialOrderDao.findByStageNumUp(preTitle,stageNum,progressId);
|
||
}
|
||
|
||
public List<MaterialOrder> findByHasPurchaseApplyNull() {
|
||
return materialOrderDao.findByHasPurchaseApplyNull();
|
||
}
|
||
|
||
public MaterialOrder findByMaxFlowNum(Long progressId){
|
||
return materialOrderDao.findByMaxFlowNum(progressId);
|
||
}
|
||
|
||
public List<MaterialOrder> findAvailableList() {
|
||
OrderQuery orderQuery = new OrderQuery();
|
||
orderQuery.setStatusList(Arrays.asList(OrderStatus.approved, OrderStatus.completed));
|
||
return findList(orderQuery);
|
||
}
|
||
|
||
@Transactional
|
||
public void saveMaterialOrder(MaterialOrder materialOrder) {
|
||
Admin admin = adminService.find(materialOrder.getAdminId());
|
||
if (admin == null) {
|
||
throw new RuntimeException("请购人不能为空");
|
||
}
|
||
|
||
Department department = admin.getDepartment();
|
||
if (department != null) {
|
||
materialOrder.setDepartmentId(department.getId());
|
||
materialOrder.setDepartmentName(department.getName());
|
||
}
|
||
|
||
PaymentMethod paymentMethod = paymentMethodService.find(materialOrder.getPaymentMethodId());
|
||
if (paymentMethod != null) {
|
||
materialOrder.setPaymentMethodId(paymentMethod.getId());
|
||
materialOrder.setPaymentMethodName(paymentMethod.getName());
|
||
}
|
||
|
||
materialOrder.setAdminName(admin.getName());
|
||
materialOrder.setStatus(OrderStatus.create);
|
||
|
||
materialOrder.setStatus(OrderStatus.create);
|
||
if (findByAttribute("sn",materialOrder.getSn()) != null){
|
||
throw new RuntimeException("编号已存在");
|
||
}
|
||
// materialOrder.setSn(orderTool.generateSn(materialOrder.getSn(), MaterialOrder.class));
|
||
materialOrder.setInternalFlag(companyService.internal(materialOrder.getOwnerName()));
|
||
save(materialOrder);
|
||
|
||
BigDecimal totalWeight = BigDecimal.ZERO;
|
||
BigDecimal totalCount = BigDecimal.ZERO;
|
||
BigDecimal subtotal = BigDecimal.ZERO;
|
||
Integer ind = 1;
|
||
for (MaterialOrderItem materialOrderItem : materialOrder.getMaterialOrderItemList()) {
|
||
Product product = productService.find(materialOrderItem.getProductId());
|
||
ProductType productType = product.getProductType();
|
||
ProductType bigType = null;
|
||
if (productType != null) {
|
||
if (productType.getParentId() != null) {
|
||
bigType = productTypeService.find(productType.getParentId());
|
||
}
|
||
if (bigType != null) {
|
||
materialOrderItem.setBigProductType(bigType.getName());
|
||
materialOrderItem.setSmallProductType(productType.getName());
|
||
} else {
|
||
materialOrderItem.setBigProductType(productType.getName());
|
||
}
|
||
}
|
||
if (materialOrderItem.getCount() == null){
|
||
throw new RuntimeException("数量不能为空");
|
||
}
|
||
if (product.getType().equals(Product.Type.conduit) && materialOrderItem.getgWeight() == null){
|
||
throw new RuntimeException("重量不能为空");
|
||
}
|
||
materialOrderItem.setName(product.getName());
|
||
materialOrderItem.setProductCode(product.getCode());
|
||
// materialOrderItem.setAreaAccount(product.getAreaAccount());
|
||
// materialOrderItem.setUnitAccount(product.getUnitAccount());
|
||
// materialOrderItem.setSiteAccount(product.getSiteAccount());
|
||
// materialOrderItem.setLineAccount(product.getLineAccount());
|
||
materialOrderItem.setShortDescription(product.getShortDescription());
|
||
materialOrderItem.setLongDescription(product.getLongDescription());
|
||
// materialOrderItem.setUnit(product.getUnit());
|
||
if(product.getProductType() != null) {
|
||
if (product.getProductType().getParentId() != null) {
|
||
materialOrderItem.setBigProductTypeId(product.getProductType().getParentId());
|
||
materialOrderItem.setSmallTypeId(product.getProductType().getId());
|
||
}else {
|
||
materialOrderItem.setBigProductTypeId(product.getProductType().getId());
|
||
}
|
||
}
|
||
materialOrderItem.setVersionNum(materialOrder.getVersionNum());
|
||
// materialOrderItem.setDiameterL(product.getDiameterL());
|
||
// materialOrderItem.setDiameterS(product.getDiameterS());
|
||
// materialOrderItem.setWallThicknessS(product.getWallThicknessS());
|
||
// materialOrderItem.setWallThicknessL(product.getWallThicknessL());
|
||
// materialOrderItem.setPressureLevel(product.getPressureLevel());
|
||
// materialOrderItem.setMaterial(product.getMaterial());
|
||
// materialOrderItem.setInsulationCode(product.getInsulationCode());
|
||
// materialOrderItem.setgWeight(product.getgWeight());
|
||
materialOrderItem.setPicNo(product.getPicNo());
|
||
materialOrderItem.setMaterialOrder(materialOrder);
|
||
String flowCode = "0000";
|
||
if (ind < 10) {
|
||
flowCode = "000" + ind;
|
||
} else if (ind < 100) {
|
||
flowCode = "00" + ind;
|
||
} else if (ind < 1000) {
|
||
flowCode = "0" + ind;
|
||
} else {
|
||
flowCode = "" + ind;
|
||
}
|
||
String itemCode = "R" + materialOrderItem.getName() + materialOrderItem.getAreaAccount() + materialOrderItem.getUnitAccount() + materialOrderItem.getSiteAccount() + flowCode;
|
||
materialOrderItem.setItemCode(itemCode);
|
||
if (materialOrderItem.getgWeight() != null) {
|
||
subtotal = materialOrderItem.getgWeight().multiply(materialOrderItem.getCount());
|
||
} else {
|
||
subtotal = BigDecimal.ZERO;
|
||
}
|
||
materialOrderItem.setTotalWeight(subtotal);
|
||
materialOrderItem.setInd(ind);
|
||
ind++;
|
||
materialOrderItemService.save(materialOrderItem);
|
||
totalWeight = totalWeight.add(subtotal);
|
||
totalCount = totalCount.add(materialOrderItem.getCount());
|
||
}
|
||
materialOrder.setTotalWeight(totalWeight);
|
||
materialOrder.setTotalCount(totalCount);
|
||
update(materialOrder);
|
||
}
|
||
|
||
@Transactional
|
||
public MaterialOrder updateMaterialOrder(MaterialOrder materialOrder) {
|
||
MaterialOrder source = find(materialOrder.getId());
|
||
if(source.getCreateContract()== null || !source.getCreateContract()){
|
||
List<PurchaseApplyOrder> orders = purchaseApplyOrderService.findByaMaterialOrder(source.getId());
|
||
for (PurchaseApplyOrder order : orders){
|
||
purchaseApplyOrderService.delete(order);
|
||
}
|
||
}
|
||
// ApprovalUtils.judgeStatusForUpdate(source.getStatus());
|
||
Admin admin = adminService.find(materialOrder.getAdminId());
|
||
if (admin == null) {
|
||
throw new RuntimeException("创建人不能为空");
|
||
}
|
||
|
||
if (StringUtils.isBlank(materialOrder.getSn())) {
|
||
throw new RuntimeException("编号不能为空");
|
||
}
|
||
MaterialOrder materialOrder1 = findByAttribute("sn",materialOrder.getSn());
|
||
if (materialOrder1 != null && !materialOrder1.getId().equals(materialOrder.getId())){
|
||
throw new RuntimeException("编号已存在");
|
||
}
|
||
source.setSn(materialOrder.getSn());
|
||
|
||
source.setAdminId(admin.getId());
|
||
source.setAdminName(admin.getName());
|
||
|
||
if (materialOrder.getOrderDate() != null) {
|
||
source.setOrderDate(materialOrder.getOrderDate());
|
||
}
|
||
|
||
if (source.getVersionNum() == null) {
|
||
source.setVersionNum(0);
|
||
}
|
||
source.setVersionNum(source.getVersionNum() + 1);
|
||
update(source);
|
||
for (MaterialOrderItem item : source.getMaterialOrderItemList()) {
|
||
item.setOldVersion(true);
|
||
materialOrderItemService.update(item);
|
||
}
|
||
|
||
List<Long> originalItemIds = new ArrayList<>();
|
||
BigDecimal totalWeight = BigDecimal.ZERO;
|
||
BigDecimal totalCount = BigDecimal.ZERO;
|
||
BigDecimal subtotal = BigDecimal.ZERO;
|
||
Integer ind = 1;
|
||
for (MaterialOrderItem materialOrderItem : materialOrder.getMaterialOrderItemList()) {
|
||
Product product = productService.find(materialOrderItem.getProductId());
|
||
ProductType productType = product.getProductType();
|
||
ProductType bigType = null;
|
||
if (productType != null && productType.getParentId() != null) {
|
||
bigType = productTypeService.find(productType.getParentId());
|
||
}
|
||
// if (materialOrderItem.getId() == null) {
|
||
if (bigType != null) {
|
||
materialOrderItem.setBigProductType(bigType.getName());
|
||
materialOrderItem.setSmallProductType(productType.getName());
|
||
} else if (productType != null) {
|
||
materialOrderItem.setBigProductType(productType.getName());
|
||
}
|
||
materialOrderItem.setName(product.getName());
|
||
materialOrderItem.setProductCode(product.getCode());
|
||
// materialOrderItem.setAreaAccount(product.getAreaAccount());
|
||
// materialOrderItem.setUnitAccount(product.getUnitAccount());
|
||
// materialOrderItem.setSiteAccount(product.getSiteAccount());
|
||
// materialOrderItem.setLineAccount(product.getLineAccount());
|
||
materialOrderItem.setShortDescription(product.getShortDescription());
|
||
materialOrderItem.setLongDescription(product.getLongDescription());
|
||
// materialOrderItem.setUnit(product.getUnit());
|
||
if (product.getProductType() != null) {
|
||
if (product.getProductType().getParentId() != null) {
|
||
materialOrderItem.setBigProductTypeId(product.getProductType().getParentId());
|
||
materialOrderItem.setSmallTypeId(product.getProductType().getId());
|
||
}else {
|
||
materialOrderItem.setBigProductTypeId(product.getProductType().getId());
|
||
}
|
||
}
|
||
materialOrderItem.setVersionNum(source.getVersionNum());
|
||
// materialOrderItem.setDiameterL(product.getDiameterL());
|
||
// materialOrderItem.setDiameterS(product.getDiameterS());
|
||
// materialOrderItem.setWallThicknessS(product.getWallThicknessS());
|
||
// materialOrderItem.setWallThicknessL(product.getWallThicknessL());
|
||
// materialOrderItem.setPressureLevel(product.getPressureLevel());
|
||
// materialOrderItem.setMaterial(product.getMaterial());
|
||
// materialOrderItem.setInsulationCode(product.getInsulationCode());
|
||
// materialOrderItem.setgWeight(product.getgWeight());
|
||
materialOrderItem.setPicNo(product.getPicNo());
|
||
materialOrderItem.setMaterialOrder(source);
|
||
if (materialOrderItem.getgWeight() != null) {
|
||
subtotal = materialOrderItem.getgWeight().multiply(materialOrderItem.getCount());
|
||
} else {
|
||
subtotal = BigDecimal.ZERO;
|
||
}
|
||
materialOrderItem.setTotalWeight(subtotal);
|
||
materialOrderItem.setInd(ind);
|
||
ind++;
|
||
materialOrderItemService.save(materialOrderItem);
|
||
originalItemIds.add(materialOrderItem.getId());
|
||
// }else {
|
||
// MaterialOrderItem sourceItem = materialOrderItemService.find(materialOrderItem.getId());
|
||
// sourceItem.setProductId(product.getId());
|
||
// sourceItem.setCount(materialOrderItem.getCount());
|
||
// sourceItem.setSpecialRequest(materialOrderItem.getSpecialRequest());
|
||
// if (bigType != null){
|
||
// sourceItem.setBigProductType(bigType.getName());
|
||
// sourceItem.setSmallProductType(productType.getName());
|
||
// }else if (productType != null){
|
||
// sourceItem.setBigProductType(productType.getName());
|
||
// }
|
||
// sourceItem.setVersionNum(materialOrderItem.getVersionNum());
|
||
// sourceItem.setPurchaseCode(materialOrderItem.getPurchaseCode());
|
||
// sourceItem.setName(product.getName());
|
||
// sourceItem.setProductCode(product.getCode());
|
||
// sourceItem.setAreaAccount(product.getAreaAccount());
|
||
// sourceItem.setUnitAccount(product.getUnitAccount());
|
||
// sourceItem.setSiteAccount(product.getSiteAccount());
|
||
// sourceItem.setLineAccount(product.getLineAccount());
|
||
// sourceItem.setShortDescription(product.getShortDescription());
|
||
// sourceItem.setLongDescription(product.getLongDescription());
|
||
// sourceItem.setUnit(product.getUnit());
|
||
// if (product.getProductType() != null) {
|
||
// sourceItem.setProductTypeId(product.getProductType().getId());
|
||
// }
|
||
// sourceItem.setDiameterL(materialOrderItem.getDiameterL());
|
||
// sourceItem.setDiameterS(materialOrderItem.getDiameterS());
|
||
// sourceItem.setWallThicknessS(materialOrderItem.getWallThicknessS());
|
||
// sourceItem.setWallThicknessL(materialOrderItem.getWallThicknessL());
|
||
// sourceItem.setPressureLevel(materialOrderItem.getPressureLevel());
|
||
// sourceItem.setMaterial(materialOrderItem.getMaterial());
|
||
// sourceItem.setInsulationCode(materialOrderItem.getInsulationCode());
|
||
// sourceItem.setgWeight(product.getgWeight());
|
||
// sourceItem.setPicNo(product.getPicNo());
|
||
// sourceItem.setMaterialOrder(source);
|
||
// if (materialOrder.getType().equals(MaterialOrder.Type.device)){
|
||
// sourceItem.setPrice(materialOrderItem.getPrice());
|
||
// sourceItem.setSupplierName(materialOrderItem.getSupplierName());
|
||
// }
|
||
// if (materialOrderItem.getgWeight() != null) {
|
||
// subtotal = materialOrderItem.getgWeight().multiply(materialOrderItem.getCount());
|
||
// }else {
|
||
// subtotal = BigDecimal.ZERO;
|
||
// }
|
||
// sourceItem.setTotalWeight(subtotal);
|
||
// sourceItem.setExtraField(materialOrderItem);
|
||
// materialOrderItemService.update(sourceItem);
|
||
// originalItemIds.add(sourceItem.getId());
|
||
// }
|
||
totalWeight = totalWeight.add(subtotal);
|
||
totalCount = totalCount.add(materialOrderItem.getCount());
|
||
}
|
||
source.setTotalWeight(totalWeight);
|
||
source.setTotalCount(totalCount);
|
||
update(source);
|
||
|
||
// for (MaterialOrderItem materialOrderItem : source.getMaterialOrderItemList()) {
|
||
// if (!originalItemIds.contains(materialOrderItem.getId())) {
|
||
// materialOrderItemService.delete(materialOrderItem);
|
||
// }
|
||
// }
|
||
|
||
return source;
|
||
}
|
||
|
||
@Transactional
|
||
public MaterialOrder updateDevice(MaterialOrder materialOrder) {
|
||
MaterialOrder source = find(materialOrder.getId());
|
||
if(source.getCreateContract()== null || !source.getCreateContract()){
|
||
List<PurchaseApplyOrder> orders = purchaseApplyOrderService.findByaMaterialOrder(source.getId());
|
||
for (PurchaseApplyOrder order : orders){
|
||
purchaseApplyOrderService.delete(order);
|
||
}
|
||
}
|
||
// ApprovalUtils.judgeStatusForUpdate(source.getStatus());
|
||
Admin admin = adminService.find(materialOrder.getAdminId());
|
||
if (admin == null) {
|
||
throw new RuntimeException("创建人不能为空");
|
||
}
|
||
|
||
if (StringUtils.isBlank(materialOrder.getSn())) {
|
||
throw new RuntimeException("编号不能为空");
|
||
}
|
||
MaterialOrder materialOrder1 = findByAttribute("sn",materialOrder.getSn());
|
||
if (materialOrder1 != null && !materialOrder1.getId().equals(materialOrder.getId())){
|
||
throw new RuntimeException("编号已存在");
|
||
}
|
||
source.setSn(materialOrder.getSn());
|
||
|
||
source.setAdminId(admin.getId());
|
||
source.setAdminName(admin.getName());
|
||
|
||
if (materialOrder.getOrderDate() != null) {
|
||
source.setOrderDate(materialOrder.getOrderDate());
|
||
}
|
||
update(source);
|
||
|
||
List<Long> originalItemIds = new ArrayList<>();
|
||
BigDecimal totalCount = BigDecimal.ZERO;
|
||
Integer ind = 1;
|
||
for (MaterialOrderItem materialOrderItem : materialOrder.getMaterialOrderItemList()) {
|
||
Product product = productService.find(materialOrderItem.getProductId());
|
||
MaterialOrderItem sourceItem = materialOrderItemService.find(materialOrderItem.getId());
|
||
|
||
if (materialOrderItem.getId() != null){
|
||
sourceItem.setMaterialOrder(source);
|
||
sourceItem.setProductCode(product.getCode());
|
||
sourceItem.setName(product.getName());
|
||
sourceItem.setPicNo(product.getPicNo());
|
||
sourceItem.setMemo(materialOrderItem.getMemo());
|
||
sourceItem.setPrice(materialOrderItem.getPrice());
|
||
sourceItem.setSupplierName(materialOrderItem.getSupplierName());
|
||
sourceItem.setPurchaseType(materialOrderItem.getPurchaseType());
|
||
sourceItem.setInd(ind);
|
||
materialOrderItemService.update(sourceItem);
|
||
originalItemIds.add(sourceItem.getId());
|
||
}else {
|
||
materialOrderItem.setMaterialOrder(source);
|
||
materialOrderItem.setProductCode(product.getCode());
|
||
materialOrderItem.setName(product.getName());
|
||
materialOrderItem.setPicNo(product.getPicNo());
|
||
materialOrderItem.setInd(ind);
|
||
materialOrderItem.setVersionNum(source.getVersionNum());
|
||
materialOrderItemService.save(materialOrderItem);
|
||
originalItemIds.add(materialOrderItem.getId());
|
||
}
|
||
totalCount = totalCount.add(materialOrderItem.getCount());
|
||
ind++;
|
||
}
|
||
source.setTotalCount(totalCount);
|
||
update(source);
|
||
|
||
for (MaterialOrderItem materialOrderItem : source.getMaterialOrderItemList()) {
|
||
if (!originalItemIds.contains(materialOrderItem.getId())) {
|
||
materialOrderItemService.delete(materialOrderItem);
|
||
}
|
||
}
|
||
return source;
|
||
}
|
||
|
||
|
||
public OrderInfo analyze(Supplier owner, Date startDate, Date endDate) {
|
||
OrderInfo orderInfo = materialOrderDao.analyze(owner, startDate, endDate);
|
||
if (orderInfo.getAmount() == null) {
|
||
orderInfo.setAmount(BigDecimal.ZERO);
|
||
}
|
||
if (orderInfo.getCount() == null) {
|
||
orderInfo.setCount(0L);
|
||
}
|
||
return orderInfo;
|
||
}
|
||
|
||
// /**
|
||
// * 导出客户报价单模板
|
||
// */
|
||
// public void exportSupplier(HttpServletResponse response, Long id) {
|
||
// MaterialOrder materialOrder = find(id);
|
||
// Map<Integer, List<Map<String, Object>>> valueList = new HashMap<>();
|
||
// int i = 0;
|
||
// String templateUrl = "excel/template/materialOrder.xlsx";
|
||
// TemplateExportParams params = new TemplateExportParams(templateUrl);
|
||
// List<Supplier> supplierList = supplierService.findAll();
|
||
// Map<Long, List<MaterialOrderItem>> dataMap = new HashMap<>();
|
||
// params.setColForEach(true);
|
||
// for (MaterialOrderItem item : materialOrder.getMaterialOrderItemList()) {
|
||
// for (Supplier supplier : supplierList) {
|
||
// for (SupplierProduct supplierProduct : supplier.getSupplierProductList()) {
|
||
// if (supplierProduct.getProductType().getId().equals(item.getProductTypeId())) {
|
||
// //不在取值范围内
|
||
// if (item.getDiameterL() != null && (item.getDiameterL().compareTo(supplierProduct.getDiameterL()) > 0 || item.getDiameterL().compareTo(supplierProduct.getDiameterS()) < 0)) {
|
||
// continue;
|
||
// }
|
||
// if (item.getDiameterS() != null && (item.getDiameterL().compareTo(supplierProduct.getDiameterL()) > 0 || item.getDiameterL().compareTo(supplierProduct.getDiameterS()) < 0)) {
|
||
// continue;
|
||
// }
|
||
// if (item.getWallThicknessL() != null && (item.getWallThicknessL().compareTo(supplierProduct.getWallThicknessL()) > 0 || item.getWallThicknessL().compareTo(supplierProduct.getWallThicknessS()) < 0)) {
|
||
// continue;
|
||
// }
|
||
// if (item.getWallThicknessS() != null && (item.getWallThicknessS().compareTo(supplierProduct.getWallThicknessL()) > 0 || item.getWallThicknessS().compareTo(supplierProduct.getWallThicknessS()) < 0)) {
|
||
// continue;
|
||
// }
|
||
// if (item.getPressureLevel() != null && !item.getPressureLevel().equals(supplierProduct.getPressureLevel())) {
|
||
// continue;
|
||
// }
|
||
// if (item.getMaterial() != null && !item.getMaterial().equals(supplierProduct.getMaterial())) {
|
||
// continue;
|
||
// }
|
||
// List<MaterialOrderItem> dataList = dataMap.getOrDefault(supplier.getId(), new ArrayList<>());
|
||
// dataList.add(item);
|
||
// dataMap.put(supplier.getId(), dataList);
|
||
// break;
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// for (Supplier supplier : supplierList) {
|
||
//
|
||
// List<MaterialOrderItem> list = dataMap.getOrDefault(supplier.getId(), null);
|
||
// if (list == null) {
|
||
// continue;
|
||
// }
|
||
//
|
||
// List<Map<String, Object>> list1 = new ArrayList<>();
|
||
// Map<String, Object> value = new HashMap<>();
|
||
// List<Map<String, Object>> listMap = new ArrayList<>();
|
||
// for (MaterialOrderItem item : list) {
|
||
// Map<String, Object> lm = new HashMap<>();
|
||
// lm.put("id", item.getId());
|
||
// lm.put("name", item.getName());
|
||
// lm.put("areaAccount", item.getAreaAccount());
|
||
// lm.put("unitAccount", item.getUnitAccount());
|
||
// lm.put("siteAccount", item.getSiteAccount());
|
||
// lm.put("lineAccount", item.getLineAccount());
|
||
// lm.put("shortDescription", item.getShortDescription());
|
||
// lm.put("longDescription", item.getLongDescription());
|
||
// lm.put("gWeight", item.getgWeight());
|
||
// lm.put("totalWeight", item.getTotalWeight());
|
||
// lm.put("count", item.getCount());
|
||
// lm.put("unit", item.getUnit());
|
||
// lm.put("versionNum", item.getVersionNum());
|
||
// lm.put("codeType", item.getCodeType());
|
||
// lm.put("bigType", item.getBigProductType());
|
||
// lm.put("smallType", item.getSmallProductType());
|
||
// lm.put("diameterL", item.getDiameterL());
|
||
// lm.put("diameterS", item.getDiameterS());
|
||
// lm.put("wallThicknessL", item.getWallThicknessL());
|
||
// lm.put("wallThicknessS", item.getWallThicknessS());
|
||
// lm.put("pressureLevel", item.getPressureLevel());
|
||
// lm.put("insulationCode", item.getInsulationCode());
|
||
// lm.put("specialRequest", item.getSpecialRequest());
|
||
// lm.put("memo", item.getMemo());
|
||
// listMap.add(lm);
|
||
// }
|
||
// value.put("maplist", listMap);
|
||
// value.put("supplierId", supplier.getId());
|
||
// value.put("totalSend", materialOrder.getSn());
|
||
// value.put("sheetName", supplier.getName());
|
||
// list1.add(value);
|
||
// valueList.put(i, list1);
|
||
// i++;
|
||
// }
|
||
// ExcelUtils.exportAll(response, valueList, params, "materialOrder.xls");
|
||
// }
|
||
|
||
// @Transactional(propagation = Propagation.NESTED)
|
||
@Transactional
|
||
public Integer saveFile(MultipartFile file, Long adminId, String preTitle, Integer flowNum, String code, Long stageId,String remark,String orderName, Boolean ignoreLineAccount) {
|
||
specialList = new ArrayList<>();
|
||
List<ProductType> productTypeList = new ArrayList<>();
|
||
Admin admin = adminService.find(adminId);
|
||
//获得Workbook工作薄对象
|
||
Workbook workbook = ExcelUtil2.getWorkBook(file);
|
||
//创建返回对象,把每行中的值作为一个数组,所有行作为一个集合返回
|
||
Map<Integer, PurchaseOrderItem> itemMap = new HashMap<>();
|
||
MaterialOrder materialOrder = new MaterialOrder();
|
||
materialOrder.setAdminId(adminId);
|
||
materialOrder.setAdminName(admin.getName());
|
||
materialOrder.setStatus(OrderStatus.create);
|
||
materialOrder.setType(MaterialOrder.Type.conduit);
|
||
materialOrder.setVersionNum(0);
|
||
materialOrder.setPreTitle(preTitle);
|
||
materialOrder.setProgressId(admin.getNowProgress());
|
||
materialOrder.setName(orderName);
|
||
materialOrder.setIgnoreLineAccount(ignoreLineAccount);
|
||
if (admin.getNowProgress() != null) {
|
||
Progress progress = progressService.find(admin.getNowProgress());
|
||
materialOrder.setProgressName(progress.getName());
|
||
materialOrder.setProgressCode(progress.getCode());
|
||
}else {
|
||
materialOrder.setProgressName("公司");
|
||
}
|
||
MaterialOrderStage stage = materialOrderStageService.find(stageId);
|
||
if(stage == null || stage.getStageNum() == null){
|
||
throw new RuntimeException("阶段或者阶段等级不存在");
|
||
}
|
||
List<MaterialOrder> upOrderList = findByStageNumUp(preTitle,stage.getStageNum(),admin.getNowProgress());
|
||
if (upOrderList.size()>0){
|
||
throw new RuntimeException("已到下一阶段,该阶段无法修改");
|
||
}
|
||
boolean firstStage = false;
|
||
if (stage.getStageNum() == 1){
|
||
firstStage = true;
|
||
}
|
||
|
||
//产品库存
|
||
List<Product> productList = productService.findList(
|
||
Filter.gt("stockCount",0)
|
||
);
|
||
Map<String,ProgressStock> stockMap = new HashMap<>();
|
||
for(ProgressStock progressStock : progressStockService.findByProgress(materialOrder.getProgressId())){
|
||
stockMap.put(progressStock.getProgressId()+"_"+progressStock.getProduct().getCode(),progressStock);
|
||
}
|
||
|
||
|
||
Map<String,BigDecimal> countMap = new HashMap<>();
|
||
Map<String, MaterialOrderItem> ignoreLineAccountMergeItemMap = new HashMap<>();
|
||
Set<String> ignoreLineAccountSubtractUseCountSet = new HashSet<>();
|
||
if (!firstStage){
|
||
List<MaterialOrder> materialOrderList = findByStageNum(preTitle, stage.getStageNum(),admin.getNowProgress());
|
||
// if(materialOrderList.size()<1){
|
||
// throw new RuntimeException("缺失阶段"+(stage.getStageNum()-1)+"的料单");
|
||
// }
|
||
for (MaterialOrder materialOrder1 : materialOrderList){
|
||
List<MaterialOrderItem> itemList = materialOrderItemService.findByVersionNum(materialOrder1.getVersionNum(),materialOrder1.getId());
|
||
for (MaterialOrderItem materialOrderItem : itemList){
|
||
String diameterSStr = materialOrderItem.getDiameterS()==null?"null":materialOrderItem.getDiameterS().stripTrailingZeros().toString();
|
||
String diameterLStr = materialOrderItem.getDiameterL()==null?"null":materialOrderItem.getDiameterL().stripTrailingZeros().toString();
|
||
String wallThicknessSStr = materialOrderItem.getWallThicknessS()==null?"null":materialOrderItem.getWallThicknessS();
|
||
String wallThicknessLStr = materialOrderItem.getWallThicknessL()==null?"null":materialOrderItem.getWallThicknessL();
|
||
String str = materialOrderItem.getName()+"_"+materialOrderItem.getProductId()+"_"+diameterSStr
|
||
+"_"+diameterLStr+"_"+wallThicknessSStr+"_"+materialOrderItem.getShortDescription()
|
||
+"_"+wallThicknessLStr+"_"+materialOrderItem.getMaterial()
|
||
+"_"+materialOrderItem.getMemo()+"_"+materialOrderItem.getSize()
|
||
+"_"+materialOrderItem.getSpecialRequest()+"_"+materialOrderItem.getInsulationCode()
|
||
+"_"+ MaterialOrderItemConsts.getPrevStageLineAccount(ignoreLineAccount, materialOrderItem.getLineAccount()) +"_"+materialOrderItem.getAreaAccount()
|
||
+"_"+materialOrderItem.getSiteAccount()+"_"+materialOrderItem.getUnitAccount()
|
||
+"_"+materialOrderItem.getProductCode()+"_"+materialOrderItem.getPurchaseCode()
|
||
+"_"+materialOrderItem.getMakeCode()+"_"+materialOrderItem.getMaterialType()
|
||
+"_"+materialOrderItem.getEndFace()+"_"+materialOrderItem.getPressureLevel();
|
||
if (!countMap.containsKey(str)){
|
||
countMap.put(str,materialOrderItem.getCount());
|
||
}else {
|
||
BigDecimal count = countMap.get(str);
|
||
count = count.add(materialOrderItem.getCount());
|
||
countMap.put(str,count);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
materialOrder.setStage(stage.getId().intValue());
|
||
materialOrder.setStageCode(stage.getCode());
|
||
materialOrder.setStageName(stage.getName());
|
||
materialOrder.setStageNum(stage.getStageNum());
|
||
materialOrder.setRemark(remark);
|
||
// materialOrder.setStage(stage);
|
||
// materialOrder.setSn(orderTool.generateSn(materialOrder.getSn(), MaterialOrder.class));
|
||
FlowSn flowSn = flowSnService.findByType(FlowSn.Type.material,admin.getNowProgress());
|
||
flowSn.setLastValue(flowSn.getLastValue() + 1);
|
||
flowSnService.update(flowSn);
|
||
materialOrder.setFlowNum(flowSn.getLastValue());
|
||
String flowCode = "" + flowSn.getLastValue();
|
||
while (flowNum > flowCode.length()) {
|
||
flowCode = "0" + flowCode;
|
||
}
|
||
String sn = preTitle + "-" + flowCode + "-"+stage.getCode() + "-V0";
|
||
String preSn = preTitle+"-"+flowCode + "-"+stage.getCode();
|
||
materialOrder.setPreSn(preSn);
|
||
materialOrder.setSn(sn);
|
||
save(materialOrder);
|
||
Map<String, ProductType> productTypeMap = new HashMap<>();
|
||
Map<String, Product> productMap = new HashMap<>();
|
||
Map<String, BigDecimal> diameterMap = new HashMap<>();
|
||
// Map<String, BigDecimal> wallThicknessMap = new HashMap<>();
|
||
for (Diameter diameter : diameterService.findAll()){
|
||
diameterMap.put(diameter.getName(),diameter.getValue());
|
||
}
|
||
// for (WallThickness wallThickness : wallThicknessService.findAll()){
|
||
// wallThicknessMap.put(wallThickness.getName(),wallThickness.getValue());
|
||
// }
|
||
for (ProductType productType : productTypeService.findAll()){
|
||
productTypeMap.put(productType.getName(),productType);
|
||
}
|
||
for (Product product : productService.findByType(Product.Type.conduit)) {
|
||
productMap.put(product.getCode(), product);
|
||
}
|
||
int successNum = 0;
|
||
int failNum = 0;
|
||
if (workbook != null) {
|
||
for (int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum++) {
|
||
//获得当前sheet工作表
|
||
Sheet sheet = workbook.getSheetAt(sheetNum);
|
||
if (sheet == null || sheetNum != 0) {
|
||
continue;
|
||
}
|
||
//获得当前sheet的开始行
|
||
int firstRowNum = sheet.getFirstRowNum();
|
||
//获得当前sheet的结束行
|
||
int lastRowNum = sheet.getLastRowNum();
|
||
|
||
List<ExtraField> extraFields = extraFieldService.findByProgress("materialOrderItem",materialOrder.getProgressId(),null);
|
||
Map<String, String> extraMap = new HashMap<>();
|
||
for (ExtraField extraField : extraFields) {
|
||
extraMap.put(extraField.getName(), extraField.getFieldName());
|
||
}
|
||
|
||
String name1 = "";
|
||
String name2 = "";
|
||
String name3 = "";
|
||
String name4 = "";
|
||
String name5 = "";
|
||
String name6 = "";
|
||
String name7 = "";
|
||
String name8 = "";
|
||
|
||
Map<Integer, String> valueMap = new HashMap<>();
|
||
BigDecimal orderWeight = BigDecimal.ZERO;
|
||
BigDecimal orderCount = BigDecimal.ZERO;
|
||
//循环除了所有行,如果要循环除第一行以外的就firstRowNum+1
|
||
for (int rowNum = firstRowNum + 0; rowNum <= lastRowNum; rowNum++) {
|
||
boolean notFindFlag = false;
|
||
String errorMessage = "";
|
||
//获得当前行
|
||
Row row = sheet.getRow(rowNum);
|
||
if (row == null) {
|
||
continue;
|
||
}
|
||
//获得当前行的列数
|
||
int lastCellNum = row.getLastCellNum();
|
||
if (lastCellNum > 0) {
|
||
if (rowNum == 0) {
|
||
name1 = ExcelUtil2.getCellValue(row.getCell(33));
|
||
String fieldName1 = extraMap.getOrDefault(name1, null);
|
||
if (fieldName1 != null) {
|
||
valueMap.put(33, fieldName1);
|
||
}
|
||
|
||
name2 = ExcelUtil2.getCellValue(row.getCell(34));
|
||
String fieldName2 = extraMap.getOrDefault(name2, null);
|
||
if (fieldName2 != null) {
|
||
valueMap.put(34, fieldName2);
|
||
}
|
||
|
||
name3 = ExcelUtil2.getCellValue(row.getCell(35));
|
||
String fieldName3 = extraMap.getOrDefault(name3, null);
|
||
if (fieldName3 != null) {
|
||
valueMap.put(35, fieldName3);
|
||
}
|
||
|
||
name4 = ExcelUtil2.getCellValue(row.getCell(36));
|
||
String fieldName4 = extraMap.getOrDefault(name4, null);
|
||
if (fieldName4 != null) {
|
||
valueMap.put(36, fieldName4);
|
||
}
|
||
|
||
name5 = ExcelUtil2.getCellValue(row.getCell(37));
|
||
String fieldName5 = extraMap.getOrDefault(name5, null);
|
||
if (fieldName5 != null) {
|
||
valueMap.put(37, fieldName5);
|
||
}
|
||
|
||
name6 = ExcelUtil2.getCellValue(row.getCell(38));
|
||
String fieldName6 = extraMap.getOrDefault(name6, null);
|
||
if (fieldName6 != null) {
|
||
valueMap.put(38, fieldName6);
|
||
}
|
||
|
||
name7 = ExcelUtil2.getCellValue(row.getCell(39));
|
||
String fieldName7 = extraMap.getOrDefault(name7, null);
|
||
if (fieldName7 != null) {
|
||
valueMap.put(39, fieldName7);
|
||
}
|
||
|
||
name8 = ExcelUtil2.getCellValue(row.getCell(40));
|
||
String fieldName8 = extraMap.getOrDefault(name8, null);
|
||
if (fieldName8 != null) {
|
||
valueMap.put(40, fieldName8);
|
||
}
|
||
|
||
|
||
}
|
||
if (rowNum >= 2) {
|
||
if (ExcelUtil2.getCellValue(row.getCell(0)).equals("")) {
|
||
continue;
|
||
}
|
||
Integer ind = Integer.valueOf(ExcelUtil2.getCellValue(row.getCell(0)));
|
||
String name = ExcelUtil2.getCellValue(row.getCell(1));
|
||
String areaAccount = ExcelUtil2.getCellValue(row.getCell(2));
|
||
String unitAccount = ExcelUtil2.getCellValue(row.getCell(3));
|
||
String siteAccount = ExcelUtil2.getCellValue(row.getCell(4));
|
||
String lineAccount = BooleanUtils.isTrue(ignoreLineAccount) ? "-" : ExcelUtil2.getCellValue(row.getCell(5));
|
||
String codeType = ExcelUtil2.getCellValue(row.getCell(6));
|
||
String purchaseCode = ExcelUtil2.getCellValue(row.getCell(7));
|
||
String shortDescription = ExcelUtil2.getCellValue(row.getCell(8));
|
||
String longDescription = ExcelUtil2.getCellValue(row.getCell(9));
|
||
BigDecimal gWeight = null;
|
||
if (!ExcelUtil2.getCellValue(row.getCell(10)).equals("")) {
|
||
gWeight = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(10)));
|
||
}
|
||
|
||
BigDecimal totalWeight = null;
|
||
if (!ExcelUtil2.getCellValue(row.getCell(11)).equals("")) {
|
||
totalWeight = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(11)));
|
||
orderWeight = orderWeight.add(totalWeight);
|
||
}
|
||
|
||
String unit = ExcelUtil2.getCellValue(row.getCell(14));
|
||
String bigType = ExcelUtil2.getCellValue(row.getCell(15));
|
||
// if (bigType.equals("")){
|
||
// throw new RuntimeException("大类编号不能为空");
|
||
// }
|
||
String bigDes = ExcelUtil2.getCellValue(row.getCell(16));
|
||
String smallType = ExcelUtil2.getCellValue(row.getCell(17));
|
||
String smallDes = ExcelUtil2.getCellValue(row.getCell(18));
|
||
|
||
String makeCode = ExcelUtil2.getCellValue(row.getCell(19));
|
||
String makeName = ExcelUtil2.getCellValue(row.getCell(20));
|
||
|
||
BigDecimal diameterL = null;
|
||
BigDecimal diameterS = null;
|
||
String wallThicknessL = null;
|
||
String wallThicknessS = null;
|
||
|
||
try {
|
||
if (!ExcelUtil2.getCellValue(row.getCell(21)).equals("")) {
|
||
String cellValue = ExcelUtil2.getCellValue(row.getCell(21));
|
||
diameterL = diameterMap.getOrDefault(cellValue,null);
|
||
if (diameterL == null){
|
||
diameterL = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(21)));
|
||
}
|
||
// diameterL = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(16)));
|
||
}
|
||
if (!ExcelUtil2.getCellValue(row.getCell(22)).equals("")) {
|
||
String cellValue = ExcelUtil2.getCellValue(row.getCell(22));
|
||
diameterS = diameterMap.getOrDefault(cellValue,null);
|
||
if (diameterS == null){
|
||
diameterS = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(22)));
|
||
}
|
||
// diameterS = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(17)));
|
||
}
|
||
|
||
wallThicknessL = ExcelUtil2.getCellValue(row.getCell(23));
|
||
wallThicknessS = ExcelUtil2.getCellValue(row.getCell(24));
|
||
|
||
|
||
}catch (Exception e){
|
||
e.printStackTrace();
|
||
// throw new RuntimeException("未找到"+ind+"行直径壁厚");
|
||
notFindFlag = true;
|
||
errorMessage += "未找到直径壁厚;";
|
||
}
|
||
|
||
|
||
String size = ExcelUtil2.getCellValue(row.getCell(25));
|
||
String pressureLevel = ExcelUtil2.getCellValue(row.getCell(26));
|
||
String endFace = ExcelUtil2.getCellValue(row.getCell(27));
|
||
String materialType = ExcelUtil2.getCellValue(row.getCell(28));
|
||
String material = ExcelUtil2.getCellValue(row.getCell(29));
|
||
String insulationCode = ExcelUtil2.getCellValue(row.getCell(30));
|
||
String specialRequest = ExcelUtil2.getCellValue(row.getCell(31));
|
||
String memo = ExcelUtil2.getCellValue(row.getCell(32));
|
||
String jacketSpec = ExcelUtil2.getCellValue(row.getCell(33));
|
||
|
||
MaterialOrderItem item = new MaterialOrderItem();
|
||
|
||
if (bigType.isEmpty() || productTypeMap.getOrDefault(bigType, null) == null) {
|
||
// ProductType productType = new ProductType();
|
||
// productType.setName(bigType);
|
||
// productType.setLevel(1);
|
||
// productType.setTypeDescribe(bigDes);
|
||
// productTypeService.saveProductType(productType);
|
||
// productTypeMap.put(bigType,productType);
|
||
// item.setBigProductTypeId(productType.getId());
|
||
// item.setBigProductType(productType.getName());
|
||
// item.setBigProductDes(bigDes);
|
||
// throw new RuntimeException(bigType+"大类不存在");
|
||
notFindFlag = true;
|
||
errorMessage += "未找到产品大类;";
|
||
}else {
|
||
item.setBigProductTypeId( productTypeMap.get(bigType).getId());
|
||
item.setBigProductType( productTypeMap.get(bigType).getName());
|
||
item.setBigProductDes( productTypeMap.get(bigType).getTypeDescribe());
|
||
}
|
||
|
||
if (smallType.isEmpty() || productTypeMap.getOrDefault(smallType, null) == null) {
|
||
// throw new RuntimeException(smallType+"小类不存在");
|
||
// ProductType parent = productTypeMap.get(bigType);
|
||
// ProductType productType = new ProductType();
|
||
// productType.setName(smallType);
|
||
// productType.setTypeDescribe(smallDes);
|
||
// productType.setLevel(2);
|
||
// productType.setParentId(parent.getId());
|
||
// productTypeService.saveProductType(productType);
|
||
// productTypeMap.put(smallType,productType);
|
||
// item.setSmallTypeId(productType.getId());
|
||
// item.setSmallProductType(productType.getName());
|
||
// item.setSmallProductDes(productType.getTypeDescribe());
|
||
notFindFlag = true;
|
||
errorMessage += "未找到产品小类;";
|
||
}else {
|
||
item.setSmallTypeId( productTypeMap.get(smallType).getId());
|
||
item.setSmallProductType( productTypeMap.get(smallType).getName());
|
||
item.setSmallProductDes( productTypeMap.get(smallType).getTypeDescribe());
|
||
|
||
}
|
||
Product product = productMap.get(purchaseCode);
|
||
if (product == null) {
|
||
product = new Product();
|
||
product.setCode(purchaseCode);
|
||
product.setName(name);
|
||
product.setType(Product.Type.conduit);
|
||
if (!smallType.equals("")){
|
||
product.setProductType(productTypeMap.get(smallType));
|
||
}else {
|
||
product.setProductType(productTypeMap.get(bigType));
|
||
}
|
||
product.setShortDescription(shortDescription);
|
||
product.setLongDescription(longDescription);
|
||
product.setDiameterL(diameterL);
|
||
product.setDiameterS(diameterS);
|
||
product = productService.save(product);
|
||
productMap.put(purchaseCode,product);
|
||
// throw new RuntimeException("未找到" + purchaseCode + "产品");
|
||
// continue;
|
||
}else {
|
||
if (product.getProductType() != null) {
|
||
Long productTypeId = product.getProductType().getId();
|
||
if (!smallType.equals("")) {
|
||
product.setProductType(productTypeMap.get(smallType));
|
||
}else if(!bigType.equals("")){
|
||
product.setProductType(productTypeMap.get(bigType));
|
||
}
|
||
if (!productTypeId.equals(product.getProductType().getId())) {
|
||
product = productService.update(product);
|
||
}
|
||
}
|
||
}
|
||
item.setInd(ind);
|
||
item.setProductId(product.getId());
|
||
if (product.getProductType() != null && !productTypeList.contains(product.getProductType())){
|
||
productTypeList.add(product.getProductType());
|
||
}
|
||
item.setName(name);
|
||
item.setAreaAccount(areaAccount);
|
||
item.setUnitAccount(unitAccount);
|
||
item.setSiteAccount(siteAccount);
|
||
item.setLineAccount(lineAccount);
|
||
item.setCodeType(codeType);
|
||
item.setProductCode(purchaseCode);
|
||
item.setShortDescription(shortDescription);
|
||
item.setLongDescription(longDescription);
|
||
item.setgWeight(gWeight == null ? BigDecimal.ZERO :gWeight);
|
||
item.setUnit(unit);
|
||
item.setDiameterL(diameterL);
|
||
item.setDiameterS(diameterS);
|
||
item.setWallThicknessL(wallThicknessL);
|
||
item.setWallThicknessS(wallThicknessS);
|
||
item.setSize(size);
|
||
item.setPressureLevel(pressureLevel);
|
||
item.setEndFace(endFace);
|
||
item.setMaterial(material);
|
||
item.setInsulationCode(insulationCode);
|
||
item.setSpecialRequest(specialRequest);
|
||
item.setMaterialType(materialType);
|
||
item.setMakeCode(makeCode);
|
||
item.setMakeName(makeName);
|
||
item.setMemo(memo);
|
||
item.setJacketSpec(jacketSpec);
|
||
item.setVersionNum(0);
|
||
|
||
//除阶段1以外的数量需要计算得出(设计数量-前一阶段采购量)
|
||
BigDecimal needCount = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(12)));
|
||
BigDecimal nowCount = null;
|
||
if(!ExcelUtil2.getCellValue(row.getCell(13)).equals("")){
|
||
nowCount = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(13)));
|
||
}
|
||
BigDecimal count = BigDecimal.ZERO;
|
||
BigDecimal negativeCount = BigDecimal.ZERO;
|
||
String diameterSStr = item.getDiameterS()==null?"null":item.getDiameterS().stripTrailingZeros().toString();
|
||
String diameterLStr = item.getDiameterL()==null?"null":item.getDiameterL().stripTrailingZeros().toString();
|
||
String wallThicknessSStr = item.getWallThicknessS()==null?"null":item.getWallThicknessS();
|
||
String wallThicknessLStr = item.getWallThicknessL()==null?"null":item.getWallThicknessL();
|
||
String str = item.getName()+"_"+item.getProductId()+"_"+diameterSStr
|
||
+"_"+diameterLStr+"_"+wallThicknessSStr+"_"+item.getShortDescription()
|
||
+"_"+wallThicknessLStr+"_"+item.getMaterial()
|
||
+"_"+item.getMemo()+"_"+item.getSize()
|
||
+"_"+item.getSpecialRequest()+"_"+item.getInsulationCode()
|
||
+"_"+item.getLineAccount()+"_"+item.getAreaAccount()
|
||
+"_"+item.getSiteAccount()+"_"+item.getUnitAccount()
|
||
+"_"+item.getProductCode()+"_"+item.getPurchaseCode()
|
||
+"_"+item.getMakeCode()+"_"+item.getMaterialType()
|
||
+"_"+item.getEndFace()+"_"+item.getPressureLevel();
|
||
if (firstStage) {
|
||
if (ExcelUtil2.getCellValue(row.getCell(13)).equals("")){
|
||
// throw new RuntimeException("本次采购量不能为空");
|
||
notFindFlag = true;
|
||
errorMessage += "采购量不能为空;";
|
||
} else {
|
||
count = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(13)));
|
||
}
|
||
}else if (nowCount != null){
|
||
count = nowCount;
|
||
} else {
|
||
BigDecimal useCount = countMap.get(str);
|
||
if (useCount!=null && !ignoreLineAccountSubtractUseCountSet.contains(str)){
|
||
count = needCount.subtract(useCount);
|
||
if (BooleanUtils.isTrue(ignoreLineAccount)) {
|
||
// 不考虑管线号的情况,只操作一次减去前阶段的采购量
|
||
ignoreLineAccountSubtractUseCountSet.add(str);
|
||
}
|
||
} else {
|
||
count = needCount;
|
||
}
|
||
// count = needCount.subtract(useCount);
|
||
//后续阶段数量意外减少
|
||
if (count.compareTo(BigDecimal.ZERO)<0){
|
||
// Map<String,Object> map = new HashMap<>();
|
||
// map.put("ind",item.getInd());
|
||
// map.put("name",item.getName());
|
||
// map.put("unit",item.getUnitAccount());
|
||
// map.put("site",item.getSiteAccount());
|
||
// map.put("line",item.getLineAccount());
|
||
// map.put("code",item.getProductCode());
|
||
// map.put("longDescription",item.getLongDescription());
|
||
// map.put("needCount",needCount);
|
||
// map.put("preCount",useCount);
|
||
// map.put("errorMessage","当前阶段较以往阶段采购数量减少");
|
||
// specialList.add(map);
|
||
negativeCount = count;
|
||
count = BigDecimal.ZERO;
|
||
}
|
||
}
|
||
item.setNeedCount(needCount);
|
||
item.setCount(count.add(negativeCount));
|
||
//后续添加虚拟仓库时使用下列代码,目前绑定在库存管理错误
|
||
// if (stockMap.containsKey(materialOrder.getProgressId()+"_"+item.getProductCode())){
|
||
// ProgressStock stockProduct = stockMap.get(materialOrder.getProgressId()+"_"+item.getProductCode());
|
||
// if (stockProduct.getStockCount().compareTo(count)>=0){
|
||
//// item.setCount(BigDecimal.ZERO);
|
||
// item.setCount(negativeCount);
|
||
// item.setUseStockCount(count);
|
||
// stockProduct.setStockCount(stockProduct.getStockCount().subtract(count));
|
||
// count=BigDecimal.ZERO;
|
||
// }else {
|
||
// item.setCount(count.subtract(stockProduct.getStockCount()));
|
||
// item.setUseStockCount(stockProduct.getStockCount());
|
||
// stockProduct.setStockCount(BigDecimal.ZERO);
|
||
// count=count.subtract(stockProduct.getStockCount());
|
||
// }
|
||
// stockMap.put(materialOrder.getProgressId()+"_"+item.getProductCode(),stockProduct);
|
||
// }else {
|
||
// item.setCount(count);
|
||
// }
|
||
item.setTotalWeight(totalWeight == null ? (product.getgWeight()==null?BigDecimal.ZERO:product.getgWeight()).multiply(count) : totalWeight);
|
||
orderCount = orderCount.add(count);
|
||
if(negativeCount.compareTo(BigDecimal.ZERO)<0){//后续阶段数量意外减少,采购数量为负数
|
||
orderCount = orderCount.add(negativeCount);
|
||
}
|
||
|
||
item.setSupplierIds(new ArrayList<>());
|
||
for (Integer key : valueMap.keySet()) {
|
||
String value = ExcelUtil2.getCellValue(row.getCell(key));
|
||
String extraName = valueMap.get(key);
|
||
if (extraName.equals("extraField1")) {
|
||
item.setExtraField1(value);
|
||
}
|
||
if (extraName.equals("extraField2")) {
|
||
item.setExtraField2(value);
|
||
}
|
||
if (extraName.equals("extraField3")) {
|
||
item.setExtraField3(value);
|
||
}
|
||
if (extraName.equals("extraField4")) {
|
||
item.setExtraField4(value);
|
||
}
|
||
if (extraName.equals("extraField5")) {
|
||
item.setExtraField5(value);
|
||
}
|
||
if (extraName.equals("extraField6")) {
|
||
item.setExtraField6(value);
|
||
}
|
||
if (extraName.equals("extraField7")) {
|
||
item.setExtraField7(value);
|
||
}
|
||
if (extraName.equals("extraField8")) {
|
||
item.setExtraField8(value);
|
||
}
|
||
}
|
||
boolean itemSave = true;
|
||
// 不考虑管线号的情况下,料单项合并
|
||
if (BooleanUtils.isTrue(ignoreLineAccount)) {
|
||
MaterialOrderItem orderItem = ignoreLineAccountMergeItemMap.get(str);
|
||
if (orderItem != null) {
|
||
orderItem.setNeedCount(orderItem.getNeedCount().add(item.getNeedCount()));
|
||
orderItem.setCount(orderItem.getCount().add(item.getCount()));
|
||
orderItem.setTotalWeight(totalWeight == null ? (product.getgWeight()==null?BigDecimal.ZERO:product.getgWeight()).multiply(orderItem.getCount()) : totalWeight);
|
||
materialOrderItemService.update(orderItem);
|
||
itemSave = false;
|
||
}
|
||
}
|
||
if (itemSave) {
|
||
item.setMaterialOrder(materialOrder);
|
||
materialOrderItemService.save(item);
|
||
if (BooleanUtils.isTrue(ignoreLineAccount)) {
|
||
ignoreLineAccountMergeItemMap.put(str, item);
|
||
}
|
||
}
|
||
|
||
if (notFindFlag) {
|
||
Cell notFindCell = ExcelUtil2.getOrCreateCell(row, 34);
|
||
notFindCell.setCellValue(errorMessage);
|
||
failNum++;
|
||
} else {
|
||
successNum++;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
materialOrder.setTotalCount(orderCount);
|
||
materialOrder.setTotalWeight(orderWeight);
|
||
update(materialOrder);
|
||
for (String key : stockMap.keySet()){
|
||
ProgressStock product = stockMap.get(key);
|
||
progressStockService.update(product);
|
||
}
|
||
}
|
||
if (failNum > 0) {
|
||
String importErrorExcel = ExcelImportErrorUtil.materialOrderSiee(workbook);
|
||
Map<String, Object> map = new HashMap<>();
|
||
map.put("importErrorExcel", importErrorExcel);
|
||
map.put("successNum", successNum);
|
||
map.put("failNum", failNum);
|
||
throw new ImportExcelException(failNum+"条导入失败", "3", map);
|
||
}
|
||
}
|
||
if (!firstStage){
|
||
PrevStageComparisonExcel(materialOrder.getId());
|
||
}
|
||
return specialList.size();
|
||
}
|
||
|
||
// 根据前缀和阶段找以往阶段的料单
|
||
public List<MaterialOrder> findPrevStageList(Long adminId, String preTitle, Long stageId) {
|
||
List<MaterialOrder> res = new ArrayList<>();
|
||
if (StringUtils.isBlank(preTitle)) {
|
||
return res;
|
||
}
|
||
Admin admin = adminService.find(adminId);
|
||
MaterialOrderStage stage = materialOrderStageService.find(stageId);
|
||
if (stage == null || stage.getStageNum() == null || stage.getStageNum() == 1) {
|
||
return res;
|
||
}
|
||
return findByStageNum(preTitle, stage.getStageNum(), admin.getNowProgress());
|
||
}
|
||
|
||
public void exportSpecial(HttpServletResponse response){
|
||
String templateUrl = "excel/template/specialMO.xlsx";
|
||
TemplateExportParams params = new TemplateExportParams(templateUrl);
|
||
params.setColForEach(true);
|
||
Map<String, Object> value = new HashMap<>();
|
||
List<Map<String, Object>> listMap = new ArrayList<>();
|
||
for (Map<String,Object> item : specialList) {
|
||
Map<String, Object> lm = new HashMap<>();
|
||
lm.put("ind", item.get("ind"));
|
||
lm.put("name",item.get("name"));
|
||
lm.put("unit",item.get("unit"));
|
||
lm.put("site",item.get("site"));
|
||
lm.put("line",item.get("line"));
|
||
lm.put("code",item.get("code"));
|
||
lm.put("longDescription", item.get("longDescription"));
|
||
lm.put("needCount", item.get("needCount"));
|
||
lm.put("preCount", item.get("preCount"));
|
||
lm.put("errorMessage", item.get("errorMessage"));
|
||
listMap.add(lm);
|
||
}
|
||
value.put("maplist", listMap);
|
||
ExcelUtils.export(response, value, params, "料单阶段比较报告.xlsx");
|
||
}
|
||
|
||
@Transactional
|
||
public void PrevStageComparisonExcel(Long materialOrderId){
|
||
specialList = new ArrayList<>();
|
||
Map<String, Object> map = new HashMap<>();
|
||
MaterialOrder materialOrder = find(materialOrderId);
|
||
//获取以前阶段
|
||
Map<String,BigDecimal> prevMap = new HashMap<>();
|
||
Map<String,MaterialOrderItem> prevMapM = new HashMap<>();
|
||
List<MaterialOrder> prevMaterialOrderList = findByStageNum(materialOrder.getPreTitle(), materialOrder.getStageNum(), materialOrder.getProgressId());
|
||
for (MaterialOrder prevMaterialOrder : prevMaterialOrderList) {
|
||
List<MaterialOrderItem> prevItemList = materialOrderItemService.findByVersionNum(prevMaterialOrder.getVersionNum(), prevMaterialOrder.getId());
|
||
for (MaterialOrderItem prevItem : prevItemList){
|
||
String str = prevItem.getName()+"_"+prevItem.getUnitAccount()+"_"+prevItem.getSiteAccount()
|
||
+"_"+ MaterialOrderItemConsts.getPrevStageLineAccount(materialOrder.getIgnoreLineAccount(), prevItem.getLineAccount()) +"_"+prevItem.getProductCode();
|
||
if (!prevMap.containsKey(str)){
|
||
prevMap.put(str,prevItem.getCount());
|
||
prevMapM.put(str,prevItem);
|
||
}else {
|
||
BigDecimal prevCount = prevMap.get(str).add(prevItem.getCount());
|
||
prevMap.put(str,prevCount);
|
||
prevMapM.put(str,prevItem);
|
||
}
|
||
}
|
||
}
|
||
//获取当前阶段
|
||
List<MaterialOrderItem> itemList = materialOrderItemService.findByVersionNum(materialOrder.getVersionNum(), materialOrder.getId());
|
||
int ind=0;
|
||
for (MaterialOrderItem item : itemList){
|
||
String str = item.getName()+"_"+item.getUnitAccount()+"_"+item.getSiteAccount()
|
||
+"_"+item.getLineAccount()+"_"+item.getProductCode();
|
||
if (ind<item.getInd())
|
||
ind=item.getInd();
|
||
if (prevMap.containsKey(str)){
|
||
BigDecimal prevCount = prevMap.get(str);
|
||
if (prevCount.compareTo(item.getNeedCount()) > 0){
|
||
map = new HashMap<>();
|
||
map.put("ind",item.getInd());
|
||
map.put("name",item.getName());
|
||
map.put("unit",item.getUnitAccount());
|
||
map.put("site",item.getSiteAccount());
|
||
map.put("line",item.getLineAccount());
|
||
map.put("code",item.getProductCode());
|
||
map.put("longDescription",item.getLongDescription());
|
||
map.put("needCount",item.getNeedCount());
|
||
map.put("preCount",prevCount);
|
||
map.put("errorMessage","当前阶段较以往阶段采购数量减少");
|
||
specialList.add(map);
|
||
} else if (prevCount.compareTo(item.getNeedCount()) < 0) {
|
||
map = new HashMap<>();
|
||
map.put("ind",item.getInd());
|
||
map.put("name",item.getName());
|
||
map.put("unit",item.getUnitAccount());
|
||
map.put("site",item.getSiteAccount());
|
||
map.put("line",item.getLineAccount());
|
||
map.put("code",item.getProductCode());
|
||
map.put("longDescription",item.getLongDescription());
|
||
map.put("needCount",item.getNeedCount());
|
||
map.put("preCount",prevCount);
|
||
map.put("errorMessage","当前阶段较以往阶段采购数量增加");
|
||
specialList.add(map);
|
||
}
|
||
prevMap.remove(str);
|
||
prevMapM.remove(str);
|
||
} else {
|
||
map = new HashMap<>();
|
||
map.put("ind",item.getInd());
|
||
map.put("name",item.getName());
|
||
map.put("unit",item.getUnitAccount());
|
||
map.put("site",item.getSiteAccount());
|
||
map.put("line",item.getLineAccount());
|
||
map.put("code",item.getProductCode());
|
||
map.put("longDescription",item.getLongDescription());
|
||
map.put("needCount",item.getNeedCount());
|
||
map.put("preCount",' ');
|
||
map.put("errorMessage","当前阶段料单新增采购");
|
||
specialList.add(map);
|
||
}
|
||
}
|
||
// for (Map.Entry<String,BigDecimal> entry : prevMap.entrySet()) {
|
||
// map = new HashMap<>();
|
||
// map.put("ind",' ');
|
||
// map.put("name",entry.getKey().split("_")[0]);
|
||
// map.put("unit",entry.getKey().split("_")[1]);
|
||
// map.put("site",entry.getKey().split("_")[2]);
|
||
// map.put("line",entry.getKey().split("_")[3]);
|
||
// map.put("code",entry.getKey().split("_")[4]);
|
||
// map.put("longDescription",LongMap.get(entry.getKey()));
|
||
// map.put("needCount",' ');
|
||
// map.put("preCount",entry.getValue());
|
||
// map.put("errorMessage","以往阶段已采购,当前阶段没有采购");
|
||
// specialList.add(map);
|
||
// }
|
||
for (Map.Entry<String,MaterialOrderItem> entry : prevMapM.entrySet()) {
|
||
System.out.println(materialOrder);
|
||
MaterialOrderItem materialOrderItem = new MaterialOrderItem();
|
||
materialOrderItem.setMaterialOrder(materialOrder);
|
||
ind=ind+1;
|
||
materialOrderItem.setInd(ind);
|
||
materialOrderItem.setBigProductTypeId(entry.getValue().getBigProductTypeId());
|
||
materialOrderItem.setBigProductType(entry.getValue().getBigProductType());
|
||
materialOrderItem.setBigProductDes(entry.getValue().getBigProductDes());
|
||
materialOrderItem.setSmallTypeId(entry.getValue().getSmallTypeId());
|
||
materialOrderItem.setSmallProductType(entry.getValue().getSmallProductType());
|
||
materialOrderItem.setSmallProductDes(entry.getValue().getSmallProductDes());
|
||
materialOrderItem.setProductId(entry.getValue().getProductId());
|
||
materialOrderItem.setName(entry.getValue().getName());
|
||
materialOrderItem.setAreaAccount(entry.getValue().getAreaAccount());
|
||
materialOrderItem.setUnitAccount(entry.getValue().getUnitAccount());
|
||
materialOrderItem.setSiteAccount(entry.getValue().getSiteAccount());
|
||
materialOrderItem.setLineAccount(MaterialOrderItemConsts.getPrevStageLineAccount(materialOrder.getIgnoreLineAccount(), entry.getValue().getLineAccount()));
|
||
materialOrderItem.setCodeType(entry.getValue().getCodeType());
|
||
materialOrderItem.setProductCode(entry.getValue().getProductCode());
|
||
materialOrderItem.setShortDescription(entry.getValue().getShortDescription());
|
||
materialOrderItem.setLongDescription(entry.getValue().getLongDescription());
|
||
materialOrderItem.setgWeight(entry.getValue().getgWeight());
|
||
materialOrderItem.setUnit(entry.getValue().getUnit());
|
||
materialOrderItem.setDiameterL(entry.getValue().getDiameterL());
|
||
materialOrderItem.setDiameterS(entry.getValue().getDiameterS());
|
||
materialOrderItem.setWallThicknessL(entry.getValue().getWallThicknessL());
|
||
materialOrderItem.setWallThicknessS(entry.getValue().getWallThicknessS());
|
||
materialOrderItem.setSize(entry.getValue().getSize());
|
||
materialOrderItem.setPressureLevel(entry.getValue().getPressureLevel());
|
||
materialOrderItem.setEndFace(entry.getValue().getEndFace());
|
||
materialOrderItem.setMaterial(entry.getValue().getMaterial());
|
||
materialOrderItem.setInsulationCode(entry.getValue().getInsulationCode());
|
||
materialOrderItem.setSpecialRequest(entry.getValue().getSpecialRequest());
|
||
materialOrderItem.setMaterialType(entry.getValue().getMaterialType());
|
||
materialOrderItem.setMakeCode(entry.getValue().getMakeCode());
|
||
materialOrderItem.setMakeName(entry.getValue().getMakeName());
|
||
materialOrderItem.setMemo(entry.getValue().getMemo());
|
||
materialOrderItem.setJacketSpec(entry.getValue().getJacketSpec());
|
||
materialOrderItem.setVersionNum(materialOrder.getVersionNum());
|
||
materialOrderItem.setCount(BigDecimal.ZERO.subtract(prevMap.get(entry.getKey())));
|
||
materialOrderItem.setNeedCount(BigDecimal.ZERO);
|
||
materialOrderItem.setUseStockCount(BigDecimal.ZERO);
|
||
materialOrderItem.setTotalWeight(BigDecimal.ZERO);
|
||
materialOrderItemService.save(materialOrderItem);
|
||
|
||
materialOrder.setTotalCount(materialOrder.getTotalCount().subtract(prevMap.get(entry.getKey())));
|
||
|
||
map = new HashMap<>();
|
||
map.put("ind",' ');
|
||
map.put("name",entry.getValue().getName());
|
||
map.put("unit",entry.getValue().getUnitAccount());
|
||
map.put("site",entry.getValue().getSiteAccount());
|
||
map.put("line", MaterialOrderItemConsts.getPrevStageLineAccount(materialOrder.getIgnoreLineAccount(), entry.getValue().getLineAccount()));
|
||
map.put("code",entry.getValue().getProductCode());
|
||
map.put("longDescription",entry.getValue().getLongDescription());
|
||
map.put("needCount",' ');
|
||
map.put("preCount",prevMap.get(entry.getKey()));
|
||
map.put("errorMessage","以往阶段已采购,当前阶段没有采购");
|
||
specialList.add(map);
|
||
}
|
||
update(materialOrder);
|
||
}
|
||
|
||
|
||
// @Transactional(propagation = Propagation.NESTED)
|
||
//老版
|
||
@Transactional
|
||
public void updateFile(MultipartFile file, Long adminId, Long orderId,String remark) {
|
||
List<ProductType> productTypeList = new ArrayList<>();
|
||
Admin admin = adminService.find(adminId);
|
||
//获得Workbook工作薄对象
|
||
Workbook workbook = ExcelUtil2.getWorkBook(file);
|
||
//创建返回对象,把每行中的值作为一个数组,所有行作为一个集合返回
|
||
Map<Integer, PurchaseOrderItem> itemMap = new HashMap<>();
|
||
MaterialOrder materialOrder = find(orderId);
|
||
if(materialOrder.getCreateContract()== null || !materialOrder.getCreateContract()){
|
||
List<PurchaseApplyOrder> orders = purchaseApplyOrderService.findByaMaterialOrder(orderId);
|
||
for (PurchaseApplyOrder order : orders){
|
||
purchaseApplyOrderService.delete(order);
|
||
}
|
||
}
|
||
|
||
materialOrder.setAdminId(adminId);
|
||
materialOrder.setAdminName(admin.getName());
|
||
materialOrder.setStatus(OrderStatus.create);
|
||
materialOrder.setType(MaterialOrder.Type.conduit);
|
||
materialOrder.setVersionNum(materialOrder.getVersionNum()+1);
|
||
materialOrder.setSn(materialOrder.getPreSn()+"-V"+materialOrder.getVersionNum());
|
||
materialOrder.setProgressId(admin.getNowProgress());
|
||
if (admin.getNowProgress() != null) {
|
||
Progress progress = progressService.find(admin.getNowProgress());
|
||
materialOrder.setProgressName(progress.getName());
|
||
materialOrder.setProgressCode(progress.getCode());
|
||
}else {
|
||
materialOrder.setProgressName("公司");
|
||
}
|
||
materialOrder.setRemark(remark);
|
||
update(materialOrder);
|
||
//原先数量
|
||
Map<String,BigDecimal> countMap = new HashMap<>();
|
||
//已签合同数量
|
||
Map<String,BigDecimal> contractCountMap = new HashMap<>();
|
||
Map<String,BigDecimal> contractCountViewMap = new HashMap<>();
|
||
for (MaterialOrderItem materialOrderItem : materialOrder.getMaterialOrderItemList()){
|
||
String diameterSStr = materialOrderItem.getDiameterS()==null?"null":materialOrderItem.getDiameterS().stripTrailingZeros().toString();
|
||
String diameterLStr = materialOrderItem.getDiameterL()==null?"null":materialOrderItem.getDiameterL().stripTrailingZeros().toString();
|
||
String wallThicknessSStr = materialOrderItem.getWallThicknessS()==null?"null":materialOrderItem.getWallThicknessS();
|
||
String wallThicknessLStr = materialOrderItem.getWallThicknessL()==null?"null":materialOrderItem.getWallThicknessL();
|
||
String str = materialOrderItem.getName()+"_"+materialOrderItem.getProductId()+"_"+diameterSStr
|
||
+"_"+diameterLStr+"_"+wallThicknessSStr
|
||
+"_"+wallThicknessLStr+"_"+materialOrderItem.getMaterial()
|
||
+"_"+materialOrderItem.getMemo()+"_"+materialOrderItem.getSize()
|
||
+"_"+materialOrderItem.getSpecialRequest()+"_"+materialOrderItem.getInsulationCode()
|
||
+"_"+materialOrderItem.getLineAccount()+"_"+materialOrderItem.getAreaAccount()
|
||
+"_"+materialOrderItem.getSiteAccount()+"_"+materialOrderItem.getUnitAccount()
|
||
+"_"+materialOrderItem.getProductCode()+"_"+materialOrderItem.getPurchaseCode()
|
||
+"_"+materialOrderItem.getMakeCode()+"_"+materialOrderItem.getMaterialType()
|
||
+"_"+materialOrderItem.getEndFace()+"_"+materialOrderItem.getPressureLevel();
|
||
BigDecimal count = countMap.getOrDefault(str,BigDecimal.ZERO);
|
||
count = count.add(materialOrderItem.getCount());
|
||
countMap.put(str,count);
|
||
if (materialOrderItem.getOrderItemId() != null){
|
||
BigDecimal contractCount = contractCountMap.getOrDefault(str,BigDecimal.ZERO);
|
||
contractCount = contractCount.add(materialOrderItem.getCount());
|
||
contractCountMap.put(str,contractCount);
|
||
|
||
str = str+"_"+materialOrderItem.getOrderItemId();
|
||
BigDecimal contractViewCount = contractCountMap.getOrDefault(str,BigDecimal.ZERO);
|
||
contractViewCount = contractViewCount.add(materialOrderItem.getCount());
|
||
contractCountViewMap.put(str,contractViewCount);
|
||
}
|
||
}
|
||
Map<String, Product> productMap = new HashMap<>();
|
||
Map<String, ProductType> productTypeMap = new HashMap<>();
|
||
Map<String, BigDecimal> diameterMap = new HashMap<>();
|
||
// Map<String, BigDecimal> wallThicknessMap = new HashMap<>();
|
||
for (Diameter diameter : diameterService.findAll()){
|
||
diameterMap.put(diameter.getName(),diameter.getValue());
|
||
}
|
||
// for (WallThickness wallThickness : wallThicknessService.findAll()){
|
||
// wallThicknessMap.put(wallThickness.getName(),wallThickness.getValue());
|
||
// }
|
||
for (ProductType productType : productTypeService.findAll()){
|
||
productTypeMap.put(productType.getName(),productType);
|
||
}
|
||
for (Product product : productService.findByType(Product.Type.conduit)) {
|
||
productMap.put(product.getCode(), product);
|
||
}
|
||
|
||
if (workbook != null) {
|
||
for (int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum++) {
|
||
//获得当前sheet工作表
|
||
Sheet sheet = workbook.getSheetAt(sheetNum);
|
||
if (sheet == null || sheetNum != 0) {
|
||
continue;
|
||
}
|
||
//获得当前sheet的开始行
|
||
int firstRowNum = sheet.getFirstRowNum();
|
||
//获得当前sheet的结束行
|
||
int lastRowNum = sheet.getLastRowNum();
|
||
|
||
List<ExtraField> extraFields = extraFieldService.findByProgress("materialOrderItem",materialOrder.getProgressId(),null);
|
||
Map<String, String> extraMap = new HashMap<>();
|
||
for (ExtraField extraField : extraFields) {
|
||
extraMap.put(extraField.getName(), extraField.getFieldName());
|
||
}
|
||
|
||
String name1 = "";
|
||
String name2 = "";
|
||
String name3 = "";
|
||
String name4 = "";
|
||
String name5 = "";
|
||
String name6 = "";
|
||
String name7 = "";
|
||
String name8 = "";
|
||
|
||
Map<Integer, String> valueMap = new HashMap<>();
|
||
BigDecimal orderWeight = BigDecimal.ZERO;
|
||
BigDecimal orderCount = BigDecimal.ZERO;
|
||
//循环除了所有行,如果要循环除第一行以外的就firstRowNum+1
|
||
for (int rowNum = firstRowNum + 0; rowNum <= lastRowNum; rowNum++) {
|
||
//获得当前行
|
||
Row row = sheet.getRow(rowNum);
|
||
if (row == null) {
|
||
continue;
|
||
}
|
||
//获得当前行的列数
|
||
int lastCellNum = row.getLastCellNum();
|
||
if (lastCellNum > 0) {
|
||
if (rowNum == 0) {
|
||
name1 = ExcelUtil2.getCellValue(row.getCell(33));
|
||
String fieldName1 = extraMap.getOrDefault(name1, null);
|
||
if (fieldName1 != null) {
|
||
valueMap.put(33, fieldName1);
|
||
}
|
||
|
||
name2 = ExcelUtil2.getCellValue(row.getCell(34));
|
||
String fieldName2 = extraMap.getOrDefault(name2, null);
|
||
if (fieldName2 != null) {
|
||
valueMap.put(34, fieldName2);
|
||
}
|
||
|
||
name3 = ExcelUtil2.getCellValue(row.getCell(35));
|
||
String fieldName3 = extraMap.getOrDefault(name3, null);
|
||
if (fieldName3 != null) {
|
||
valueMap.put(35, fieldName3);
|
||
}
|
||
|
||
name4 = ExcelUtil2.getCellValue(row.getCell(36));
|
||
String fieldName4 = extraMap.getOrDefault(name4, null);
|
||
if (fieldName4 != null) {
|
||
valueMap.put(36, fieldName4);
|
||
}
|
||
|
||
name5 = ExcelUtil2.getCellValue(row.getCell(37));
|
||
String fieldName5 = extraMap.getOrDefault(name5, null);
|
||
if (fieldName5 != null) {
|
||
valueMap.put(37, fieldName5);
|
||
}
|
||
|
||
name6 = ExcelUtil2.getCellValue(row.getCell(38));
|
||
String fieldName6 = extraMap.getOrDefault(name6, null);
|
||
if (fieldName6 != null) {
|
||
valueMap.put(38, fieldName6);
|
||
}
|
||
|
||
name7 = ExcelUtil2.getCellValue(row.getCell(39));
|
||
String fieldName7 = extraMap.getOrDefault(name7, null);
|
||
if (fieldName7 != null) {
|
||
valueMap.put(39, fieldName7);
|
||
}
|
||
|
||
name8 = ExcelUtil2.getCellValue(row.getCell(40));
|
||
String fieldName8 = extraMap.getOrDefault(name8, null);
|
||
if (fieldName8 != null) {
|
||
valueMap.put(40, fieldName8);
|
||
}
|
||
|
||
|
||
}
|
||
if (rowNum >= 2) {
|
||
if (ExcelUtil2.getCellValue(row.getCell(0)).equals("")) {
|
||
continue;
|
||
}
|
||
Integer ind = Integer.valueOf(ExcelUtil2.getCellValue(row.getCell(0)));
|
||
String name = ExcelUtil2.getCellValue(row.getCell(1));
|
||
String areaAccount = ExcelUtil2.getCellValue(row.getCell(2));
|
||
String unitAccount = ExcelUtil2.getCellValue(row.getCell(3));
|
||
String siteAccount = ExcelUtil2.getCellValue(row.getCell(4));
|
||
String lineAccount = ExcelUtil2.getCellValue(row.getCell(5));
|
||
String codeType = ExcelUtil2.getCellValue(row.getCell(6));
|
||
String purchaseCode = ExcelUtil2.getCellValue(row.getCell(7));
|
||
String shortDescription = ExcelUtil2.getCellValue(row.getCell(8));
|
||
String longDescription = ExcelUtil2.getCellValue(row.getCell(9));
|
||
BigDecimal gWeight = null;
|
||
if (!ExcelUtil2.getCellValue(row.getCell(10)).equals("")) {
|
||
gWeight = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(10)));
|
||
}
|
||
|
||
BigDecimal totalWeight = null;
|
||
if (!ExcelUtil2.getCellValue(row.getCell(11)).equals("")) {
|
||
totalWeight = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(11)));
|
||
orderWeight = orderWeight.add(totalWeight);
|
||
}
|
||
|
||
BigDecimal needCount = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(12)));
|
||
BigDecimal count = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(13)));
|
||
orderCount = orderCount.add(count);
|
||
String unit = ExcelUtil2.getCellValue(row.getCell(14));
|
||
String bigType = ExcelUtil2.getCellValue(row.getCell(15));
|
||
String bigDes = ExcelUtil2.getCellValue(row.getCell(16));
|
||
String smallType = ExcelUtil2.getCellValue(row.getCell(17));
|
||
String smallDes = ExcelUtil2.getCellValue(row.getCell(18));
|
||
|
||
String makeCode = ExcelUtil2.getCellValue(row.getCell(19));
|
||
String makeName = ExcelUtil2.getCellValue(row.getCell(20));
|
||
|
||
BigDecimal diameterL = null;
|
||
BigDecimal diameterS = null;
|
||
String wallThicknessL = null;
|
||
String wallThicknessS = null;
|
||
|
||
try {
|
||
if (!ExcelUtil2.getCellValue(row.getCell(21)).equals("")) {
|
||
String cellValue = ExcelUtil2.getCellValue(row.getCell(21));
|
||
diameterL = diameterMap.getOrDefault(cellValue,null);
|
||
if (diameterL == null){
|
||
diameterL = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(21)));
|
||
}
|
||
// diameterL = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(16)));
|
||
}
|
||
if (!ExcelUtil2.getCellValue(row.getCell(22)).equals("")) {
|
||
String cellValue = ExcelUtil2.getCellValue(row.getCell(22));
|
||
diameterS = diameterMap.getOrDefault(cellValue,null);
|
||
if (diameterS == null){
|
||
diameterS = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(22)));
|
||
}
|
||
// diameterS = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(17)));
|
||
}
|
||
|
||
wallThicknessL = ExcelUtil2.getCellValue(row.getCell(23));
|
||
wallThicknessS = ExcelUtil2.getCellValue(row.getCell(24));
|
||
|
||
}catch (Exception e){
|
||
throw new RuntimeException(ind+"行公称直径,壁厚不正确");
|
||
}
|
||
|
||
|
||
String size = ExcelUtil2.getCellValue(row.getCell(25));
|
||
String pressureLevel = ExcelUtil2.getCellValue(row.getCell(26));
|
||
String endFace = ExcelUtil2.getCellValue(row.getCell(27));
|
||
String material = ExcelUtil2.getCellValue(row.getCell(29));
|
||
String materialType = ExcelUtil2.getCellValue(row.getCell(28));
|
||
String insulationCode = ExcelUtil2.getCellValue(row.getCell(30));
|
||
String specialRequest = ExcelUtil2.getCellValue(row.getCell(31));
|
||
String memo = ExcelUtil2.getCellValue(row.getCell(32));
|
||
MaterialOrderItem item = new MaterialOrderItem();
|
||
if (productTypeMap.getOrDefault(bigType, null) == null) {
|
||
throw new RuntimeException(bigType+"大类不存在");
|
||
// ProductType productType = new ProductType();
|
||
// productType.setName(bigType);
|
||
// productType.setLevel(1);
|
||
// productType.setTypeDescribe(bigDes);
|
||
// productTypeService.saveProductType(productType);
|
||
// productTypeMap.put(bigType,productType);
|
||
// item.setBigProductTypeId(productType.getId());
|
||
// item.setBigProductType(productType.getName());
|
||
// item.setBigProductDes(bigDes);
|
||
}else {
|
||
item.setBigProductTypeId( productTypeMap.get(bigType).getId());
|
||
item.setBigProductType( productTypeMap.get(bigType).getName());
|
||
item.setBigProductDes( productTypeMap.get(bigType).getTypeDescribe());
|
||
}
|
||
if (!smallType.equals("") && productTypeMap.getOrDefault(smallType, null) == null) {
|
||
throw new RuntimeException(smallType+"小类不存在");
|
||
// ProductType parent = productTypeMap.get(bigType);
|
||
// ProductType productType = new ProductType();
|
||
// productType.setName(smallType);
|
||
// productType.setLevel(2);
|
||
// productType.setParentId(parent.getId());
|
||
// productType.setTypeDescribe(smallDes);
|
||
// productTypeService.saveProductType(productType);
|
||
// productTypeMap.put(smallType,productType);
|
||
// item.setSmallTypeId(productType.getId());
|
||
// item.setSmallProductType(productType.getName());
|
||
// item.setSmallProductDes(smallDes);
|
||
}else {
|
||
item.setSmallTypeId( productTypeMap.get(smallType).getId());
|
||
item.setSmallProductType( productTypeMap.get(smallType).getName());
|
||
item.setSmallProductDes( productTypeMap.get(smallType).getTypeDescribe());
|
||
}
|
||
Product product = productMap.get(purchaseCode);
|
||
if (product == null) {
|
||
product = new Product();
|
||
product.setCode(purchaseCode);
|
||
product.setName(name);
|
||
product.setType(Product.Type.conduit);
|
||
if (!smallType.equals("")){
|
||
product.setProductType(productTypeMap.get(smallType));
|
||
}else {
|
||
product.setProductType(productTypeMap.get(bigType));
|
||
}
|
||
product.setShortDescription(shortDescription);
|
||
product.setLongDescription(longDescription);
|
||
product = productService.save(product);
|
||
productMap.put(purchaseCode,product);
|
||
// throw new RuntimeException("未找到" + purchaseCode + "产品");
|
||
// continue;
|
||
}else {
|
||
Long productTypeId = product.getProductType().getId();
|
||
if (!smallType.equals("")) {
|
||
product.setProductType(productTypeMap.get(smallType));
|
||
}else {
|
||
product.setProductType(productTypeMap.get(bigType));
|
||
}
|
||
if (!productTypeId.equals(product.getProductType().getId())) {
|
||
product = productService.update(product);
|
||
}
|
||
}
|
||
item.setInd(ind);
|
||
item.setProductId(product.getId());
|
||
// item.setProductTypeId(product.getProductType().getId());
|
||
if (!productTypeList.contains(product.getProductType())){
|
||
productTypeList.add(product.getProductType());
|
||
}
|
||
item.setName(name);
|
||
item.setAreaAccount(areaAccount);
|
||
item.setUnitAccount(unitAccount);
|
||
item.setSiteAccount(siteAccount);
|
||
item.setLineAccount(lineAccount);
|
||
item.setCodeType(codeType);
|
||
item.setProductCode(purchaseCode);
|
||
item.setShortDescription(shortDescription);
|
||
item.setLongDescription(longDescription);
|
||
item.setgWeight(gWeight == null ? BigDecimal.ZERO :gWeight);
|
||
item.setCount(count);
|
||
item.setTotalWeight(gWeight.multiply(count));
|
||
item.setUnit(unit);
|
||
item.setDiameterL(diameterL);
|
||
item.setDiameterS(diameterS);
|
||
item.setWallThicknessL(wallThicknessL);
|
||
item.setWallThicknessS(wallThicknessS);
|
||
item.setSize(size);
|
||
item.setPressureLevel(pressureLevel);
|
||
item.setEndFace(endFace);
|
||
item.setMaterial(material);
|
||
item.setInsulationCode(insulationCode);
|
||
item.setSpecialRequest(specialRequest);
|
||
item.setMaterialType(materialType);
|
||
item.setMakeCode(makeCode);
|
||
item.setMakeName(makeName);
|
||
item.setNeedCount(needCount);
|
||
item.setMemo(memo);
|
||
item.setVersionNum(materialOrder.getVersionNum());
|
||
for (Integer key : valueMap.keySet()) {
|
||
String value = ExcelUtil2.getCellValue(row.getCell(key));
|
||
String extraName = valueMap.get(key);
|
||
if (extraName.equals("extraField1")) {
|
||
item.setExtraField1(value);
|
||
}
|
||
if (extraName.equals("extraField2")) {
|
||
item.setExtraField2(value);
|
||
}
|
||
if (extraName.equals("extraField3")) {
|
||
item.setExtraField3(value);
|
||
}
|
||
if (extraName.equals("extraField4")) {
|
||
item.setExtraField4(value);
|
||
}
|
||
if (extraName.equals("extraField5")) {
|
||
item.setExtraField5(value);
|
||
}
|
||
if (extraName.equals("extraField6")) {
|
||
item.setExtraField6(value);
|
||
}
|
||
if (extraName.equals("extraField7")) {
|
||
item.setExtraField7(value);
|
||
}
|
||
if (extraName.equals("extraField8")) {
|
||
item.setExtraField8(value);
|
||
}
|
||
}
|
||
item.setMaterialOrder(materialOrder);
|
||
item.setSupplierIds(new ArrayList<>());
|
||
|
||
String diameterSStr = item.getDiameterS()==null?"null":item.getDiameterS().stripTrailingZeros().toString();
|
||
String diameterLStr = item.getDiameterL()==null?"null":item.getDiameterL().stripTrailingZeros().toString();
|
||
String wallThicknessSStr = item.getWallThicknessS()==null?"null":item.getWallThicknessS().toString();
|
||
String wallThicknessLStr = item.getWallThicknessL()==null?"null":item.getWallThicknessL().toString();
|
||
|
||
String str = item.getName()+"_"+item.getProductId()+"_"+diameterSStr
|
||
+"_"+diameterLStr+"_"+wallThicknessSStr
|
||
+"_"+wallThicknessLStr+"_"+item.getMaterial()
|
||
+"_"+item.getMemo()+"_"+item.getSize()
|
||
+"_"+item.getSpecialRequest()+"_"+item.getInsulationCode()
|
||
+"_"+item.getLineAccount()+"_"+item.getAreaAccount()
|
||
+"_"+item.getSiteAccount()+"_"+item.getUnitAccount()
|
||
+"_"+item.getProductCode()+"_"+item.getPurchaseCode()
|
||
+"_"+item.getMakeCode()+"_"+item.getMaterialType()
|
||
+"_"+item.getEndFace()+"_"+item.getPressureLevel();
|
||
//没有合同,直接创建单条数据
|
||
if (!contractCountMap.containsKey(str)){
|
||
materialOrderItemService.save(item);
|
||
}else {
|
||
BigDecimal oldCount = contractCountMap.get(str);
|
||
BigDecimal newCount = item.getCount().subtract(oldCount);
|
||
//有合同并且多出的数量部分创建新数据
|
||
if (newCount.compareTo(BigDecimal.ZERO)>0) {
|
||
item.setCount(newCount);
|
||
materialOrderItemService.save(item);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
materialOrder.setTotalCount(orderCount);
|
||
materialOrder.setTotalWeight(orderWeight);
|
||
update(materialOrder);
|
||
}
|
||
}
|
||
}
|
||
|
||
@Transactional
|
||
public void updateFile2(MultipartFile file, Long adminId, Long orderId,String remark,String upReason) {
|
||
if (upReason == null){
|
||
throw new RuntimeException("升版原因不能为空");
|
||
}
|
||
List<ProductType> productTypeList = new ArrayList<>();
|
||
Admin admin = adminService.find(adminId);
|
||
//获得Workbook工作薄对象
|
||
Workbook workbook = ExcelUtil2.getWorkBook(file);
|
||
//创建返回对象,把每行中的值作为一个数组,所有行作为一个集合返回
|
||
Map<String, PurchaseOrderItem> itemMap = new HashMap<>();
|
||
Map<String, BigDecimal> itemCountMap = new HashMap<>();
|
||
MaterialOrder materialOrder = find(orderId);
|
||
List<PurchaseApplyOrder> purchaseApplyOrders = purchaseApplyOrderService.findByaMaterialOrder(materialOrder.getId());
|
||
if (purchaseApplyOrders.size()>0){
|
||
throw new RuntimeException("已有采购申请,无法升版");
|
||
}
|
||
List<MaterialOrder> upOrderList = findByStageNumUp(materialOrder.getPreTitle(),materialOrder.getStageNum(),admin.getNowProgress());
|
||
if (upOrderList.size()>0){
|
||
throw new RuntimeException("已到下一阶段,该阶段无法修改");
|
||
}
|
||
boolean haveContract = false;
|
||
List<Long> loadIds = new ArrayList<>();
|
||
List<MaterialOrderItem> nowList = materialOrderItemService.findByVersionNum(materialOrder.getVersionNum(), materialOrder.getId());
|
||
materialOrder.setMaterialOrderItemList(nowList);
|
||
for (MaterialOrderItem item : materialOrder.getMaterialOrderItemList()){
|
||
if (item.getOrderItemId() != null && !loadIds.contains(item.getOrderItemId())) {
|
||
loadIds.add(item.getOrderItemId());
|
||
List<PurchaseStockItem> purchaseStockItemList = purchaseStockItemService.findListByAttribute("purchaseOrderItemId",item.getOrderItemId());
|
||
if (purchaseStockItemList.size()>0){
|
||
throw new RuntimeException("已发货,无法升版");
|
||
}
|
||
PurchaseOrderItem purchaseOrderItem = purchaseOrderItemService.find(item.getOrderItemId());
|
||
if (purchaseOrderItem != null && purchaseOrderItem.getPurchaseOrder().getOrderType().equals(PurchaseOrder.OrderType.contract)){
|
||
throw new RuntimeException("已创建合同,无法升版");
|
||
}
|
||
if (purchaseOrderItem != null){
|
||
haveContract = true;
|
||
itemMap.put(purchaseOrderItem.getProductCode(),purchaseOrderItem);
|
||
itemCountMap.put(purchaseOrderItem.getProductCode(),purchaseOrderItem.getPurchaseCount());
|
||
}
|
||
}
|
||
}
|
||
|
||
if(!haveContract){
|
||
List<PurchaseApplyOrder> orders = purchaseApplyOrderService.findByaMaterialOrder(orderId);
|
||
for (PurchaseApplyOrder order : orders){
|
||
purchaseApplyOrderService.delete(order);
|
||
}
|
||
}
|
||
|
||
// 产品库存
|
||
// List<Product> productList = productService.findList(
|
||
// Filter.gt("stockCount",0)
|
||
// );
|
||
Map<String,ProgressStock> stockMap = new HashMap<>();
|
||
// for(Product product : productList){
|
||
// stockMap.put(product.getCode(),product);
|
||
// }
|
||
|
||
Map<String, Product> productMap = new HashMap<>();
|
||
for (ProgressStock product : progressStockService.findByProgress(materialOrder.getProgressId())) {
|
||
stockMap.put(product.getProgressId()+"_"+product.getProduct().getCode(), product);
|
||
}
|
||
for (Product product : productService.findByType(Product.Type.conduit)) {
|
||
productMap.put(product.getCode(), product);
|
||
}
|
||
|
||
materialOrder.setAdminId(adminId);
|
||
materialOrder.setAdminName(admin.getName());
|
||
materialOrder.setStatus(OrderStatus.create);
|
||
materialOrder.setType(MaterialOrder.Type.conduit);
|
||
materialOrder.setVersionNum(materialOrder.getVersionNum()+1);
|
||
materialOrder.setSn(materialOrder.getPreSn()+"-V"+materialOrder.getVersionNum());
|
||
materialOrder.setProgressId(admin.getNowProgress());
|
||
if (admin.getNowProgress() != null) {
|
||
Progress progress = progressService.find(admin.getNowProgress());
|
||
materialOrder.setProgressName(progress.getName());
|
||
materialOrder.setProgressCode(progress.getCode());
|
||
}else {
|
||
materialOrder.setProgressName("公司");
|
||
}
|
||
materialOrder.setRemark(remark);
|
||
List<String> upReasonList = new ArrayList<>(materialOrder.getUpReason());
|
||
upReasonList.add(upReason);
|
||
materialOrder.setUpReason(upReasonList);
|
||
update(materialOrder);
|
||
//原先数量
|
||
Map<String,BigDecimal> needCountMap = new HashMap<>();
|
||
Map<String,BigDecimal> countMap = new HashMap<>();
|
||
//已签合同数量
|
||
Map<String,BigDecimal> contractCountMap = new HashMap<>();
|
||
// Map<String,BigDecimal> contractCountViewMap = new HashMap<>();
|
||
for (MaterialOrderItem materialOrderItem : materialOrder.getMaterialOrderItemList()){
|
||
if (materialOrderItem.getUseStockCount().compareTo(BigDecimal.ZERO)>0){
|
||
ProgressStock stockProduct = stockMap.get(materialOrderItem.getMaterialOrder().getProgressId()+"_"+materialOrderItem.getProductCode());
|
||
stockProduct.setStockCount(stockProduct.getStockCount().add(materialOrderItem.getUseStockCount()));
|
||
stockMap.put(materialOrderItem.getMaterialOrder().getProgressId()+"_"+materialOrderItem.getProductCode(),stockProduct);
|
||
}
|
||
String diameterSStr = materialOrderItem.getDiameterS()==null?"null":materialOrderItem.getDiameterS().stripTrailingZeros().toString();
|
||
String diameterLStr = materialOrderItem.getDiameterL()==null?"null":materialOrderItem.getDiameterL().stripTrailingZeros().toString();
|
||
String wallThicknessSStr = materialOrderItem.getWallThicknessS()==null?"null":materialOrderItem.getWallThicknessS();
|
||
String wallThicknessLStr = materialOrderItem.getWallThicknessL()==null?"null":materialOrderItem.getWallThicknessL();
|
||
String str = materialOrderItem.getName()+"_"+materialOrderItem.getProductId()+"_"+diameterSStr
|
||
+"_"+diameterLStr+"_"+wallThicknessSStr+"_"+materialOrderItem.getShortDescription()
|
||
+"_"+wallThicknessLStr+"_"+materialOrderItem.getMaterial()
|
||
+"_"+materialOrderItem.getMemo()+"_"+materialOrderItem.getSize()
|
||
+"_"+materialOrderItem.getSpecialRequest()+"_"+materialOrderItem.getInsulationCode()
|
||
+"_"+materialOrderItem.getLineAccount()+"_"+materialOrderItem.getAreaAccount()
|
||
+"_"+materialOrderItem.getSiteAccount()+"_"+materialOrderItem.getUnitAccount()
|
||
+"_"+materialOrderItem.getProductCode()+"_"+materialOrderItem.getPurchaseCode()
|
||
+"_"+materialOrderItem.getMakeCode()+"_"+materialOrderItem.getMaterialType()
|
||
+"_"+materialOrderItem.getEndFace()+"_"+materialOrderItem.getPressureLevel();
|
||
BigDecimal count = countMap.getOrDefault(str,BigDecimal.ZERO);
|
||
BigDecimal needCount = needCountMap.getOrDefault(str,BigDecimal.ZERO);
|
||
count = count.add(materialOrderItem.getCount());
|
||
needCount = needCount.add(materialOrderItem.getNeedCount());
|
||
countMap.put(str,count);
|
||
needCountMap.put(str,needCount);
|
||
if (materialOrderItem.getOrderItemId() != null){
|
||
BigDecimal contractCount = contractCountMap.getOrDefault(str,BigDecimal.ZERO);
|
||
contractCount = contractCount.add(materialOrderItem.getCount());
|
||
contractCountMap.put(str,contractCount);
|
||
|
||
// str = str+"_"+materialOrderItem.getOrderItemId();
|
||
// BigDecimal contractViewCount = contractCountMap.getOrDefault(str,BigDecimal.ZERO);
|
||
// contractViewCount = contractViewCount.add(materialOrderItem.getCount());
|
||
// contractCountViewMap.put(str,contractViewCount);
|
||
}
|
||
}
|
||
Map<String, ProductType> productTypeMap = new HashMap<>();
|
||
Map<String, BigDecimal> diameterMap = new HashMap<>();
|
||
// Map<String, BigDecimal> wallThicknessMap = new HashMap<>();
|
||
for (Diameter diameter : diameterService.findAll()){
|
||
diameterMap.put(diameter.getName(),diameter.getValue());
|
||
}
|
||
// for (WallThickness wallThickness : wallThicknessService.findAll()){
|
||
// wallThicknessMap.put(wallThickness.getName(),wallThickness.getValue());
|
||
// }
|
||
for (ProductType productType : productTypeService.findAll()){
|
||
productTypeMap.put(productType.getName(),productType);
|
||
}
|
||
|
||
int successNum = 0;
|
||
int failNum = 0;
|
||
if (workbook != null) {
|
||
for (int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum++) {
|
||
//获得当前sheet工作表
|
||
Sheet sheet = workbook.getSheetAt(sheetNum);
|
||
if (sheet == null || sheetNum != 0) {
|
||
continue;
|
||
}
|
||
//获得当前sheet的开始行
|
||
int firstRowNum = sheet.getFirstRowNum();
|
||
//获得当前sheet的结束行
|
||
int lastRowNum = sheet.getLastRowNum();
|
||
|
||
List<ExtraField> extraFields = extraFieldService.findByProgress("materialOrderItem",materialOrder.getProgressId(),null);
|
||
Map<String, String> extraMap = new HashMap<>();
|
||
for (ExtraField extraField : extraFields) {
|
||
extraMap.put(extraField.getName(), extraField.getFieldName());
|
||
}
|
||
|
||
String name1 = "";
|
||
String name2 = "";
|
||
String name3 = "";
|
||
String name4 = "";
|
||
String name5 = "";
|
||
String name6 = "";
|
||
String name7 = "";
|
||
String name8 = "";
|
||
|
||
Map<Integer, String> valueMap = new HashMap<>();
|
||
BigDecimal orderWeight = BigDecimal.ZERO;
|
||
BigDecimal orderCount = BigDecimal.ZERO;
|
||
//循环除了所有行,如果要循环除第一行以外的就firstRowNum+1
|
||
for (int rowNum = firstRowNum + 0; rowNum <= lastRowNum; rowNum++) {
|
||
boolean notFindFlag = false;
|
||
String errorMessage = "";
|
||
//获得当前行
|
||
Row row = sheet.getRow(rowNum);
|
||
if (row == null) {
|
||
continue;
|
||
}
|
||
//获得当前行的列数
|
||
int lastCellNum = row.getLastCellNum();
|
||
if (lastCellNum > 0) {
|
||
if (rowNum == 0) {
|
||
name1 = ExcelUtil2.getCellValue(row.getCell(33));
|
||
String fieldName1 = extraMap.getOrDefault(name1, null);
|
||
if (fieldName1 != null) {
|
||
valueMap.put(33, fieldName1);
|
||
}
|
||
|
||
name2 = ExcelUtil2.getCellValue(row.getCell(34));
|
||
String fieldName2 = extraMap.getOrDefault(name2, null);
|
||
if (fieldName2 != null) {
|
||
valueMap.put(34, fieldName2);
|
||
}
|
||
|
||
name3 = ExcelUtil2.getCellValue(row.getCell(35));
|
||
String fieldName3 = extraMap.getOrDefault(name3, null);
|
||
if (fieldName3 != null) {
|
||
valueMap.put(35, fieldName3);
|
||
}
|
||
|
||
name4 = ExcelUtil2.getCellValue(row.getCell(36));
|
||
String fieldName4 = extraMap.getOrDefault(name4, null);
|
||
if (fieldName4 != null) {
|
||
valueMap.put(36, fieldName4);
|
||
}
|
||
|
||
name5 = ExcelUtil2.getCellValue(row.getCell(37));
|
||
String fieldName5 = extraMap.getOrDefault(name5, null);
|
||
if (fieldName5 != null) {
|
||
valueMap.put(37, fieldName5);
|
||
}
|
||
|
||
name6 = ExcelUtil2.getCellValue(row.getCell(38));
|
||
String fieldName6 = extraMap.getOrDefault(name6, null);
|
||
if (fieldName6 != null) {
|
||
valueMap.put(38, fieldName6);
|
||
}
|
||
|
||
name7 = ExcelUtil2.getCellValue(row.getCell(39));
|
||
String fieldName7 = extraMap.getOrDefault(name7, null);
|
||
if (fieldName7 != null) {
|
||
valueMap.put(39, fieldName7);
|
||
}
|
||
|
||
name8 = ExcelUtil2.getCellValue(row.getCell(40));
|
||
String fieldName8 = extraMap.getOrDefault(name8, null);
|
||
if (fieldName8 != null) {
|
||
valueMap.put(40, fieldName8);
|
||
}
|
||
|
||
|
||
}
|
||
if (rowNum >= 2) {
|
||
if (ExcelUtil2.getCellValue(row.getCell(0)).equals("")) {
|
||
continue;
|
||
}
|
||
Integer ind = Integer.valueOf(ExcelUtil2.getCellValue(row.getCell(0)));
|
||
String name = ExcelUtil2.getCellValue(row.getCell(1));
|
||
String areaAccount = ExcelUtil2.getCellValue(row.getCell(2));
|
||
String unitAccount = ExcelUtil2.getCellValue(row.getCell(3));
|
||
String siteAccount = ExcelUtil2.getCellValue(row.getCell(4));
|
||
String lineAccount = ExcelUtil2.getCellValue(row.getCell(5));
|
||
String codeType = ExcelUtil2.getCellValue(row.getCell(6));
|
||
String purchaseCode = ExcelUtil2.getCellValue(row.getCell(7));
|
||
String shortDescription = ExcelUtil2.getCellValue(row.getCell(8));
|
||
String longDescription = ExcelUtil2.getCellValue(row.getCell(9));
|
||
BigDecimal gWeight = null;
|
||
if (!ExcelUtil2.getCellValue(row.getCell(10)).equals("")) {
|
||
gWeight = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(10)));
|
||
}
|
||
|
||
BigDecimal totalWeight = null;
|
||
if (!ExcelUtil2.getCellValue(row.getCell(11)).equals("")) {
|
||
totalWeight = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(11)));
|
||
orderWeight = orderWeight.add(totalWeight);
|
||
}
|
||
|
||
String unit = ExcelUtil2.getCellValue(row.getCell(14));
|
||
String bigType = ExcelUtil2.getCellValue(row.getCell(15));
|
||
// if (bigType.equals("")){
|
||
// throw new RuntimeException("大类编号不能为空");
|
||
// }
|
||
String bigDes = ExcelUtil2.getCellValue(row.getCell(16));
|
||
String smallType = ExcelUtil2.getCellValue(row.getCell(17));
|
||
String smallDes = ExcelUtil2.getCellValue(row.getCell(18));
|
||
|
||
String makeCode = ExcelUtil2.getCellValue(row.getCell(19));
|
||
String makeName = ExcelUtil2.getCellValue(row.getCell(20));
|
||
|
||
BigDecimal diameterL = null;
|
||
BigDecimal diameterS = null;
|
||
String wallThicknessL = null;
|
||
String wallThicknessS = null;
|
||
|
||
try {
|
||
if (!ExcelUtil2.getCellValue(row.getCell(21)).equals("")) {
|
||
String cellValue = ExcelUtil2.getCellValue(row.getCell(21));
|
||
diameterL = diameterMap.getOrDefault(cellValue,null);
|
||
if (diameterL == null){
|
||
diameterL = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(21)));
|
||
}
|
||
// diameterL = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(16)));
|
||
}
|
||
if (!ExcelUtil2.getCellValue(row.getCell(22)).equals("")) {
|
||
String cellValue = ExcelUtil2.getCellValue(row.getCell(22));
|
||
diameterS = diameterMap.getOrDefault(cellValue,null);
|
||
if (diameterS == null){
|
||
diameterS = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(22)));
|
||
}
|
||
// diameterS = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(17)));
|
||
}
|
||
|
||
wallThicknessL = ExcelUtil2.getCellValue(row.getCell(23));
|
||
wallThicknessS = ExcelUtil2.getCellValue(row.getCell(24));
|
||
|
||
}catch (Exception e){
|
||
e.printStackTrace();
|
||
// throw new RuntimeException("未找到"+ind+"行直径壁厚");
|
||
notFindFlag = true;
|
||
errorMessage += "未找到直径壁厚;";
|
||
}
|
||
|
||
|
||
String size = ExcelUtil2.getCellValue(row.getCell(25));
|
||
String pressureLevel = ExcelUtil2.getCellValue(row.getCell(26));
|
||
String endFace = ExcelUtil2.getCellValue(row.getCell(27));
|
||
String material = ExcelUtil2.getCellValue(row.getCell(29));
|
||
String materialType = ExcelUtil2.getCellValue(row.getCell(28));
|
||
String insulationCode = ExcelUtil2.getCellValue(row.getCell(30));
|
||
String specialRequest = ExcelUtil2.getCellValue(row.getCell(31));
|
||
String memo = ExcelUtil2.getCellValue(row.getCell(32));
|
||
String jacketSpec = ExcelUtil2.getCellValue(row.getCell(33));
|
||
MaterialOrderItem item = new MaterialOrderItem();
|
||
if (productTypeMap.getOrDefault(bigType, null) == null) {
|
||
// throw new RuntimeException(bigType+"大类不存在");
|
||
// ProductType productType = new ProductType();
|
||
// productType.setName(bigType);
|
||
// productType.setLevel(1);
|
||
// productType.setTypeDescribe(bigDes);
|
||
// productTypeService.saveProductType(productType);
|
||
// productTypeMap.put(bigType,productType);
|
||
// item.setBigProductTypeId(productType.getId());
|
||
// item.setBigProductType(productType.getName());
|
||
// item.setBigProductDes(bigDes);
|
||
notFindFlag = true;
|
||
errorMessage += "未找到产品大类;";
|
||
}else {
|
||
item.setBigProductTypeId( productTypeMap.get(bigType).getId());
|
||
item.setBigProductType( productTypeMap.get(bigType).getName());
|
||
item.setBigProductDes( productTypeMap.get(bigType).getTypeDescribe());
|
||
}
|
||
if (smallType.equals("") || productTypeMap.getOrDefault(smallType, null) == null) {
|
||
// throw new RuntimeException(smallType+"小类不存在");
|
||
// ProductType parent = productTypeMap.get(bigType);
|
||
// ProductType productType = new ProductType();
|
||
// productType.setName(smallType);
|
||
// productType.setLevel(2);
|
||
// productType.setParentId(parent.getId());
|
||
// productType.setTypeDescribe(smallDes);
|
||
// productTypeService.saveProductType(productType);
|
||
// productTypeMap.put(smallType,productType);
|
||
// item.setSmallTypeId(productType.getId());
|
||
// item.setSmallProductType(productType.getName());
|
||
// item.setSmallProductDes(smallDes);
|
||
notFindFlag = true;
|
||
errorMessage += "未找到产品小类;";
|
||
}else {
|
||
item.setSmallTypeId( productTypeMap.get(smallType).getId());
|
||
item.setSmallProductType( productTypeMap.get(smallType).getName());
|
||
item.setSmallProductDes( productTypeMap.get(smallType).getTypeDescribe());
|
||
}
|
||
Product product = productMap.get(purchaseCode);
|
||
if (product == null) {
|
||
product = new Product();
|
||
product.setCode(purchaseCode);
|
||
product.setName(name);
|
||
product.setType(Product.Type.conduit);
|
||
if (!smallType.equals("")){
|
||
product.setProductType(productTypeMap.get(smallType));
|
||
}else {
|
||
product.setProductType(productTypeMap.get(bigType));
|
||
}
|
||
product.setShortDescription(shortDescription);
|
||
product.setLongDescription(longDescription);
|
||
product = productService.save(product);
|
||
productMap.put(purchaseCode,product);
|
||
// throw new RuntimeException("未找到" + purchaseCode + "产品");
|
||
// continue;
|
||
}else {
|
||
if (product.getProductType() != null) {
|
||
Long productTypeId = product.getProductType().getId();
|
||
if (!smallType.equals("")) {
|
||
product.setProductType(productTypeMap.get(smallType));
|
||
}else {
|
||
product.setProductType(productTypeMap.get(bigType));
|
||
}
|
||
if (!productTypeId.equals(product.getProductType().getId())) {
|
||
product = productService.update(product);
|
||
}
|
||
}
|
||
}
|
||
item.setInd(ind);
|
||
item.setProductId(product.getId());
|
||
// item.setProductTypeId(product.getProductType().getId());
|
||
if (product.getProductType() != null && !productTypeList.contains(product.getProductType())){
|
||
productTypeList.add(product.getProductType());
|
||
}
|
||
item.setName(name);
|
||
item.setAreaAccount(areaAccount);
|
||
item.setUnitAccount(unitAccount);
|
||
item.setSiteAccount(siteAccount);
|
||
item.setLineAccount(lineAccount);
|
||
item.setCodeType(codeType);
|
||
item.setProductCode(purchaseCode);
|
||
item.setShortDescription(shortDescription);
|
||
item.setLongDescription(longDescription);
|
||
item.setgWeight(gWeight == null ? BigDecimal.ZERO :gWeight);
|
||
|
||
item.setUnit(unit);
|
||
item.setDiameterL(diameterL);
|
||
item.setDiameterS(diameterS);
|
||
item.setWallThicknessL(wallThicknessL);
|
||
item.setWallThicknessS(wallThicknessS);
|
||
item.setSize(size);
|
||
item.setPressureLevel(pressureLevel);
|
||
item.setEndFace(endFace);
|
||
item.setMaterial(material);
|
||
item.setInsulationCode(insulationCode);
|
||
item.setSpecialRequest(specialRequest);
|
||
item.setMaterialType(materialType);
|
||
item.setMakeCode(makeCode);
|
||
item.setMakeName(makeName);
|
||
item.setMemo(memo);
|
||
item.setJacketSpec(jacketSpec);
|
||
item.setVersionNum(materialOrder.getVersionNum());
|
||
for (Integer key : valueMap.keySet()) {
|
||
String value = ExcelUtil2.getCellValue(row.getCell(key));
|
||
String extraName = valueMap.get(key);
|
||
if (extraName.equals("extraField1")) {
|
||
item.setExtraField1(value);
|
||
}
|
||
if (extraName.equals("extraField2")) {
|
||
item.setExtraField2(value);
|
||
}
|
||
if (extraName.equals("extraField3")) {
|
||
item.setExtraField3(value);
|
||
}
|
||
if (extraName.equals("extraField4")) {
|
||
item.setExtraField4(value);
|
||
}
|
||
if (extraName.equals("extraField5")) {
|
||
item.setExtraField5(value);
|
||
}
|
||
if (extraName.equals("extraField6")) {
|
||
item.setExtraField6(value);
|
||
}
|
||
if (extraName.equals("extraField7")) {
|
||
item.setExtraField7(value);
|
||
}
|
||
if (extraName.equals("extraField8")) {
|
||
item.setExtraField8(value);
|
||
}
|
||
}
|
||
item.setMaterialOrder(materialOrder);
|
||
item.setSupplierIds(new ArrayList<>());
|
||
|
||
String diameterSStr = item.getDiameterS()==null?"null":item.getDiameterS().stripTrailingZeros().toString();
|
||
String diameterLStr = item.getDiameterL()==null?"null":item.getDiameterL().stripTrailingZeros().toString();
|
||
String wallThicknessSStr = item.getWallThicknessS()==null?"null":item.getWallThicknessS().toString();
|
||
String wallThicknessLStr = item.getWallThicknessL()==null?"null":item.getWallThicknessL().toString();
|
||
|
||
String str = item.getName()+"_"+item.getProductId()+"_"+diameterSStr
|
||
+"_"+diameterLStr+"_"+wallThicknessSStr+"_"+item.getShortDescription()
|
||
+"_"+wallThicknessLStr+"_"+item.getMaterial()
|
||
+"_"+item.getMemo()+"_"+item.getSize()
|
||
+"_"+item.getSpecialRequest()+"_"+item.getInsulationCode()
|
||
+"_"+item.getLineAccount()+"_"+item.getAreaAccount()
|
||
+"_"+item.getSiteAccount()+"_"+item.getUnitAccount()
|
||
+"_"+item.getProductCode()+"_"+item.getPurchaseCode()
|
||
+"_"+item.getMakeCode()+"_"+item.getMaterialType()
|
||
+"_"+item.getEndFace()+"_"+item.getPressureLevel();
|
||
|
||
BigDecimal needCount = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(12)));
|
||
BigDecimal count = BigDecimal.ZERO;
|
||
if (materialOrder.getStageNum() == 1) {
|
||
count = new BigDecimal(ExcelUtil2.getCellValue(row.getCell(13)));
|
||
}else {
|
||
BigDecimal sourceCount = countMap.get(str);
|
||
count = countMap.get(str).add(needCount.subtract(needCountMap.get(str)));
|
||
}
|
||
//优先使用库存数据
|
||
if (stockMap.containsKey(item.getMaterialOrder().getProgressId()+"_"+item.getProductCode())){
|
||
ProgressStock stockProduct = stockMap.get(item.getMaterialOrder().getProgressId()+"_"+item.getProductCode());
|
||
if (stockProduct.getStockCount().compareTo(count)>=0){
|
||
item.setCount(BigDecimal.ZERO);
|
||
item.setUseStockCount(count);
|
||
stockProduct.setStockCount(stockProduct.getStockCount().subtract(count));
|
||
}else {
|
||
item.setCount(count.subtract(stockProduct.getStockCount()));
|
||
item.setUseStockCount(stockProduct.getStockCount());
|
||
stockProduct.setStockCount(BigDecimal.ZERO);
|
||
}
|
||
stockMap.put(item.getMaterialOrder().getProgressId()+"_"+item.getProductCode(),stockProduct);
|
||
}else {
|
||
item.setCount(count);
|
||
}
|
||
// item.setCount(count);
|
||
item.setNeedCount(needCount);
|
||
item.setTotalWeight(gWeight.multiply(count));
|
||
orderCount = orderCount.add(count);
|
||
//没有合同,直接创建单条数据
|
||
// if (!contractCountMap.containsKey(str)){
|
||
// materialOrderItemService.save(item);
|
||
// }else {
|
||
// BigDecimal oldCount = contractCountMap.get(str);
|
||
// BigDecimal newCount = item.getCount().subtract(oldCount);
|
||
// //有合同并且多出的数量部分创建新数据
|
||
// if (newCount.compareTo(BigDecimal.ZERO)>0) {
|
||
// item.setCount(newCount);
|
||
// materialOrderItemService.save(item);
|
||
// }
|
||
// }
|
||
|
||
BigDecimal oldCount = contractCountMap.getOrDefault(str,BigDecimal.ZERO);
|
||
BigDecimal changeCount = item.getCount().subtract(oldCount);
|
||
PurchaseOrderItem purchaseOrderItem = itemMap.getOrDefault(item.getProductCode(),null);
|
||
if (purchaseOrderItem != null && purchaseOrderItem.getPurchaseCount() != null){
|
||
if (purchaseOrderItem.getPurchaseOrder().getOrderType().equals(PurchaseOrder.OrderType.order)) {
|
||
purchaseOrderItem.setCount(purchaseOrderItem.getCount().add(changeCount));
|
||
//当采购数量高于订单数量时,需要变动采购数量
|
||
// if (purchaseOrderItem.getCount().compareTo(purchaseOrderItem.getPurchaseCount())<0) {
|
||
// purchaseOrderItem.setPrePurchaseCount(itemCountMap.get(item.getProductCode()));
|
||
// purchaseOrderItem.setPurchaseCount(purchaseOrderItem.getCount());
|
||
// }
|
||
itemMap.put(item.getProductCode(), purchaseOrderItem);
|
||
}
|
||
item.setOrderItemId(purchaseOrderItem.getId());
|
||
if (purchaseOrderItem.getPurchaseCount().compareTo(purchaseOrderItem.getCount())>=0){
|
||
item.setStockType(MaterialOrderItem.StockType.all);
|
||
}else if (purchaseOrderItem.getPurchaseCount().compareTo(BigDecimal.ZERO)>0){
|
||
item.setStockType(MaterialOrderItem.StockType.half);
|
||
}else{
|
||
item.setStockType(MaterialOrderItem.StockType.none);
|
||
}
|
||
item.setOrderId(purchaseOrderItem.getPurchaseOrder().getId());
|
||
}
|
||
materialOrderItemService.save(item);
|
||
|
||
if (notFindFlag) {
|
||
Cell notFindCell = ExcelUtil2.getOrCreateCell(row, 34);
|
||
notFindCell.setCellValue(errorMessage);
|
||
failNum++;
|
||
} else {
|
||
successNum++;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
materialOrder.setTotalCount(orderCount);
|
||
materialOrder.setTotalWeight(orderWeight);
|
||
update(materialOrder);
|
||
for (String key : stockMap.keySet()){
|
||
ProgressStock product = stockMap.get(key);
|
||
progressStockService.update(product);
|
||
}
|
||
|
||
for (String key : itemMap.keySet()){
|
||
PurchaseOrderItem purchaseOrderItem = itemMap.get(key);
|
||
// BigDecimal preCount = itemCountMap.get(purchaseOrderItem.getProductCode());
|
||
// if(preCount != null && preCount.compareTo(purchaseOrderItem.getCount())<=0){
|
||
// purchaseOrderItem.setPurchaseCount(preCount);
|
||
// }
|
||
purchaseOrderItemService.update(purchaseOrderItem);
|
||
}
|
||
}
|
||
if (failNum > 0) {
|
||
String importErrorExcel = ExcelImportErrorUtil.materialOrderSiee(workbook);
|
||
Map<String, Object> map = new HashMap<>();
|
||
map.put("importErrorExcel", importErrorExcel);
|
||
map.put("successNum", successNum);
|
||
map.put("failNum", failNum);
|
||
throw new ImportExcelException(failNum+"条导入失败", "3", map);
|
||
}
|
||
}
|
||
}
|
||
|
||
@Transactional
|
||
public void selectSupplierIds(Long id, Integer number,Long progressId,String ids) {
|
||
if (number == null) {
|
||
throw new RuntimeException("数量不能为空");
|
||
}
|
||
List<MaterialOrder> materialOrderList = new ArrayList<>();
|
||
if (id != null) {
|
||
MaterialOrder materialOrder = find(id);
|
||
materialOrderList.add(materialOrder);
|
||
}else {
|
||
String[] arr = ids.split(";");
|
||
for (String idStr : arr){
|
||
if (idStr != null && !idStr.equals("")){
|
||
Long thisId = Long.valueOf(idStr);
|
||
MaterialOrder materialOrder = find(thisId);
|
||
materialOrderList.add(materialOrder);
|
||
}
|
||
}
|
||
}
|
||
for (MaterialOrder materialOrder : materialOrderList) {
|
||
Map<MaterialOrderItem, Map<Long, Integer>> itemMap = new HashMap<>();
|
||
Integer maxInd = null;
|
||
Long maxIndSupplier = null;
|
||
Map<Long, Integer> indMap = new HashMap<>();
|
||
CompanyQuery companyQuery = new CompanyQuery();
|
||
companyQuery.setProgressId(progressId);
|
||
List<Supplier> supplierList = supplierService.findList(companyQuery);
|
||
Map<Long, String> supplierMap = new HashMap<>();
|
||
for (Supplier supplier : supplierList) {
|
||
supplierMap.put(supplier.getId(), supplier.getName());
|
||
}
|
||
List<SupplierProduct> supplierProductList = supplierProductService.findByProgress(progressId);
|
||
List<MaterialOrderItem> materialOrderItemList = materialOrderItemService.findByVersionNum2(materialOrder.getVersionNum(), materialOrder.getId());
|
||
for (MaterialOrderItem item : materialOrderItemList) {
|
||
indMap = new HashMap<>();
|
||
maxInd = null;
|
||
maxIndSupplier = null;
|
||
for (SupplierProduct supplierProduct : supplierProductList) {
|
||
if (supplierProduct.getBigTypeId() == null && supplierProduct.getSmallTypeId() == null) {
|
||
continue;
|
||
}
|
||
boolean flag = false;
|
||
|
||
if (supplierProduct.getSmallTypeId() != null){
|
||
if (supplierProduct.getSmallTypeId().equals(item.getSmallTypeId())) {
|
||
flag = true;
|
||
}
|
||
}else {
|
||
if (supplierProduct.getBigTypeId().equals(item.getBigProductTypeId()) ){
|
||
flag = true;
|
||
}
|
||
}
|
||
if (flag) {
|
||
//不在取值范围内
|
||
if (supplierProduct.getDiameterL() != null) {
|
||
if (item.getDiameterL() == null) {
|
||
continue;
|
||
}
|
||
if (item.getDiameterL().compareTo(supplierProduct.getDiameterL()) > 0) {
|
||
continue;
|
||
}
|
||
}
|
||
if (supplierProduct.getDiameterS() != null) {
|
||
if (item.getDiameterL() == null) {
|
||
continue;
|
||
}
|
||
if (item.getDiameterL().compareTo(supplierProduct.getDiameterS()) < 0) {
|
||
continue;
|
||
}
|
||
}
|
||
if (supplierProduct.getWallThicknessLName() != null && !supplierProduct.getWallThicknessLName().equals("")) {
|
||
if (!supplierProduct.getWallThicknessLName().equals(item.getWallThicknessL())) {
|
||
continue;
|
||
}
|
||
}
|
||
if (supplierProduct.getWallThicknessSName() != null && !supplierProduct.getWallThicknessSName().equals("")){
|
||
if (!supplierProduct.getWallThicknessSName().equals(item.getWallThicknessS())) {
|
||
continue;
|
||
}
|
||
}
|
||
if (supplierProduct.getMakeCode() != null && !supplierProduct.getMakeCode().equals("")){
|
||
if (!supplierProduct.getMakeCode().equals(item.getMakeCode())) {
|
||
continue;
|
||
}
|
||
}
|
||
if (supplierProduct.getMaterialType() != null && !supplierProduct.getMaterialType().equals("")){
|
||
if (!supplierProduct.getMaterialType().equals(item.getMaterialType())) {
|
||
continue;
|
||
}
|
||
}
|
||
if (supplierProduct.getPressureLevel() != null && !supplierProduct.getPressureLevel().equals("")) {
|
||
if (!supplierProduct.getPressureLevel().equals(item.getPressureLevel())) {
|
||
continue;
|
||
}
|
||
}
|
||
if (supplierProduct.getMaterial() != null && !supplierProduct.getMaterial().equals("")) {
|
||
if (!supplierProduct.getMaterial().equals(item.getMaterial())) {
|
||
continue;
|
||
}
|
||
}
|
||
if (supplierProduct.getSize() != null && !supplierProduct.getSize().equals("")) {
|
||
if (!supplierProduct.getSize().equals(item.getSize())) {
|
||
continue;
|
||
}
|
||
}
|
||
if (supplierProduct.getEndFace() != null && !supplierProduct.getEndFace().equals("")) {
|
||
if (!supplierProduct.getEndFace().equals(item.getEndFace())) {
|
||
continue;
|
||
}
|
||
}
|
||
//确认供应商列表
|
||
Integer ind = indMap.getOrDefault(supplierProduct.getSupplier().getId(), null);
|
||
if (ind == null) {
|
||
if (maxInd == null) {
|
||
indMap.put(supplierProduct.getSupplier().getId(), supplierProduct.getInd());
|
||
maxInd = supplierProduct.getInd();
|
||
maxIndSupplier = supplierProduct.getSupplier().getId();
|
||
} else {
|
||
if (indMap.size() >= number && supplierProduct.getInd().compareTo(maxInd) < 0) {
|
||
indMap.remove(maxIndSupplier);
|
||
indMap.put(supplierProduct.getSupplier().getId(), supplierProduct.getInd());
|
||
maxInd = supplierProduct.getInd();
|
||
maxIndSupplier = supplierProduct.getSupplier().getId();
|
||
}else if(indMap.size()<number){
|
||
indMap.put(supplierProduct.getSupplier().getId(), supplierProduct.getInd());
|
||
if (supplierProduct.getInd().compareTo(maxInd)>0){
|
||
maxInd = supplierProduct.getInd();
|
||
maxIndSupplier = supplierProduct.getSupplier().getId();
|
||
}
|
||
}
|
||
}
|
||
} else if (ind.compareTo(supplierProduct.getInd()) > 0) {
|
||
indMap.put(supplierProduct.getSupplier().getId(), supplierProduct.getInd());
|
||
}
|
||
}
|
||
}
|
||
itemMap.put(item, indMap);
|
||
}
|
||
|
||
List<Long> supplierIds = new ArrayList<>();
|
||
String supplierNames = "1:";
|
||
for (MaterialOrderItem item : itemMap.keySet()) {
|
||
Map<Long, Integer> supplierIdMap = itemMap.get(item);
|
||
int x = 2;
|
||
for (Long supplierId : supplierIdMap.keySet()) {
|
||
String name = supplierMap.get(supplierId);
|
||
supplierNames = supplierNames + name + ";"+x+":";
|
||
x++;
|
||
}
|
||
supplierNames = supplierNames.substring(0,supplierNames.length()-2);
|
||
supplierIds = new ArrayList<>(supplierIdMap.keySet());
|
||
item.setSupplierIds(supplierIds);
|
||
item.setSupplierNameList(supplierNames);
|
||
materialOrderItemService.update(item);
|
||
supplierNames = "1:";
|
||
}
|
||
}
|
||
}
|
||
|
||
@Transactional
|
||
public void changeSupplierList(MaterialOrderItem item){
|
||
MaterialOrderItem sourceItem = materialOrderItemService.find(item.getId());
|
||
String supplierNames = "";
|
||
for (Long supplierId : item.getSupplierIds()){
|
||
if(supplierId != null) {
|
||
Supplier supplier = supplierService.find(supplierId);
|
||
supplierNames = supplierNames + supplier.getName() + ";";
|
||
}
|
||
}
|
||
sourceItem.setSupplierNameList(supplierNames);
|
||
sourceItem.setSupplierIds(item.getSupplierIds());
|
||
materialOrderItemService.update(sourceItem);
|
||
}
|
||
|
||
public void exportView(HttpServletResponse response, Long id,String productCode,String name,String areaAccount,
|
||
String unitAccount,String siteAccount,String lineAccount,String codeType,
|
||
String shortDescription,String longDescription,String gWeight,String totalWeight,
|
||
String count,String unit,String bigProductType,String smallProductType,
|
||
String diameterL,String diameterS,String wallThicknessL,String wallThicknessS,
|
||
String size,String pressureLevel,String endFace,String material,
|
||
String insulationCode,String specialRequest,String memo,String supplierNameList,String supplierName,
|
||
String price,String bigProductDes,String smallProductDes,String makeCode,String makeName,String materialType) {
|
||
MaterialOrder materialOrder = find(id);
|
||
String templateUrl = "excel/template/materialOrderView.xlsx";
|
||
TemplateExportParams params = new TemplateExportParams(templateUrl);
|
||
Map<Long, List<PurchaseApplyOrderItem>> dataMap = new HashMap<>();
|
||
|
||
List<Map<String, Object>> list1 = new ArrayList<>();
|
||
Map<String, Object> value = new HashMap<>();
|
||
List<Map<String, Object>> listMap = new ArrayList<>();
|
||
List<MaterialOrderItem> materialOrderItemList = materialOrderItemService.findByVersionNum(materialOrder.getVersionNum(),id);
|
||
materialOrderItemList = materialOrderItemService.findSelect(materialOrderItemList,productCode,name,areaAccount,
|
||
unitAccount,siteAccount,lineAccount,codeType,
|
||
shortDescription,longDescription,gWeight,totalWeight,
|
||
count,unit,bigProductType,smallProductType,
|
||
diameterL,diameterS,wallThicknessL,wallThicknessS,
|
||
size,pressureLevel,endFace,material,
|
||
insulationCode,specialRequest,memo,supplierNameList,supplierName,
|
||
price,bigProductDes,smallProductDes,makeCode,makeName,materialType);
|
||
for (MaterialOrderItem item : materialOrderItemList) {
|
||
if(item.getNoShow() != null && item.getNoShow()){
|
||
continue;
|
||
}
|
||
Map<String, Object> lm = new HashMap<>();
|
||
lm.put("productCode", item.getProductCode());
|
||
lm.put("name", item.getName());
|
||
lm.put("areaAccount", item.getAreaAccount());
|
||
lm.put("unitAccount", item.getUnitAccount());
|
||
lm.put("siteAccount", item.getSiteAccount());
|
||
lm.put("lineAccount", item.getLineAccount());
|
||
lm.put("shortDescription", item.getShortDescription());
|
||
lm.put("longDescription", item.getLongDescription());
|
||
lm.put("gWeight", item.getgWeight());
|
||
lm.put("totalWeight", item.getTotalWeight());
|
||
lm.put("count", item.getCount());
|
||
lm.put("useStockCount", item.getUseStockCount());
|
||
lm.put("unit", item.getUnit());
|
||
lm.put("versionNum", item.getVersionNum());
|
||
lm.put("codeType", item.getCodeType());
|
||
lm.put("bigType", item.getBigProductType());
|
||
lm.put("bigDes", item.getBigProductDes());
|
||
lm.put("smallType", item.getSmallProductType());
|
||
lm.put("smallDes", item.getSmallProductDes());
|
||
lm.put("makeCode", item.getMakeCode());
|
||
lm.put("makeName", item.getMakeName());
|
||
lm.put("diameterL", item.getDiameterL());
|
||
lm.put("diameterS", item.getDiameterS());
|
||
lm.put("wallThicknessL", item.getWallThicknessL());
|
||
lm.put("wallThicknessS", item.getWallThicknessS());
|
||
lm.put("size", item.getSize());
|
||
lm.put("pressureLevel", item.getPressureLevel());
|
||
lm.put("material", item.getMaterial());
|
||
lm.put("materialType", item.getMaterialType());
|
||
lm.put("endFace", item.getEndFace());
|
||
lm.put("insulationCode", item.getInsulationCode());
|
||
lm.put("specialRequest", item.getSpecialRequest());
|
||
lm.put("memo", item.getMemo());
|
||
lm.put("supplierName", item.getSupplierName());
|
||
lm.put("price", item.getPrice());
|
||
listMap.add(lm);
|
||
}
|
||
value.put("maplist", listMap);
|
||
list1.add(value);
|
||
String fileName = "综合材料明细表筛选结果"+DateUtil.dateToStr(new Date(),"yyyy-MM-dd")+".xlsx";
|
||
ExcelUtils.export(response, value, params, fileName);
|
||
}
|
||
|
||
|
||
public void exportDiff(HttpServletResponse response, Long id,Integer nowVersion,Integer oldVersion) {
|
||
MaterialOrder materialOrder = find(id);
|
||
String templateUrl = "excel/template/materialOrderView.xlsx";
|
||
TemplateExportParams params = new TemplateExportParams(templateUrl);
|
||
Map<Long, List<PurchaseApplyOrderItem>> dataMap = new HashMap<>();
|
||
Map<Integer, List<Map<String, Object>>> valueList = new HashMap<>();
|
||
|
||
List<Map<String, Object>> list1 = new ArrayList<>();
|
||
Map<String, Object> value = new HashMap<>();
|
||
List<Map<String, Object>> listMap = new ArrayList<>();
|
||
List<MaterialOrderItem> oldList = materialOrderItemService.findByVersionNum(oldVersion, id);
|
||
List<MaterialOrderItem> nowList = materialOrderItemService.findByVersionNum(nowVersion, id);
|
||
|
||
Map<Integer, MaterialOrderItem> diffMap = new HashMap<>();
|
||
for (MaterialOrderItem item : oldList) {
|
||
diffMap.put(item.getInd(), item);
|
||
Map<String, Object> lm = new HashMap<>();
|
||
lm.put("name", item.getName());
|
||
lm.put("areaAccount", item.getAreaAccount());
|
||
lm.put("unitAccount", item.getUnitAccount());
|
||
lm.put("siteAccount", item.getSiteAccount());
|
||
lm.put("lineAccount", item.getLineAccount());
|
||
lm.put("shortDescription", item.getShortDescription());
|
||
lm.put("longDescription", item.getLongDescription());
|
||
lm.put("gWeight", item.getgWeight());
|
||
lm.put("totalWeight", item.getTotalWeight());
|
||
lm.put("count", item.getCount());
|
||
lm.put("useStockCount", item.getUseStockCount());
|
||
lm.put("unit", item.getUnit());
|
||
lm.put("versionNum", item.getVersionNum());
|
||
lm.put("codeType", item.getCodeType());
|
||
lm.put("bigType", item.getBigProductType());
|
||
lm.put("bigDes", item.getBigProductDes());
|
||
lm.put("smallType", item.getSmallProductType());
|
||
lm.put("smallDes", item.getSmallProductDes());
|
||
lm.put("makeCode", item.getMakeCode());
|
||
lm.put("makeName", item.getMakeName());
|
||
lm.put("diameterL", item.getDiameterL());
|
||
lm.put("diameterS", item.getDiameterS());
|
||
lm.put("wallThicknessL", item.getWallThicknessL());
|
||
lm.put("wallThicknessS", item.getWallThicknessS());
|
||
lm.put("size", item.getSize());
|
||
lm.put("pressureLevel", item.getPressureLevel());
|
||
lm.put("material", item.getMaterial());
|
||
lm.put("materialType", item.getMaterialType());
|
||
lm.put("endFace", item.getEndFace());
|
||
lm.put("insulationCode", item.getInsulationCode());
|
||
lm.put("specialRequest", item.getSpecialRequest());
|
||
lm.put("memo", item.getMemo());
|
||
lm.put("supplierName", item.getSupplierName());
|
||
lm.put("price", item.getPrice());
|
||
listMap.add(lm);
|
||
}
|
||
value.put("maplist", listMap);
|
||
value.put("sheetName", "版本"+oldVersion);
|
||
list1.add(value);
|
||
valueList.put(1, list1);
|
||
list1 = new ArrayList<>();
|
||
listMap = new ArrayList<>();
|
||
value = new HashMap<>();
|
||
|
||
|
||
List<CellDto> cellDtoList = new ArrayList<>();
|
||
int i =1;
|
||
for (MaterialOrderItem item : nowList) {
|
||
MaterialOrderItem oldItem = diffMap.get(item.getInd());
|
||
Map<String, Object> lm = new HashMap<>();
|
||
lm.put("name", item.getName());
|
||
if (oldItem == null || !compareField(oldItem.getName(),(item.getName()))){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(0);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("areaAccount", item.getAreaAccount());
|
||
if (oldItem == null || !compareField(oldItem.getAreaAccount(),item.getAreaAccount())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(1);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("unitAccount", item.getUnitAccount());
|
||
if (oldItem == null || !compareField(oldItem.getUnitAccount(),item.getUnitAccount())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(2);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("siteAccount", item.getSiteAccount());
|
||
if (oldItem == null || !compareField(oldItem.getSiteAccount(),item.getSiteAccount())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(3);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("lineAccount", item.getLineAccount());
|
||
if (oldItem == null || !compareField(oldItem.getLineAccount(),item.getLineAccount())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(4);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
|
||
lm.put("codeType", item.getCodeType());
|
||
if (oldItem == null || !compareField(oldItem.getCodeType(),item.getCodeType())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(5);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
|
||
lm.put("shortDescription", item.getShortDescription());
|
||
if (oldItem == null || !compareField(oldItem.getShortDescription(),item.getShortDescription())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(6);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("longDescription", item.getLongDescription());
|
||
if (oldItem == null || !compareField(oldItem.getLongDescription(),item.getLongDescription())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(7);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("gWeight", item.getgWeight());
|
||
if (oldItem == null || !compareField(oldItem.getgWeight(),item.getgWeight())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(8);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("totalWeight", item.getTotalWeight());
|
||
if (oldItem == null || !compareField(oldItem.getTotalWeight(),item.getTotalWeight())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(9);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("count", item.getCount());
|
||
if (oldItem == null || !compareField(oldItem.getCount(),item.getCount())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(10);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("useStockCount", item.getUseStockCount());
|
||
if (oldItem == null || !compareField(oldItem.getUseStockCount(),item.getUseStockCount())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(11);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("unit", item.getUnit());
|
||
if (oldItem == null || !compareField(oldItem.getUnit(),item.getUnit())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(12);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("versionNum", item.getVersionNum());
|
||
|
||
lm.put("bigType", item.getBigProductType());
|
||
if (oldItem == null || !compareField(oldItem.getBigProductType(),item.getBigProductType())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(14);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("bigDes", item.getBigProductDes());
|
||
if (oldItem == null || !compareField(oldItem.getBigProductDes(),item.getBigProductDes())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(15);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("smallType", item.getSmallProductType());
|
||
if (oldItem == null || !compareField(oldItem.getSmallProductType(),item.getSmallProductType())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(16);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("smallDes", item.getSmallProductDes());
|
||
if (oldItem == null || !compareField(oldItem.getSmallProductDes(),item.getSmallProductDes())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(17);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("makeCode", item.getMakeCode());
|
||
if (oldItem == null || !compareField(oldItem.getMakeCode(),item.getMakeCode())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(18);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("makeName", item.getMakeName());
|
||
if (oldItem == null || !compareField(oldItem.getMakeName(),item.getMakeName())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(19);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("diameterL", item.getDiameterL());
|
||
if (oldItem == null || !compareField(oldItem.getDiameterL(),item.getDiameterL())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(20);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("diameterS", item.getDiameterS());
|
||
if (oldItem == null || !compareField(oldItem.getDiameterS(),item.getDiameterS())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(21);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("wallThicknessL", item.getWallThicknessL());
|
||
if (oldItem == null || !compareField(oldItem.getWallThicknessL(),item.getWallThicknessL())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(22);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("wallThicknessS", item.getWallThicknessS());
|
||
if (oldItem == null || !compareField(oldItem.getWallThicknessS(),item.getWallThicknessS())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(23);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("size", item.getSize());
|
||
if (oldItem == null || !compareField(oldItem.getSize(),item.getSize())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(24);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("pressureLevel", item.getPressureLevel());
|
||
if (oldItem == null || !compareField(oldItem.getPressureLevel(),item.getPressureLevel())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(25);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("endFace", item.getEndFace());
|
||
if (oldItem == null || !compareField(oldItem.getEndFace(),item.getEndFace())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(26);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("material", item.getMaterial());
|
||
if (oldItem == null || !compareField(oldItem.getMaterial(),item.getMaterial())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(27);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("materialType", item.getMaterialType());
|
||
if (oldItem == null || !compareField(oldItem.getMaterialType(),item.getMaterialType())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(28);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
|
||
lm.put("insulationCode", item.getInsulationCode());
|
||
if (oldItem == null || !compareField(oldItem.getInsulationCode(),item.getInsulationCode())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(29);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("specialRequest", item.getSpecialRequest());
|
||
if (oldItem == null || !compareField(oldItem.getSpecialRequest(),item.getSpecialRequest())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(30);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("memo", item.getMemo());
|
||
if (oldItem == null || !compareField(oldItem.getMemo(),item.getMemo())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(31);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("supplierName", item.getSupplierName());
|
||
if (oldItem == null || !compareField(oldItem.getSupplierName(),item.getSupplierName())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(32);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
lm.put("price", item.getPrice());
|
||
if (oldItem == null || !compareField(oldItem.getPrice(),item.getPrice())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(33);
|
||
cellDtoList.add(cellDto);
|
||
}
|
||
listMap.add(lm);
|
||
i++;
|
||
}
|
||
value.put("maplist", listMap);
|
||
value.put("sheetName", "版本"+nowVersion);
|
||
list1.add(value);
|
||
valueList.put(0, list1);
|
||
|
||
ExcelUtils.exportSpecialAll(response, valueList, params, "料单"+materialOrder.getSn()+"版本差异.xlsx",cellDtoList);
|
||
}
|
||
public void exportDiff2(HttpServletResponse response, Long id,Integer nowVersion,Integer oldVersion) {
|
||
MaterialOrder materialOrder = find(id);
|
||
String templateUrl = "excel/template/materialOrderView.xlsx";
|
||
TemplateExportParams params = new TemplateExportParams(templateUrl);
|
||
|
||
Map<Integer, List<Map<String, Object>>> valueList = new HashMap<>();
|
||
|
||
List<Map<String, Object>> list1 = new ArrayList<>();
|
||
Map<String, Object> value = new HashMap<>();
|
||
List<Map<String, Object>> listMap = new ArrayList<>();
|
||
List<MaterialOrderItem> oldList = materialOrderItemService.findByVersionNum(oldVersion, id);
|
||
List<MaterialOrderItem> nowList = materialOrderItemService.findByVersionNum(nowVersion, id);
|
||
|
||
Map<String, MaterialOrderItem> diffMap = new HashMap<>();
|
||
for (MaterialOrderItem item : oldList) {
|
||
String uniKey = String.join("###"
|
||
, Optional.ofNullable(item.getProductCode()).orElse("")
|
||
, Optional.ofNullable(item.getLineAccount()).orElse("")
|
||
, Optional.ofNullable(item.getUnitAccount()).orElse("")
|
||
);
|
||
diffMap.put(uniKey, item);
|
||
}
|
||
// value.put("maplist", listMap);
|
||
// value.put("sheetName", "版本"+oldVersion);
|
||
// list1.add(value);
|
||
// valueList.put(1, list1);
|
||
// list1 = new ArrayList<>();
|
||
// listMap = new ArrayList<>();
|
||
// value = new HashMap<>();
|
||
|
||
List<String> titleList = new ArrayList<>(Arrays.asList(
|
||
"productCode", "name", "areaAccount", "unitAccount", "siteAccount", "lineAccount", "codeType", "shortDescription"
|
||
, "longDescription", "gWeight", "totalWeight", "count", "useStockCount", "unit", "versionNum", "bigType", "bigDes"
|
||
, "smallType", "smallDes", "makeCode", "makeName", "diameterL", "diameterS", "wallThicknessL", "wallThicknessS"
|
||
, "size", "pressureLevel", "endFace", "material", "materialType", "insulationCode", "specialRequest", "memo"
|
||
, "supplierName", "price"
|
||
));
|
||
int titleListSize = titleList.size();
|
||
int titleListEndCol = titleListSize - 1;
|
||
|
||
|
||
List<CellDto> cellDtoList = new ArrayList<>();
|
||
int i = 1;
|
||
for (MaterialOrderItem item : nowList) {
|
||
String uniKey = String.join("###"
|
||
, Optional.ofNullable(item.getProductCode()).orElse("")
|
||
, Optional.ofNullable(item.getLineAccount()).orElse("")
|
||
, Optional.ofNullable(item.getUnitAccount()).orElse("")
|
||
);
|
||
|
||
MaterialOrderItem oldItem = diffMap.get(uniKey);
|
||
diffMap.remove(uniKey);
|
||
if (oldItem == null) {
|
||
// todo 新增处理
|
||
cellDtoList.add(CellDto.add(i++, titleListEndCol));
|
||
|
||
Map<String, Object> lm = new HashMap<>();
|
||
lm.put("productCode", item.getProductCode());
|
||
lm.put("name", item.getName());
|
||
lm.put("areaAccount", item.getAreaAccount());
|
||
lm.put("unitAccount", item.getUnitAccount());
|
||
lm.put("siteAccount", item.getSiteAccount());
|
||
lm.put("lineAccount", item.getLineAccount());
|
||
lm.put("shortDescription", item.getShortDescription());
|
||
lm.put("longDescription", item.getLongDescription());
|
||
lm.put("gWeight", item.getgWeight());
|
||
lm.put("totalWeight", item.getTotalWeight());
|
||
lm.put("count", item.getCount());
|
||
lm.put("useStockCount", item.getUseStockCount());
|
||
lm.put("unit", item.getUnit());
|
||
lm.put("versionNum", item.getVersionNum());
|
||
lm.put("codeType", item.getCodeType());
|
||
lm.put("bigType", item.getBigProductType());
|
||
lm.put("bigDes", item.getBigProductDes());
|
||
lm.put("smallType", item.getSmallProductType());
|
||
lm.put("smallDes", item.getSmallProductDes());
|
||
lm.put("makeCode", item.getMakeCode());
|
||
lm.put("makeName", item.getMakeName());
|
||
lm.put("diameterL", item.getDiameterL());
|
||
lm.put("diameterS", item.getDiameterS());
|
||
lm.put("wallThicknessL", item.getWallThicknessL());
|
||
lm.put("wallThicknessS", item.getWallThicknessS());
|
||
lm.put("size", item.getSize());
|
||
lm.put("pressureLevel", item.getPressureLevel());
|
||
lm.put("material", item.getMaterial());
|
||
lm.put("materialType", item.getMaterialType());
|
||
lm.put("endFace", item.getEndFace());
|
||
lm.put("insulationCode", item.getInsulationCode());
|
||
lm.put("specialRequest", item.getSpecialRequest());
|
||
lm.put("memo", item.getMemo());
|
||
lm.put("supplierName", item.getSupplierName());
|
||
lm.put("price", item.getPrice());
|
||
listMap.add(lm);
|
||
continue;
|
||
}
|
||
|
||
int starCellDtoListSize = cellDtoList.size();
|
||
|
||
Map<String, Object> lm = new HashMap<>();
|
||
lm.put("productCode", item.getProductCode());
|
||
lm.put("lineAccount", item.getLineAccount());
|
||
lm.put("unitAccount", item.getUnitAccount());
|
||
lm.put("versionNum", item.getVersionNum());
|
||
|
||
String tmpName = null;
|
||
tmpName = "name";
|
||
lm.put(tmpName, item.getName());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getName(), item.getName())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getName() + " <- " + oldItem.getName());
|
||
}
|
||
tmpName = "areaAccount";
|
||
lm.put(tmpName, item.getAreaAccount());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getAreaAccount(),item.getAreaAccount())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getAreaAccount() + " <- " + oldItem.getAreaAccount());
|
||
}
|
||
tmpName = "siteAccount";
|
||
lm.put(tmpName, item.getSiteAccount());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getSiteAccount(),item.getSiteAccount())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getSiteAccount() + " <- " + oldItem.getSiteAccount());
|
||
}
|
||
tmpName = "codeType";
|
||
lm.put(tmpName, item.getCodeType());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getCodeType(),item.getCodeType())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getCodeType() + " <- " + oldItem.getCodeType());
|
||
}
|
||
|
||
tmpName = "shortDescription";
|
||
lm.put(tmpName, item.getShortDescription());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getShortDescription(),item.getShortDescription())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getShortDescription() + " <- " + oldItem.getShortDescription());
|
||
}
|
||
tmpName = "longDescription";
|
||
lm.put(tmpName, item.getLongDescription());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getLongDescription(),item.getLongDescription())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getLongDescription() + " <- " + oldItem.getLongDescription());
|
||
}
|
||
tmpName = "gWeight";
|
||
lm.put(tmpName, item.getgWeight());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getgWeight(),item.getgWeight())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getgWeight() + " <- " + oldItem.getgWeight());
|
||
}
|
||
tmpName = "totalWeight";
|
||
lm.put(tmpName, item.getTotalWeight());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getTotalWeight(),item.getTotalWeight())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getTotalWeight() + " <- " + oldItem.getTotalWeight());
|
||
}
|
||
tmpName = "count";
|
||
lm.put(tmpName, item.getCount());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getCount(),item.getCount())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getCount() + " <- " + oldItem.getCount());
|
||
}
|
||
tmpName = "useStockCount";
|
||
lm.put(tmpName, item.getUseStockCount());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getUseStockCount(),item.getUseStockCount())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getUseStockCount() + " <- " + oldItem.getUseStockCount());
|
||
}
|
||
tmpName = "unit";
|
||
lm.put(tmpName, item.getUnit());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getUnit(),item.getUnit())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getUnit() + " <- " + oldItem.getUnit());
|
||
}
|
||
|
||
|
||
tmpName = "bigType";
|
||
lm.put(tmpName, item.getBigProductType());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getBigProductType(),item.getBigProductType())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getBigProductType() + " <- " + oldItem.getBigProductType());
|
||
}
|
||
tmpName = "bigDes";
|
||
lm.put(tmpName, item.getBigProductDes());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getBigProductDes(),item.getBigProductDes())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getBigProductDes() + " <- " + oldItem.getBigProductDes());
|
||
}
|
||
tmpName = "smallType";
|
||
lm.put(tmpName, item.getSmallProductType());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getSmallProductType(),item.getSmallProductType())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getSmallProductType() + " <- " + oldItem.getSmallProductType());
|
||
}
|
||
tmpName = "smallDes";
|
||
lm.put(tmpName, item.getSmallProductDes());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getSmallProductDes(),item.getSmallProductDes())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getSmallProductDes() + " <- " + oldItem.getSmallProductDes());
|
||
}
|
||
tmpName = "makeCode";
|
||
lm.put(tmpName, item.getMakeCode());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getMakeCode(),item.getMakeCode())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getMakeCode() + " <- " + oldItem.getMakeCode());
|
||
}
|
||
tmpName = "makeName";
|
||
lm.put(tmpName, item.getMakeName());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getMakeName(),item.getMakeName())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getMakeName() + " <- " + oldItem.getMakeName());
|
||
}
|
||
tmpName = "diameterL";
|
||
lm.put(tmpName, item.getDiameterL());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getDiameterL(),item.getDiameterL())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getDiameterL() + " <- " + oldItem.getDiameterL());
|
||
}
|
||
tmpName = "diameterS";
|
||
lm.put(tmpName, item.getDiameterS());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getDiameterS(),item.getDiameterS())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getDiameterS() + " <- " + oldItem.getDiameterS());
|
||
}
|
||
tmpName = "wallThicknessL";
|
||
lm.put(tmpName, item.getWallThicknessL());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getWallThicknessL(),item.getWallThicknessL())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getWallThicknessL() + " <- " + oldItem.getWallThicknessL());
|
||
}
|
||
tmpName = "wallThicknessS";
|
||
lm.put(tmpName, item.getWallThicknessS());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getWallThicknessS(),item.getWallThicknessS())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getWallThicknessS() + " <- " + oldItem.getWallThicknessS());
|
||
}
|
||
tmpName = "size";
|
||
lm.put(tmpName, item.getSize());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getSize(),item.getSize())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getSize() + " <- " + oldItem.getSize());
|
||
}
|
||
tmpName = "pressureLevel";
|
||
lm.put(tmpName, item.getPressureLevel());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getPressureLevel(),item.getPressureLevel())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getPressureLevel() + " <- " + oldItem.getPressureLevel());
|
||
}
|
||
tmpName = "endFace";
|
||
lm.put(tmpName, item.getEndFace());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getEndFace(),item.getEndFace())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getEndFace() + " <- " + oldItem.getEndFace());
|
||
}
|
||
tmpName = "material";
|
||
lm.put(tmpName, item.getMaterial());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getMaterial(),item.getMaterial())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getMaterial() + " <- " + oldItem.getMaterial());
|
||
}
|
||
tmpName = "materialType";
|
||
lm.put(tmpName, item.getMaterialType());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getMaterialType(),item.getMaterialType())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getMaterialType() + " <- " + oldItem.getMaterialType());
|
||
}
|
||
|
||
tmpName = "insulationCode";
|
||
lm.put(tmpName, item.getInsulationCode());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getInsulationCode(),item.getInsulationCode())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getInsulationCode() + " <- " + oldItem.getInsulationCode());
|
||
}
|
||
tmpName = "specialRequest";
|
||
lm.put(tmpName, item.getSpecialRequest());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getSpecialRequest(),item.getSpecialRequest())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getSpecialRequest() + " <- " + oldItem.getSpecialRequest());
|
||
}
|
||
tmpName = "memo";
|
||
lm.put(tmpName, item.getMemo());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getMemo(),item.getMemo())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getMemo() + " <- " + oldItem.getMemo());
|
||
}
|
||
tmpName = "supplierName";
|
||
lm.put(tmpName, item.getSupplierName());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getSupplierName(),item.getSupplierName())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getSupplierName() + " <- " + oldItem.getSupplierName());
|
||
}
|
||
tmpName = "price";
|
||
lm.put(tmpName, item.getPrice());
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getPrice(),item.getPrice())){
|
||
CellDto cellDto = new CellDto();
|
||
cellDto.setRowNum(i);
|
||
cellDto.setColNum(titleList.indexOf(tmpName));
|
||
cellDtoList.add(cellDto);
|
||
lm.put(tmpName, item.getPrice() + " <- " + oldItem.getPrice());
|
||
}
|
||
// 只加入有修改的项
|
||
if (starCellDtoListSize != cellDtoList.size()) {
|
||
listMap.add(lm);
|
||
i++;
|
||
}
|
||
}
|
||
// todo 删除处理
|
||
for (MaterialOrderItem item : diffMap.values()) {
|
||
cellDtoList.add(CellDto.delete(i++, titleListEndCol));
|
||
|
||
Map<String, Object> lm = new HashMap<>();
|
||
lm.put("productCode", item.getProductCode());
|
||
lm.put("name", item.getName());
|
||
lm.put("areaAccount", item.getAreaAccount());
|
||
lm.put("unitAccount", item.getUnitAccount());
|
||
lm.put("siteAccount", item.getSiteAccount());
|
||
lm.put("lineAccount", item.getLineAccount());
|
||
lm.put("shortDescription", item.getShortDescription());
|
||
lm.put("longDescription", item.getLongDescription());
|
||
lm.put("gWeight", item.getgWeight());
|
||
lm.put("totalWeight", item.getTotalWeight());
|
||
lm.put("count", item.getCount());
|
||
lm.put("useStockCount", item.getUseStockCount());
|
||
lm.put("unit", item.getUnit());
|
||
lm.put("versionNum", item.getVersionNum());
|
||
lm.put("codeType", item.getCodeType());
|
||
lm.put("bigType", item.getBigProductType());
|
||
lm.put("bigDes", item.getBigProductDes());
|
||
lm.put("smallType", item.getSmallProductType());
|
||
lm.put("smallDes", item.getSmallProductDes());
|
||
lm.put("makeCode", item.getMakeCode());
|
||
lm.put("makeName", item.getMakeName());
|
||
lm.put("diameterL", item.getDiameterL());
|
||
lm.put("diameterS", item.getDiameterS());
|
||
lm.put("wallThicknessL", item.getWallThicknessL());
|
||
lm.put("wallThicknessS", item.getWallThicknessS());
|
||
lm.put("size", item.getSize());
|
||
lm.put("pressureLevel", item.getPressureLevel());
|
||
lm.put("material", item.getMaterial());
|
||
lm.put("materialType", item.getMaterialType());
|
||
lm.put("endFace", item.getEndFace());
|
||
lm.put("insulationCode", item.getInsulationCode());
|
||
lm.put("specialRequest", item.getSpecialRequest());
|
||
lm.put("memo", item.getMemo());
|
||
lm.put("supplierName", item.getSupplierName());
|
||
lm.put("price", item.getPrice());
|
||
listMap.add(lm);
|
||
}
|
||
|
||
value.put("maplist", listMap);
|
||
value.put("sheetName", "版本"+nowVersion + "与" + oldVersion + "的差异");
|
||
list1.add(value);
|
||
valueList.put(0, list1);
|
||
|
||
// ExcelUtils.exportSpecialAll(response, valueList, params, "料单"+materialOrder.getSn()+"版本差异.xlsx",cellDtoList);
|
||
String filename = "料单"+materialOrder.getSn()+"版本差异.xlsx";
|
||
Workbook workbook = ExcelExportUtil.exportExcelClone(valueList, params);
|
||
|
||
CellStyle updateCellStyle = workbook.createCellStyle();
|
||
updateCellStyle.setFillForegroundColor(IndexedColors.BRIGHT_GREEN.getIndex());
|
||
updateCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||
|
||
CellStyle addCellStyle = workbook.createCellStyle();
|
||
addCellStyle.cloneStyleFrom(updateCellStyle);
|
||
addCellStyle.setFillForegroundColor(IndexedColors.SKY_BLUE.getIndex());
|
||
|
||
CellStyle deleteCellStyle = workbook.createCellStyle();
|
||
deleteCellStyle.cloneStyleFrom(updateCellStyle);
|
||
deleteCellStyle.setFillForegroundColor(IndexedColors.RED1.getIndex());
|
||
|
||
Sheet firstSheet = workbook.getSheetAt(0);
|
||
for (CellDto cellDto : cellDtoList) {
|
||
Row row = firstSheet.getRow(cellDto.getRowNum());
|
||
if (CellDto.Status.Update.equals(cellDto.getStatus())) {
|
||
Cell cell = row.getCell(cellDto.getColNum());
|
||
cell.setCellStyle(updateCellStyle);
|
||
} else {
|
||
CellStyle tmpCellStyle = CellDto.Status.Add.equals(cellDto.getStatus()) ? addCellStyle : deleteCellStyle ;
|
||
for (int j = 0; j <= cellDto.getColNum(); j++) {
|
||
Cell cell = row.getCell(j);
|
||
cell.setCellStyle(tmpCellStyle);
|
||
}
|
||
}
|
||
}
|
||
|
||
try (ServletOutputStream outputStream = response.getOutputStream()) {
|
||
filename = URLEncoder.encode(filename,"UTF8");
|
||
response.setHeader("Content-Disposition", "attachment;filename=" + filename);
|
||
workbook.write(outputStream);
|
||
} catch (IOException e) {
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
public void loadDiffItemUpdate(Map<Long, Object> diffMap, MaterialOrderItem item, MaterialOrderItem oldItem) {
|
||
Map<String, Object> lm = CellDto.generateUpdateMap();
|
||
String tmpName = null;
|
||
tmpName = "name";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getName(), item.getName())){
|
||
lm.put(tmpName, " <- " + oldItem.getName());
|
||
}
|
||
tmpName = "areaAccount";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getAreaAccount(),item.getAreaAccount())){
|
||
lm.put(tmpName, " <- " + oldItem.getAreaAccount());
|
||
}
|
||
tmpName = "siteAccount";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getSiteAccount(),item.getSiteAccount())){
|
||
lm.put(tmpName, " <- " + oldItem.getSiteAccount());
|
||
}
|
||
tmpName = "codeType";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getCodeType(),item.getCodeType())){
|
||
lm.put(tmpName, " <- " + oldItem.getCodeType());
|
||
}
|
||
|
||
tmpName = "shortDescription";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getShortDescription(),item.getShortDescription())){
|
||
lm.put(tmpName, " <- " + oldItem.getShortDescription());
|
||
}
|
||
tmpName = "longDescription";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getLongDescription(),item.getLongDescription())){
|
||
lm.put(tmpName, " <- " + oldItem.getLongDescription());
|
||
}
|
||
tmpName = "gWeight";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getgWeight(),item.getgWeight())){
|
||
lm.put(tmpName, " <- " + Optional.ofNullable(oldItem.getgWeight()).map(BigDecimal::stripTrailingZeros).map(BigDecimal::toPlainString).orElse(""));
|
||
}
|
||
tmpName = "totalWeight";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getTotalWeight(),item.getTotalWeight())){
|
||
lm.put(tmpName, " <- " + Optional.ofNullable(oldItem.getTotalWeight()).map(BigDecimal::stripTrailingZeros).map(BigDecimal::toPlainString).orElse(""));
|
||
}
|
||
tmpName = "count";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getCount(),item.getCount())){
|
||
lm.put(tmpName, " <- " + Optional.ofNullable(oldItem.getCount()).map(BigDecimal::stripTrailingZeros).map(BigDecimal::toPlainString).orElse(""));
|
||
}
|
||
tmpName = "useStockCount";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getUseStockCount(),item.getUseStockCount())){
|
||
lm.put(tmpName, " <- " + Optional.ofNullable(oldItem.getUseStockCount()).map(BigDecimal::stripTrailingZeros).map(BigDecimal::toPlainString).orElse(""));
|
||
}
|
||
tmpName = "unit";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getUnit(),item.getUnit())){
|
||
lm.put(tmpName, " <- " + oldItem.getUnit());
|
||
}
|
||
|
||
|
||
tmpName = "bigType";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getBigProductType(),item.getBigProductType())){
|
||
lm.put(tmpName, " <- " + oldItem.getBigProductType());
|
||
}
|
||
tmpName = "bigDes";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getBigProductDes(),item.getBigProductDes())){
|
||
lm.put(tmpName, " <- " + oldItem.getBigProductDes());
|
||
}
|
||
tmpName = "smallType";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getSmallProductType(),item.getSmallProductType())){
|
||
lm.put(tmpName, " <- " + oldItem.getSmallProductType());
|
||
}
|
||
tmpName = "smallDes";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getSmallProductDes(),item.getSmallProductDes())){
|
||
lm.put(tmpName, " <- " + oldItem.getSmallProductDes());
|
||
}
|
||
tmpName = "makeCode";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getMakeCode(),item.getMakeCode())){
|
||
lm.put(tmpName, " <- " + oldItem.getMakeCode());
|
||
}
|
||
tmpName = "makeName";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getMakeName(),item.getMakeName())){
|
||
lm.put(tmpName, " <- " + oldItem.getMakeName());
|
||
}
|
||
tmpName = "diameterL";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getDiameterL(),item.getDiameterL())){
|
||
lm.put(tmpName, " <- " + Optional.ofNullable(oldItem.getDiameterL()).map(BigDecimal::stripTrailingZeros).map(BigDecimal::toPlainString).orElse(""));
|
||
}
|
||
tmpName = "diameterS";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getDiameterS(),item.getDiameterS())){
|
||
lm.put(tmpName, " <- " + Optional.ofNullable(oldItem.getDiameterS()).map(BigDecimal::stripTrailingZeros).map(BigDecimal::toPlainString).orElse(""));
|
||
}
|
||
tmpName = "wallThicknessL";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getWallThicknessL(),item.getWallThicknessL())){
|
||
lm.put(tmpName, " <- " + oldItem.getWallThicknessL());
|
||
}
|
||
tmpName = "wallThicknessS";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getWallThicknessS(),item.getWallThicknessS())){
|
||
lm.put(tmpName, " <- " + oldItem.getWallThicknessS());
|
||
}
|
||
tmpName = "size";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getSize(),item.getSize())){
|
||
lm.put(tmpName, " <- " + oldItem.getSize());
|
||
}
|
||
tmpName = "pressureLevel";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getPressureLevel(),item.getPressureLevel())){
|
||
lm.put(tmpName, " <- " + oldItem.getPressureLevel());
|
||
}
|
||
tmpName = "endFace";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getEndFace(),item.getEndFace())){
|
||
lm.put(tmpName, " <- " + oldItem.getEndFace());
|
||
}
|
||
tmpName = "material";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getMaterial(),item.getMaterial())){
|
||
lm.put(tmpName, " <- " + oldItem.getMaterial());
|
||
}
|
||
tmpName = "materialType";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getMaterialType(),item.getMaterialType())){
|
||
lm.put(tmpName, " <- " + oldItem.getMaterialType());
|
||
}
|
||
|
||
tmpName = "insulationCode";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getInsulationCode(),item.getInsulationCode())){
|
||
lm.put(tmpName, " <- " + oldItem.getInsulationCode());
|
||
}
|
||
tmpName = "specialRequest";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getSpecialRequest(),item.getSpecialRequest())){
|
||
lm.put(tmpName, " <- " + oldItem.getSpecialRequest());
|
||
}
|
||
tmpName = "memo";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getMemo(),item.getMemo())){
|
||
lm.put(tmpName, " <- " + oldItem.getMemo());
|
||
}
|
||
tmpName = "supplierName";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getSupplierName(),item.getSupplierName())){
|
||
lm.put(tmpName, " <- " + oldItem.getSupplierName());
|
||
}
|
||
tmpName = "price";
|
||
if (ObjectCompareUtil.diffFrom(oldItem.getPrice(),item.getPrice())){
|
||
lm.put(tmpName, " <- " + Optional.ofNullable(oldItem.getPrice()).map(BigDecimal::stripTrailingZeros).map(BigDecimal::toPlainString).orElse(""));
|
||
}
|
||
if (lm.keySet().size() > 1) {
|
||
diffMap.put(item.getId(), lm);
|
||
}
|
||
}
|
||
public void loadDiffItemAdd(Map<Long, Object> diffMap, MaterialOrderItem orderItem) {
|
||
diffMap.put(orderItem.getId(), CellDto.generateAddMap());
|
||
}
|
||
public void loadDiffItemDelete(Map<Long, Object> diffMap, Long materialOrderId, Integer nowVersion, Integer oldVersion, List<MaterialOrderItem> list) {
|
||
List<MaterialOrderItem> oldList = materialOrderItemService.findByVersionNum(oldVersion, materialOrderId);
|
||
List<MaterialOrderItem> nowList = materialOrderItemService.findByVersionNum(nowVersion, materialOrderId);
|
||
List<String> uniKeyList = new ArrayList<>();
|
||
for (MaterialOrderItem orderItem : nowList) {
|
||
String uniKey = String.join("###"
|
||
, Optional.ofNullable(orderItem.getProductCode()).orElse("")
|
||
, Optional.ofNullable(orderItem.getLineAccount()).orElse("")
|
||
, Optional.ofNullable(orderItem.getUnitAccount()).orElse("")
|
||
);
|
||
uniKeyList.add(uniKey);
|
||
}
|
||
for (MaterialOrderItem orderItem : oldList) {
|
||
String uniKey = String.join("###"
|
||
, Optional.ofNullable(orderItem.getProductCode()).orElse("")
|
||
, Optional.ofNullable(orderItem.getLineAccount()).orElse("")
|
||
, Optional.ofNullable(orderItem.getUnitAccount()).orElse("")
|
||
);
|
||
if (!uniKeyList.contains(uniKey)) {
|
||
diffMap.put(orderItem.getId(), CellDto.generateDeleteMap());
|
||
list.add(orderItem);
|
||
}
|
||
}
|
||
}
|
||
|
||
public boolean compareField(Object value1,Object value2){
|
||
if (value1 == null && value2 == null){
|
||
return true;
|
||
}else if (value1 != null && value2 != null){
|
||
if (value1.equals(value2)){
|
||
return true;
|
||
}else {
|
||
return false;
|
||
}
|
||
}else {
|
||
return false;
|
||
}
|
||
}
|
||
|
||
public void export(HttpServletResponse response, OrderQuery orderQuery) {
|
||
|
||
String templateUrl = "excel/template/materialOrder.xlsx";
|
||
TemplateExportParams params = new TemplateExportParams(templateUrl);
|
||
List<Map<String, Object>> list1 = new ArrayList<>();
|
||
Map<String, Object> value = new HashMap<>();
|
||
List<Map<String, Object>> listMap = new ArrayList<>();
|
||
List<MaterialOrder> materialOrderList = findList(orderQuery);
|
||
for (MaterialOrder item : materialOrderList) {
|
||
Map<String, Object> lm = new HashMap<>();
|
||
lm.put("sn", item.getSn());
|
||
lm.put("totalCount", item.getTotalCount());
|
||
lm.put("totalWeight", item.getTotalWeight());
|
||
lm.put("adminName", item.getAdminName());
|
||
lm.put("createDate", DateUtil.dateToStr(item.getCreateDate(),"yyyy-MM-dd"));
|
||
listMap.add(lm);
|
||
}
|
||
value.put("maplist", listMap);
|
||
list1.add(value);
|
||
String fileName = "综合材料明细表"+DateUtil.dateToStr(new Date(),"yyyy-MM-dd")+".xlsx";
|
||
ExcelUtils.export(response, value, params, fileName);
|
||
}
|
||
|
||
@Transactional
|
||
public void saveDeviceFile(MultipartFile file, Long adminId, String preTitle, Integer flowNum, String code, Long stageId,String orderName) {
|
||
Admin admin = adminService.find(adminId);
|
||
//获得Workbook工作薄对象
|
||
Workbook workbook = ExcelUtil2.getWorkBook(file);
|
||
//创建返回对象,把每行中的值作为一个数组,所有行作为一个集合返回
|
||
Map<Integer, PurchaseOrderItem> itemMap = new HashMap<>();
|
||
MaterialOrder materialOrder = new MaterialOrder();
|
||
materialOrder.setAdminId(adminId);
|
||
materialOrder.setAdminName(admin.getName());
|
||
materialOrder.setStatus(OrderStatus.create);
|
||
materialOrder.setType(MaterialOrder.Type.device);
|
||
materialOrder.setVersionNum(0);
|
||
materialOrder.setProgressId(admin.getNowProgress());
|
||
materialOrder.setName(orderName);
|
||
if (admin.getNowProgress() != null) {
|
||
Progress progress = progressService.find(admin.getNowProgress());
|
||
materialOrder.setProgressName(progress.getName());
|
||
materialOrder.setProgressCode(progress.getCode());
|
||
}else {
|
||
materialOrder.setProgressName("公司");
|
||
}
|
||
MaterialOrderStage stage = materialOrderStageService.find(stageId);
|
||
materialOrder.setStageCode(stage.getCode());
|
||
materialOrder.setStageName(stage.getName());
|
||
// materialOrder.setSn(orderTool.generateSn(materialOrder.getSn(), MaterialOrder.class));
|
||
FlowSn flowSn = flowSnService.findByType(FlowSn.Type.material,admin.getNowProgress());
|
||
flowSn.setLastValue(flowSn.getLastValue() + 1);
|
||
flowSnService.update(flowSn);
|
||
materialOrder.setFlowNum(flowSn.getLastValue());
|
||
String flowCode = "" + flowSn.getLastValue();
|
||
while (flowNum > flowCode.length()) {
|
||
flowCode = "0" + flowCode;
|
||
}
|
||
String sn = preTitle + "-" + flowCode + "-"+stage.getCode() + "-V0";
|
||
String preSn = preTitle+"-"+flowCode + "-"+stage.getCode();
|
||
materialOrder.setPreSn(preSn);
|
||
materialOrder.setSn(sn);
|
||
save(materialOrder);
|
||
Map<String, Product> productMap = new HashMap<>();
|
||
for (Product product : productService.findByType(Product.Type.device)) {
|
||
productMap.put(product.getCode(), product);
|
||
}
|
||
File path = new File("tempImage");
|
||
if (!path.exists()) {
|
||
path.mkdirs();
|
||
}
|
||
if (workbook != null) {
|
||
for (int sheetNum = 0; sheetNum < workbook.getNumberOfSheets(); sheetNum++) {
|
||
//获得当前sheet工作表
|
||
Sheet sheet = workbook.getSheetAt(sheetNum);
|
||
if (sheet == null || sheetNum != 0) {
|
||
continue;
|
||
}
|
||
//获得当前sheet的开始行
|
||
int firstRowNum = sheet.getFirstRowNum();
|
||
//获得当前sheet的结束行
|
||
int lastRowNum = sheet.getLastRowNum();
|
||
|
||
Map<String, PictureData> mapList = null;
|
||
// 判断用07还是03的方法获取图片
|
||
String filePath = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
|
||
if (filePath.endsWith(".xls")) {
|
||
try {
|
||
mapList = ExcelUtil2.getPictures1((HSSFSheet) sheet);
|
||
} catch (Exception e) {
|
||
|
||
}
|
||
} else if (filePath.endsWith(".xlsx")) {
|
||
try {
|
||
mapList = ExcelUtil2.getPictures2((XSSFSheet) sheet);
|
||
} catch (Exception e) {
|
||
}
|
||
}
|
||
|
||
Map<Integer, String> valueMap = new HashMap<>();
|
||
BigDecimal orderWeight = BigDecimal.ZERO;
|
||
BigDecimal orderCount = BigDecimal.ZERO;
|
||
//循环除了所有行,如果要循环除第一行以外的就firstRowNum+1
|
||
for (int rowNum = firstRowNum + 0; rowNum <= lastRowNum; rowNum++) {
|
||
//获得当前行
|
||
Row row = sheet.getRow(rowNum);
|
||
if (row == null) {
|
||
continue;
|
||
}
|
||
//获得当前行的列数
|
||
int lastCellNum = row.getLastCellNum();
|
||
if (lastCellNum > 0) {
|
||
if (rowNum >= 1) {
|
||
if (ExcelUtil2.getCellValue(row.getCell(0)).equals("")) {
|
||
continue;
|
||
}
|
||
Integer ind = Integer.valueOf(ExcelUtil2.getCellValue(row.getCell(0)));
|
||
String deviceCode = ExcelUtil2.getCellValue(row.getCell(1));
|
||
String name = ExcelUtil2.getCellValue(row.getCell(2));
|
||
String picNo = ExcelUtil2.getCellValue(row.getCell(3));
|
||
String siteAccount = ExcelUtil2.getCellValue(row.getCell(4));
|
||
String purchaseType = ExcelUtil2.getCellValue(row.getCell(5));
|
||
String itemCode = ExcelUtil2.getCellValue(row.getCell(6));
|
||
String memo = ExcelUtil2.getCellValue(row.getCell(7));
|
||
|
||
List<Long> ids = new ArrayList<>();
|
||
if (mapList.containsKey(String.valueOf(rowNum))) {
|
||
try {
|
||
File file1 = new File(path, "test.jpg");
|
||
FileOutputStream fin = new FileOutputStream(file1);
|
||
//可能溢出,简单起见就不考虑太多,如果太大就要另外想办法,比如一次传入固定长度byte[]
|
||
byte[] bytes = mapList.get(String.valueOf(rowNum)).getData();
|
||
//将文件内容写入字节数组,提供测试的case
|
||
fin.write(bytes);
|
||
fin.close();
|
||
FileInputStream input = new FileInputStream(file1);
|
||
MultipartFile multipartFile = new MockMultipartFile("file", file1.getName(), "text/plain", IOUtils.toByteArray(input));
|
||
String url = uploadFileService.ossUpload(multipartFile);
|
||
AttachFile attachFile = new AttachFile(file.getOriginalFilename(), file.getSize(), new Date(), url);
|
||
attachFileService.save(attachFile);
|
||
ids.add(attachFile.getId());
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
File file1 = new File(path, "test.jpg");
|
||
ExcelUtil2.recurDelete(file1);
|
||
}
|
||
|
||
if (productMap.getOrDefault(deviceCode, null) == null) {
|
||
Product product = new Product();
|
||
product.setCode(deviceCode);
|
||
product.setName(name);
|
||
product.setPicNo(picNo);
|
||
product.setType(Product.Type.device);
|
||
product = productService.save(product);
|
||
productMap.put(deviceCode,product);
|
||
}
|
||
MaterialOrderItem item = new MaterialOrderItem();
|
||
Product product = productMap.get(deviceCode);
|
||
product.setAttachFileIds(ids);
|
||
product = productService.update(product);
|
||
item.setInd(ind);
|
||
item.setProductId(product.getId());
|
||
item.setName(product.getName());
|
||
item.setProductCode(deviceCode);
|
||
item.setPicNo(product.getPicNo());
|
||
item.setPurchaseType(purchaseType);
|
||
item.setItemCode(itemCode);
|
||
item.setMemo(memo);
|
||
item.setCount(BigDecimal.ONE);
|
||
item.setVersionNum(0);
|
||
item.setSupplierIds(new ArrayList<>());
|
||
item.setMaterialOrder(materialOrder);
|
||
materialOrderItemService.save(item);
|
||
orderCount = orderCount.add(BigDecimal.ONE);
|
||
}
|
||
}
|
||
}
|
||
materialOrder.setTotalCount(orderCount);
|
||
// materialOrder.setTotalWeight(orderWeight);
|
||
update(materialOrder);
|
||
}
|
||
}
|
||
}
|
||
|
||
@Transactional
|
||
public void sendMessage(List<ProductType> productTypeList,Long adminId,MaterialOrder materialOrder,String contentStr){
|
||
try {
|
||
Admin sendAdmin = adminService.find(adminId);
|
||
List<Admin> adminList = new ArrayList<>();
|
||
for (Admin admin : adminService.findAll()){
|
||
if (admin.getEmail() != null && admin.getAdminPurchaseList().size()>0) {
|
||
List<AdminPurchase> adminPurchaseList = admin.getAdminPurchaseList();
|
||
List<Long> ids = new ArrayList<>();
|
||
for (AdminPurchase adminPurchase : adminPurchaseList){
|
||
for (AdminPurchaseProductType adminPurchaseProductType : adminPurchase.getAdminPurchaseProductTypeList()) {
|
||
ids.add(adminPurchaseProductType.getProductType().getId());
|
||
}
|
||
// ids.add(adminPurchase.getProductType().getId());
|
||
}
|
||
for (ProductType productType : productTypeList) {
|
||
if (ids.contains(productType.getId())||ids.contains(productType.getParentId())) {
|
||
adminList.add(admin);
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
List<String> fileUrls = new ArrayList<>();
|
||
for (Admin admin : adminList) {
|
||
NoticeEntity noticeEntity = new NoticeEntity();
|
||
noticeEntity.setAdmin(admin);
|
||
noticeEntity.setRead(false);
|
||
noticeEntity.setTitle("请购通知");
|
||
if (contentStr != null && !contentStr.equals("")){
|
||
noticeEntity.setContent(contentStr);
|
||
noticeEntityService.save(noticeEntity);
|
||
MailUtil.sendAttachmentMail(admin.getEmail(), "请购通知", contentStr, fileUrls,null);
|
||
}else {
|
||
String content = DateUtil.dateToStr(new Date(),"yyyy-MM-dd HH:mm")+":";
|
||
content =content + (sendAdmin.getDepartment() == null?sendAdmin.getName():sendAdmin.getDepartment().getName()+":"+sendAdmin.getName());
|
||
content = content +"导入了请购单:"+materialOrder.getSn();
|
||
noticeEntity.setContent(content);
|
||
noticeEntityService.save(noticeEntity);
|
||
MailUtil.sendAttachmentMail(admin.getEmail(), "请购通知", content, fileUrls,null);
|
||
}
|
||
|
||
}
|
||
}catch (Exception e){
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
|
||
/** 导出请购单生成(materialOrder)评标不合理价格:中标但价格最高 */
|
||
public void exportUnreasonableBidPrice(HttpServletResponse response, Long[] ids) {
|
||
try {
|
||
List<Map<String, Object>> mapList = new ArrayList<>();
|
||
for (Long id : ids) {
|
||
if (id == null){
|
||
continue;
|
||
}
|
||
MaterialOrder materialOrder = find(id);
|
||
String sn = materialOrder.getSn();
|
||
|
||
List<MaterialOrderItem> orderItemList = materialOrderItemService.findTopByVersionNum(materialOrder.getVersionNum(), id);
|
||
for (MaterialOrderItem item : orderItemList) {
|
||
Map<String, Object> lm = new HashMap<>();
|
||
List<String> othPriceList = new ArrayList<>();
|
||
|
||
int index = 0;
|
||
boolean unreasonable = false;
|
||
List<MaterialOrderItemPrice> materialOrderItemPriceList = materialOrderItemPriceService.findByOrderByPrice(item.getId());
|
||
if (materialOrderItemPriceList.size() <= 1) {
|
||
continue;
|
||
}
|
||
for (MaterialOrderItemPrice mop : materialOrderItemPriceList) {
|
||
if (index == 0) {
|
||
unreasonable = mop.getHaveUse();
|
||
if (!unreasonable) {
|
||
break;
|
||
}
|
||
// else {
|
||
// MaterialOrderItemPrice materialOrderItemPrice = materialOrderItemPriceList.get(1);
|
||
// if (materialOrderItemPrice.getPrice().compareTo(mop.getPrice()) == 0) {
|
||
// unreasonable = false;
|
||
// break;
|
||
// }
|
||
// }
|
||
lm.put("urbPrice", mop.getSupplierName()+"-报价:"+Optional.ofNullable(mop.getPrice()).map(BigDecimal::stripTrailingZeros).map(BigDecimal::toPlainString).orElse(""));
|
||
} else {
|
||
othPriceList.add(mop.getSupplierName()+"-报价:"+Optional.ofNullable(mop.getPrice()).map(BigDecimal::stripTrailingZeros).map(BigDecimal::toPlainString).orElse(""));
|
||
}
|
||
index++;
|
||
}
|
||
if (!unreasonable) {
|
||
continue;
|
||
}
|
||
lm.put("othPriceList", othPriceList);
|
||
|
||
lm.put("sn", sn);
|
||
lm.put("productCode", item.getProductCode());
|
||
lm.put("shortDescription", item.getShortDescription());
|
||
lm.put("longDescription", item.getLongDescription());
|
||
lm.put("diameterL", item.getDiameterL());
|
||
lm.put("diameterS", item.getDiameterS());
|
||
lm.put("gWeight", item.getgWeight());
|
||
lm.put("totalWeight", item.getTotalWeight());
|
||
lm.put("count", item.getCount());
|
||
lm.put("unit", item.getUnit());
|
||
|
||
lm.put("memo", item.getMemo());
|
||
mapList.add(lm);
|
||
}
|
||
}
|
||
|
||
Map<String, Object> value = new HashMap<>();
|
||
value.put("maplist", mapList);
|
||
|
||
String fileName = "评标不合理价格"+DateUtil.dateToStr(new Date(),"yyyy-MM-dd")+".xlsx";
|
||
TemplateExportParams params = new TemplateExportParams("excel/template/unreasonableBidPrice.xlsx");
|
||
ExcelUtils.export(response, value, params, fileName);
|
||
} catch (Exception e) {
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
|
||
//导出不合理的中标报价
|
||
public void exportUnreasonableBidPrice2(HttpServletResponse response, Long[] ids)throws Exception {
|
||
|
||
Map<String,MaterialOrderItem> map = new HashMap<>();
|
||
|
||
//更高的报价
|
||
boolean moreFlag = false;
|
||
//更低的报价
|
||
boolean lessFlag = false;
|
||
Integer maxSupplierSize = 0;
|
||
for (Long id : ids){
|
||
MaterialOrder materialOrder = find(id);
|
||
for (MaterialOrderItem materialOrderItem : materialOrder.getMaterialOrderItemList()){
|
||
moreFlag = false;
|
||
lessFlag = false;
|
||
if (maxSupplierSize<materialOrderItem.getSupplierIds().size()){
|
||
maxSupplierSize = materialOrderItem.getSupplierIds().size();
|
||
}
|
||
for (MaterialOrderItemPrice materialOrderItemPrice : materialOrderItem.getMaterialOrderItemPriceList()){
|
||
if (!materialOrderItemPrice.getHaveUse() && materialOrderItemPrice.getPrice().compareTo(materialOrderItem.getPrice())>0) {
|
||
moreFlag= true;
|
||
break;
|
||
}
|
||
if (!materialOrderItemPrice.getHaveUse() && materialOrderItemPrice.getPrice().compareTo(materialOrderItem.getPrice())<0) {
|
||
lessFlag= true;
|
||
}
|
||
}
|
||
if (!moreFlag && lessFlag){
|
||
String str = materialOrder.getSn()+"_"+materialOrderItem.getProductCode();
|
||
map.put(str,materialOrderItem);
|
||
}
|
||
}
|
||
}
|
||
|
||
ByteArrayOutputStream aos = new ByteArrayOutputStream();
|
||
HSSFWorkbook workbook = new HSSFWorkbook();
|
||
HSSFSheet sheet = workbook.createSheet("sheet1");
|
||
HSSFRow row = sheet.createRow(0);
|
||
HSSFCellStyle style = workbook.createCellStyle();
|
||
style.setAlignment(HorizontalAlignment.CENTER);
|
||
|
||
sheet.setColumnWidth(0,20*256);
|
||
sheet.setColumnWidth(1,20*256);
|
||
sheet.setColumnWidth(2,20*256);
|
||
sheet.setColumnWidth(3,20*256);
|
||
sheet.setColumnWidth(4,20*256);
|
||
sheet.setColumnWidth(5,20*256);
|
||
sheet.setColumnWidth(6,20*256);
|
||
sheet.setColumnWidth(7,20*256);
|
||
sheet.setColumnWidth(8,20*256);
|
||
sheet.setColumnWidth(9,20*256);
|
||
sheet.setColumnWidth(10,20*256);
|
||
sheet.setColumnWidth(11,20*256);
|
||
sheet.setColumnWidth(12,20*256);
|
||
sheet.setColumnWidth(13,20*256);
|
||
sheet.setColumnWidth(14,20*256);
|
||
sheet.setColumnWidth(15,20*256);
|
||
|
||
HSSFCell cell = row.createCell(0);
|
||
|
||
cell.setCellValue("综合材料表单号");
|
||
cell.setCellStyle(style);
|
||
|
||
cell = row.createCell(1);
|
||
cell.setCellValue("采购码");
|
||
cell.setCellStyle(style);
|
||
|
||
cell = row.createCell(2);
|
||
cell.setCellValue("短描述");
|
||
cell.setCellStyle(style);
|
||
|
||
cell = row.createCell(3);
|
||
cell.setCellValue("长描述");
|
||
cell.setCellStyle(style);
|
||
|
||
cell = row.createCell(4);
|
||
cell.setCellValue("公称直径(L)");
|
||
cell.setCellStyle(style);
|
||
|
||
cell = row.createCell(5);
|
||
cell.setCellValue("公称直径(S)");
|
||
cell.setCellStyle(style);
|
||
|
||
cell = row.createCell(6);
|
||
cell.setCellValue("单重");
|
||
cell.setCellStyle(style);
|
||
|
||
cell = row.createCell(7);
|
||
cell.setCellValue("总重");
|
||
cell.setCellStyle(style);
|
||
|
||
cell = row.createCell(8);
|
||
cell.setCellValue("数量");
|
||
cell.setCellStyle(style);
|
||
|
||
cell = row.createCell(9);
|
||
cell.setCellValue("单位");
|
||
cell.setCellStyle(style);
|
||
|
||
cell = row.createCell(10);
|
||
cell.setCellValue("备注");
|
||
cell.setCellStyle(style);
|
||
|
||
for (Integer size = 0;size<maxSupplierSize;size++){
|
||
cell = row.createCell(11+size*2);
|
||
cell.setCellValue("供应商"+(1+size));
|
||
cell.setCellStyle(style);
|
||
|
||
cell = row.createCell(12+size*2);
|
||
cell.setCellValue("报价"+(1+size));
|
||
cell.setCellStyle(style);
|
||
}
|
||
|
||
|
||
HSSFCellStyle style_2 = workbook.createCellStyle();
|
||
style_2.setWrapText(true);
|
||
style_2.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||
style_2.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
|
||
style_2.setAlignment(HorizontalAlignment.CENTER);
|
||
|
||
|
||
int i = 1;
|
||
for (String key : map.keySet()) {
|
||
MaterialOrderItem item = map.get(key);
|
||
row = sheet.createRow(i);
|
||
row.createCell(0).setCellValue(item.getMaterialOrder().getSn());
|
||
row.createCell(1).setCellValue(item.getProductCode());
|
||
row.createCell(2).setCellValue(item.getShortDescription());
|
||
row.createCell(3).setCellValue(item.getLongDescription());
|
||
row.createCell(4).setCellValue(item.getDiameterL()==null?"":item.getDiameterL().stripTrailingZeros().toPlainString());
|
||
row.createCell(5).setCellValue(item.getDiameterS()==null?"":item.getDiameterS().stripTrailingZeros().toPlainString());
|
||
row.createCell(6).setCellValue(item.getgWeight().stripTrailingZeros().toPlainString());
|
||
row.createCell(7).setCellValue(item.getTotalWeight().stripTrailingZeros().toPlainString());
|
||
row.createCell(8).setCellValue(item.getCount().stripTrailingZeros().toPlainString());
|
||
row.createCell(9).setCellValue(item.getUnit());
|
||
row.createCell(10).setCellValue(item.getMemo());
|
||
int j = 11;
|
||
for (MaterialOrderItemPrice itemPrice : item.getMaterialOrderItemPriceList()){
|
||
if (item.getSupplierIds().contains(itemPrice.getSupplierId())){
|
||
if (itemPrice.getSupplierId().equals(item.getSupplierId())) {
|
||
cell = row.createCell(j);
|
||
cell.setCellValue(itemPrice.getSupplierName());
|
||
cell.setCellStyle(style_2);
|
||
j++;
|
||
|
||
cell = row.createCell(j);
|
||
cell.setCellValue(itemPrice.getPrice().stripTrailingZeros().toPlainString());
|
||
cell.setCellStyle(style_2);
|
||
j++;
|
||
}else {
|
||
cell = row.createCell(j);
|
||
cell.setCellValue(itemPrice.getSupplierName());
|
||
cell.setCellStyle(style);
|
||
j++;
|
||
|
||
cell = row.createCell(j);
|
||
cell.setCellValue(itemPrice.getPrice().stripTrailingZeros().toPlainString());
|
||
cell.setCellStyle(style);
|
||
j++;
|
||
}
|
||
}
|
||
}
|
||
i++;
|
||
}
|
||
workbook.write(aos);
|
||
response.setContentType("application/x-msdownload");
|
||
response.setCharacterEncoding("utf-8");
|
||
// 对文件名进行处理。防止文件名乱码
|
||
String fileName = "不合理报价单.xls";
|
||
fileName = URLEncoder.encode(fileName,"UTF8");
|
||
// Content-disposition属性设置成以附件方式进行下载
|
||
response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
|
||
// FileOutputStream fis = new FileOutputStream("/home/zhs/Downloads/logs1.xls");
|
||
// workbook.write(fis);9
|
||
response.setContentLength(aos.toByteArray().length);
|
||
response.getOutputStream().write(aos.toByteArray());
|
||
response.getOutputStream().flush();
|
||
response.getOutputStream().close();
|
||
}
|
||
|
||
@Transactional
|
||
public void deleteEntity(Long[] ids){
|
||
Map<String,ProgressStock> productMap = new HashMap<>();
|
||
for(ProgressStock product : progressStockService.findAll()){
|
||
productMap.put(product.getProgressId()+"_"+product.getProduct().getCode(),product);
|
||
}
|
||
delete(ids);
|
||
//后续添加虚拟仓库时使用下列代码,目前绑定在库存管理错误
|
||
// for(Long id : ids){
|
||
// MaterialOrder materialOrder = find(id);
|
||
// List<MaterialOrderItem> materialOrderItemList = materialOrderItemService.findByVersionNum(materialOrder.getVersionNum(),materialOrder.getId());
|
||
// for (MaterialOrderItem item : materialOrderItemList){
|
||
// if (item.getUseStockCount() != null && item.getUseStockCount().compareTo(BigDecimal.ZERO)>0){
|
||
// ProgressStock product = productMap.getOrDefault(item.getMaterialOrder().getProgressId()+"_"+item.getProductCode(),null);
|
||
// if (product != null){
|
||
// product.setStockCount(product.getStockCount().add(item.getUseStockCount()));
|
||
// productMap.put(item.getMaterialOrder().getProgressId()+"_"+item.getProductCode(),product);
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
// for (String key : productMap.keySet()){
|
||
// progressStockService.update(productMap.get(key));
|
||
// }
|
||
}
|
||
}
|