yejian 3 лет назад
Родитель
Сommit
5ab6eafc0a

+ 2 - 1
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/operationManagementCenter/service/OrderService.java

@@ -3,7 +3,6 @@ package com.github.zuihou.business.operationManagementCenter.service;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.github.zuihou.base.R;
 import com.github.zuihou.base.service.SuperService;
-import com.github.zuihou.business.operationManagementCenter.dto.OrderSaveDTO;
 import com.github.zuihou.business.operationManagementCenter.dto.OrderUpdateDTO;
 import com.github.zuihou.business.operationManagementCenter.entity.Order;
 import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
@@ -90,4 +89,6 @@ public interface OrderService extends SuperService<Order> {
     Boolean deleteOrder(Order model);
 
     void downloadOrderTemplate(HttpServletResponse httpServletResponse);
+
+    R<Boolean> saveExcelOrder(Order order, List<Map> detailList);
 }

+ 100 - 20
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/operationManagementCenter/service/impl/OrderServiceImpl.java

@@ -56,9 +56,7 @@ import com.github.zuihou.utils.BeanPlusUtil;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.hssf.usermodel.*;
-import org.apache.poi.ss.usermodel.BorderStyle;
-import org.apache.poi.ss.usermodel.FillPatternType;
-import org.apache.poi.ss.usermodel.IndexedColors;
+import org.apache.poi.ss.usermodel.*;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.CellRangeAddressList;
 import org.apache.poi.xssf.usermodel.*;
@@ -1045,6 +1043,7 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
            style.setBorderLeft(BorderStyle.THIN);
            style.setBorderBottom(BorderStyle.THIN);
 
+
            XSSFCellStyle style1 = wb.createCellStyle();
            style1.setBorderRight(BorderStyle.THIN);
            style1.setBorderTop(BorderStyle.THIN);
@@ -1052,15 +1051,28 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
            style1.setBorderBottom(BorderStyle.THIN);
            style1.setFillForegroundColor(IndexedColors.GREY_50_PERCENT.getIndex()); //设置背景色
            style1.setFillPattern(FillPatternType.SOLID_FOREGROUND);
+           style1.setAlignment(HorizontalAlignment.CENTER);
 
+           XSSFCellStyle style2 = wb.createCellStyle();
+           XSSFDataFormat format = wb.createDataFormat();
+           style2.setBorderRight(BorderStyle.THIN);
+           style2.setBorderTop(BorderStyle.THIN);
+           style2.setBorderLeft(BorderStyle.THIN);
+           style2.setBorderBottom(BorderStyle.THIN);
+           style2.setDataFormat(format.getFormat("@"));
 
            XSSFSheet sheet = wb.createSheet("orderTemplate");
-           for (int i = 0; i <= 5; i++)
-           {
-               sheet.autoSizeColumn((short)i,true); //调整列宽
-           }
+
+           XSSFRow row0 = sheet.createRow(0);
+           XSSFCell row0cell1 = row0.createCell(0);
+           row0cell1.setCellValue("订单导入:");
+           row0cell1.setCellStyle(style1);
+           // 起始行, 终止行, 起始列, 终止列
+           CellRangeAddress cra =new CellRangeAddress(0, 0, 0, 5);
+           sheet.addMergedRegion(cra);
+
            // 在第一行插入需要填写的订单信息
-           XSSFRow row1 = sheet.createRow(0);
+           XSSFRow row1 = sheet.createRow(1);
 
            XSSFCell row1cell1 = row1.createCell(0);
            XSSFCell row1cell2 = row1.createCell(1);
@@ -1072,11 +1084,17 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
            row1cell3.setCellValue("下单时间:");
            row1cell5.setCellValue("所属产线:");
            row1cell6.setCellValue("请选择");
-           row1cell1.setCellStyle(style);
+           row1cell1.setCellStyle(style1);
            row1cell2.setCellStyle(style);
-           row1cell3.setCellStyle(style);
-           row1cell4.setCellStyle(style);
-           row1cell5.setCellStyle(style);
+           row1cell3.setCellStyle(style1);
+           row1cell4.setCellStyle(style2);
+           row1cell5.setCellStyle(style1);
+           XSSFDrawing patr1 = sheet.createDrawingPatriarch();
+           // 定义注释的大小和位置,详见文档
+           XSSFComment comment = patr1.createCellComment(new XSSFClientAnchor(1, 3, 1,3, (short) 2, 1, (short) 3, 5));// 设置注释内容
+           XSSFComment comment1 = patr1.createCellComment(new XSSFClientAnchor(4, 6, 4,6, (short) 3, 2, (short) 4, 7));// 设置注释内容
+           comment.setString(new XSSFRichTextString("日期请输入yyyy-MM-dd!"));
+           comment1.setString(new XSSFRichTextString("日期请输入yyyy-MM-dd!"));
            row1cell6.setCellStyle(style);
            // 生成下拉框内容
            QueryWrapper<ZZone> zZoneWrapper = new QueryWrapper<ZZone>();
