OPC
懒羊羊
2023-12-13 21fde820e495c08cfa0ba277685468baa5bf9118
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
package cn.stylefeng.guns.modular.kb.greaseBoard;
 
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.gm.greaseManage.entity.GreaseManage;
import cn.stylefeng.guns.modular.gm.greaseManage.model.params.GreaseManageParam;
import cn.stylefeng.guns.modular.gm.greaseManage.model.result.GreaseManageResult;
import cn.stylefeng.guns.modular.gm.greaseManage.service.GreaseManageService;
import cn.stylefeng.guns.modular.kb.utils.IPUtil;
import cn.stylefeng.guns.modular.om.productionOrdeInfo.model.result.ProductionOrdeInfoResult;
import cn.stylefeng.guns.modular.sc.kanbanConf.model.params.KanbanConfParam;
import cn.stylefeng.guns.modular.sc.kanbanConf.service.KanbanConfService;
import cn.stylefeng.guns.plcserver.opc.unit.OPCUnit;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import javafx.stage.Stage;
import org.springframework.beans.factory.annotation.Autowired;
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 javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
 
/**
 * 返修上线看板
 *
 * @author cl
 * @Date 2022-10-27 15:50:56
 */
@Controller
@RequestMapping("/greaseBoard")
public class GreaseBoardController extends BaseController {
 
    private String PREFIX = "modular/kb/greaseBoard";
    @Autowired
    private KanbanConfService kanbanConfService;
 
    @Autowired
    private GreaseManageService greaseManageService;
    /**
     * 跳转到主页面
     *
     * @author cl
     * @Date 2022-10-27
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/greaseBoard.html";
    }
 
    /**
     * 新增看板配置页面
     *
     * @author cl
     * @Date 2022-10-31
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/kanbanConf_add.html";
    }
 
    /**
     * 编辑页面
     *
     * @author cl
     * @Date 2022-10-31
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/kanbanConf_edit.html";
    }
 
    @RequestMapping("/orderEdit")
    public String orderEdit() {
        return PREFIX + "/kanbanConf_orderEdit.html";
    }
 
    /**
     * 新增接口
     *
     * @author cl
     * @Date 2022-10-31
     */
    @RequestMapping("/addKanBanConfItem")
    @ResponseBody
    public ResponseData addItem(KanbanConfParam kanbanConfParam, HttpServletRequest request) {
        String realIp = IPUtil.getRealIp(request);
        kanbanConfParam.setIpAddress(realIp);
        kanbanConfParam.setWarehouseCode(kanbanConfParam.getScrapReason());
        kanbanConfParam.setWarehouseName(kanbanConfParam.getScrapCategory());
        this.kanbanConfService.add(kanbanConfParam);
        return ResponseData.success();
    }
 
    /**
     * 新增接口
     * MIGICC17500E00136V250WX23K03A0003B
     * @author cl
     * @Date 2022-10-31
     */
    @RequestMapping("/updategreaseManage")
    @ResponseBody
    public ResponseData updategreaseManage(GreaseManageParam greaseManageParam) {
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        String currentDate = format.format(new Date());
        String barCode = greaseManageParam.getBarcode();
        String lastTwelveChars = barCode.substring(barCode.length() - 12);
        String locationCode = getLocationCode(lastTwelveChars);
        String DuaDate = getDuaDate(lastTwelveChars);
        GreaseManage greaseManage = new GreaseManage();
        greaseManage.setBarcode(barCode);
        greaseManage.setLocationCode(locationCode);
        greaseManage.setDuaDate(DuaDate);
        greaseManage.setDaysRemaining(getRemainder(currentDate,DuaDate));
        greaseManage.setCreateTime(new Date());
        greaseManage.setCreateUser("admin");
//        greaseManageService.save(greaseManage);
        greaseManageService.update(greaseManage,new LambdaQueryWrapper<GreaseManage>().eq(GreaseManage::getLocationCode, locationCode));
        return ResponseData.success();
    }
 
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/bigListGreaseBoard")
    public ResponseData orderDescListFive() {
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        String currentDate = format.format(new Date());
        List list = new ArrayList();
        List<GreaseManage> results = greaseManageService.list();
        for (GreaseManage result : results) {
            String DuaDate = result.getDuaDate();
            String remainder = getRemainder(currentDate, DuaDate);
            if(Integer.valueOf(remainder)<=90){
                List itemList = new ArrayList();
                itemList.add(boldText(result.getLocationCode()));
                itemList.add(boldText(DuaDate));
                itemList.add(boldText(remainder));
                list.add(itemList);
            }else {
                List itemList = new ArrayList();
                itemList.add(whiteBoldText(result.getLocationCode()));
                itemList.add(whiteBoldText(DuaDate));
                itemList.add(whiteBoldText(remainder));
                list.add(itemList);
            }
 
        }
        return ResponseData.success(list);
    }
 
