package com.ld.igds.n2.controller;
|
|
import com.bstek.bdf2.core.business.IUser;
|
import com.ld.igds.common.manager.CommonManager;
|
import com.ld.igds.constant.Constant;
|
import com.ld.igds.constant.RespCodeEnum;
|
import com.ld.igds.data.PageResponse;
|
import com.ld.igds.io.constant.OrderRespEnum;
|
import com.ld.igds.io.request.N2MacRequest;
|
import com.ld.igds.io.response.BaseResponse;
|
import com.ld.igds.models.N2MacConf;
|
import com.ld.igds.n2.manager.N2MacManager;
|
import com.ld.igds.util.ContextUtil;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestParam;
|
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.servlet.ModelAndView;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import java.util.List;
|
|
/**
|
* 制氮机控制
|
*/
|
@RestController
|
@RequestMapping("basic/n2")
|
public class N2MacController {
|
|
@Resource
|
private N2MacManager n2MacManager;
|
@Resource
|
private CommonManager commonManager;
|
|
/**
|
* 打开制氮机操作弹出框页面,默认如果有多个制氮机支持用户选择某个制氮机进行操作
|
*
|
* @return
|
*/
|
@RequestMapping("/mac-control")
|
public ModelAndView n2Mac(@RequestParam(value = "sn", required = false) String sn) {
|
|
ModelAndView view = new ModelAndView();
|
|
IUser user = ContextUtil.getLoginUser();
|
view.addObject(Constant.MODEL_KEY_LOGIN_USER, user);
|
|
String deptId = ContextUtil.subDeptId(user);
|
view.addObject("deptId", deptId);
|
|
List<N2MacConf> listN2Mac = n2MacManager.listN2Mac(user.getCompanyId(), deptId);
|
|
view.addObject("listN2Mac", listN2Mac);
|
|
view.setViewName("admin/n2/n2-mac-control");
|
return view;
|
}
|
|
/**
|
* 开启制氮机
|
*
|
* @param param
|
* @return
|
*/
|
@RequestMapping("/run-mac")
|
public BaseResponse runMac(@RequestBody N2MacRequest param) {
|
if (null == param.getSn()) {
|
return new BaseResponse(
|
OrderRespEnum.ORDER_ERROR.getCode(),
|
"没有获取到制氮机信息,无法执行");
|
}
|
return n2MacManager.runMac(param);
|
}
|
|
/**
|
* 关停制氮机
|
*
|
* @param param
|
* @return
|
*/
|
@RequestMapping("/stop-mac")
|
public BaseResponse stopMac(@RequestBody N2MacRequest param) {
|
if (null == param.getSn()) {
|
return new BaseResponse(
|
OrderRespEnum.ORDER_ERROR.getCode(),
|
"没有获取到制氮机信息,无法执行");
|
}
|
return n2MacManager.stopMac(param);
|
}
|
|
/**
|
* 查询制氮机状态
|
*
|
* @param param
|
* @return
|
*/
|
@RequestMapping("/query-status-mac")
|
public BaseResponse queryStatusMac(@RequestBody N2MacRequest param) {
|
if (null == param.getSn()) {
|
return new BaseResponse(
|
OrderRespEnum.ORDER_ERROR.getCode(),
|
"没有获取到制氮机信息,无法执行");
|
}
|
return n2MacManager.queryStatusMac(param);
|
}
|
|
|
/**
|
* 刷新制氮机信息,默认获取当前用户已经选择的制氮机,如果没有获取当前分库下的第一个制氮机
|
*
|
* @param param
|
* @return
|
*/
|
@RequestMapping("/get-mac")
|
public PageResponse<N2MacConf> getMac(HttpServletRequest httpRequest, @RequestBody N2MacRequest param) {
|
String sn = commonManager.getSelectN2MacByClient(httpRequest);
|
N2MacConf n2MacConf = null;
|
if (null != sn) {
|
n2MacConf = n2MacManager.getDataBySn(sn);
|
}
|
if (null == n2MacConf) {
|
List<N2MacConf> list = n2MacManager.listN2Mac(param.getCompanyId(), param.getDeptId());
|
if (null != list) n2MacConf = list.get(0);
|
}
|
return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "获取成功", n2MacConf);
|
}
|
|
|
/**
|
* 更新用户默认选择的制氮机信息,只针对有多个设备时候使用
|
*
|
* @param request
|
* @param param
|
* @return
|
*/
|
@RequestMapping("/update-select-mac")
|
public PageResponse<String> updateSelectMac(HttpServletRequest request, @RequestBody N2MacRequest param) {
|
try {
|
if (null == param.getSn()) {
|
return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
|
"没有获取到设备信息");
|
}
|
commonManager.setSelectN2MacByClient(request, param.getSn());
|
return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(), "更新成功");
|
} catch (Exception e) {
|
return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
|
"后台异常:" + e.getMessage());
|
}
|
}
|
|
}
|