xiaochen před 2 roky
rodič
revize
9d636397a6

+ 3 - 0
build.gradle

@@ -42,6 +42,9 @@ dependencies {
     //rabbitMq
     implementation 'org.springframework.boot:spring-boot-starter-amqp'
     implementation 'org.springframework.boot:spring-boot-starter-security'
+    //oss
+    implementation 'com.aliyun:aliyun-java-sdk-core:4.5.13'
+    implementation 'com.aliyun.oss:aliyun-sdk-oss:3.10.2'
     implementation fileTree(dir:'lib',includes:['*jar'])
     annotationProcessor 'org.projectlombok:lombok'
     developmentOnly 'org.springframework.boot:spring-boot-devtools'

+ 12 - 0
src/main/java/com/model/controller/DispatchController.java

@@ -46,4 +46,16 @@ public class DispatchController {
         return dispatchService.updDispatch(dispatch);
     }
 
+    /** 
+    * @Description: 查询发货单列表
+    * @Param: dispatch
+    * @return: CommRes
+    * @Author: XiaoChen
+    * @Date: 2023/4/19
+    */
+    @GetMapping("getDispatchList")
+    private CommRes getDispatchList(Dispatch dispatch){
+        return dispatchService.getDispatchList(dispatch);
+    }
+
 }

+ 84 - 0
src/main/java/com/model/controller/UploadController.java

@@ -0,0 +1,84 @@
+package com.model.controller;
+
+import cn.hutool.core.date.DateUtil;
+
+import com.model.util.ossFileUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.multipart.MultipartFile;
+import java.text.SimpleDateFormat;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
+
+/**
+ * 上传接口
+ */
+@Controller
+@RequestMapping("upload")
+@Slf4j
+@CrossOrigin
+public class UploadController {
+
+    /**
+     * 上传
+     * @param file 文件
+     * @return 返回结果
+     */
+    @RequestMapping(value = "/uploadFile")
+    @ResponseBody
+    public Map<String, Object> upload(MultipartFile file) {
+        Map<String, Object> map = new HashMap<>();
+        if (!file.isEmpty()) {
+            try {
+                SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
+                String suffix = file.getOriginalFilename()
+                        .substring(file.getOriginalFilename().lastIndexOf("."));
+                // 生成文件名称
+                String nameSuffix = file.getOriginalFilename()
+                        .substring(0, file.getOriginalFilename().lastIndexOf("."))
+                        .replaceAll(" ", "_").replaceAll(",", "")
+                        + format.format(DateUtil.date())
+                        + new Random().nextInt(1000) + suffix;
+                //上传原始图片到阿里云
+                return ossFileUtil.uploadAliyun(file, nameSuffix);
+            } catch (Exception e) {
+                log.error("上传附件错误" + e.getMessage());
+                map.put("errMsg", "系统未知错误");
+                map.put("msg", "500");
+            }
+        } else {
+            map.put("msg", "500");
+            map.put("errMsg", "文件不能为空");
+        }
+        return map;
+    }
+
+    /**
+     * 删除文件
+     * @param fileName 文件名称
+     * @return 返回结果
+     */
+    @RequestMapping(value = "/delUpload")
+    @ResponseBody
+    public Map<String, Object> delUpload(String fileName) {
+        Map<String, Object> map = new HashMap<>();
+        if (!fileName.isEmpty()) {
+            try {
+                //删除文件
+                return ossFileUtil.delUploadAliyun(fileName);
+            } catch (Exception e) {
+                log.error("上传附件错误" + e.getMessage());
+                map.put("errMsg", "系统未知错误");
+                map.put("msg", "500");
+            }
+        } else {
+            map.put("msg", "500");
+            map.put("errMsg", "文件不能为空");
+        }
+        return map;
+    }
+}

+ 4 - 0
src/main/java/com/model/entity/Dispatch.java