    @ResponseBody
    @CrossOrigin
    @RequestMapping("/testhandleOilState")
    public long handleOilState(){
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        String currentDate = format.format(new Date());
        GreaseManageParam param = new GreaseManageParam();
        param.setLocationCode("OP050");
        List<GreaseManageResult> list = greaseManageService.findListBySpec(param);
        if(list.size()>0) {
            String duaDate = list.get(0).getDuaDate();
//
            long  daysBetween = Long.parseLong(getRemainder(currentDate,duaDate));
 
//            long daysBetween = ChronoUnit.DAYS.between(date1, date2);
//            return daysBetween;
        }
        return  0;
    }
 
    public static String boldText(String param){
        return "<span style='font-size: 20px' class='colorRed'>"+param+"</span>";
    }
 
    public static String whiteBoldText(String param){
        return "<span style='font-size: 20px'>"+param+"</span>";
    }
 
    public static void main(String[] args) {
        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        String format1 = format.format(new Date());
        System.out.println("Difference in days: " + getRemainder("20231215",format1));
    }
 
    public static String getRemainder(String currentDate,String tableDate){
        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyyMMdd");
        LocalDate localDate1 = LocalDate.parse(currentDate, dateFormatter);
        LocalDate localDate2 = LocalDate.parse(tableDate, dateFormatter);
        long days = ChronoUnit.DAYS.between(localDate1, localDate2);
        return String.valueOf(days);
    }
 
    public static String getDuaDate(String str){
        String year = str.substring(1,3);
        String month = getMonth(str.substring(3,4));
        String day = str.substring(4,6);
        return "20"+year+month+day;
    }
 
    public static String getLocationCode(String str){
        String locationCode = "";
        switch (str.substring(0,1)) {
            case "X":
                locationCode = "DOP020";
                break;
            case "Y":
                locationCode = "OP050";
                break;
            case "Z":
                locationCode = "BOP030/040";
                break;
            default:
                break;
        }
        return locationCode;
    }
 
    public static String getMonth(String str){
        String Month = "";
        switch (str) {
            case "A":
                Month = "1";
                break;
            case "B":
                Month = "2";
                break;
            case "C":
                Month = "3";
                break;
            case "D":
                Month = "4";
                break;
            case "E":
                Month = "5";
                break;
            case "F":
                Month = "6";
                break;
            case "G":
                Month = "7";
                break;
            case "H":
                Month = "8";
                break;
            case "I":
                Month = "9";
                break;
            case "J":
                Month = "10";
                break;
            case "K":
                Month = "11";
                break;
            case "L":
                Month = "12";
                break;
            default:
                break;
        }
        return Month;
    }
 
 
    /**
     * 编辑接口
     *
     * @author cl
     * @Date 2022-10-31
     */
    @RequestMapping("/editKanBanConfItem")
    @ResponseBody
    public ResponseData editItem(KanbanConfParam kanbanConfParam) {
        this.kanbanConfService.update(kanbanConfParam);
        return ResponseData.success();
    }
 
    /**
     * 查询列表
     *
     * @author cl
     * @Date 2022-10-31
     */
    @ResponseBody
    @RequestMapping("/qryKBConflist")
    public LayuiPageInfo list(KanbanConfParam kanbanConfParam, HttpServletRequest request) {
        String realIp = IPUtil.getRealIp(request);
        kanbanConfParam.setIpAddress(realIp);
 
        return this.kanbanConfService.findPageBySpec(kanbanConfParam);
    }
}