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();
|
}
|
}
|
}
|
|
}
|