瀏覽代碼

修改获取MES作业工单接口,现在调整为获取全部的工单而不是某一天的工单

xiaoyuzhang 1 天之前
父節點
當前提交
efdf48c8d9

+ 27 - 0
src/main/java/cn/mrdear/conf/CorsConfig.java

@@ -0,0 +1,27 @@
1
+package cn.mrdear.conf;
2
+
3
+import org.springframework.context.annotation.Bean;
4
+import org.springframework.context.annotation.Configuration;
5
+import org.springframework.web.cors.CorsConfiguration;
6
+import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
7
+import org.springframework.web.filter.CorsFilter;
8
+
9
+/**
10
+ * @Author: zxy
11
+ * @Date: create in 2025/4/9 9:35
12
+ */
13
+@Configuration
14
+public class CorsConfig {
15
+    @Bean
16
+    public CorsFilter corsFilter() {
17
+        final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
18
+        final CorsConfiguration config = new CorsConfiguration();
19
+        config.setAllowCredentials(true); // 允许cookies跨域
20
+        config.addAllowedOrigin("*");// 允许向该服务器提交请求的URI,*表示全部允许。。这里尽量限制来源域,比如http://xxxx:8080 ,以降低安全风险。。
21
+        config.addAllowedHeader("*");// 允许访问的头信息,*表示全部
22
+        config.setMaxAge(3600L);// 预检请求的缓存时间(秒),即在这个时间段里,对于相同的跨域请求不会再预检了
23
+        config.addAllowedMethod("*");// 允许提交请求的方法,*表示全部允许,也可以单独设置GET、PUT等
24
+        source.registerCorsConfiguration("/**", config);
25
+        return new CorsFilter(source);
26
+    }
27
+}

+ 90 - 0
src/main/java/cn/mrdear/controller/JobOrderController.java

