chenlu
2024-03-08 062822b57a29a767f2fbbd7cc1a8b1f6417cf966
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
 
package com.example.erp.service.pp;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.erp.entity.pp.ProductionScheduling;
import com.example.erp.entity.sd.OrderDetail;
import com.example.erp.mapper.pp.ProductionSchedulingMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@Service
@DS("pp")
public class ProductionSchedulingService {
    @Autowired
    ProductionSchedulingMapper productionSchedulingMapper;
 
    //未排产查询
    public Map<String, Object> selectSchedulingSv(String selectTime1, String selectTime2, String orderId,String processes, Integer state, ProductionScheduling productionScheduling ) {
        Map<String, Object> map = new HashMap<>();
        if(orderId.equals("null")){
            orderId="";
        }
        if (processes.equals("null")){
 
            processes="";
        }
 
        if (state==2){//已排产
            map.put("data", productionSchedulingMapper.selectOkSchedulingMp(selectTime1, selectTime2,orderId,processes, productionScheduling));
 
        }else if (state==1){//未排产
            map.put("data", productionSchedulingMapper.selectNoSchedulingMp(selectTime1, selectTime2,orderId,processes, productionScheduling));
 
        }
 
        return map;
    }
 
 
    //首次查询排产数据
    public Map<String, Object> selectLastScheduling(String selectTime1, String selectTime2,ProductionScheduling productionScheduling ) {
        Map<String, Object> map = new HashMap<>();
        map.put("data", productionSchedulingMapper.selectLastSchedulingMp(selectTime1, selectTime2, productionScheduling));
        map.put("process", productionSchedulingMapper.selectProcess());
        return map;
    }
 
    //带订单号查询
    public Map<String, Object> selectSchedulingNotSv(String selectTime1, String selectTime2, String orderId, String processes, Integer state, ProductionScheduling productionScheduling) {
        Map<String, Object> map = new HashMap<>();
        map.put("data", productionSchedulingMapper.selectSchedulingNotMp(selectTime1, selectTime2,orderId,processes, productionScheduling));
        return map;
    }
 
    public Boolean addSchedulingSv(Map<String, Object> object) {
        String userName = "";
        if (object.get("userName") != null) {
            userName = object.get("userName").toString();
        }
        String processes = "";
        if (object.get("processes") != null) {
            processes = object.get("processes").toString();
        }
 
        Integer maxId = productionSchedulingMapper.selectMaxId();
        //查询订单id,并且自增
        String formattedNumber = String.format("%02d", maxId+1);
        //格式化当前日期
        java.util.Date currentDate = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMdd");
        String formattedDate = dateFormat.format(currentDate);
        String schedulingId =  "PC"+formattedDate+formattedNumber;
 
        List<ProductionScheduling> schedulinglist = JSONArray.parseArray(JSONObject.toJSONString(object.get("scheduling")), ProductionScheduling.class);
        if (!schedulinglist.isEmpty()) {
            for (ProductionScheduling productionScheduling : schedulinglist) {
                //查询已排产工序数量
              Integer num =  productionSchedulingMapper.selectNumberMp(productionScheduling.getOrderId(),productionScheduling.getOrderNumber(),processes);
 
               productionSchedulingMapper.insertSelective(schedulingId,productionScheduling.getOrderId(),productionScheduling.getOrderNumber(),processes,productionScheduling.getSchedulingQuantity(),productionScheduling.getScheduledStartTime(),productionScheduling.getPlanEndTime(),productionScheduling.getNotes());
               // System.out.println(productionScheduling.getOrderNumber()+"***"+productionScheduling.getOrderId());
            }
            return true;
        }
        else {
            return false;
 
        }
 
    }
 
    public boolean deleteSchedulingSv(Map<String, Object> object) throws Exception {
        JSONObject objJson = new JSONObject(object);
        List<ProductionScheduling> Scheduling = JSONArray.parseArray(JSONObject.toJSONString(objJson.get("scheduling")), ProductionScheduling.class);
        if (!Scheduling.isEmpty()) {
            for (ProductionScheduling productionScheduling : Scheduling) {
                productionSchedulingMapper.deleteSchedulingMp(productionScheduling.getSchedulingId());
                // System.out.println(productionScheduling.getOrderNumber()+"***"+productionScheduling.getOrderId());
            }
            return true;
        }
        else {
            return false;
        }
    }
 
    public boolean examineSchedulingSv(Map<String, Object> object) {
        String userName = "";
        if (object.get("userName") != null) {
            userName = object.get("userName").toString();
        }
        List<ProductionScheduling> schedulinglist = JSONArray.parseArray(JSONObject.toJSONString(object.get("scheduling")), ProductionScheduling.class);
 
        if (!schedulinglist.isEmpty()) {
            for (ProductionScheduling productionScheduling : schedulinglist) {
                productionSchedulingMapper.examineSchedulingMp(productionScheduling.getSchedulingId(),userName);
                // System.out.println(productionScheduling.getOrderNumber()+"***"+productionScheduling.getOrderId());
            }
            return true;
        }
        else {
            return false;
        }
    }
}