Ver código fonte

后端MES功能处理

oyq28 3 meses atrás
pai
commit
c74f1d08ee

+ 10 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/externalApi/dao/MesAttachmentMapper.java

@@ -0,0 +1,10 @@
+package com.github.zuihou.business.externalApi.dao;
+
+import com.github.zuihou.base.mapper.SuperMapper;
+import com.github.zuihou.business.externalApi.entity.MesAttachment;
+import org.springframework.stereotype.Repository;
+
+@Repository
+public interface MesAttachmentMapper extends SuperMapper<MesAttachment> {
+
+}

+ 11 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/externalApi/service/MesAttachmentService.java

@@ -0,0 +1,11 @@
+package com.github.zuihou.business.externalApi.service;
+
+import com.github.zuihou.base.service.SuperService;
+import com.github.zuihou.business.externalApi.entity.MesAttachment;
+import com.github.zuihou.business.externalApi.entity.MesNotice;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+
+public interface MesAttachmentService extends SuperService<MesAttachment> {
+}

+ 13 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/externalApi/service/impl/MesAttachmentServiceImpl.java

@@ -0,0 +1,13 @@
+package com.github.zuihou.business.externalApi.service.impl;
+
+import com.github.zuihou.base.service.SuperServiceImpl;
+import com.github.zuihou.business.externalApi.dao.MesAttachmentMapper;
+import com.github.zuihou.business.externalApi.entity.MesAttachment;
+import com.github.zuihou.business.externalApi.service.MesAttachmentService;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Service;
+
+@Slf4j
+@Service
+public class MesAttachmentServiceImpl extends SuperServiceImpl<MesAttachmentMapper, MesAttachment> implements MesAttachmentService {
+}

+ 156 - 0
imcs-admin-boot/imcs-business-biz/src/main/java/com/github/zuihou/business/util/ZipFileUtils.java