@@ -0,0 +1,90 @@
1
+package cn.mrdear.controller;
2
+
3
+import cn.mrdear.entity.dto.ManuOrderDTO;
4
+import cn.mrdear.entity.dto.MesJobOrderDTO;
5
+import cn.mrdear.entity.dto.ProductDTO;
6
+import cn.mrdear.entity.vo.JobOrderListVO;
7
+import cn.mrdear.mapper.ManuOrderMapper;
8
+import cn.mrdear.mapper.MesJobOrderMapper;
9
+import cn.mrdear.mapper.ProductMapper;
10
+import cn.mrdear.util.DateUtil;
11
+import org.springframework.beans.factory.annotation.Autowired;
12
+import org.springframework.format.annotation.DateTimeFormat;
13
+import org.springframework.web.bind.annotation.*;
14
+
15
+import java.util.*;
16
+import java.util.stream.Collectors;
17
+
18
+/**
19
+ * @Author: zxy
20
+ * @Date: create in 2025/4/9 16:10
21
+ */
22
+@RestController()
23
+@RequestMapping("jobOrder")
24
+public class JobOrderController {
25
+    @Autowired
26
+    MesJobOrderMapper mesJobOrderMapper;
27
+    @Autowired
28
+    ProductMapper productMapper;
29
+    @Autowired
30
+    ManuOrderMapper manuOrderMapper;
31
+    @GetMapping("getList")
32
+    public Map<String,Object> getJobOrderList() {
33
+        HashMap<String, Object> resultMap = new HashMap<>();
34
+        List<JobOrderListVO> jobOrderListVOS = new ArrayList<>();
35
+        List<MesJobOrderDTO> jobOrderDTOList = mesJobOrderMapper.getListByDate();
36
+        if(jobOrderDTOList.size() == 0) {
37
+            resultMap.put("data",jobOrderListVOS);
38
+            return resultMap;
39
+        }
40
+        Map<Integer, List<MesJobOrderDTO>> ordersByYear = jobOrderDTOList.stream()
41
+                // 过滤掉 code 太短或格式不对的项(可选)
42
+                .filter(dto -> dto.getCode() != null && dto.getCode().length() >= 4)
43
+                .collect(Collectors.groupingBy(dto -> {
44
+                    String yy = dto.getCode().substring(2, 4);      // e.g. "25"
45
+                    int year = 2000 + Integer.parseInt(yy);         // 转成 2025
46
+                    return year;
47
+                }));
48
+        // 将map按年份倒序
49
+        Map<Integer, List<MesJobOrderDTO>> descByYear = new TreeMap<>(Comparator.reverseOrder());
50
+        descByYear.putAll(ordersByYear);
51
+        for (Map.Entry<Integer, List<MesJobOrderDTO>> entry : descByYear.entrySet()) {
52
+            Integer year = entry.getKey();
53
+            List<MesJobOrderDTO> listForYear = entry.getValue();
54
+            // 获取订单详情
55
+            List<String> manuOrderIds = listForYear.stream().map(MesJobOrderDTO::getEmesoManuorderId)
56
+                    .collect(Collectors.toList());
57
+            // 获取形体
58
+            List<String> productIds = listForYear.stream().map(MesJobOrderDTO::getmProductId).distinct()
59
+                    .collect(Collectors.toList());
60
+            List<ProductDTO> productDTOList = productMapper.getProductMap(productIds);
61
+            Map<String, String> productMap = productDTOList.stream().collect(Collectors.toMap(ProductDTO::getmProductId, ProductDTO::getValue));
62
+            String tableName = "emeso_manuorder_" + year;
63
+            List<ManuOrderDTO> manuOrderList = manuOrderMapper.getManuOrderList(tableName, manuOrderIds);
64
+            Map<String, ManuOrderDTO> manuOrderDTOMap = manuOrderList.stream().collect(Collectors.toMap(ManuOrderDTO::getManuOrderId, o -> o));
65
+            for (MesJobOrderDTO mesJobOrderDTO : listForYear) {
66
+                JobOrderListVO jobOrderListVO = new JobOrderListVO();
67
+                jobOrderListVO.setJobOrderId(mesJobOrderDTO.getEmesoJobOrderId());
68
+                jobOrderListVO.setCode(mesJobOrderDTO.getCode()); // 工单号
69
+                jobOrderListVO.setQty(mesJobOrderDTO.getQty()); // 数量
70
+                jobOrderListVO.setDescription(mesJobOrderDTO.getDescription());
71
+                jobOrderListVO.setColor(mesJobOrderDTO.getColor());
72
+                jobOrderListVO.setType(mesJobOrderDTO.getType());
73
+                String mProductId = mesJobOrderDTO.getmProductId();
74
+                if(productMap.containsKey(mProductId)) {
75
+                    jobOrderListVO.setGoodsCode(productMap.get(mProductId));
76
+                }
77
+                String emesoManuorderId = mesJobOrderDTO.getEmesoManuorderId();
78
+                if(manuOrderDTOMap.containsKey(emesoManuorderId)) {
79
+                    ManuOrderDTO manuOrderDTO = manuOrderDTOMap.get(emesoManuorderId);
80
+                    jobOrderListVO.setOrderCode(manuOrderDTO.getOrderCode());
81
+                    jobOrderListVO.setShoesSize(manuOrderDTO.getSizeCode());
82
+                }
83
+                jobOrderListVOS.add(jobOrderListVO);
84
+            }
85
+        }
86
+        resultMap.put("data",jobOrderListVOS);
87
+        return resultMap;
88
+    }
89
+
90
+}

+ 35 - 0
src/main/java/cn/mrdear/entity/dto/ManuOrderDTO.java

@@ -0,0 +1,35 @@
1
+package cn.mrdear.entity.dto;
2
+
3
+/**
4
+ * @Author: zxy
5
+ * @Date: create in 2025/4/10 10:41
6
+ */
7
+public class ManuOrderDTO {
8
+    private String manuOrderId;
9
+    private String orderCode; // 订单号
10
+    private String sizeCode; // 尺码
11
+
12
+    public String getManuOrderId() {
13
+        return manuOrderId;
14
+    }
15
+
16
+    public void setManuOrderId(String manuOrderId) {
17
+        this.manuOrderId = manuOrderId;
18
+    }
19
+
20
+    public String getOrderCode() {
21
+        return orderCode;
22
+    }
23
+
24
+    public void setOrderCode(String orderCode) {
25
+        this.orderCode = orderCode;
26
+    }
27
+
28
+    public String getSizeCode() {
29
+        return sizeCode;
30
+    }
31
+
32
+    public void setSizeCode(String sizeCode) {
33
+        this.sizeCode = sizeCode;
34
+    }
35
+}

+ 98 - 0
src/main/java/cn/mrdear/entity/dto/MesJobOrderDTO.java