@@ -48,6 +48,10 @@ public class Dispatch implements Serializable {
      * 图片
      */
     private String imgs;
+    /**
+     * uuid
+     */
+    private String uuid;
     /**
      * 实际到达时间
      */

+ 5 - 1
src/main/java/com/model/mapper/DispatchMapper.java

@@ -14,7 +14,11 @@ public interface DispatchMapper {
 
     Dispatch getDispatch(Dispatch map);
 
-    void addDispatchZ(@Param("truckNo") String truckNo, List<DispatchSublist> dataList);
+    void addDispatchZ(@Param("truckNo") String truckNo, List<DispatchSublist> dataList,@Param("uuid") String uuid);
 
     void updDispatch(Dispatch dispatch);
+
+    List<Dispatch> getDispatchList(Dispatch dispatch);
+
+    List<DispatchSublist> getDispatchLists(Dispatch dispatch1);
 }

+ 2 - 0
src/main/java/com/model/service/DispatchService.java

@@ -10,4 +10,6 @@ public interface DispatchService {
     CommRes addDispatch(Dispatch dispatch);
 
     CommRes updDispatch(Dispatch dispatch);
+
+    CommRes getDispatchList(Dispatch dispatch);
 }

+ 28 - 1
src/main/java/com/model/service/impl/DispatchServiceImpl.java

@@ -8,8 +8,10 @@ import com.model.service.DispatchService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
+import java.util.UUID;
 
 /**
  * @program: model
@@ -35,8 +37,10 @@ public class DispatchServiceImpl implements DispatchService {
     public CommRes addDispatch(Dispatch dispatch) {
         Dispatch dispatch1 = dispatchMapper.getDispatch(dispatch);
         if (dispatch1 == null) {
+            UUID uuid = UUID.randomUUID();
+            dispatch.setUuid(uuid.toString());
             dispatchMapper.addDispatch(dispatch);
-            dispatchMapper.addDispatchZ(dispatch.getTruckNo(), dispatch.getDataList());
+            dispatchMapper.addDispatchZ(dispatch.getTruckNo(), dispatch.getDataList(),dispatch.getUuid());
         } else {
             return CommRes.fail("发货单已上传");
         }
@@ -60,4 +64,27 @@ public class DispatchServiceImpl implements DispatchService {
         return CommRes.success(null);
     }
 
+    /**
+     * @Description: 查询发货单列表
+     * @Param: dispatch
+     * @return: CommRes
+     * @Author: XiaoChen
+     * @Date: 2023/4/19
+     */
+    @Override
+    public CommRes getDispatchList(Dispatch dispatch) {
+        LinkedList<Dispatch> linkedList = new LinkedList<>();
+        try {
+            List<Dispatch> list = dispatchMapper.getDispatchList(dispatch);
+            for (Dispatch dispatch1 : list) {
+                List<DispatchSublist> list1 = dispatchMapper.getDispatchLists(dispatch1);
+                dispatch1.setDataList(list1);
+                linkedList.add(dispatch1);
+            }
+        }catch (Exception e){
+            e.printStackTrace();
+        }
+        return CommRes.success(linkedList);
+    }
+
 }

+ 121 - 0
src/main/java/com/model/util/ossFileUtil.java

@@ -0,0 +1,121 @@
+package com.model.util;
+
+import com.aliyun.oss.ClientException;
+import com.aliyun.oss.OSS;
+import com.aliyun.oss.OSSClientBuilder;
+import com.aliyun.oss.OSSException;
+import org.springframework.web.multipart.MultipartFile;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 上传阿里云oos
+ */
+public class ossFileUtil {
+    /**
+     * 上传
+     * @param file 文件
+     * @param fileName 文件名称
+     * @return 返回路径
+     * @throws IOException 异常
+     */
+    public static Map<String, Object> uploadAliyun(MultipartFile file, String fileName) throws IOException {
+        Map<String, Object> map = new HashMap<>();
+        // 1 获取上传需要的固定值
+        String endpoint = "oss-cn-beijing.aliyuncs.com";     //你的站点
+        String accessKeyId = "LTAI5tGNYXMJNMWa1pBVqCYt";  //你的acess_key_id
+        String accessKeySecret = "M8f45Cysl13t0eAMzyd1vey2FvDaAz"; //你的acess_key_secret
+        String bucketName = "lidaotech";       //你的bucket_name
+        String objectName = "tuya/" + fileName;
+        //外面获取文件输入流,最后方便关闭
+        InputStream in = file.getInputStream();
+        //2 创建OssClient对象
+        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
+        try {
+            //3 获取文件信息,为了上传
+            // meta设置请求头
+//            ObjectMetadata meta = new ObjectMetadata();
+//            meta.setContentType("image/png");
+            //4 设置知道文件夹
+            ossClient.putObject(bucketName, objectName, in);
+            //5 关闭
+            ossClient.shutdown();
+            //6 返回上传之后地址,拼接地址
+            String uploadUrl = "https://" + bucketName + "." + endpoint + "/" + objectName;
+            map.put("data", uploadUrl);
+            map.put("msg", "200");
+            return map;
+        } catch (OSSException oe) {
+            System.out.println("Caught an OSSException, which means your request made it to OSS, "
+                    + "but was rejected with an error response for some reason.");
+            System.out.println("Error Message:" + oe.getErrorMessage());
+            System.out.println("Error Code:" + oe.getErrorCode());
+            System.out.println("Request ID:" + oe.getRequestId());
+            System.out.println("Host ID:" + oe.getHostId());
+            map.put("msg", "500");
+            return map;
+        } catch (ClientException ce) {
+            System.out.println("Caught an ClientException, which means the client encountered "
+                    + "a serious internal problem while trying to communicate with OSS, "
+                    + "such as not being able to access the network.");
+            System.out.println("Error Message:" + ce.getMessage());
+            map.put("msg", "500");
+            return map;
+        } finally {
+            //5 关闭ossClient
+            if (ossClient != null) {
+                ossClient.shutdown();
+            }
+            in.close();
+        }
+    }
+
+    /**
+     * 删除文件
+     * @param fileName 文件名称
+     * @return 返回路径
+     * @throws IOException 异常
+     */
+    public static Map<String, Object> delUploadAliyun(String fileName) throws IOException {
+        Map<String, Object> map = new HashMap<>();
+        // 1 获取上传需要的固定值
+        String endpoint = "oss-cn-beijing.aliyuncs.com";     //你的站点
+        String accessKeyId = "LTAI5tGNYXMJNMWa1pBVqCYt";  //你的acess_key_id
+        String accessKeySecret = "M8f45Cysl13t0eAMzyd1vey2FvDaAz"; //你的acess_key_secret
+        String bucketName = "lidaotech";       //你的bucket_name
+        String objectName = "tuya/" + fileName;
+        //2 创建OssClient对象
+        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
+        try {
+            //3 文件删除
+            ossClient.deleteObject(bucketName, objectName);
+            //4 关闭
+            ossClient.shutdown();
+            map.put("msg", "200");
+            return map;
+        } catch (OSSException oe) {
+            System.out.println("Caught an OSSException, which means your request made it to OSS, "
+                    + "but was rejected with an error response for some reason.");
+            System.out.println("Error Message:" + oe.getErrorMessage());
+            System.out.println("Error Code:" + oe.getErrorCode());
+            System.out.println("Request ID:" + oe.getRequestId());
+            System.out.println("Host ID:" + oe.getHostId());
+            map.put("msg", "500");
+            return map;
+        } catch (ClientException ce) {
+            System.out.println("Caught an ClientException, which means the client encountered "
+                    + "a serious internal problem while trying to communicate with OSS, "
+                    + "such as not being able to access the network.");
+            System.out.println("Error Message:" + ce.getMessage());
+            map.put("msg", "500");
+            return map;
+        } finally {
+            //5 关闭ossClient
+            if (ossClient != null) {
+                ossClient.shutdown();
+            }
+        }
+    }
+}