@@ -0,0 +1,156 @@
+package com.github.zuihou.business.util;
+
+import com.github.zuihou.business.externalApi.entity.MesAttachment;
+import com.github.zuihou.file.entity.Attachment;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.*;
+import java.net.URL;
+import java.net.URLConnection;
+import java.nio.file.Files;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+public class ZipFileUtils {
+
+        /**
+         * web下载打成压缩包的文件--流方式
+         *
+         * @param response 响应
+         * @param fileList 文件列表
+         * @param zipName  压缩包名
+         */
+        public static void downloadZipFiles(HttpServletResponse response, List<String> fileList, String zipName) {
+            ZipOutputStream zipOutputStream = null;
+            try {
+                //设置响应头
+                response.reset();
+                response.setContentType("application/octet-stream");
+                response.setCharacterEncoding("utf-8");
+                //设置文件名称
+                response.setHeader("Content-Disposition", "attachment;filename=" + zipName);
+                zipOutputStream = new ZipOutputStream(response.getOutputStream());
+                for (String file : fileList) {
+                    toZip(zipOutputStream, new File(file));
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+                throw new RuntimeException(e);
+            } finally {
+                //关闭资源
+                if (null != zipOutputStream) {
+                    try {
+                        zipOutputStream.close();
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+        }
+
+        /**
+         * 压缩文件
+         *
+         * @param zipOutputStream 压缩文件流
+         * @param file            待压缩文件
+         */
+        private static void toZip(ZipOutputStream zipOutputStream, File file) {
+            String filename = file.getName();
+            BufferedInputStream bis = null;
+            try {
+                bis = new BufferedInputStream(Files.newInputStream(file.toPath()));
+                //设置压缩包内文件的名称
+                zipOutputStream.putNextEntry(new ZipEntry(filename));
+                int size;
+                byte[] buffer = new byte[4096];
+                while ((size = bis.read(buffer)) > 0) {
+                    zipOutputStream.write(buffer, 0, size);
+                }
+                zipOutputStream.closeEntry();
+            } catch (Exception e) {
+                e.printStackTrace();
+                throw new RuntimeException(e);
+            } finally {
+                //关闭资源
+                if (null != bis) {
+                    try {
+                        bis.close();
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+        }
+
+    /**
+     * 批量文件压缩下载
+     * @param urlList 需要批量下载文件的链接地址列表
+     * @param zipName 输出的压缩包名称
+     */
+    public static void downZip(List<MesAttachment> urlList, String zipName, HttpServletRequest request, HttpServletResponse response){
+        //响应头的设置
+        response.reset();
+        response.setCharacterEncoding("utf-8");
+        response.setContentType("multipart/form-data");
+        String downloadName = zipName+".zip";
+        //返回客户端浏览器的版本号、类型
+        String agent = request.getHeader("USER-AGENT");
+        try {
+            //针对IE或者以IE为内核的浏览器:
+            if (agent.contains("MSIE")||agent.contains("Trident")) {
+                downloadName = java.net.URLEncoder.encode(downloadName, "UTF-8");
+            } else {
+                //非IE浏览器的处理:
+                downloadName = new String(downloadName.getBytes("UTF-8"),"ISO-8859-1");
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        response.setHeader("Content-Disposition", "attachment;fileName=\"" + downloadName + "\"");
+
+        //设置压缩流:直接写入response,实现边压缩边下载
+        ZipOutputStream zipos = null;
+        try {
+            zipos = new ZipOutputStream(new BufferedOutputStream(response.getOutputStream()));
+            zipos.setMethod(ZipOutputStream.DEFLATED); //设置压缩方法
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        //循环将文件写入压缩流
+        DataOutputStream os = null;
+
+        for (MesAttachment mesAttachment : urlList) {
+            try {
+                URL url = new URL(mesAttachment.getUrl());
+                URLConnection urlConnection = url.openConnection();
+                //File file = new File(mesAttachment.getUrl());
+                //此处应该加个文件是否存在的判断
+                String filename = mesAttachment.getName();
+                //添加ZipEntry,并ZipEntry中写入文件流
+                zipos.putNextEntry(new ZipEntry(filename));
+                os = new DataOutputStream(zipos);
+                InputStream is =  urlConnection.getInputStream();
+                byte[] b = new byte[1024];
+                int length = 0;
+                while((length = is.read(b))!= -1){
+                    os.write(b, 0, length);
+                }
+                is.close();
+                zipos.closeEntry();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+        //关闭流
+        try {
+            os.flush();
+            os.close();
+            zipos.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+}

+ 3 - 3
imcs-admin-boot/imcs-business-controller/src/main/java/com/github/zuihou/business/controller/externalApi/MesController.java

@@ -21,7 +21,7 @@ import com.github.zuihou.business.externalApi.dto.MesNoticeUpdateDTO;
 import com.github.zuihou.business.externalApi.entity.MesAttachment;
 import com.github.zuihou.business.externalApi.entity.MesNotice;
 import com.github.zuihou.business.externalApi.service.MesAttachmentService;
-import com.github.zuihou.business.externalApi.service.MesNoticeService;
+
 import com.github.zuihou.business.operationManagementCenter.entity.Order;
 import com.github.zuihou.business.operationManagementCenter.entity.OrderProduct;
 import com.github.zuihou.business.operationManagementCenter.service.OrderProductService;
@@ -320,7 +320,7 @@ public class MesController extends SuperController<MesNoticeService, Long, MesNo
 
               Order order = Order.builder().build();
               order.setOrderNo(workOrder.getString("workOrderNo")).setOrderTime(StringUtil.isNotEmpty(workOrder.getString("plannedStartTime"))?DateUtil.stringToDate3(workOrder.getString("plannedStartTime")):new Date()).setDeliveryTime(StringUtil.isNotEmpty(workOrder.getString("plannedEndTime"))?DateUtil.stringToDate3(workOrder.getString("plannedEndTime")): new Date()).setSource("2").setProductNum(workPieceList.size())
-                      .setStatus("1").setSingleTaskFlag("0").setOrderStatus("1").setBatchNo(workOrder.getString("batchNo"));
+                      .setStatus("1").setSingleTaskFlag(0).setOrderStatus("1").setBatchNo(workOrder.getString("batchNo"));
               //产品编码+生产类型编码(P/B P:按序列生产 B:按批次生产)+ 密级编码 + 批次号 + 工艺版本
               String orderName = "MES_"+workOrder.getString("materialCode")+"_"+workOrder.getString("productPhase").toUpperCase()+"_"+ workOrder.getString("planSecretLevel").toUpperCase() + "_" + workOrder.getString("batchNo") + "_"+workOrder.getString("processRouteVersion");
               order.setCustId(0L).setOrderName(orderName).setZoneId(zone.getId());
@@ -795,7 +795,7 @@ public class MesController extends SuperController<MesNoticeService, Long, MesNo
         //处理工单信息
         Order order = Order.builder().build();
         order.setOrderNo(workOrder.getString("workOrderNo")).setOrderTime(StringUtil.isNotEmpty(workOrder.getString("plannedStartTime"))?DateUtil.stringToDate3(workOrder.getString("plannedStartTime")):new Date()).setDeliveryTime(StringUtil.isNotEmpty(workOrder.getString("plannedEndTime"))?DateUtil.stringToDate3(workOrder.getString("plannedEndTime")): new Date()).setSource("2").setProductNum(workPieceList.size())
-                .setStatus("1").setSingleTaskFlag("0").setOrderStatus("1").setBatchNo(workOrder.getString("batchNo"));
+                .setStatus("1").setSingleTaskFlag(0).setOrderStatus("1").setBatchNo(workOrder.getString("batchNo"));
         //产品编码+生产类型编码(P/B P:按序列生产 B:按批次生产)+ 密级编码 + 批次号 + 工艺版本
         String orderName = "MES_"+workOrder.getString("materialCode")+"_"+workOrder.getString("productPhase").toUpperCase()+"_"+ workOrder.getString("planSecretLevel").toUpperCase() + "_" + workOrder.getString("batchNo") + "_"+workOrder.getString("processRouteVersion");
         order.setCustId(0L).setOrderName(orderName).setZoneId(zone.getId());

+ 11 - 1
imcs-admin-boot/imcs-business-entity/src/main/java/com/github/zuihou/business/operationManagementCenter/entity/Order.java

@@ -281,12 +281,21 @@ public class Order extends Entity<Long> {
     @TableField(exist = false)
     private Long planId;
 
+    /**
+     * 订单批次号
+     */
+    @ApiModelProperty(value = "订单批次号")
+    @Length(max = 255, message = "订单批次号长度不能超过255")
+    @TableField(value = "batch_no")
+    @Excel(name = "订单批次号")
+    private String batchNo;
+
 
     @Builder
     public Order(Long id, LocalDateTime createTime, LocalDateTime updateTime,
                     String orderNo, Long custId, Long zoneId, String source, String orderStatus, String auditStatus,
                     String status, String planStatus, Date orderTime, Date deliveryTime, String remark,
-                    Integer prority, String schedulingStatus, String rhythmType, String produceStatus) {
+                    Integer prority, String schedulingStatus, String rhythmType, String produceStatus, String batchNo) {
         this.id = id;
         this.createTime = createTime;
         this.updateTime = updateTime;
@@ -305,6 +314,7 @@ public class Order extends Entity<Long> {
         this.schedulingStatus = schedulingStatus;
         this.rhythmType = rhythmType;
         this.produceStatus = produceStatus;
+        this.batchNo = batchNo;
     }
 
 }

+ 2 - 1
imcs-admin-boot/imcs-business-entity/src/main/java/com/github/zuihou/business/productionReadyCenter/entity/MMeterialReceiveLog.java

@@ -150,7 +150,7 @@ public class MMeterialReceiveLog extends Entity<Long> {
     @Builder
     public MMeterialReceiveLog(Long id, LocalDateTime createTime, Long createUser, LocalDateTime updateTime, Long updateUser, 
                     Long meterialId, String furnaceBatchNo, String bomBatchNo, Integer batchStand, String factory, 
-                    String meterialBatchNo, Date factoryDate) {
+                    String meterialBatchNo, Date factoryDate,Integer usedNum) {
         this.id = id;
         this.createTime = createTime;
         this.createUser = createUser;
@@ -163,6 +163,7 @@ public class MMeterialReceiveLog extends Entity<Long> {
         this.factory = factory;
         this.meterialBatchNo = meterialBatchNo;
         this.factoryDate = factoryDate;
+        this.usedNum = usedNum;
     }
 
 }