package com.ld.igds.view;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
|
import com.ld.igds.io.RemoteCommonService;
|
import com.ld.igds.io.RemoteManager;
|
import com.ld.igds.io.constant.OrderRespEnum;
|
import com.ld.igds.io.request.DepotStatusRequest;
|
import com.ld.igds.io.response.BaseResponse;
|
import com.ld.igds.models.*;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import com.bstek.bdf2.core.business.IUser;
|
import com.bstek.dorado.annotation.DataProvider;
|
import com.bstek.dorado.annotation.DataResolver;
|
import com.bstek.dorado.annotation.Expose;
|
import com.ld.igds.common.CoreCommonService;
|
import com.ld.igds.common.CoreSerService;
|
import com.ld.igds.constant.BizType;
|
import com.ld.igds.constant.Constant;
|
import com.ld.igds.constant.DepotStatus;
|
import com.ld.igds.constant.DepotType;
|
import com.ld.igds.constant.FoodLevel;
|
import com.ld.igds.order.ExeOrderService;
|
import com.ld.igds.order.data.ExeRequest;
|
import com.ld.igds.util.ContextUtil;
|
import com.ld.igds.view.service.HDepotService;
|
|
/**
|
* @author jiazx
|
*/
|
@Slf4j
|
@Component
|
public class DepotPR {
|
|
@Autowired
|
private HDepotService depotService;
|
@Autowired
|
private CoreCommonService coreCommonService;
|
@Autowired
|
private CoreSerService coreSerService;
|
@Autowired
|
private RemoteManager remoteManager;
|
@Autowired
|
private ExeOrderService exeOrderService;
|
|
|
/**
|
* 仓房类型-非国标定义
|
* ${dorado.getDataProvider("depotPR#triggerDepotType").getResult()}
|
*
|
* @return
|
*/
|
@DataProvider
|
public List<DicTrigger> triggerDepotType() {
|
List<DicTrigger> list = new ArrayList<DicTrigger>();
|
list.add(new DicTrigger(DepotType.TYPE_01.getCode(), DepotType.TYPE_01.getMsg()));
|
list.add(new DicTrigger(DepotType.TYPE_02.getCode(), DepotType.TYPE_02.getMsg()));
|
list.add(new DicTrigger(DepotType.TYPE_03.getCode(), DepotType.TYPE_03.getMsg()));
|
list.add(new DicTrigger(DepotType.TYPE_04.getCode(), DepotType.TYPE_04.getMsg()));
|
list.add(new DicTrigger(DepotType.TYPE_99.getCode(), DepotType.TYPE_99.getMsg()));
|
return list;
|
}
|
|
/**
|
* 仓房状态
|
* ${dorado.getDataProvider("depotPR#triggerDepotStatus").getResult()}
|
*
|
* @return
|
*/
|
@DataProvider
|
public List<DicTrigger> triggerDepotStatus() {
|
List<DicTrigger> list = new ArrayList<DicTrigger>();
|
list.add(new DicTrigger(DepotStatus.STATUS_1.getCode(), DepotStatus.STATUS_1.getMsg()));
|
list.add(new DicTrigger(DepotStatus.STATUS_2.getCode(), DepotStatus.STATUS_2.getMsg()));
|
list.add(new DicTrigger(DepotStatus.STATUS_3.getCode(), DepotStatus.STATUS_3.getMsg()));
|
list.add(new DicTrigger(DepotStatus.STATUS_4.getCode(), DepotStatus.STATUS_4.getMsg()));
|
list.add(new DicTrigger(DepotStatus.STATUS_31.getCode(), DepotStatus.STATUS_31.getMsg()));
|
list.add(new DicTrigger(DepotStatus.STATUS_32.getCode(), DepotStatus.STATUS_32.getMsg()));
|
list.add(new DicTrigger(DepotStatus.STATUS_33.getCode(), DepotStatus.STATUS_33.getMsg()));
|
list.add(new DicTrigger(DepotStatus.STATUS_34.getCode(), DepotStatus.STATUS_34.getMsg()));
|
list.add(new DicTrigger(DepotStatus.STATUS_9.getCode(), DepotStatus.STATUS_9.getMsg()));
|
return list;
|
}
|
|
/**
|
* 粮食等级
|
* ${dorado.getDataProvider("depotPR#triggerFoodLevel").getResult()}
|
*
|
* @return
|
*/
|
@DataProvider
|
public List<DicTrigger> triggerFoodLevel() {
|
List<DicTrigger> list = new ArrayList<DicTrigger>();
|
list.add(new DicTrigger(FoodLevel.LEVEL_01.getCode(), FoodLevel.LEVEL_01.getMsg()));
|
list.add(new DicTrigger(FoodLevel.LEVEL_02.getCode(), FoodLevel.LEVEL_02.getMsg()));
|
list.add(new DicTrigger(FoodLevel.LEVEL_03.getCode(), FoodLevel.LEVEL_03.getMsg()));
|
list.add(new DicTrigger(FoodLevel.LEVEL_04.getCode(), FoodLevel.LEVEL_04.getMsg()));
|
list.add(new DicTrigger(FoodLevel.LEVEL_05.getCode(), FoodLevel.LEVEL_05.getMsg()));
|
list.add(new DicTrigger(FoodLevel.LEVEL_06.getCode(), FoodLevel.LEVEL_06.getMsg()));
|
return list;
|
}
|
|
/**
|
* 储粮方式
|
* ${dorado.getDataProvider("depotPR#triggerStoreType").getResult()}
|
*
|
* @return
|
*/
|
@DataProvider
|
public List<DicTrigger> triggerStoreType() {
|
List<DicTrigger> list = new ArrayList<DicTrigger>();
|
list.add(new DicTrigger("1", "散装储粮"));
|
list.add(new DicTrigger("2", "包装储粮"));
|
list.add(new DicTrigger("3", "围包存"));
|
list.add(new DicTrigger("9", "其他"));
|
return list;
|
}
|
|
/**
|
* 管理方式
|
* ${dorado.getDataProvider("depotPR#triggerManagerType").getResult()}
|
*
|
* @return
|
*/
|
@DataProvider
|
public List<DicTrigger> triggerManagerType() {
|
List<DicTrigger> list = new ArrayList<DicTrigger>();
|
list.add(new DicTrigger("01", "直储"));
|
list.add(new DicTrigger("02", "代储"));
|
list.add(new DicTrigger("03", "租仓"));
|
list.add(new DicTrigger("04", "委托"));
|
return list;
|
}
|
|
/**
|
* 电缆起始方位
|
* ${dorado.getDataProvider("depotPR#triggerStartOrientation").getResult()}
|
*
|
* @return
|
*/
|
@DataProvider
|
public List<DicTrigger> triggerStartOrientation() {
|
List<DicTrigger> list = new ArrayList<DicTrigger>();
|
list.add(new DicTrigger(Constant.GRAIN_START_ORIENTATION_RIGHT, "右边"));
|
list.add(new DicTrigger(Constant.GRAIN_START_ORIENTATION_RIGHT_UP, "右上"));
|
list.add(new DicTrigger(Constant.GRAIN_START_ORIENTATION_LEFT, "左边"));
|
list.add(new DicTrigger(Constant.GRAIN_START_ORIENTATION_LEFT_UP, "左上"));
|
return list;
|
}
|
|
/**
|
* 电缆布线方向
|
* ${dorado.getDataProvider("depotPR#triggerStartDirection").getResult()}
|
*
|
* @return
|
*/
|
@DataProvider
|
public List<DicTrigger> triggerStartDirection() {
|
List<DicTrigger> list = new ArrayList<DicTrigger>();
|
list.add(new DicTrigger(Constant.GRAIN_START_DIRECTION_PORTRAIT, "纵向"));
|
list.add(new DicTrigger(Constant.GRAIN_START_DIRECTION_TRANSVERSE, "横向"));
|
|
return list;
|
}
|
|
/**
|
* 电缆起始点位
|
* ${dorado.getDataProvider("depotPR#triggerStartPoint").getResult()}
|
*
|
* @return
|
*/
|
@DataProvider
|
public List<DicTrigger> triggerStartPoint() {
|
List<DicTrigger> list = new ArrayList<DicTrigger>();
|
list.add(new DicTrigger(Constant.GRAIN_START_POINT_TOP, "顶部"));
|
list.add(new DicTrigger(Constant.GRAIN_START_POINT_BELOW, "底部"));
|
|
return list;
|
}
|
|
/**
|
* 层行转换
|
* ${dorado.getDataProvider("depotPR#triggerStartConvert").getResult()}
|
*
|
* @return
|
*/
|
@DataProvider
|
public List<DicTrigger> triggerStartConvert() {
|
List<DicTrigger> list = new ArrayList<DicTrigger>();
|
list.add(new DicTrigger(Constant.GRAIN_CONVERT_DEFAULT, "默认"));
|
list.add(new DicTrigger(Constant.GRAIN_CONVERT_CLOCKWISE, "顺时针"));
|
list.add(new DicTrigger(Constant.GRAIN_CONVERT_ANTICLOCKWISE, "逆时针"));
|
|
return list;
|
}
|
|
/**
|
* 筒仓锥形
|
* ${dorado.getDataProvider("depotPR#triggerCableCone").getResult()}
|
*
|
* @return
|
*/
|
@DataProvider
|
public List<DicTrigger> triggerCableCone() {
|
List<DicTrigger> list = new ArrayList<DicTrigger>();
|
list.add(new DicTrigger(Constant.CABLE_CONE_0, "无锥形"));
|
list.add(new DicTrigger(Constant.CABLE_CONE_1, "上锥形"));
|
list.add(new DicTrigger(Constant.CABLE_CONE_2, "下锥形"));
|
|
return list;
|
}
|
|
// depotPR#getData
|
@DataProvider
|
public List<Depot> getData(Map<String, Object> param) throws Exception {
|
return depotService.getData(param);
|
}
|
|
// ${dorado.getDataProvider("depotPR#getAllCache").getResult()}
|
@DataProvider
|
public List<Depot> getAllCache(String name) {
|
return depotService.getAllCache(name, ContextUtil.getCompanyId());
|
}
|
|
|
// depotPR#ajaxGetAllCache
|
@Expose
|
public List<Depot> ajaxGetAllCache() {
|
return depotService.getAllCache(null, null);
|
}
|
|
// depotPR#flushCache
|
@Expose
|
public void flushCache() {
|
depotService.flushCache(ContextUtil.getCompanyId());
|
}
|
|
// depotPR#saveOrUpdate
|
@DataResolver
|
@Transactional
|
public String saveOrUpdate(Depot depot) throws Exception {
|
IUser user = ContextUtil.getLoginUser();
|
|
if (null == depot.getDeptId()) {
|
depot.setDeptId(ContextUtil.subDeptId(user));
|
}
|
|
String msg = null;
|
|
if (null == depot.getCompanyId()) {
|
depotService.saveDepot(depot);
|
} else {
|
depotService.updateDepot(depot);
|
}
|
|
flushCache();
|
|
return msg;
|
}
|
|
// depotPR#deletedepot
|
@Expose
|
@Transactional
|
public void deletedepot(Depot depot) throws Exception {
|
depotService.deleteDepot(depot);
|
}
|
|
/**
|
* depotPR#getDepot 获取仓库信息
|
*
|
* @param depotId
|
* @return
|
*/
|
@Expose
|
public Depot getDepot(String depotId) {
|
return depotService.getDepotById(ContextUtil.getCompanyId(), depotId);
|
}
|
|
// --------------- 以下为仓库参数配置页面-------------------//
|
|
/**
|
* 参数配置列表 depotPR#getConfList
|
*
|
* @return
|
*/
|
@DataProvider
|
public List<DepotConf> getConfList() {
|
return depotService.getConfList(ContextUtil.getCompanyId());
|
}
|
|
/**
|
* depotPR#saveConf 参数配置更新,包括新增和修改
|
*
|
* @param conf
|
*/
|
@DataResolver
|
public void saveConf(DepotConf conf) {
|
depotService.saveConf(conf);
|
}
|
|
/**
|
* depotPR#delDepotConf 删除参数配置
|
*
|
* @param conf
|
* @throws Exception
|
*/
|
@Expose
|
public String delDepotConf(DepotConf conf) {
|
return depotService.deleteDepotConf(conf);
|
}
|
|
/**
|
* depotPR#flushConfCache 刷新配置缓存
|
*/
|
@Expose
|
public void flushConfCache() {
|
depotService.flushConfCache(ContextUtil.getCompanyId());
|
}
|
|
/**
|
* depotPR#updateFreq 更新所有粮库的粮情频率
|
*/
|
@Expose
|
public void updateFreq(String freq) {
|
depotService.updateFreq(freq);
|
}
|
|
public void updateByStore(DepotStore data) throws Exception {
|
|
Depot depot = depotService.getDepotById(data.getCompanyId(), data.getDepotId());
|
|
if (null == depot) return;
|
|
depot.setStorageReal(data.getStorageReal());
|
depot.setDepotStatus(data.getDepotStatus());
|
depot.setFoodLevel(data.getFoodLevel());
|
depot.setFoodLocation(data.getFoodLocation());
|
depot.setFoodVariety(data.getFoodVariety());
|
depot.setFoodType(data.getFoodType());
|
depot.setFoodYear(data.getFoodYear());
|
if (null != data.getStoreDate()) {
|
depot.setStoreDate(data.getStoreDate());
|
}
|
|
|
depotService.updateDepot(depot);
|
}
|
|
public String pullDepotStatus(String companyId, String depotId, String status) {
|
// 执行推送
|
DepotConf depotConf = coreCommonService.getCacheDepotConf(companyId, depotId);
|
|
|
String msg = "未获取到关联控制柜协议,远程同步取消执行!";
|
|
|
if (null == depotConf) {
|
msg = "未获取到仓库配置信息,远程同步取消执行!";
|
|
log.error("------远程同步仓库状态失败-----{}---{}", depotId, msg);
|
return msg;
|
}
|
|
|
DeviceSer ser = coreSerService.getCacheSer(depotConf.getCompanyId(),
|
depotConf.getGrainSer());
|
|
if (null == ser) {
|
msg = "未获取到关联控制柜,远程同步取消执行!";
|
log.error("------远程同步仓库状态失败-----{}---{}", depotId, msg);
|
return msg;
|
}
|
if (Constant.YN_N.equals(ser.getStatus())) {
|
msg = "关联控制柜不在线,远程同步取消执行!";
|
log.error("------远程同步仓库状态失败-----{}---{}", depotId, msg);
|
return msg;
|
}
|
|
DepotStatusRequest request = new DepotStatusRequest();
|
request.setIp(ser.getIp());
|
request.setSerName(ser.getName());
|
request.setPort(ser.getPort());
|
request.setCompanyId(ser.getCompanyId());
|
request.setBizType(BizType.SYS.getCode());
|
request.setSerId(ser.getId());
|
request.setStatus(status);
|
request.setDepotId(depotConf.getDepotId());
|
request.setDepotName(depotConf.getDepotName());
|
|
RemoteCommonService remoteCommonService = remoteManager.getRemoteCommonService(ser.getProtocol());
|
|
if (null == remoteCommonService) {
|
msg = "未获取到关联控制柜协议,远程同步取消执行!";
|
log.error("------远程同步仓库状态失败-----{}---{}", depotId, msg);
|
return msg;
|
}
|
|
ExeRequest exeRequest = new ExeRequest(request);
|
exeRequest.setAddLogTag(true);
|
exeRequest.setRepeatTag(true);
|
exeRequest.setMsg(msg);
|
|
BaseResponse response = remoteCommonService.pullDepotStatus(request);
|
|
if (OrderRespEnum.ORDER_SUCCESS.getCode().equals(response.getCode())) {
|
exeOrderService.checkExecute(exeRequest);
|
return null;
|
}
|
|
msg = "数据保存成功,远程同步状态失败:" + response.getMsg();
|
log.error("------远程同步仓库状态失败-----{}---{}", depotId, msg);
|
return msg;
|
}
|
|
|
}
|