+ 46 - 5
src/main/resources/mapper/DispatchMapper.xml

@@ -5,15 +5,15 @@
 
     <!--添加发货单信息-->
     <insert id="addDispatch">
-        insert into sg_dispatch(truck_no,customer,scrq,arrival_time)
-        values  (#{truckNo},#{customer},now(),#{arrivalTime})
+        insert into sg_dispatch(truck_no,customer,scrq,arrival_time,uuid)
+        values  (#{truckNo},#{customer},now(),#{arrivalTime},#{uuid})
     </insert>
     <!--添加子表信息-->
     <insert id="addDispatchZ">
-        insert into sg_dispatch_z(truck_no,part_number,qty)
+        insert into sg_dispatch_z(truck_no,part_number,qty,uuid)
         values
         <foreach collection="dataList" index="index" item="item" separator=",">
-            (#{truckNo},#{item.partNumber},#{item.qty})
+            (#{truckNo},#{item.partNumber},#{item.qty},#{uuid})
         </foreach>
     </insert>
     <!--确认收货-->
@@ -25,5 +25,46 @@
     <select id="getDispatch" resultType="com.model.entity.Dispatch">
         select id,truck_no,customer,scrq from sg_dispatch where truck_no = #{truckNo} and customer = #{customer}
     </select>
-
+    <!--查询父表信息-->
+    <select id="getDispatchList" resultType="com.model.entity.Dispatch">
+        select
+            id,
+            truck_no,
+            customer,
+            scrq,
+            arrival_time,
+            anomaly,
+            note,
+            imgs,
+            final_time,
+            uuid
+        from sg_dispatch
+        <trim prefix="WHERE" prefixOverrides="and |or">
+            <if test="arrivalTime != null and arrivalTime != ''">
+                and arrival_time like CONCAT(CONCAT('%', #{arrivalTime}), '%')
+            </if>
+            <if test="finalTime != null and finalTime != ''">
+                and final_time like CONCAT(CONCAT('%', #{finalTime}), '%')
+            </if>
+            <if test="customer != null and customer != ''">
+                and customer = #{customer}
+            </if>
+            <if test="truckNo != null and truckNo != ''">
+                and truck_no = #{truckNo}
+            </if>
+            <if test="anomaly != null and anomaly != ''">
+                and anomaly = #{anomaly}
+            </if>
+        </trim>
+    </select>
+    <!--根据父表uuid查询子表信息-->
+    <select id="getDispatchLists" resultType="com.model.entity.DispatchSublist">
+        select
+            id,
+            truck_no,
+            part_number,
+            qty,
+            uuid
+        from sg_dispatch_z where uuid = #{uuid}
+    </select>
 </mapper>