package com.ld.igds.common.manager;
|
|
import com.bstek.bdf2.core.business.IUser;
|
import com.bstek.bdf2.core.model.DefaultDept;
|
import com.ld.igds.common.CoreCommonService;
|
import com.ld.igds.common.CoreDeviceIotService;
|
import com.ld.igds.common.CoreDeviceService;
|
import com.ld.igds.common.CoreDicService;
|
import com.ld.igds.common.dto.PosDto;
|
import com.ld.igds.constant.*;
|
import com.ld.igds.data.BaseParam;
|
import com.ld.igds.data.Page;
|
import com.ld.igds.data.PageResponse;
|
import com.ld.igds.data.SimpleDepot;
|
import com.ld.igds.grain.dto.GrainData;
|
import com.ld.igds.grain.service.CoreGrainService;
|
import com.ld.igds.models.*;
|
import com.ld.igds.sys.service.DicTriggerService;
|
import com.ld.igds.sys.service.SysDeptService;
|
import com.ld.igds.util.ContextUtil;
|
import com.ld.igds.util.DateUtil;
|
import com.ld.igds.util.SystemUtil;
|
import com.ld.igds.util.RedisUtil;
|
import com.ld.igds.warn.data.WarnData;
|
import com.ld.igds.warn.data.WarnParam;
|
import com.ld.igds.warn.service.CoreWarnService;
|
import com.ld.igds.weather.CoreWeatherService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.StringUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.util.*;
|
import java.util.stream.Collectors;
|
|
/**
|
* 逻辑管理,用于实现控制层的逻辑
|
*/
|
@Slf4j
|
@Component
|
public class CommonManager {
|
|
@Autowired
|
private CoreCommonService coreCommonService;
|
@Autowired
|
private DicTriggerService dicTriggerService;
|
@Autowired
|
private CoreDicService coreDicService;
|
@Autowired
|
private CoreDeviceService coreDeviceService;
|
@Autowired
|
private CoreDeviceIotService deviceIotService;
|
@Autowired
|
private CoreGrainService coreGrainService;
|
@Autowired
|
private CoreWeatherService weatherService;
|
@Autowired
|
private SysDeptService sysDeptService;
|
@Autowired
|
private CoreWarnService coreWarnService;
|
@Resource
|
private RedisUtil redisUtil;
|
|
|
/**
|
* 获取入库作业中,仓库下拉框,值获取状态=非满仓的粮库
|
*
|
* @return
|
*/
|
public List<SimpleDepot> getCacheDeptIn(String companyId, String deptId) {
|
|
List<SimpleDepot> result = new ArrayList<>();
|
List<Depot> list = coreCommonService.getCacheDepotList(companyId, deptId);
|
|
for (Depot depot : list) {
|
if (DepotStatus.STATUS_3.getCode().equals(depot.getDepotStatus())) continue;
|
if (DepotStatus.STATUS_31.getCode().equals(depot.getDepotStatus())) continue;
|
if (DepotStatus.STATUS_32.getCode().equals(depot.getDepotStatus())) continue;
|
if (DepotStatus.STATUS_33.getCode().equals(depot.getDepotStatus())) continue;
|
if (DepotStatus.STATUS_34.getCode().equals(depot.getDepotStatus())) continue;
|
|
result.add(new SimpleDepot(depot));
|
}
|
|
return result;
|
}
|
|
/**
|
* 获取出库下拉框列表,自动屏蔽空仓
|
*
|
* @return
|
*/
|
public List<SimpleDepot> getCacheDeptOut(String companyId, String deptId) {
|
List<SimpleDepot> result = new ArrayList<>();
|
List<Depot> list = coreCommonService.getCacheDepotList(companyId, deptId);
|
|
for (Depot depot : list) {
|
if (DepotStatus.STATUS_1.getCode().equals(depot.getDepotStatus())) continue;
|
if (DepotStatus.STATUS_2.getCode().equals(depot.getDepotStatus())) continue;
|
|
result.add(new SimpleDepot(depot));
|
}
|
|
return result;
|
}
|
|
/**
|
* 根据部门编码获取下属的所有库区集合
|
*
|
* @param deptId
|
* @return
|
*/
|
public List<DefaultDept> getDeptListByDeptId(String deptId) {
|
|
if (StringUtils.isEmpty(deptId)) {
|
return null;
|
}
|
String companyId = ContextUtil.getCompanyId();
|
List<DefaultDept> list = sysDeptService.getCacheDept(companyId);
|
if (list == null || list.isEmpty()) {
|
return null;
|
}
|
|
List<DefaultDept> deptList = new ArrayList<>();
|
|
for (DefaultDept dept : list) {
|
if (StringUtils.isNotEmpty(dept.getParentId()) &&
|
dept.getParentId().contains(deptId) &&
|
dept.getType().equals(Constant.DEPT_TYPE_20)) {
|
deptList.add(dept);
|
}
|
}
|
|
return deptList;
|
}
|
|
/**
|
* 查询部门下属所有仓库列表
|
*
|
* @param companyId
|
* @param deptId
|
* @return
|
*/
|
public List<Depot> listDepotByDeptId(String companyId, String deptId) {
|
return coreCommonService.getCacheDepotList(companyId, deptId);
|
}
|
|
/**
|
* 查询警告信息
|
*
|
* @param deptId
|
* @return
|
*/
|
public List<WarnData> listWarnByDeptId(String deptId) {
|
WarnParam param = new WarnParam();
|
param.setCompanyId(ContextUtil.getCompanyId());
|
if (StringUtils.isNotEmpty(deptId)) {
|
param.setDeptId(deptId + "%");
|
}
|
param.setStart(DateUtil.getNewByDay(new Date(), -7));
|
param.setEnd(new Date());
|
return coreWarnService.queryWarn(param);
|
}
|
|
|
/**
|
* 根据分库编号获取当前分库下仓库列表
|
*
|
* @param deptId
|
* @return
|
*/
|
public List<Depot> listDepot(String deptId) {
|
|
IUser user = ContextUtil.getLoginUser();
|
|
if (StringUtils.isEmpty(deptId)) {
|
deptId = ContextUtil.subDeptId(user);
|
}
|
|
List<Depot> list = coreCommonService.getCacheDepotList(user.getCompanyId(), deptId);
|
|
if (null == list || list.isEmpty()) return null;
|
|
return list;
|
}
|
|
/**
|
* 获取当前人所在实时部门下的仓库列表
|
*
|
* @param isDelOther 是否删除其他类型仓库
|
* @return
|
*/
|
public List<Depot> listDepot(boolean isDelOther, String deptId) {
|
String companyId = ContextUtil.getCompanyId();
|
|
if (StringUtils.isEmpty(deptId) || "NULL".equalsIgnoreCase(deptId)) {
|
deptId = ContextUtil.subDeptId(null);
|
}
|
|
List<Depot> list;
|
list = coreCommonService.getCacheDepotList(companyId, deptId);
|
if (null == list || list.isEmpty()) {
|
return list;
|
}
|
// 删除非仓库列表
|
if (isDelOther) {
|
return list
|
.stream()
|
.filter(item -> !item.getDepotType().equals(
|
DepotType.TYPE_99.getCode()))
|
.collect(Collectors.toList());
|
}
|
|
return list;
|
}
|
|
/**
|
* 根据分库编号获取当前分库下仓库列表
|
*
|
* @param isDelOther
|
* @return
|
*/
|
public List<Depot> listDepot(boolean isDelOther) {
|
return listDepot(isDelOther, null);
|
}
|
|
|
public PageResponse<String> updateDevicePos(List<PosDto> list) {
|
if (null == list || list.isEmpty()) {
|
return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(),
|
"没有获取到需要更新信息!");
|
}
|
|
try {
|
// 首先根据参数删除原来的信息
|
String companyId = ContextUtil.getCompanyId();
|
|
// 开始保存新的数据
|
for (PosDto posDto : list) {
|
posDto.setId(ContextUtil.getUUID());
|
posDto.setBizTag("DEVICE");
|
posDto.setCompanyId(companyId);
|
coreDeviceService.updatePos(posDto.getBizId(), posDto.getPosX(), posDto.getPosY());
|
}
|
|
// 跟新缓存
|
coreDeviceService.refreshCache(companyId);
|
|
} catch (Exception e) {
|
log.error("后端异常:{}", e);
|
return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(), "后端异常:"
|
+ e.getMessage());
|
}
|
return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(),
|
"设备位置信息更新成功!");
|
|
|
}
|
|
public PageResponse<String> updateVerbPos(List<PosDto> list) {
|
if (null == list || list.isEmpty()) {
|
return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(),
|
"没有获取到需要更新信息!");
|
}
|
log.debug("前端传递过过来的设备位置信息={}", list.toString());
|
|
try {
|
// 首先根据参数删除原来的信息
|
String companyId = ContextUtil.getCompanyId();
|
|
// 开始保存新的数据
|
for (PosDto posDto : list) {
|
posDto.setId(ContextUtil.getUUID());
|
posDto.setBizTag(BizType.AREATION.getCode());
|
posDto.setCompanyId(companyId);
|
|
// 先删除原有的配置
|
//coreDicService.delPosByBizId(posDto);
|
|
// 后添加新数据
|
//coreDicService.addPos(posDto);
|
}
|
|
// 跟新缓存
|
coreDeviceService.refreshCache(companyId);
|
|
} catch (Exception e) {
|
log.error("后端异常:{}", e);
|
return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(), "后端异常:"
|
+ e.getMessage());
|
}
|
return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(),
|
"设备位置信息更新成功!");
|
}
|
|
public PageResponse<String> updateTempPos(List<PosDto> list) {
|
if (null == list || list.isEmpty()) {
|
return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(),
|
"没有获取到需要更新信息!");
|
}
|
log.debug("前端传递过过来的设备位置信息={}", list.toString());
|
try {
|
// 首先根据参数删除原来的信息
|
String companyId = ContextUtil.getCompanyId();
|
// 开始保存新的数据
|
for (PosDto posDto : list) {
|
posDto.setId(ContextUtil.getUUID());
|
posDto.setBizTag(BizType.TEMPCONTROL.getCode());
|
posDto.setCompanyId(companyId);
|
|
// 先删除原有的配置
|
//coreDicService.delPosByBizId(posDto);
|
// 后添加新数据
|
//coreDicService.addPos(posDto);
|
}
|
|
// 跟新缓存
|
coreDeviceService.refreshCache(companyId);
|
|
} catch (Exception e) {
|
log.error("后端异常:{}", e);
|
return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(), "后端异常:"
|
+ e.getMessage());
|
}
|
return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(),
|
"设备位置信息更新成功!");
|
}
|
|
public PageResponse<String> updateN2Pos(List<PosDto> list) {
|
if (null == list || list.isEmpty()) {
|
return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(),
|
"没有获取到需要更新信息!");
|
}
|
log.debug("前端传递过过来的设备位置信息={}", list.toString());
|
try {
|
// 首先根据参数删除原来的信息
|
String companyId = ContextUtil.getCompanyId();
|
// 开始保存新的数据
|
for (PosDto posDto : list) {
|
posDto.setId(ContextUtil.getUUID());
|
posDto.setBizTag(BizType.N2.getCode());
|
posDto.setCompanyId(companyId);
|
|
// 先删除原有的配置
|
//coreDicService.delPosByBizId(posDto);
|
|
// 后添加新数据
|
//coreDicService.addPos(posDto);
|
|
coreDeviceService.updatePos(posDto.getBizId(), posDto.getPosX(), posDto.getPosY());
|
}
|
|
// 跟新缓存
|
coreDeviceService.refreshCache(companyId);
|
|
} catch (Exception e) {
|
log.error("后端异常:{}", e);
|
return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(), "后端异常:"
|
+ e.getMessage());
|
}
|
return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(),
|
"设备位置信息更新成功!");
|
}
|
|
public PageResponse<String> updateDoorPos(List<PosDto> list) {
|
if (null == list || list.isEmpty()) {
|
return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(),
|
"没有获取到需要更新信息!");
|
}
|
log.debug("前端传递过过来的设备位置信息={}", list.toString());
|
try {
|
// 首先根据参数删除原来的信息
|
String companyId = ContextUtil.getCompanyId();
|
// 开始保存新的数据
|
for (PosDto posDto : list) {
|
posDto.setId(ContextUtil.getUUID());
|
posDto.setBizTag(BizType.SECURITY.getCode());
|
posDto.setCompanyId(companyId);
|
|
// 先删除原有的配置
|
coreDicService.delPosByBizId(posDto);
|
|
// 后添加新数据
|
coreDicService.addPos(posDto);
|
}
|
// 跟新缓存
|
coreDeviceService.refreshCache(companyId);
|
} catch (Exception e) {
|
log.error("后端异常:{}", e);
|
return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(), "后端异常:"
|
+ e.getMessage());
|
}
|
return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(),
|
"设备位置信息更新成功!");
|
}
|
|
public PageResponse<String> updateGrainPos(List<PosDto> list) {
|
if (null == list || list.isEmpty()) {
|
return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(),
|
"没有获取到需要更新信息!");
|
}
|
log.debug("前端传递过过来的设备位置信息={}", list.toString());
|
try {
|
// 首先根据参数删除原来的信息
|
String companyId = ContextUtil.getCompanyId();
|
// 开始保存新的数据
|
for (PosDto posDto : list) {
|
posDto.setId(ContextUtil.getUUID());
|
posDto.setBizTag(BizType.TEMPCONTROL.getCode());
|
posDto.setCompanyId(companyId);
|
|
// 先删除原有的配置
|
coreDicService.delPosByBizId(posDto);
|
|
// 后添加新数据
|
coreDicService.addPos(posDto);
|
}
|
|
// 跟新缓存
|
deviceIotService.refreshCache(companyId);
|
|
} catch (Exception e) {
|
log.error("后端异常:{}", e);
|
return new PageResponse<>(RespCodeEnum.CODE_2000.getCode(), "后端异常:"
|
+ e.getMessage());
|
}
|
return new PageResponse<>(RespCodeEnum.CODE_0000.getCode(),
|
"设备位置信息更新成功!");
|
}
|
|
public DicSlogan getDicSlogan() {
|
Map<String, Object> parameter = new HashMap<>();
|
parameter.put("companyId", ContextUtil.getCompanyId());
|
parameter.put("status", Constant.YN_Y);
|
return coreDicService.getDicSlogan(parameter);
|
}
|
|
/**
|
* 根据父编码获取下拉框信息
|
*
|
* @param parentCode
|
* @param companyId 为空默认系统配置
|
* @return
|
*/
|
public List<DicTrigger> getListByParent(String parentCode, String companyId) {
|
if (null == companyId) {
|
companyId = ContextUtil.getCompanyId();
|
}
|
return dicTriggerService.getCacheDicByParent(companyId, parentCode);
|
}
|
|
public WeatherInfo getWeather() {
|
return weatherService.getCacheWeather(ContextUtil.getCompanyId());
|
}
|
|
public PageResponse<GrainData> queryGrainData(BaseParam param) {
|
if (StringUtils.isEmpty(param.getDepotId())) {
|
return new PageResponse<>(
|
RespCodeEnum.CODE_1111.getCode(), "没有获取到所选择的仓库信息!");
|
}
|
|
if (StringUtils.isEmpty(param.getCompanyId())) {
|
param.setCompanyId(ContextUtil.getCompanyId());
|
}
|
|
Map<String, GrainData> result = coreGrainService.getCacheGrainDateMap(param.getCompanyId(), param.getDeptId());
|
|
if (null == result || result.isEmpty()) {
|
return new PageResponse<>(
|
RespCodeEnum.CODE_1111.getCode(), "缓存中没有获取到当前仓库的粮情信息!");
|
}
|
|
GrainData data = result.get(param.getDepotId());
|
|
if (null == data) {
|
return new PageResponse<>(RespCodeEnum.CODE_1111.getCode(),
|
"缓存中没有获取到当前仓库的粮情信息!");
|
}
|
return new PageResponse<>(RespCodeEnum.CODE_0000, data);
|
}
|
|
|
public DepotConf getDepotConf(String companyId, String depotId) {
|
return coreCommonService.getCacheDepotConf(companyId, depotId);
|
}
|
|
|
/**
|
* 获取当前人所在实际库点部门
|
*
|
* @param user 当前登录用户
|
* @param deptId 当前用户所在分库编号,可以为空
|
* @return
|
*/
|
public DefaultDept getSubDept(IUser user, String deptId) {
|
|
if (StringUtils.isEmpty(deptId)) {
|
deptId = ContextUtil.subDeptId(user);
|
}
|
return sysDeptService.getSubDept(user, deptId);
|
}
|
|
/**
|
* 获取系统配置文档
|
*
|
* @param companyId
|
* @return
|
*/
|
public DicSysConf getSysConf(String companyId) {
|
if (StringUtils.isEmpty(companyId)) {
|
companyId = ContextUtil.getCompanyId();
|
}
|
return coreCommonService.getCacheSysConf(companyId);
|
}
|
|
/**
|
* 给仓库添加 鸟瞰图的位置坐标
|
*
|
* @param companyId
|
* @param listDepot
|
* @return
|
*/
|
public List<Depot> updateDepotPos(String companyId, List<Depot> listDepot) {
|
if (null == listDepot)
|
return null;
|
if (listDepot.isEmpty())
|
return listDepot;
|
|
// 获取所有坐标信息
|
List<PosDto> posDtoList = coreDicService.getPosByBizTag(companyId, PosDto.BIZ_TAG_DEPOT);
|
|
if (null == posDtoList || posDtoList.isEmpty())
|
return listDepot;
|
|
for (Depot depot : listDepot) {
|
for (PosDto posDto : posDtoList) {
|
if (depot.getId().equals(posDto.getBizId())) {
|
depot.setPosX(posDto.getPosX());
|
depot.setPosY(posDto.getPosY());
|
break;
|
}
|
}
|
}
|
|
return listDepot;
|
}
|
|
|
/**
|
* 根据用户请求信息,根据当前客户电脑IP,获取出入库称重上次选择的地磅
|
*
|
* @param httpRequest
|
* @return
|
*/
|
public String getInoutWeightByClient(HttpServletRequest httpRequest) {
|
String userIp = SystemUtil.getIP(httpRequest);
|
log.debug("----------------根据用户IP获取选择-地磅----{}", userIp);
|
|
String key = "INOUT:WEIGHT:" + userIp;
|
String sort = (String)redisUtil.get(key);
|
if(StringUtils.isEmpty(sort))sort="1";
|
return sort;
|
}
|
|
/**
|
* 根据用户请求信息,根据当前客户电脑IP,把用户选择的地磅存在缓存中
|
*
|
* @param httpRequest
|
* @return
|
*/
|
public void setInoutWeightByClient(HttpServletRequest httpRequest, String sort) {
|
String userIp = SystemUtil.getIP(httpRequest);
|
log.debug("----------------根据用户IP更新选择-地磅----{}---{}", userIp, sort);
|
String key = "INOUT:WEIGHT:" + userIp;
|
redisUtil.set(key, sort);
|
}
|
|
/**
|
* 用户选择默认查看制氮机,进行客户端信息缓存保留,针对多个制氮机时候生效
|
*
|
* @param httpRequest
|
* @param sn
|
*/
|
public void setSelectN2MacByClient(HttpServletRequest httpRequest, String sn) {
|
String userIp = SystemUtil.getIP(httpRequest);
|
log.debug("----------------根据用户IP更新选择-制氮机----{}---{}", userIp, sn);
|
String key = "N2:MAC:" + userIp;
|
redisUtil.set(key, sn);
|
}
|
|
|
/**
|
* 真多多个制氮机时候,根据当前电脑之前查看的制氮机获取之前的选择
|
*
|
* @param httpRequest
|
* @return
|
*/
|
public String getSelectN2MacByClient(HttpServletRequest httpRequest) {
|
String userIp = SystemUtil.getIP(httpRequest);
|
log.debug("----------------根据用户IP获取选择-制氮机----{}", userIp);
|
|
String key = "N2:MAC:" + userIp;
|
|
return (String) redisUtil.get(key);
|
}
|
|
public Page<DicArea> pageDicArea(BaseParam param) {
|
|
Page<DicArea> page = new Page<>(param.getPage(), param.getLimit());
|
|
List<DicArea> list = coreDicService.listDicArea(page, param);
|
page.setRecords(list);
|
|
return page;
|
}
|
|
|
}
|