@@ -1092,14 +1110,14 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
            XSSFDataValidationHelper dvHelper = new XSSFDataValidationHelper((XSSFSheet)sheet);
            XSSFDataValidationConstraint zZoneConstraint = (XSSFDataValidationConstraint) dvHelper
                    .createExplicitListConstraint(zZoneInfos);
-           CellRangeAddressList zZoneRange = new CellRangeAddressList(0, 0, 5, 5);
+           CellRangeAddressList zZoneRange = new CellRangeAddressList(1, 1, 5, 5);
            XSSFDataValidation zZoneValidation = (XSSFDataValidation) dvHelper.createValidation(zZoneConstraint, zZoneRange);
            zZoneValidation.setSuppressDropDownArrow(true);
            zZoneValidation.setShowErrorBox(true);
            sheet.addValidationData(zZoneValidation);
 
            // 设置第二行表头
-           XSSFRow row2 = sheet.createRow(1);
+           XSSFRow row2 = sheet.createRow(2);
            XSSFCell row2cell1 = row2.createCell(0);
            XSSFCell row2cell2 = row2.createCell(1);
            XSSFCell row2cell3 = row2.createCell(2);
@@ -1115,12 +1133,13 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
            row2cell3.setCellStyle(style1);
            row2cell4.setCellStyle(style1);
            row2cell5.setCellStyle(style1);
+
            // 起始行, 终止行, 起始列, 终止列
-           CellRangeAddress cra =new CellRangeAddress(1, 1, 4, 5);
+           cra =new CellRangeAddress(2, 2, 4, 5);
            sheet.addMergedRegion(cra);
 
            // 设置第三行选中零件
-           XSSFRow row3 = sheet.createRow(2);
+           XSSFRow row3 = sheet.createRow(3);
            XSSFCell row3cell1 = row3.createCell(0);
            XSSFCell row3cell2 = row3.createCell(1);
            XSSFCell row3cell3 = row3.createCell(2);
@@ -1131,11 +1150,11 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
            row3cell2.setCellValue("请选择");
            row3cell1.setCellStyle(style);
            row3cell2.setCellStyle(style);
-           row3cell3.setCellStyle(style);
-           row3cell4.setCellStyle(style);
+           row3cell3.setCellStyle(style2);
+           row3cell4.setCellStyle(style2);
            row3cell5.setCellStyle(style);
            row3cell6.setCellStyle(style);
-           CellRangeAddress cra1 =new CellRangeAddress(2, 2, 4, 5);
+           CellRangeAddress cra1 =new CellRangeAddress(3, 3, 4, 5);
            sheet.addMergedRegion(cra1);
 
            QueryWrapper<BBom> bBomWrapper = new QueryWrapper<BBom>();
@@ -1209,5 +1228,66 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
 //               temp.delete();
            }
        }
