|
@@ -11,12 +11,23 @@ import com.management.platform.service.ProdProcedureService;
|
|
|
import com.management.platform.service.ProductService;
|
|
|
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.openxml4j.exceptions.InvalidFormatException;
|
|
|
+import org.apache.poi.ss.usermodel.CellType;
|
|
|
+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.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
+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;
|
|
@@ -46,6 +57,8 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
ProdMaterialService prodMaterialService;
|
|
|
@Resource
|
|
|
PlanMapper planMapper;
|
|
|
+ @Resource
|
|
|
+ ProdCategoryMapper prodCategoryMapper;
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -123,12 +136,12 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
@Override
|
|
|
public HttpRespMsg delete(Integer id) {
|
|
|
HttpRespMsg msg = new HttpRespMsg();
|
|
|
- //TODO : 需检测是否被使用
|
|
|
+
|
|
|
int count = planMapper.selectCount(
|
|
|
new LambdaQueryWrapper<Plan>()
|
|
|
.eq(id != null, Plan::getProductId, id)
|
|
|
);
|
|
|
- System.out.println(count);
|
|
|
+
|
|
|
if(count==0){
|
|
|
|
|
|
prodProcedureMapper.delete(new LambdaQueryWrapper<ProdProcedure>().eq(id!=null,ProdProcedure::getProductId,id));
|
|
@@ -140,5 +153,208 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
}
|
|
|
|
|
|
return msg;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * todo 待定
|
|
|
+ * @param multipartFile
|
|
|
+ * @param categoryId
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public HttpRespMsg importData(MultipartFile multipartFile, Integer categoryId, HttpServletRequest request) {
|
|
|
+ HttpRespMsg msg=new HttpRespMsg();
|
|
|
+ DateTimeFormatter df=DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
|
|
+ String fileName = multipartFile.getOriginalFilename();
|
|
|
+ File file = new File(fileName == null ? "file" : fileName);
|
|
|
+ InputStream inputStream = null;
|
|
|
+ OutputStream outputStream = null;
|
|
|
+
|
|
|
+
|
|
|
+ try {
|
|
|
+ inputStream= multipartFile.getInputStream();
|
|
|
+ outputStream=new FileOutputStream(file);
|
|
|
+
|
|
|
+ byte[] buffer = new byte[4096];
|
|
|
+ int temp = 0;
|
|
|
+ while ((temp = inputStream.read(buffer, 0, 4096)) != -1) {
|
|
|
+ outputStream.write(buffer, 0, temp);
|
|
|
+ }
|
|
|
+ inputStream.close();
|
|
|
+ outputStream.close();
|
|
|
+ //然后解析表格
|
|
|
+ XSSFWorkbook workbook = new XSSFWorkbook(file);
|
|
|
+ //我们只需要第一个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){
|
|
|
+ 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("订单数量不能为空");
|
|
|
+ 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())));
|
|
|
+
|
|
|
+ }
|
|
|
+ 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);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (NullPointerException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //msg.setError("数据格式有误或存在空数据 导入失败");
|
|
|
+ msg.setError(MessageUtils.message("file.dataFormatError"));
|
|
|
+ return msg;
|
|
|
+ } catch (InvalidFormatException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //msg.setError("文件格式错误,如果安装了加密软件需要先解密再上传");
|
|
|
+ msg.setError(MessageUtils.message("file.FormatErrorAndDecrypt"));
|
|
|
+ } catch (EncryptedDocumentException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //msg.setError("文件加密状态,需要先解除加密状态再上传");
|
|
|
+ msg.setError(MessageUtils.message("file.encryption"));
|
|
|
+ return msg;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ //msg.setError("上传失败:" + e.getMessage());
|
|
|
+ msg.setError(MessageUtils.message("file.uploadError",e.getMessage()));
|
|
|
+ return msg;
|
|
|
+ } finally {
|
|
|
+ //关闭流
|
|
|
+ try {
|
|
|
+ if (outputStream != null && inputStream != null) {
|
|
|
+ outputStream.close();
|
|
|
+ inputStream.close();
|
|
|
+ System.out.println("流已关闭");
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+// file.deleteOnExit();//程序退出时删除临时文件
|
|
|
+ System.out.println(file.delete());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
}
|