@@ -0,0 +1,98 @@
1
+package cn.mrdear.entity.dto;
2
+
3
+import com.alibaba.fastjson.annotation.JSONField;
4
+
5
+import java.io.Serializable;
6
+import java.util.Date;
7
+
8
+/**
9
+ * @Author: zxy
10
+ * @Date: create in 2025/4/9 17:27
11
+ */
12
+public class MesJobOrderDTO implements Serializable {
13
+    private static final long serialVersionUID = 1L;
14
+    private String emesoJobOrderId;
15
+    private String emesoManuorderId;
16
+
17
+    @JSONField(format="yyyy-MM-dd HH:mm:ss")
18
+    private Date created;
19
+    private String code;
20
+    private Integer qty;
21
+    private String description;
22
+    private String type; // 楦型
23
+    private String color; // 颜色
24
+
25
+    private String mProductId;
26
+
27
+    public String getEmesoJobOrderId() {
28
+        return emesoJobOrderId;
29
+    }
30
+
31
+    public void setEmesoJobOrderId(String emesoJobOrderId) {
32
+        this.emesoJobOrderId = emesoJobOrderId;
33
+    }
34
+
35
+    public String getType() {
36
+        return type;
37
+    }
38
+
39
+    public void setType(String type) {
40
+        this.type = type;
41
+    }
42
+
43
+    public String getColor() {
44
+        return color;
45
+    }
46
+
47
+    public void setColor(String color) {
48
+        this.color = color;
49
+    }
50
+
51
+    public Date getCreated() {
52
+        return created;
53
+    }
54
+
55
+    public void setCreated(Date created) {
56
+        this.created = created;
57
+    }
58
+
59
+    public String getCode() {
60
+        return code;
61
+    }
62
+
63
+    public void setCode(String code) {
64
+        this.code = code;
65
+    }
66
+
67
+    public Integer getQty() {
68
+        return qty;
69
+    }
70
+
71
+    public void setQty(Integer qty) {
72
+        this.qty = qty;
73
+    }
74
+
75
+    public String getDescription() {
76
+        return description;
77
+    }
78
+
79
+    public void setDescription(String description) {
80
+        this.description = description;
81
+    }
82
+
83
+    public String getEmesoManuorderId() {
84
+        return emesoManuorderId;
85
+    }
86
+
87
+    public void setEmesoManuorderId(String emesoManuorderId) {
88
+        this.emesoManuorderId = emesoManuorderId;
89
+    }
90
+
91
+    public String getmProductId() {
92
+        return mProductId;
93
+    }
94
+
95
+    public void setmProductId(String mProductId) {
96
+        this.mProductId = mProductId;
97
+    }
98
+}

+ 26 - 0
src/main/java/cn/mrdear/entity/dto/ProductDTO.java

@@ -0,0 +1,26 @@
1
+package cn.mrdear.entity.dto;
2
+
3
+/**
4
+ * @Author: zxy
5
+ * @Date: create in 2025/4/9 16:29
6
+ */
7
+public class ProductDTO {
8
+    private String mProductId; // 产品id
9
+    private String value; // 形体名称
10
+
11
+    public String getmProductId() {
12
+        return mProductId;
13
+    }
14
+
15
+    public void setmProductId(String mProductId) {
16
+        this.mProductId = mProductId;
17
+    }
18
+
19
+    public String getValue() {
20
+        return value;
21
+    }
22
+
23
+    public void setValue(String value) {
24
+        this.value = value;
25
+    }
26
+}

+ 93 - 0
src/main/java/cn/mrdear/entity/vo/JobOrderListVO.java

@@ -0,0 +1,93 @@
1
+package cn.mrdear.entity.vo;
2
+
3
+/**
4
+ * @Author: zxy
5
+ * @Date: create in 2025/4/9 16:11
6
+ */
7
+
8
+public class JobOrderListVO {
9
+
10
+    private String jobOrderId; // 订单id
11
+    private String goodsCode; // 形体
12
+    private String color; // 颜色
13
+    private String shoesSize; // 尺码
14
+    private String type; // 楦型
15
+    private Integer qty; // 数量
16
+    private String orderCode; // 订单号 117429040931-67090
17
+    private String code; // 工单号
18
+    private String description; // 备注
19
+
20
+
21
+    public String getJobOrderId() {
22
+        return jobOrderId;
23
+    }
24
+
25
+    public void setJobOrderId(String jobOrderId) {
26
+        this.jobOrderId = jobOrderId;
27
+    }
28
+
29
+    public String getDescription() {
30
+        return description;
31
+    }
32
+
33
+    public void setDescription(String description) {
34
+        this.description = description;
35
+    }
36
+
37
+
38
+    public String getGoodsCode() {
39
+        return goodsCode;
40
+    }
41
+
42
+    public void setGoodsCode(String goodsCode) {
43
+        this.goodsCode = goodsCode;
44
+    }
45
+
46
+    public String getColor() {
47
+        return color;
48
+    }
49
+
50
+    public void setColor(String color) {
51
+        this.color = color;
52
+    }
53
+
54
+    public String getShoesSize() {
55
+        return shoesSize;
56
+    }
57
+
58
+    public void setShoesSize(String shoesSize) {
59
+        this.shoesSize = shoesSize;
60
+    }
61
+
62
+    public String getType() {
63
+        return type;
64
+    }
65
+
66
+    public void setType(String type) {
67
+        this.type = type;
68
+    }
69
+
70
+    public Integer getQty() {
71
+        return qty;
72
+    }
73
+
74
+    public void setQty(Integer qty) {
75
+        this.qty = qty;
76
+    }
77
+
78
+    public String getOrderCode() {
79
+        return orderCode;
80
+    }
81
+
82
+    public void setOrderCode(String orderCode) {
83
+        this.orderCode = orderCode;
84
+    }
85
+
86
+    public String getCode() {
87
+        return code;
88
+    }
89
+
90
+    public void setCode(String code) {
91
+        this.code = code;
92
+    }
93
+}