-   }
+    }
+    @Override
+    public R<Boolean> saveExcelOrder(Order order, List<Map> detailList){
+        //验证是否配置了工序
+        List<String> bomList = detailList.stream().map(p -> p.get("bomId").toString()).collect(Collectors.toList());
+        List<BomProcedure> bomProcedureList = bomProcedureService.list(Wraps.<BomProcedure>lbQ().in(BomProcedure::getBomId,bomList));
+
+        Map<Long,List<BomProcedure>> bomProcedureMap = bomProcedureList.stream().collect(groupingBy(BomProcedure::getBomId, LinkedHashMap::new, toList()));
+
+        isFalse(CollectionUtil.isEmpty(bomProcedureList),"零件尚未配置工序,请确认");
+        for(Long l:bomProcedureMap.keySet()){
+            isFalse(bomProcedureMap.get(l).size()==0,"零件尚未配置工序,请确认");
+        }
+
+        //验证炉号
+        if(detailList != null && detailList.size() > 0){
+            List<String> furnaceBatchList = detailList.stream().map(p -> p.get("furnaceBatchNo").toString()).collect(Collectors.toList());
+            List<MMeterialReceiveLog> meterialReceiveLogList = meterialReceiveLogService.list(Wraps.<MMeterialReceiveLog>lbQ().in(MMeterialReceiveLog::getFurnaceBatchNo,furnaceBatchList));
+            Map<String,MMeterialReceiveLog> meterialReceiveLogMap = meterialReceiveLogList.stream().collect(Collectors.toMap(t->t.getFurnaceBatchNo().toString(), t->t));
+            List<MMeterialReceiveLog>l = new ArrayList<MMeterialReceiveLog>();
+            for(Map map:detailList){
+                String furnaceBatchNo = map.get("furnaceBatchNo")==null?"":map.get("furnaceBatchNo").toString();
+                int bomNum = Double.valueOf(map.get("bomNum").toString()).intValue();
+                MMeterialReceiveLog m = meterialReceiveLogMap.get(furnaceBatchNo);
+                map.put("meterialReceiveId",m.getId());
+                int usedNum = (m.getUsedNum()==null?0:m.getUsedNum());
+                isFalse(bomNum>m.getBatchStand()-usedNum,"零件数超出");
+                m.setUsedNum(bomNum+usedNum);
+                l.add(m);
+            }
+            //修改已用数量
+            meterialReceiveLogService.saveOrUpdateBatch(l);
+        }
+
+        //根据编码规则
+        String no = codeRuleService.getBillCode(CodeRuleModule.CODE_RULE_ORDER);
+        order.setOrderNo(no);
+        super.save(order);
+
+        int productNum = 0;
+        if(detailList != null && detailList.size() > 0){
+            for(Map map:detailList){
+                OrderProduct item = new OrderProduct();
+                item.setOrderId(order.getId());
+                item.setOrderNo(order.getOrderNo());
+                item.setFurnaceBatchNo(map.get("furnaceBatchNo").toString());
+                item.setMeterialReceiveId(Long.parseLong(map.get("meterialReceiveId").toString()));
+                item.setBomId(Long.parseLong(map.get("bomId").toString()));
+                item.setBomNum(Double.valueOf(map.get("bomNum").toString()).intValue());
+                productNum+=item.getBomNum();
+                if(map.get("deliveryTime")!=null){
+                    item.setDeliveryTime(DateUtil.stringToDate3(map.get("deliveryTime").toString()));
+                }
+                item.setRemark(map.get("remark")==null?"":map.get("remark").toString());
+                orderProductService.save(item);
+            }
+        }
+
+        order.setProductNum(productNum);
+        baseMapper.updateAllById(order);
+        return R.success(true);
+    }
 }

+ 142 - 4
imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/operationManagementCenter/OrderController.java

@@ -1,10 +1,15 @@
 package com.github.zuihou.business.controller.operationManagementCenter;
 
 import cn.afterturn.easypoi.excel.ExcelExportUtil;
+import cn.afterturn.easypoi.excel.ExcelImportUtil;
+import cn.afterturn.easypoi.excel.entity.ImportParams;
 import cn.afterturn.easypoi.excel.entity.TemplateExportParams;
+import cn.afterturn.easypoi.excel.entity.result.ExcelImportResult;
 import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.StrUtil;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.github.zuihou.authority.dto.auth.UserExcelVO;
+import com.github.zuihou.authority.entity.auth.User;
 import com.github.zuihou.base.request.PageParams;
 import com.github.zuihou.business.operationManagementCenter.entity.Order;
 import com.github.zuihou.business.operationManagementCenter.dto.OrderSaveDTO;
@@ -26,30 +31,41 @@ import java.util.Map;
 import java.util.stream.Collectors;
 import com.github.zuihou.base.controller.SuperController;
 import com.github.zuihou.base.R;
+import com.github.zuihou.common.constant.BizConstant;
+import com.github.zuihou.common.constant.CodeRuleModule;
+import com.github.zuihou.common.constant.DictionaryType;
+import com.github.zuihou.common.util.DateUtil;
 import com.github.zuihou.common.util.StringUtil;
 import com.github.zuihou.database.mybatis.conditions.Wraps;
 import com.github.zuihou.database.mybatis.conditions.query.LbqWrapper;
 import com.github.zuihou.database.mybatis.conditions.query.QueryWrap;
 import com.github.zuihou.log.annotation.SysLog;
+import com.github.zuihou.model.RemoteData;
 import com.github.zuihou.security.annotation.LoginUser;
 import com.github.zuihou.security.model.SysUser;
