CZT
2023-11-27 c206acfaedc69c390fb67daa81bc686f58a212ef
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
301
302
303
304
305
306
307
308
309
310
package com.ld.igds.basic.controller;
 
import com.bstek.bdf2.core.business.IUser;
import com.ld.igds.common.dto.PosDto;
import com.ld.igds.common.manager.CommonManager;
import com.ld.igds.constant.Constant;
import com.ld.igds.constant.RespCodeEnum;
import com.ld.igds.data.BaseParam;
import com.ld.igds.data.Page;
import com.ld.igds.data.PageResponse;
import com.ld.igds.grain.dto.GrainData;
import com.ld.igds.models.Depot;
import com.ld.igds.models.DicArea;
import com.ld.igds.models.DicSysConf;
import com.ld.igds.util.ContextUtil;
import com.ld.igds.util.FilesUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
 
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.List;
 
/**
 * 通用模块控制层
 */
@RestController
@RequestMapping("basic/common")
public class CommonController {
 
    @Autowired
    private CommonManager commonManager;
 
    /**
     * 更新通风设备的位置信息
     *
     * @param list
     * @return 成功或者异常信息
     */
    @RequestMapping("/update-verb-pos")
    public PageResponse<String> updateVerbPos(@RequestBody List<PosDto> list) {
        //return commonManager.updateVerbPos(list);
        return commonManager.updateDevicePos(list);
    }
 
    /**
     * 更新温控设备的位置保存
     *
     * @param list
     * @return 成功或者异常信息
     */
    @RequestMapping("/update-temp-pos")
    public PageResponse<String> updateTempPos(@RequestBody List<PosDto> list) {
        return commonManager.updateDevicePos(list);
    }
 
 
    /**
     * 更新气调设备的的位置保存
     *
     * @param list
     * @return
     */
    @RequestMapping("/update-n2-pos")
    public PageResponse<String> updateN2Pos(@RequestBody List<PosDto> list) {
        // return commonManager.updateN2Pos(list);
        return commonManager.updateDevicePos(list);
    }
 
    /**
     * 更新门禁的位置信息
     *
     * @param list
     * @return
     */
    @RequestMapping("/update-door-pos")
    public PageResponse<String> updateDoorPos(@RequestBody List<PosDto> list) {
        // return commonManager.updateDoorPos(list);
        return commonManager.updateDevicePos(list);
    }
 
    /**
     * 更新粮情Iot设备的位置保存
     *
     * @param list
     * @return 成功或者异常信息
     */
    @RequestMapping("/update-grain-pos")
    public PageResponse<String> updateGrainPos(@RequestBody List<PosDto> list) {
        return commonManager.updateGrainPos(list);
//        return commonManager.updateDevicePos(list);
    }
 
    /**
     * 根据条件查询粮情数据
     *
     * @param param
     * @return
     */
    @RequestMapping("/grain-data")
    public PageResponse<GrainData> queryGrainData(@RequestBody BaseParam param) {
 
        if (null == param.getDeptId()) {
            param.setDeptId(ContextUtil.subDeptId(null));
        }
        return commonManager.queryGrainData(param);
    }
 
    /**
     * 获取仓库的位置坐标信息
     *
     * @return
     */
    @GetMapping("/list-depot-pos")
    public PageResponse<List<Depot>> listDepotPos(@RequestParam(value = "d", required = false) String deptId) {
 
        // 仓库列表做下拉框使用
        List<Depot> listDepot = commonManager.listDepot(true, deptId);
 
        if (null == listDepot || listDepot.isEmpty()) {
            return new PageResponse<>(
                    RespCodeEnum.CODE_1111.getCode(), "没有获取到所选择的仓库信息!");
        }
 
        //为当前仓库列表添加鸟瞰位置坐标
        listDepot = commonManager.updateDepotPos(ContextUtil.getCompanyId(), listDepot);
 
        return new PageResponse<>(RespCodeEnum.CODE_0000, listDepot);
    }
 