+ 16 - 0
src/main/java/cn/mrdear/mapper/ManuOrderMapper.java

@@ -0,0 +1,16 @@
1
+package cn.mrdear.mapper;
2
+
3
+import cn.mrdear.entity.dto.ManuOrderDTO;
4
+import org.apache.ibatis.annotations.Mapper;
5
+import org.apache.ibatis.annotations.Param;
6
+
7
+import java.util.List;
8
+
9
+/**
10
+ * @Author: zxy
11
+ * @Date: create in 2025/4/10 10:38
12
+ */
13
+@Mapper
14
+public interface ManuOrderMapper {
15
+    List<ManuOrderDTO> getManuOrderList(@Param("tableName") String tableName,@Param("manuOrderIds") List<String> manuOrderIds);
16
+}

+ 17 - 0
src/main/java/cn/mrdear/mapper/MesJobOrderMapper.java

@@ -0,0 +1,17 @@
1
+package cn.mrdear.mapper;
2
+
3
+import cn.mrdear.entity.dto.MesJobOrderDTO;
4
+import org.apache.ibatis.annotations.Mapper;
5
+import org.apache.ibatis.annotations.Param;
6
+
7
+import java.util.Date;
8
+import java.util.List;
9
+
10
+/**
11
+ * @Author: zxy
12
+ * @Date: create in 2025/4/9 16:54
13
+ */
14
+@Mapper
15
+public interface MesJobOrderMapper {
16
+    List<MesJobOrderDTO> getListByDate();
17
+}

+ 21 - 0
src/main/java/cn/mrdear/mapper/ProductMapper.java

@@ -0,0 +1,21 @@
1
+package cn.mrdear.mapper;
2
+
3
+import cn.mrdear.entity.dto.ProductDTO;
4
+import org.apache.ibatis.annotations.Mapper;
5
+import org.apache.ibatis.annotations.Param;
6
+import org.apache.ibatis.annotations.Select;
7
+
8
+import java.util.List;
9
+import java.util.Map;
10
+
11
+/**
12
+ * @Author: zxy
13
+ * @Date: create in 2025/4/10 10:06
14
+ */
15
+@Mapper
16
+public interface ProductMapper {
17
+
18
+
19
+    List<ProductDTO> getProductMap(@Param("productIds") List<String> productIds);
20
+//    Map<String,String> getProductMap(@Param("productIds")List<String> productIds);
21
+}

+ 50 - 0
src/main/java/cn/mrdear/util/DateUtil.java

@@ -0,0 +1,50 @@
1
+package cn.mrdear.util;
2
+
3
+import java.text.ParseException;
4
+import java.text.SimpleDateFormat;
5
+import java.util.Date;
6
+
7
+/**
8
+ * @Author: zxy
9
+ * @Date: create in 2025/4/10 9:42
10
+ */
11
+public class DateUtil {
12
+    public static final String YEAR_PATTERN = "yyyy";
13
+    public final static String DATE_PATTERN = "yyyy-MM-dd";
14
+    /** 时间格式(yyyy-MM-dd HH:mm:ss) */
15
+    public final static String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
16
+
17
+    public static Date string2Date(String strDate) {
18
+        return toDate(strDate,DATE_PATTERN);
19
+    }
20
+
21
+    public static  Date string2Time(String strDate) {
22
+        return toDate(strDate,DATE_TIME_PATTERN);
23
+    }
24
+    public static  Date toDate(String strDate, String PATTERN) {
25
+        SimpleDateFormat sdf = new SimpleDateFormat(PATTERN);
26
+        try {
27
+            return sdf.parse(strDate);
28
+        } catch (ParseException e) {
29
+            e.printStackTrace(); // 在实际应用中,可能会选择记录日志而不是打印堆栈跟踪
30
+            return null; // 或根据你的错误处理策略,可能会抛出一个自定义异常
31
+        }
32
+    }
33
+    public static String yearFormat(Date date) {return format(date,YEAR_PATTERN);}
34
+
35
+    public static String dateFormat(Date date) {
36
+        return format(date,DATE_PATTERN);
37
+    }
38
+
39
+    public static String timeFormat(Date date) {
40
+        return format(date,DATE_TIME_PATTERN);
41
+    }
42
+
43
+    public static String format(Date date, String pattern) {
44
+        if(date != null){
45
+            SimpleDateFormat df = new SimpleDateFormat(pattern);
46
+            return df.format(date);
47
+        }
48
+        return null;
49
+    }
50
+}

