|
@@ -1,9 +1,11 @@
|
|
|
package com.management.platform.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+
|
|
|
import com.management.platform.entity.*;
|
|
|
import com.management.platform.mapper.*;
|
|
|
import com.management.platform.service.ProdMaterialService;
|
|
@@ -13,12 +15,15 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.management.platform.util.HttpRespMsg;
|
|
|
import com.management.platform.util.MessageUtils;
|
|
|
import org.apache.poi.EncryptedDocumentException;
|
|
|
+import org.apache.poi.hssf.usermodel.*;
|
|
|
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
-import org.apache.poi.ss.usermodel.CellType;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFCell;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFRow;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
@@ -27,10 +32,8 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.*;
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -43,6 +46,8 @@ import java.util.Map;
|
|
|
@Service
|
|
|
@Transactional
|
|
|
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {
|
|
|
+ /*@Value(value = "${upload.path}")
|
|
|
+ private String path;*/
|
|
|
@Resource
|
|
|
ProductMapper productMapper;
|
|
|
@Resource
|
|
@@ -93,17 +98,41 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
|
|
|
@Override
|
|
|
public HttpRespMsg saveProductInfo(Product product, HttpServletRequest request) {
|
|
|
+ HttpRespMsg msg = new HttpRespMsg();
|
|
|
+
|
|
|
String token = request.getHeader("Token");
|
|
|
User user = userMapper.selectById(token);
|
|
|
+
|
|
|
product.setCompanyId(user.getCompanyId());
|
|
|
if (product.getId() == null) {
|
|
|
- productMapper.insert(product);
|
|
|
+ Integer count = productMapper.selectCount(new LambdaQueryWrapper<Product>()
|
|
|
+ .eq(user.getCompanyId() != null, Product::getCompanyId, user.getCompanyId())
|
|
|
+ .eq(!StringUtils.isEmpty(product.getName()), Product::getName, product.getName())
|
|
|
+ );
|
|
|
+ if(count==0){
|
|
|
+ productMapper.insert(product);
|
|
|
+
|
|
|
+ }else{
|
|
|
+ msg.setError("产品名重复");
|
|
|
+ }
|
|
|
} else {
|
|
|
- productMapper.updateById(product);
|
|
|
+ Product selectOne = productMapper.selectOne(new LambdaQueryWrapper<Product>()
|
|
|
+ .eq(user.getCompanyId() != null, Product::getCompanyId, user.getCompanyId())
|
|
|
+ .eq(!StringUtils.isEmpty(product.getName()), Product::getName, product.getName())
|
|
|
+ );
|
|
|
+ if(selectOne.getId()==product.getId()){
|
|
|
+ productMapper.updateById(product);
|
|
|
+ }else{
|
|
|
+ msg.setError("产品名重复");
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
- HttpRespMsg msg = new HttpRespMsg();
|
|
|
+
|
|
|
System.out.println(product);
|
|
|
msg.setData(product);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
return msg;
|
|
|
}
|
|
|
|
|
@@ -156,7 +185,7 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * todo 待定
|
|
|
+ *
|
|
|
* @param multipartFile
|
|
|
* @param categoryId
|
|
|
* @param request
|
|
@@ -165,7 +194,12 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
@Override
|
|
|
public HttpRespMsg importData(MultipartFile multipartFile, Integer categoryId, HttpServletRequest request) {
|
|
|
HttpRespMsg msg=new HttpRespMsg();
|
|
|
- DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ List<Product> productList=new ArrayList<>();
|
|
|
+ List<ProdProcedure> prodProcedureList=new ArrayList<>();
|
|
|
+
|
|
|
+
|
|
|
+ Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
|
|
|
+
|
|
|
String fileName = multipartFile.getOriginalFilename();
|
|
|
File file = new File(fileName == null ? "file" : fileName);
|
|
|
InputStream inputStream = null;
|
|
@@ -183,138 +217,229 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
}
|
|
|
inputStream.close();
|
|
|
outputStream.close();
|
|
|
+
|
|
|
+
|
|
|
//然后解析表格
|
|
|
+
|
|
|
XSSFWorkbook workbook = new XSSFWorkbook(file);
|
|
|
- //我们只需要第一个sheet
|
|
|
+ //第一个sheet 产品信息
|
|
|
XSSFSheet sheet = workbook.getSheetAt(0);
|
|
|
int rowNum = sheet.getLastRowNum();
|
|
|
|
|
|
//获取相关数据
|
|
|
- Integer companyId = userMapper.selectById(request.getHeader("token")).getCompanyId();
|
|
|
+
|
|
|
for(int rowIndex=1;rowIndex<=rowNum;rowIndex++){
|
|
|
XSSFRow row = sheet.getRow(rowIndex);
|
|
|
//跳过空行
|
|
|
if(row==null){
|
|
|
continue;
|
|
|
}
|
|
|
- if(rowIndex==1){
|
|
|
- //产品基本信息
|
|
|
- XSSFCell nameCell = row.getCell(0);
|
|
|
- XSSFCell codeCell = row.getCell(1);
|
|
|
- XSSFCell orderNumberCell = row.getCell(2);
|
|
|
- XSSFCell unitCell = row.getCell(3);
|
|
|
- XSSFCell groupNumberCell = row.getCell(4);
|
|
|
- XSSFCell columnNumberCell = row.getCell(5);
|
|
|
- XSSFCell vehicleNumberCell = row.getCell(6);
|
|
|
- XSSFCell descriptionCell = row.getCell(7);
|
|
|
- XSSFCell categoryNameCell = row.getCell(8);
|
|
|
- if(nameCell!=null){
|
|
|
- nameCell.setCellType(CellType.STRING);
|
|
|
- }
|
|
|
- if(codeCell!=null){
|
|
|
- codeCell.setCellType(CellType.STRING);
|
|
|
- }
|
|
|
- if(orderNumberCell!=null){
|
|
|
- orderNumberCell.setCellType(CellType.NUMERIC);
|
|
|
- }
|
|
|
- if(unitCell!=null){
|
|
|
- unitCell.setCellType(CellType.STRING);
|
|
|
- }
|
|
|
- if(groupNumberCell!=null){
|
|
|
- groupNumberCell.setCellType(CellType.NUMERIC);
|
|
|
- }
|
|
|
- if(columnNumberCell!=null){
|
|
|
- columnNumberCell.setCellType(CellType.NUMERIC);
|
|
|
- }
|
|
|
- if(vehicleNumberCell!=null){
|
|
|
- vehicleNumberCell.setCellType(CellType.NUMERIC);
|
|
|
- }
|
|
|
- if(descriptionCell!=null){
|
|
|
- descriptionCell.setCellType(CellType.STRING);
|
|
|
- }
|
|
|
- if(categoryNameCell!=null){
|
|
|
- categoryNameCell.setCellType(CellType.STRING);
|
|
|
- }
|
|
|
|
|
|
- Product product=new Product();
|
|
|
- product.setCompanyId(companyId);
|
|
|
- if(nameCell!=null){
|
|
|
+ //产品基本信息
|
|
|
+ XSSFCell nameCell = row.getCell(0);
|
|
|
+ XSSFCell codeCell = row.getCell(1);
|
|
|
+ XSSFCell orderNumberCell = row.getCell(2);
|
|
|
+ XSSFCell unitCell = row.getCell(3);
|
|
|
+ XSSFCell groupNumberCell = row.getCell(4);
|
|
|
+ XSSFCell columnNumberCell = row.getCell(5);
|
|
|
+ XSSFCell vehicleNumberCell = row.getCell(6);
|
|
|
+ XSSFCell descriptionCell = row.getCell(7);
|
|
|
+
|
|
|
+ if(nameCell!=null){
|
|
|
+ nameCell.setCellType(CellType.STRING);
|
|
|
+ }
|
|
|
+ if(codeCell!=null){
|
|
|
+ codeCell.setCellType(CellType.STRING);
|
|
|
+ }
|
|
|
+ if(orderNumberCell!=null){
|
|
|
+ orderNumberCell.setCellType(CellType.NUMERIC);
|
|
|
+ }
|
|
|
+ if(unitCell!=null){
|
|
|
+ unitCell.setCellType(CellType.STRING);
|
|
|
+ }
|
|
|
+ if(groupNumberCell!=null){
|
|
|
+ groupNumberCell.setCellType(CellType.NUMERIC);
|
|
|
+ }
|
|
|
+ if(columnNumberCell!=null){
|
|
|
+ columnNumberCell.setCellType(CellType.NUMERIC);
|
|
|
+ }
|
|
|
+ if(vehicleNumberCell!=null){
|
|
|
+ vehicleNumberCell.setCellType(CellType.NUMERIC);
|
|
|
+ }
|
|
|
+ if(descriptionCell!=null){
|
|
|
+ descriptionCell.setCellType(CellType.STRING);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Product product=new Product();
|
|
|
+ product.setCompanyId(companyId);
|
|
|
+ product.setCategoryId(categoryId);
|
|
|
+ if(nameCell!=null){
|
|
|
+ Integer count = productMapper.selectCount(new LambdaQueryWrapper<Product>()
|
|
|
+ .eq(companyId != null, Product::getCompanyId, companyId)
|
|
|
+ .eq(!StringUtils.isEmpty( nameCell.getStringCellValue()), Product::getName, nameCell.getStringCellValue())
|
|
|
+ );
|
|
|
+ if(count==0){
|
|
|
product.setName(nameCell.getStringCellValue());
|
|
|
- }else{
|
|
|
- msg.setError("产品名称不能为空");
|
|
|
- return msg;
|
|
|
- }
|
|
|
- if(codeCell!=null){
|
|
|
- product.setCode(codeCell.getStringCellValue());
|
|
|
- }else{
|
|
|
- msg.setError("项目代码不能为空");
|
|
|
- return msg;
|
|
|
- }
|
|
|
- if(orderNumberCell!=null){
|
|
|
- product.setOrderNumber(Integer.valueOf(String.valueOf(orderNumberCell.getNumericCellValue())));
|
|
|
|
|
|
}else{
|
|
|
- msg.setError("订单数量不能为空");
|
|
|
+ msg.setError("产品名和已存在的产品重复");
|
|
|
return msg;
|
|
|
}
|
|
|
- if(unitCell!=null){
|
|
|
- product.setUnit(unitCell.getStringCellValue());
|
|
|
|
|
|
- }else{
|
|
|
- msg.setError("单位不能为空");
|
|
|
- return msg;
|
|
|
- }
|
|
|
- if(groupNumberCell!=null){
|
|
|
- product.setGroupNumber(Integer.valueOf(String.valueOf(groupNumberCell.getStringCellValue())));
|
|
|
- }else{
|
|
|
- msg.setError("编组不能为空");
|
|
|
- return msg;
|
|
|
- }
|
|
|
- if(columnNumberCell!=null){
|
|
|
- product.setColumnNumber(Integer.valueOf(String.valueOf(columnNumberCell.getStringCellValue())));
|
|
|
- }
|
|
|
- if(vehicleNumberCell!=null){
|
|
|
- product.setVehicleNumber(Integer.valueOf(String.valueOf(vehicleNumberCell.getStringCellValue())));
|
|
|
+ }else{
|
|
|
+ msg.setError("产品名称不能为空");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ if(codeCell!=null){
|
|
|
+ product.setCode(codeCell.getStringCellValue());
|
|
|
+ }else{
|
|
|
+ msg.setError("项目代码不能为空");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ if(orderNumberCell!=null){
|
|
|
+ product.setOrderNumber((int) Math.round(orderNumberCell.getNumericCellValue()));
|
|
|
|
|
|
+ }else{
|
|
|
+ msg.setError("订单数量不能为空");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ if(unitCell!=null){
|
|
|
+ product.setUnit(unitCell.getStringCellValue());
|
|
|
+
|
|
|
+ }else{
|
|
|
+ msg.setError("单位不能为空");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ if(groupNumberCell!=null){
|
|
|
+ product.setGroupNumber((int) Math.round(groupNumberCell.getNumericCellValue()));
|
|
|
+ }else{
|
|
|
+ msg.setError("编组不能为空");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+ if(columnNumberCell!=null){
|
|
|
+ product.setColumnNumber((int) Math.round(columnNumberCell.getNumericCellValue()));
|
|
|
+ }
|
|
|
+ if(vehicleNumberCell!=null){
|
|
|
+ product.setVehicleNumber((int) Math.round(vehicleNumberCell.getNumericCellValue()));
|
|
|
+
|
|
|
+ }
|
|
|
+ if(descriptionCell!=null){
|
|
|
+ product.setDescription(descriptionCell.getStringCellValue());
|
|
|
+ }
|
|
|
+ productList.add(product);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //获取派工单信息
|
|
|
+ sheet = workbook.getSheetAt(1);
|
|
|
+ rowNum = sheet.getLastRowNum();
|
|
|
+
|
|
|
+ for(int indexNum=1;indexNum<rowNum;indexNum++){
|
|
|
+ XSSFRow row = sheet.getRow(indexNum);
|
|
|
+ //跳过空行
|
|
|
+ if(row==null){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ //工序信息
|
|
|
+ XSSFCell productNameCell = row.getCell(0);
|
|
|
+ XSSFCell versionNumberCell = row.getCell(1);
|
|
|
+ XSSFCell nameCell = row.getCell(2);
|
|
|
+ XSSFCell workingTimeCell = row.getCell(3);
|
|
|
+ XSSFCell unitPriceCell = row.getCell(4);
|
|
|
+ XSSFCell checkTypeCell = row.getCell(5);
|
|
|
+ if( productNameCell!=null){
|
|
|
+ productNameCell.setCellType(CellType.STRING);
|
|
|
+ }
|
|
|
+ if(versionNumberCell!=null){
|
|
|
+ versionNumberCell.setCellType(CellType.STRING);
|
|
|
+ }
|
|
|
+ if(nameCell!=null){
|
|
|
+ nameCell.setCellType(CellType.STRING);
|
|
|
+ }
|
|
|
+ if(workingTimeCell!=null){
|
|
|
+ workingTimeCell.setCellType(CellType.NUMERIC);
|
|
|
+ }
|
|
|
+ if(unitPriceCell!=null){
|
|
|
+ unitPriceCell.setCellType(CellType.NUMERIC);
|
|
|
+ }
|
|
|
+ if(checkTypeCell!=null){
|
|
|
+ checkTypeCell.setCellType(CellType.STRING);
|
|
|
+ }
|
|
|
+
|
|
|
+ ProdProcedure prodProcedure=new ProdProcedure();
|
|
|
+ if( productNameCell!=null){
|
|
|
+ prodProcedure.setProductName(productNameCell.getStringCellValue());
|
|
|
+ }else{
|
|
|
+ msg.setError("产品名称不能为空");
|
|
|
+ }
|
|
|
+ if(versionNumberCell!=null){
|
|
|
+ prodProcedure.setVersionNumber(versionNumberCell.getStringCellValue());
|
|
|
+
|
|
|
+ }else{
|
|
|
+ msg.setError("版本号不能为空");
|
|
|
+ }
|
|
|
+ if(nameCell!=null){
|
|
|
+ prodProcedure.setName(nameCell.getStringCellValue());
|
|
|
+
|
|
|
+ }else{
|
|
|
+ msg.setError("工序名称不能为空");
|
|
|
+ }
|
|
|
+ if(workingTimeCell!=null){
|
|
|
+ prodProcedure.setWorkingTime((int) Math.round(workingTimeCell.getNumericCellValue()));
|
|
|
+
|
|
|
+ }else{
|
|
|
+ msg.setError("单件工时不能为空");
|
|
|
+ }
|
|
|
+ if(unitPriceCell!=null){
|
|
|
+ prodProcedure.setUnitPrice(new BigDecimal(unitPriceCell.getNumericCellValue()));
|
|
|
+ }else{
|
|
|
+ msg.setError("单件工价不能为空");
|
|
|
+ }
|
|
|
+ if(checkTypeCell!=null){
|
|
|
+ String checkType = String.valueOf(checkTypeCell.getStringCellValue());
|
|
|
+ switch (checkType){
|
|
|
+ case "自检" : prodProcedure.setCheckType(0);break;
|
|
|
+ case "互检" : prodProcedure.setCheckType(1);break;
|
|
|
+ case "专检" : prodProcedure.setCheckType(2);break;
|
|
|
+ default: msg.setError("质检类型只能为:自检,互检,专检");return msg;
|
|
|
}
|
|
|
- if(descriptionCell!=null){
|
|
|
- product.setDescription(descriptionCell.getStringCellValue());
|
|
|
- descriptionCell.setCellType(CellType.STRING);
|
|
|
- }
|
|
|
- if(categoryNameCell!=null){
|
|
|
-
|
|
|
- ProdCategory category = prodCategoryMapper.selectOne(new QueryWrapper<ProdCategory>().eq("name", categoryNameCell.getStringCellValue()));
|
|
|
- if(category==null){
|
|
|
- msg.setError("该分类不存在");
|
|
|
- return msg;
|
|
|
- }
|
|
|
- product.setCategoryName(category.getName());
|
|
|
- product.setCategoryId(category.getId());
|
|
|
- }else{
|
|
|
- msg.setError("分类名称不能为空");
|
|
|
- return msg;
|
|
|
- }
|
|
|
- rowIndex+=3;
|
|
|
}else{
|
|
|
- //工序和物料信息
|
|
|
- XSSFCell versionNumberPCell = row.getCell(0);
|
|
|
- XSSFCell namePCell = row.getCell(1);
|
|
|
- XSSFCell workingTimeCell = row.getCell(2);
|
|
|
- XSSFCell unitPriceCell = row.getCell(3);
|
|
|
- XSSFCell checkTypeCell = row.getCell(4);
|
|
|
- XSSFCell columnNumberCell = row.getCell(5);
|
|
|
- XSSFCell versionNumberMCell = row.getCell(6);
|
|
|
- XSSFCell nameMCell = row.getCell(7);
|
|
|
- XSSFCell companyCodeCell = row.getCell(8);
|
|
|
- XSSFCell materialQualityCell = row.getCell(9);
|
|
|
- XSSFCell thicknessCell = row.getCell(10);
|
|
|
- XSSFCell numberProductCell = row.getCell(11);
|
|
|
- XSSFCell numberVehicleCell = row.getCell(11);
|
|
|
+ msg.setError("质检类型不能为空");
|
|
|
+ }
|
|
|
|
|
|
+ prodProcedureList.add(prodProcedure);
|
|
|
+ }
|
|
|
+
|
|
|
+ //检查同一版本的同一版本号工序中有没有重复的
|
|
|
+ for (ProdProcedure prodProcedure : prodProcedureList) {
|
|
|
|
|
|
+ long count = prodProcedureList.stream()
|
|
|
+ .filter(procedure -> procedure.getProductName().equals(prodProcedure.getProductName()) && procedure.getVersionNumber().equals(prodProcedure.getVersionNumber()) && procedure.getName().equals(prodProcedure.getName()))
|
|
|
+ .count();
|
|
|
+ if(count>1){
|
|
|
+ msg.setError("产品"+prodProcedure.getProductName()+"的"+prodProcedure.getVersionNumber()+"版本工序重复了");
|
|
|
+ return msg;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ System.out.println(productList);
|
|
|
+ System.out.println(prodProcedureList);
|
|
|
+ //插入数据
|
|
|
+ if(saveBatch(productList)) {
|
|
|
+
|
|
|
+ for (Product product : productList) {
|
|
|
+ prodProcedureList.stream()
|
|
|
+ .filter(prodProcedure -> prodProcedure.getProductName().equals(product.getName()))
|
|
|
+ .forEach(prodProcedure ->{
|
|
|
+ prodProcedure.setProductId(product.getId());
|
|
|
+ prodProcedure.setCompanyId(companyId);
|
|
|
+
|
|
|
+ } );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ prodProcedureService.saveBatch(prodProcedureList);
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
e.printStackTrace();
|
|
@@ -351,10 +476,190 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
// file.deleteOnExit();//程序退出时删除临时文件
|
|
|
System.out.println(file.delete());
|
|
|
}
|
|
|
- return null;
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg exportData(String date, Integer productType) {
|
|
|
+ HttpRespMsg msg=new HttpRespMsg();
|
|
|
+
|
|
|
+ List<Integer> productIdList =Arrays.asList( JSONObject.parseObject(date, Integer[].class));
|
|
|
+
|
|
|
+ if(productIdList!=null&&productIdList.size()>0) {
|
|
|
+
|
|
|
+ //获取数据
|
|
|
+ List<Product> productList = productMapper.selectBatchIds(productIdList);
|
|
|
+ List<ProdProcedure> prodProcedureList = prodProcedureMapper.selectList(new LambdaQueryWrapper<ProdProcedure>().in(ProdProcedure::getProductId, productIdList));
|
|
|
+
|
|
|
+ //表格
|
|
|
+ List<String> pdTitles; //列的名称
|
|
|
+ pdTitles = Arrays.asList("产品名称", "项目代码", "订单数量", "单位", "编组", "每列数量", "每辆数量", "描述");
|
|
|
+ List<String> pcTitles; //列的名称
|
|
|
+ pcTitles = Arrays.asList("产品名称", "版本号", "工序名称", "单件工时", "单件工价", "质检类型");
|
|
|
+
|
|
|
+ //设置表格格式
|
|
|
+ HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
+
|
|
|
+ HSSFCellStyle style = wb.createCellStyle();
|
|
|
+ style.setBorderBottom(BorderStyle.valueOf((short) 1));
|
|
|
+ style.setBorderLeft(BorderStyle.valueOf((short) 1));
|
|
|
+ style.setBorderRight(BorderStyle.valueOf((short) 1));
|
|
|
+ style.setBorderTop(BorderStyle.valueOf((short) 1));
|
|
|
+ //水平居中
|
|
|
+ style.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ //垂直对齐
|
|
|
+ style.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
+ style.setBottomBorderColor(IndexedColors.BLACK.index);
|
|
|
+ //背景颜色
|
|
|
+ style.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
|
|
|
+ HSSFFont headerFont1 = (HSSFFont) wb.createFont();
|
|
|
+ //字体加粗
|
|
|
+ headerFont1.setBold(true);
|
|
|
+ //字体类型
|
|
|
+ headerFont1.setFontName("黑体");
|
|
|
+ //字体大小
|
|
|
+ headerFont1.setFontHeightInPoints((short) 15);
|
|
|
+ style.setFont(headerFont1);
|
|
|
+
|
|
|
+
|
|
|
+ HSSFSheet sheet=wb.createSheet("产品基本信息");
|
|
|
+ //设置每一列的列宽
|
|
|
+ sheet.setColumnWidth(0,256*15);
|
|
|
+ sheet.setColumnWidth(1,256*15);
|
|
|
+ sheet.setColumnWidth(2,256*15);
|
|
|
+ sheet.setColumnWidth(3,256*15);
|
|
|
+ sheet.setColumnWidth(4,256*15);
|
|
|
+ sheet.setColumnWidth(5,256*15);
|
|
|
+ sheet.setColumnWidth(6,256*15);
|
|
|
+ sheet.setColumnWidth(7,256*40);
|
|
|
+
|
|
|
+ HSSFRow row = sheet.createRow(0);
|
|
|
+ //创建标题
|
|
|
+ HSSFCell cell = null;
|
|
|
+ for (int i = 0; i < pdTitles.size(); i++) {
|
|
|
+ cell = row.createCell(i);
|
|
|
+ cell.setCellValue(pdTitles.get(i));
|
|
|
+ cell.setCellStyle(style);
|
|
|
+ }
|
|
|
+ //写入产品基本信息
|
|
|
+ for(int i=1;i<=productList.size();i++){
|
|
|
+ row=sheet.createRow(i);
|
|
|
+ row.createCell(0).setCellValue(productList.get(i-1).getName());
|
|
|
+ row.createCell(1).setCellValue(productList.get(i-1).getCode());
|
|
|
+ row.createCell(2).setCellValue(productList.get(i-1).getOrderNumber());
|
|
|
+ row.createCell(3).setCellValue(productList.get(i-1).getUnit());
|
|
|
+ row.createCell(4).setCellValue(productList.get(i-1).getGroupNumber());
|
|
|
+ row.createCell(5).setCellValue(productList.get(i-1).getColumnNumber());
|
|
|
+ row.createCell(6).setCellValue(productList.get(i-1).getVehicleNumber());
|
|
|
+ row.createCell(7).setCellValue(productList.get(i-1).getDescription());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ sheet=wb.createSheet("派工单");
|
|
|
+ //设置每一列的列宽
|
|
|
+ sheet.setColumnWidth(0,256*15);
|
|
|
+ sheet.setColumnWidth(1,256*15);
|
|
|
+ sheet.setColumnWidth(2,256*15);
|
|
|
+ sheet.setColumnWidth(3,256*15);
|
|
|
+ sheet.setColumnWidth(4,256*15);
|
|
|
+ sheet.setColumnWidth(5,256*15);
|
|
|
+
|
|
|
+
|
|
|
+ row = sheet.createRow(0);
|
|
|
+ //创建标题
|
|
|
+ cell = null;
|
|
|
+ for (int i = 0; i < pcTitles.size(); i++) {
|
|
|
+ cell = row.createCell(i);
|
|
|
+ cell.setCellValue(pcTitles.get(i));
|
|
|
+ cell.setCellStyle(style);
|
|
|
+ }
|
|
|
+ //写入工序基本信息
|
|
|
+ for(int i=1;i<=prodProcedureList.size();i++){
|
|
|
+ row=sheet.createRow(i);
|
|
|
+ row.createCell(0).setCellValue(prodProcedureList.get(i-1).getProductName());
|
|
|
+ row.createCell(1).setCellValue(prodProcedureList.get(i-1).getVersionNumber());
|
|
|
+ row.createCell(2).setCellValue(prodProcedureList.get(i-1).getName());
|
|
|
+ row.createCell(3).setCellValue(prodProcedureList.get(i-1).getWorkingTime());
|
|
|
+ row.createCell(4).setCellValue(prodProcedureList.get(i-1).getUnitPrice().toString());
|
|
|
+
|
|
|
+ String chekType="";
|
|
|
+ switch(prodProcedureList.get(i-1).getCheckType()){
|
|
|
+ case 0: chekType="自检";break;
|
|
|
+ case 1: chekType="互检";break;
|
|
|
+ case 2: chekType="专检";
|
|
|
+ }
|
|
|
+
|
|
|
+ row.createCell(5).setCellValue(chekType);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //导出excel
|
|
|
+ String result="系统提示:Excel文件导出成功!";
|
|
|
+
|
|
|
+ String title= "产品详情"+System.currentTimeMillis();
|
|
|
+ String fileName= title+".xlsx";
|
|
|
+ String path="D://cloud/upload/";
|
|
|
+ try {
|
|
|
+ File dir = null;
|
|
|
+ dir = new File(path);
|
|
|
+ // D://cloud/upload 文件上传后所存储的位置,部署到服务器上时配置服务器地址即可
|
|
|
+ if (!dir.exists()) {
|
|
|
+ dir.mkdirs();
|
|
|
+ }
|
|
|
+ FileOutputStream os = new FileOutputStream(path+fileName);//保存到本地
|
|
|
+ wb.write(os);
|
|
|
+ os.flush();
|
|
|
+ os.close();
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ msg.data ="/upload/"+fileName;
|
|
|
|
|
|
+ }
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg insertProductInfo(String name, Integer id, HttpServletRequest request) {
|
|
|
+ HttpRespMsg msg=new HttpRespMsg();
|
|
|
+ String token = request.getHeader("Token");
|
|
|
+ Integer companyId = userMapper.selectById(token).getCompanyId();
|
|
|
|
|
|
+ if(count(new LambdaQueryWrapper<Product>()
|
|
|
+ .eq(!StringUtils.isEmpty(name),Product::getName,name).eq(companyId!=null,Product::getCompanyId,companyId))>0){
|
|
|
+ msg.setError("产品名称重复");
|
|
|
+ return msg;
|
|
|
+ }
|
|
|
|
|
|
+
|
|
|
+ //1.查询目标产品的信息
|
|
|
+ Product product = productMapper.selectById(id);
|
|
|
+ List<ProdProcedure> prodProcedureList = prodProcedureMapper.selectList(new LambdaQueryWrapper<ProdProcedure>()
|
|
|
+ .eq(id != null, ProdProcedure::getProductId, id)
|
|
|
+ .eq(companyId != null, ProdProcedure::getCompanyId, companyId)
|
|
|
+ );
|
|
|
+ System.out.println(prodProcedureList);
|
|
|
+
|
|
|
+ //2.修改
|
|
|
+ product.setName(name);
|
|
|
+ product.setId(null);
|
|
|
+
|
|
|
+ System.out.println(product);
|
|
|
+
|
|
|
+ productMapper.insert(product);
|
|
|
+ prodProcedureList.stream().forEach(prodProcedure ->{
|
|
|
+ prodProcedure.setProductId(product.getId());
|
|
|
+ prodProcedure.setProductName(name);
|
|
|
+ });
|
|
|
+
|
|
|
+ prodProcedureService.saveBatch(prodProcedureList);
|
|
|
+
|
|
|
+ return msg;
|
|
|
}
|
|
|
}
|