+import com.github.zuihou.utils.MapHelper;
+import com.github.zuihou.utils.StrPool;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.collections.map.HashedMap;
 import org.apache.poi.hssf.usermodel.*;
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.ss.util.CellRangeAddressList;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.validation.annotation.Validated;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.*;
 import com.github.zuihou.security.annotation.PreAuth;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
 import springfox.documentation.annotations.ApiIgnore;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import javax.validation.groups.Default;
 
 
 /**
@@ -215,4 +231,126 @@ public class OrderController extends SuperController<OrderService, Long, Order,
 
     }
 
+    @Override
+    public R<Boolean> importExcel(@RequestParam("file") MultipartFile simpleFile, HttpServletRequest request,
+                                  HttpServletResponse response) throws Exception {
+
+        List<List<Object>> excelOrders = getBankListByExcel(simpleFile.getInputStream(), simpleFile.getOriginalFilename());
+        simpleFile.getInputStream().close();
+        if(excelOrders.size() < 3){
+            return this.validFail("导入数据订单明细不能为空");
+        }
+        Order order = new Order();
+        List<Object> orderInfo = excelOrders.get(0);
+        if(orderInfo.size() != 6){
+            return this.validFail("导入订单数据不完整");
+        }
+
+        String zZoneInfo = String.valueOf(orderInfo.get(5));
+        String[] zZoneInfos = zZoneInfo.split("-");
+        if(zZoneInfos.length != 2){
+            return this.validFail("导入订单数据所属产线不正确");
+        }
+        order.setSource("1");
+        order.setOrderStatus("1");
+        order.setStatus("1");
+        order.setOrderName(String.valueOf(orderInfo.get(1)));
+        order.setZoneId(Long.parseLong(zZoneInfos[0]));
+        order.setCustId(Long.parseLong("0"));
+        order.setOrderTime(DateUtil.stringToDate3(String.valueOf(orderInfo.get(3))));
+
+        List<Map> detailList = new ArrayList<>();
+        for(int i = 0; i < excelOrders.size(); i++){
+            // 遍历订单产品
+            if(i > 1){
+                Map orderProduct = new HashedMap();
+                List<Object> line = excelOrders.get(i);
+                // 零件
+                String[] bbomInfos = String.valueOf(line.get(0)).split("-");
+                if(bbomInfos.length != 2){
+                    return this.validFail("导入订单数据第" + "行零件名称不正确");
+                }
+                orderProduct.put("bomId",bbomInfos[0]);
+
+                // 原材料原炉号
+                String[] furnaceBatchNoInfos = String.valueOf(line.get(1)).split("-");
+                if(furnaceBatchNoInfos.length != 4){
+                    return this.validFail("导入订单数据第" + "行零件原材料原炉批号不正确");
+                }
+                orderProduct.put("furnaceBatchNo",furnaceBatchNoInfos[2]);
+                orderProduct.put("bomNum",line.get(2));
+                orderProduct.put("deliveryTime",line.get(3));
+                orderProduct.put("remark",line.get(4));
+
+                detailList.add(orderProduct);
+            }
+        }
+        return baseService.saveExcelOrder(order,detailList);
+
+    }
+
+    /**
+     * 处理上传的文件
+     *
+     * @param in
+     * @param fileName
+     * @return
+     * @throws Exception
+     */
+    private List getBankListByExcel(InputStream in, String fileName) throws Exception {
+        List list = new ArrayList<>();
+        //创建Excel工作薄
+        Workbook work = this.getWorkbook(in, fileName);
+        if (null == work) {
+            throw new Exception("创建Excel工作薄为空!");
+        }
+        Sheet sheet = null;
+        Row row = null;
+        Cell cell = null;
+
+        for (int i = 0; i < work.getNumberOfSheets(); i++) {
+            sheet = work.getSheetAt(i);
+            if (sheet == null) {
+                continue;
+            }
+
+            for (int j = sheet.getFirstRowNum(); j <= sheet.getLastRowNum(); j++) {
+                row = sheet.getRow(j);
+                if (row == null || row.getFirstCellNum() == j) {
+                    continue;
+                }
+
+                List<Object> li = new ArrayList<>();
+                for (int y = row.getFirstCellNum(); y < row.getLastCellNum(); y++) {
+                    cell = row.getCell(y);
+                    li.add(cell);
+                }
+                list.add(li);
+            }
+        }
+        work.close();
+        return list;
+    }
+
+    /**
+     * 判断文件格式
+     *
+     * @param inStr
+     * @param fileName
+     * @return
+     * @throws Exception
+     */
+    private Workbook getWorkbook(InputStream inStr, String fileName) throws Exception {
+        Workbook workbook = null;
+        String fileType = fileName.substring(fileName.lastIndexOf("."));
+        if (".xls".equals(fileType)) {
+            workbook = new HSSFWorkbook(inStr);
+        } else if (".xlsx".equals(fileType)) {
+            workbook = new XSSFWorkbook(inStr);
+        } else {
+            throw new Exception("请上传excel文件!");
+        }
+        return workbook;
+    }
+
 }