wang-hao-jie
2022-08-25 57dcc73636bb7d8dce89c808eb8cc988a7512264
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
package com.ruoyi.web.controller.station;
 
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
import com.ruoyi.common.utils.IdUtils;
import com.ruoyi.station.domain.MjEquipment;
import com.ruoyi.station.service.IMjEquipmentService;
import lombok.SneakyThrows;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.station.domain.MjOpenHnwe;
import com.ruoyi.station.service.IMjOpenHnweService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
 
/**
 * ax模式临时Controller
 * 
 * @author ruoyi
 * @date 2020-09-15
 */
@Controller
@RequestMapping("/station/openHnwe")
public class MjOpenHnweController extends BaseController
{
    private String prefix = "station/openHnwe";
 
    @Autowired
    private IMjOpenHnweService mjOpenHnweService;
    @Autowired
    private IMjEquipmentService equipmentService;
 
    @RequiresPermissions("station:openHnwe:view")
    @GetMapping()
    public String openHnwe()
    {
        return prefix + "/openHnwe";
    }
 
    /**
     * 查询ax模式临时列表
     */
    @PostMapping("/list")
    @ResponseBody
    public Object list(MjOpenHnwe mjOpenHnwe)
    {
        //startPage();
        List<MjOpenHnwe> list = mjOpenHnweService.selectMjOpenHnweList(mjOpenHnwe);
        //return getDataTable(list);
        String ids = "";
        for(MjOpenHnwe openHnwe:list){
            ids+=openHnwe.getId()+",";
        }
        if(ids.indexOf(",")!=-1){
            deleteAll(ids.substring(0,ids.length()-1));
        }
        insertAll(list);
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("list",list);
 
        MjEquipment eq = new MjEquipment();
        eq.setEquipmentType(1);
        List<MjEquipment> mjEquipments = equipmentService.selectMjEquipmentList(eq);
        if(mjEquipments.size()==1){
            MjEquipment equipment = mjEquipments.get(0);
            equipment.setStatus(1);
            equipment.setUpdateTime(new Date());
            equipmentService.updateMjEquipment(equipment);
        }
        if(mjEquipments.size()==0){
            eq.setStatus(1);
            eq.setUpdateTime(new Date());
            eq.setId(IdUtils.fastSimpleUUID());
            equipmentService.insertMjEquipment(eq);
        }
        //eq.setEquipmentType();
        return map;
    }
 
    public void deleteAll(String ids){
        mjOpenHnweService.deleteMjOpenHnweByIds(ids);
//        Thread t = new Thread(new Runnable(){
//            public void run(){
//                System.out.println("ids:"+ids);
//                mjOpenHnweService.deleteMjOpenHnweByIds(ids);
//            }
//        });
//        t.start();
    }
 
    public void insertAll(List<MjOpenHnwe> list){
        if(list.size()==0){
            return;
        }
        int i=0;
        for(MjOpenHnwe openHnwe:list){
            if(openHnwe.getDelFlag()==0){
                if(openHnwe.getDoorControlId()==null){
                    i++;
                }else if(openHnwe.getDoorControlId().equals("1")){
                    i++;
                }
            }
        }
        if(i==0){
            return;
        }
        Thread t = new Thread(new Runnable(){
            @SneakyThrows
            public void run(){
                Thread.sleep(5*1000);
                for(MjOpenHnwe openHnwe:list){
                    if(openHnwe.getDoorControlId()==null){
                        if (openHnwe.getDelFlag()==0){
                            openHnwe.setDelFlag(1);
                            openHnwe.setId(IdUtils.fastSimpleUUID());
                            mjOpenHnweService.insertMjOpenHnwe(openHnwe);
                        }
                    }else{
                        if(openHnwe.getDoorControlId().equals("1")){
                            if (openHnwe.getDelFlag()==0){
                                openHnwe.setDelFlag(1);
                                openHnwe.setId(IdUtils.fastSimpleUUID());
                                mjOpenHnweService.insertMjOpenHnwe(openHnwe);
                            }
                        }
                    }
                }
            }
        });
        t.start();
    }
 
    /**
     * 导出ax模式临时列表
     */
    @RequiresPermissions("station:openHnwe:export")
    @Log(title = "ax模式临时", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MjOpenHnwe mjOpenHnwe)
    {
        List<MjOpenHnwe> list = mjOpenHnweService.selectMjOpenHnweList(mjOpenHnwe);
        ExcelUtil<MjOpenHnwe> util = new ExcelUtil<MjOpenHnwe>(MjOpenHnwe.class);
        return util.exportExcel(list, "openHnwe");
    }
 
    /**
     * 新增ax模式临时
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }
 
    /**
     * 新增保存ax模式临时
     */
    @RequiresPermissions("station:openHnwe:add")
    @Log(title = "ax模式临时", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MjOpenHnwe mjOpenHnwe)
    {
        return toAjax(mjOpenHnweService.insertMjOpenHnwe(mjOpenHnwe));
    }
 
    /**
     * 修改ax模式临时
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        MjOpenHnwe mjOpenHnwe = mjOpenHnweService.selectMjOpenHnweById(id);
        mmap.put("mjOpenHnwe", mjOpenHnwe);
        return prefix + "/edit";
    }
 
    /**
     * 修改保存ax模式临时
     */
    @RequiresPermissions("station:openHnwe:edit")
    @Log(title = "ax模式临时", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MjOpenHnwe mjOpenHnwe)
    {
        return toAjax(mjOpenHnweService.updateMjOpenHnwe(mjOpenHnwe));
    }
 
    /**
     * 删除ax模式临时
     */
    @RequiresPermissions("station:openHnwe:remove")
    @Log(title = "ax模式临时", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mjOpenHnweService.deleteMjOpenHnweByIds(ids));
    }
}