+ 19 - 0
src/main/resources/mapper/ManuOrderMapper.xml

@@ -0,0 +1,19 @@
1
+<?xml version="1.0" encoding="UTF-8" ?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
3
+<mapper namespace="cn.mrdear.mapper.ManuOrderMapper">
4
+    <resultMap id="ManuOrderMap" type="cn.mrdear.entity.dto.ManuOrderDTO">
5
+        <id property="manuOrderId" column="emeso_manuorder_id"></id>
6
+        <result property="orderCode" column="code"></result>
7
+        <result property="sizeCode" column="foot_size_code"></result>
8
+    </resultMap>
9
+
10
+    <select id="getManuOrderList" resultMap="ManuOrderMap">
11
+        SELECT emeso_manuorder_id,code,foot_size_code
12
+        FROM ${tableName}
13
+        WHERE emeso_manuorder_id IN
14
+        <foreach collection="manuOrderIds" item="manuOrderId" index="index" open="(" separator="," close=")">
15
+            #{manuOrderId}
16
+        </foreach>
17
+    </select>
18
+
19
+</mapper>

+ 20 - 0
src/main/resources/mapper/MesJobOrderMapper.xml

@@ -0,0 +1,20 @@
1
+<?xml version="1.0" encoding="UTF-8" ?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
3
+<mapper namespace="cn.mrdear.mapper.MesJobOrderMapper">
4
+    <resultMap id="mesJobOrderMap" type="cn.mrdear.entity.dto.MesJobOrderDTO">
5
+        <id property="emesoJobOrderId" column="emeso_job_order_id"></id>
6
+        <result property="emesoManuorderId" column="emeso_manuorder_id"></result>
7
+        <result property="created" column="created"></result>
8
+        <result property="code" column="code"></result>
9
+        <result property="color" column="color"></result>
10
+        <result property="type" column="type"></result>
11
+        <result property="qty" column="qty"></result>
12
+        <result property="description" column="description"></result>
13
+        <result property="mProductId" column="m_product_id"></result>
14
+    </resultMap>
15
+    <select id="getListByDate" resultMap="mesJobOrderMap">
16
+        select emeso_job_order_id, emeso_manuorder_id, created, code,color,type, qty, description, m_product_id
17
+        from emeso_job_order where status in('START','CREATE') order by code desc ;
18
+    </select>
19
+
20
+</mapper>

+ 24 - 0
src/main/resources/mapper/ProductMapper.xml

@@ -0,0 +1,24 @@
1
+<?xml version="1.0" encoding="UTF-8" ?>
2
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
3
+<mapper namespace="cn.mrdear.mapper.ProductMapper">
4
+    <resultMap id="productMap" type="cn.mrdear.entity.dto.ProductDTO">
5
+        <id property="mProductId" column="m_product_id"></id>
6
+        <result property="value" column="value"></result>
7
+    </resultMap>
8
+<!--    <select id="getProductMap" resultMap="">-->
9
+<!--        select m_product_id,value-->
10
+<!--        from m_product where m_product_id in-->
11
+<!--        <foreach collection="productIds" item="productId" open="(" separator="," close=")">-->
12
+<!--            #{productId}-->
13
+<!--        </foreach>-->
14
+<!--    </select>-->
15
+    <select id="getProductMap" resultMap="productMap">
16
+        SELECT m_product_id , value
17
+        FROM m_product
18
+        WHERE m_product_id IN
19
+        <foreach collection="productIds" item="productId" index="index" open="(" separator="," close=")">
20
+            #{productId}
21
+        </foreach>
22
+    </select>
23
+
24
+</mapper>