    /**
     * 获取行政区域
     *
     * @return
     */
    @RequestMapping("/page-dicArea")
    public PageResponse<Page<DicArea>> pageDicArea(@RequestBody BaseParam param) {
 
        Page<DicArea> list = commonManager.pageDicArea(param);
 
        return new PageResponse<>(RespCodeEnum.CODE_0000, list);
    }
    /**
     * 帮助页面跳转
     *
     * @return
     */
    @RequestMapping("/help-center")
    public ModelAndView viewHelp() {
 
        ModelAndView view = new ModelAndView();
 
        // 用户信息
        IUser user = ContextUtil.getLoginUser();
        view.addObject(Constant.MODEL_KEY_LOGIN_USER, user);
 
        // 首先获取到系统参数
        DicSysConf sysConf = commonManager.getSysConf(user.getCompanyId());
 
        //公司名称
        view.addObject("support", sysConf.getSupport());
        //邮箱
        view.addObject("email", sysConf.getEmail());
        //售后电话
        view.addObject("phone", sysConf.getPhone());
        //网址
        view.addObject("website", sysConf.getWebsite());
        //地址
        view.addObject("address", sysConf.getAddress());
 
        //头部LOGO
        // 设置logo
        String logName = FilesUtil.getLogoByCompanyId(user.getCompanyId());
        view.addObject("logo", "../../static/img/" + logName);
 
        view.setViewName("admin/help/help-center");
        return view;
    }
 
 
    /**
     * 模块欢迎页面,根据不同的模块跳转不同的欢迎页面
     *
     * @param model 模块的编码,如果编码=all则表示没有通过模块进入默认粮情欢迎页面
     * @return
     */
    @RequestMapping("/welcome")
    public ModelAndView welcome(
            @RequestParam(value = "t", required = true) String model) {
        ModelAndView view = new ModelAndView();
        // 用户信息
        IUser user = ContextUtil.getLoginUser();
        view.addObject(Constant.MODEL_KEY_LOGIN_USER, user);
        if (Constant.MODEL_GRAIN.equals(model)) {
            view.setViewName("admin/grain/welcome");
        } else if (Constant.MODEL_VERB.equals(model)) {
            view.setViewName("admin/verb/welcome");
        } else if (Constant.MODEL_N2.equals(model)) {
            view.setViewName("admin/n2/welcome");
            //陕西安康欢迎页面
            if ("5318".equals(user.getCompanyId())) {
                view.setViewName("admin/n2/welcome-5318");
            }
        } else if (Constant.MODEL_TEMP.equals(model)) {
            view.setViewName("admin/wkgl/welcome");
        } else if (Constant.MODEL_HLXZ.equals(model)) {
            view.setViewName("admin/hlxz/welcome");
        } else if (Constant.MODEL_QUANTITY.equals(model)) {
            view.setViewName("admin/quantity/welcome");
        } else if (Constant.MODEL_TEMP.equals(model)) {
            view.setViewName("admin/hlxz/welcome");
        } else if (Constant.MODEL_INOUT.equals(model)) {
            view.setViewName("admin/inout/welcome");
        } else if (Constant.MODEL_MANAGER.equals(model)) {
            view.setViewName("admin/zhyw/welcome");
        } else if (Constant.MODEL_SYS.equals(model)) {
            view.setViewName("admin/system/welcome");
        } else if (Constant.MODEL_SECURITY.equals(model)) {
            view.setViewName("admin/afgl/welcome");
            //陕西安康欢迎页面
            if ("5318".equals(user.getCompanyId())) {
                view.setViewName("admin/afgl/welcome-5318");
            }
        } else if (Constant.MODEL_ES.equals(model)) {
            view.setViewName("admin/nhgl/welcome");
            //陕西安康欢迎页面
            if ("5318".equals(user.getCompanyId())) {
                view.setViewName("admin/nhgl/welcome-5318");
            }
        } else if (Constant.MODEL_WARN.equals(model)) {
            view.setViewName("admin/warn/welcome");
        } else if (Constant.MODEL_COMMON.equals(model)) {
            view.setViewName("admin/common/welcome");
        } else {
            view.setViewName("admin/grain/welcome");
        }
        return view;
    }
 
 
    /**
     * 用户页面切换了分库,通知到后端,并做处理
     *
     * @param deptId
     * @param userId
     * @return
     */
    @RequestMapping("/change-deptId")
    public String changeDept(
            @RequestParam(value = "deptId", required = true) String deptId,
            @RequestParam(value = "userId", required = true) String userId) {
 
        ContextUtil.updateSubDept(userId, deptId);
 
        return "SUCCESS";
    }
 
    /**
     * 文件流获取图片显示到页面
     *
     * @param filePath
     * @param response
     * @return
     * @throws IOException
     */
    @RequestMapping(value = "/getImg", method = RequestMethod.GET, produces = {"application/vnd.ms-excel;charset=UTF-8"})
    public String getImg(String filePath, HttpServletResponse response) throws IOException {
 
        if (org.apache.commons.lang3.StringUtils.isEmpty(filePath)) {
            return null;
        }
        //设置返回内容格式
        response.setContentType("image/jpeg/jpg/png/gif/bmp/tiff/svg");
        File file = new File(filePath);
        //创建一个输入流
        InputStream in = null;
        //创建输出流
        OutputStream os = null;
 
        try {
            //如果文件存在
            if (file.exists()) {
                //用该文件创建一个输入流
                in = new FileInputStream(filePath);
                //创建输出流
                os = response.getOutputStream();
                byte[] b = new byte[1024];
                while (in.read(b) != -1) {
                    os.write(b);
                }
                in.close();
                os.close();
            }
            return null;
 
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        } finally {
            if (null != in) {
                in.close();
            }
            if (null != os) {
                os.close();
            }
        }
    }
 
}