Commit 41590f00 by 史文博

Merge branch 'feature/form_statistics_05' into 'develop'

针对预警修改 lookName/lookType的后台值

See merge request kunlun/xyst_dinas/xyst_dinas_backend!74
parents 03c76df2 c01db56e
...@@ -36,38 +36,37 @@ import com.xyst.dinas.biz.warn.service.WarningService; ...@@ -36,38 +36,37 @@ import com.xyst.dinas.biz.warn.service.WarningService;
* @date 2021年3月26日 * @date 2021年3月26日
*/ */
public class BaseBusinessWarn { public class BaseBusinessWarn {
/** 业务类型*/ /** 业务类型 */
protected String billType; protected String billType;
/** 业务ID*/ /** 业务ID */
protected UUID billId; protected UUID billId;
/** 指标*/ /** 指标 */
protected String target; protected String target;
/** 预警设置ID*/ /** 预警设置ID */
protected UUID warnSettingId; protected UUID warnSettingId;
private IWarningCalculator warningCalculate; private IWarningCalculator warningCalculate;
private WarningService warningSettingService; private WarningService warningSettingService;
private RemindService remindService; private RemindService remindService;
private StaffService staffService; private StaffService staffService;
@Value("${beecode.tenant.username:}") @Value("${beecode.tenant.username:}")
private String userName; private String userName;
private StaffDAO staffDAO; private StaffDAO staffDAO;
BaseBusinessWarn(@NonNull UUID warnSettingId) { BaseBusinessWarn(@NonNull UUID warnSettingId) {
Assert.notNull(warnSettingId, "The warnSettingId must not be null!"); Assert.notNull(warnSettingId, "The warnSettingId must not be null!");
this.warnSettingId = warnSettingId; this.warnSettingId = warnSettingId;
init(); init();
} }
BaseBusinessWarn(@NonNull String billType, @Nullable UUID billId, @Nullable String target) { BaseBusinessWarn(@NonNull String billType, @Nullable UUID billId, @Nullable String target) {
Assert.notNull(billType, "The billType must not be null!"); Assert.notNull(billType, "The billType must not be null!");
this.billType = billType; this.billType = billType;
...@@ -75,86 +74,91 @@ public class BaseBusinessWarn { ...@@ -75,86 +74,91 @@ public class BaseBusinessWarn {
this.target = target; this.target = target;
init(); init();
} }
private void init() { private void init() {
remindService = getRemindService(); remindService = getRemindService();
staffService = getStaffService(); staffService = getStaffService();
warningSettingService = getWarningSettingService(); warningSettingService = getWarningSettingService();
staffDAO = getStaffDAO(); staffDAO = getStaffDAO();
} }
/** 预警设置*/ /** 预警设置 */
public WarnSetting getWarnSetting() { public WarnSetting getWarnSetting() {
if(warnSettingId!=null) { if (warnSettingId != null) {
return warningSettingService.getWarnSetting(warnSettingId); return warningSettingService.getWarnSetting(warnSettingId);
} }
return warningSettingService.getWarnSetting(billType, billId, target); return warningSettingService.getWarnSetting(billType, billId, target);
} }
/** 计算是否预警*/ /** 计算是否预警 */
public final void setWarningCalculate(IWarningCalculator warningCalculate) { public final void setWarningCalculate(IWarningCalculator warningCalculate) {
this.warningCalculate = warningCalculate; this.warningCalculate = warningCalculate;
} }
public final boolean warn() { public final boolean warn() {
return warn(true); return warn(true);
} }
/** /**
* 预警 * 预警
*
* @param isNotice 是否发送通知 * @param isNotice 是否发送通知
* @return * @return
*/ */
public final boolean warn(boolean isNotice) { public final boolean warn(boolean isNotice) {
boolean isWarning = false; boolean isWarning = false;
WarnSetting warnSetting = getWarnSetting(); WarnSetting warnSetting = getWarnSetting();
if(warnSetting==null || !warnSetting.isOpen()) return false;// if (warnSetting == null || !warnSetting.isOpen())
if(warningCalculate == null && warnSetting.warnCalculator()!=null) { return false;//
warningCalculate = Amino.getApplicationMetadataContext().getBean(warnSetting.warnCalculator(),IWarningCalculator.class); if (warningCalculate == null && warnSetting.warnCalculator() != null) {
warningCalculate = Amino.getApplicationMetadataContext().getBean(warnSetting.warnCalculator(),
IWarningCalculator.class);
} }
Assert.notNull(warningCalculate, "The warningCalculate must not be null!"); Assert.notNull(warningCalculate, "The warningCalculate must not be null!");
isWarning = warningCalculate.isWarning(warnSetting); isWarning = warningCalculate.isWarning(warnSetting);
//记录预警日志 // 记录预警日志
UUID warnSettingId = warnSetting.getSettingId(); UUID warnSettingId = warnSetting.getSettingId();
WarnExeRecord warnExeRecord = warningSettingService.queryWarnExeRecord(warnSettingId); WarnExeRecord warnExeRecord = warningSettingService.queryWarnExeRecord(warnSettingId);
//1.当前没有执行中的预警记录 // 1.当前没有执行中的预警记录
if (warnExeRecord == null) { if (warnExeRecord == null) {
if(!isWarning) return false;//1.1 没有触发预警, 则不做任何操作; if (!isWarning)
//1.2 新增预警执行信息 return false;// 1.1 没有触发预警,则不做任何操作;
// 1.2 新增预警执行信息
warnExeRecord = createWarnExeRecord(warnSetting); warnExeRecord = createWarnExeRecord(warnSetting);
warnExeRecord.setActualValue(warningCalculate.getActualValue()); warnExeRecord.setActualValue(warningCalculate.getActualValue());
warnExeRecord.setMessage(warningCalculate.warnMessage()); warnExeRecord.setMessage(warningCalculate.warnMessage());
warningSettingService.insertWarnExe(warnExeRecord); warningSettingService.insertWarnExe(warnExeRecord);
}else { } else {
//2.当前存在执行中的预警记录,则修改预警执行信息 // 2.当前存在执行中的预警记录,则修改预警执行信息
Date currentTime = new Date(); Date currentTime = new Date();
warnExeRecord.setRecentlyTime(currentTime); warnExeRecord.setRecentlyTime(currentTime);
warnExeRecord.setActualValue(warningCalculate.getActualValue()); warnExeRecord.setActualValue(warningCalculate.getActualValue());
if(!isWarning) { //2.1 如果没有触发预警,则结束该预警记录 if (!isWarning) {
// 2.1 如果没有触发预警,则结束该预警记录
warnExeRecord.setEndTime(currentTime); warnExeRecord.setEndTime(currentTime);
warnExeRecord.setMessage(warningCalculate.warnMessage()); warnExeRecord.setMessage(warningCalculate.warnMessage());
warnExeRecord.setWarnState(WarnStateEnum.OVER.getValue()); warnExeRecord.setWarnState(WarnStateEnum.OVER.getValue());
} }
warningSettingService.updateWarnExe(warnExeRecord); warningSettingService.updateWarnExe(warnExeRecord);
} }
//通知人员 // 通知人员
String[] noticePerson = warnSetting.getPersonnel(); String[] noticePerson = warnSetting.getPersonnel();
String message = warningCalculate.warnMessage(); String message = warningCalculate.warnMessage();
try { try {
if (isWarning && isNotice) if (isWarning && isNotice)
notice(noticePerson, message, warnSetting.getBillId()); notice(noticePerson, message, warnSetting.getBillId(), warnSetting);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return isWarning; return isWarning;
}; };
private WarnExeRecord createWarnExeRecord(WarnSetting warnSetting) { private WarnExeRecord createWarnExeRecord(WarnSetting warnSetting) {
WarnExeRecord warnExeRecord = new WarnExeRecord(); WarnExeRecord warnExeRecord = new WarnExeRecord();
Date currentTime = new Date(); Date currentTime = new Date();
warnExeRecord.setWarnState(WarnStateEnum.EXECUTING.getValue()); warnExeRecord.setWarnState(WarnStateEnum.EXECUTING.getValue());
warnExeRecord.setStartTime(currentTime); warnExeRecord.setStartTime(currentTime);
warnExeRecord.setRecentlyTime(currentTime); warnExeRecord.setRecentlyTime(currentTime);
warnExeRecord.setTarget(warnSetting.getTarget()); warnExeRecord.setTarget(warnSetting.getTarget());
...@@ -166,42 +170,54 @@ public class BaseBusinessWarn { ...@@ -166,42 +170,54 @@ public class BaseBusinessWarn {
warnExeRecord.setMemo(warnSetting.getMemo()); warnExeRecord.setMemo(warnSetting.getMemo());
return warnExeRecord; return warnExeRecord;
} }
/** /**
* 通知所有人员 * 通知所有人员
*
* @param noticePerson * @param noticePerson
* @param message * @param message
* @param billId * @param billId
* @throws Exception * @throws Exception
*/ */
private void notice(String[] noticePerson,String message,UUID billId) throws Exception{ private void notice(String[] noticePerson, String message, UUID billId, WarnSetting warnSetting) throws Exception {
Date currentTime = new Date(); Date currentTime = new Date();
String currentTimeStr = DateUtil.dateTime2String(currentTime); String currentTimeStr = DateUtil.dateTime2String(currentTime);
JSONObject remObject = new JSONObject(); JSONObject remObject = new JSONObject();
UUID remindId = UUID.randomUUID(); UUID remindId = UUID.randomUUID();
remObject.put("id", remindId); remObject.put("id", remindId);
remObject.put("createTime", currentTimeStr); remObject.put("createTime", currentTimeStr);
remObject.put("remindTime", currentTimeStr); remObject.put("remindTime", currentTimeStr);
remObject.put("remindContent", message);//消息 remObject.put("remindContent", message);// 消息
remObject.put("data", billId);
remObject.put("data",billId ); // remObject.put("lookName", "");//标题
remObject.put("lookName", "");//标题 remObject.put("lookName", warnSetting.getTarget());// 标题
remObject.put("lookType", "Contract"); String lookTypeName = warnSetting.getBillType().substring(0, 2);
String lookType = "Contract";
if (lookTypeName.equals("散客")) {
lookType = "RetailInfo";
} else if (lookTypeName.equals("采区")) {
lookType = "SandMiningArea";
} else if (lookTypeName.equals("库存")) {
lookType = "Inventory";
} else if (lookTypeName.equals("合同")) {
lookType = "Contract";
}
// remObject.put("lookType", "Contract");
remObject.put("lookType", lookType);
remObject.put("_type", CommonConstants.REMIND_ENTITY); remObject.put("_type", CommonConstants.REMIND_ENTITY);
remObject.put("isToCustomer", false); remObject.put("isToCustomer", false);
KObject kobject =(KObject)JSONObjectUtils.toObject(remObject.toString()); KObject kobject = (KObject) JSONObjectUtils.toObject(remObject.toString());
KObject creater = null; KObject creater = null;
List<KObject> list = staffDAO.listStaffByUsername("sysadmin"); List<KObject> list = staffDAO.listStaffByUsername("sysadmin");
if (list.isEmpty()) { if (list.isEmpty()) {
creater = MessageUtils.gerCurrentStaff(); creater = MessageUtils.gerCurrentStaff();
}else { } else {
creater = list.get(0); creater = list.get(0);
} }
kobject.set("sender", creater);// kobject.set("sender", creater);//
kobject.validate(); kobject.validate();
JSONArray parts = new JSONArray(); JSONArray parts = new JSONArray();
for (String person : noticePerson) { for (String person : noticePerson) {
JSONObject part = new JSONObject(); JSONObject part = new JSONObject();
...@@ -210,23 +226,23 @@ public class BaseBusinessWarn { ...@@ -210,23 +226,23 @@ public class BaseBusinessWarn {
parts.put(part); parts.put(part);
} }
List<KObject> listRes = new ArrayList<KObject>(); List<KObject> listRes = new ArrayList<KObject>();
for(int i=0;i<parts.length();i++) { for (int i = 0; i < parts.length(); i++) {
JSONObject item = parts.getJSONObject(i); JSONObject item = parts.getJSONObject(i);
item.put("_type", CommonConstants.REM_PART_RELATION_ENTITTY); item.put("_type", CommonConstants.REM_PART_RELATION_ENTITTY);
item.put("remindId", remindId); item.put("remindId", remindId);
item.put("id", UUID.randomUUID()); item.put("id", UUID.randomUUID());
String partType = item.getString(RemPartRelationConstants.PARTICIPATE_TYPE); String partType = item.getString(RemPartRelationConstants.PARTICIPATE_TYPE);
if(ParterType.PERSON.getPartnerType().equals(partType)){ if (ParterType.PERSON.getPartnerType().equals(partType)) {
//参与者id是员工的id // 参与者id是员工的id
String staffPartId = item.getString(RemPartRelationConstants.PARTICIPATE_ID); String staffPartId = item.getString(RemPartRelationConstants.PARTICIPATE_ID);
//根据员工的参与者id获得userId // 根据员工的参与者id获得userId
KObject staffKObject = staffService.getById(UUID.fromString(staffPartId)); KObject staffKObject = staffService.getById(UUID.fromString(staffPartId));
KObject userKObject = staffKObject.get(Staff.USER); KObject userKObject = staffKObject.get(Staff.USER);
String userId = userKObject.getString("id"); String userId = userKObject.getString("id");
item.put(RemPartRelationConstants.PARTICIPATE_ID, userId); item.put(RemPartRelationConstants.PARTICIPATE_ID, userId);
} }
KObject entity =(KObject) JSONObjectUtils.toObject(item.toString()); KObject entity = (KObject) JSONObjectUtils.toObject(item.toString());
listRes.add(entity); listRes.add(entity);
entity.validate(); entity.validate();
} }
...@@ -236,12 +252,15 @@ public class BaseBusinessWarn { ...@@ -236,12 +252,15 @@ public class BaseBusinessWarn {
private WarningService getWarningSettingService() { private WarningService getWarningSettingService() {
return Amino.getApplicationMetadataContext().getBean(WarningService.class); return Amino.getApplicationMetadataContext().getBean(WarningService.class);
} }
private RemindService getRemindService() { private RemindService getRemindService() {
return Amino.getApplicationMetadataContext().getBean(RemindService.class); return Amino.getApplicationMetadataContext().getBean(RemindService.class);
} }
private StaffService getStaffService() { private StaffService getStaffService() {
return Amino.getApplicationMetadataContext().getBean(StaffService.class); return Amino.getApplicationMetadataContext().getBean(StaffService.class);
} }
private StaffDAO getStaffDAO() { private StaffDAO getStaffDAO() {
return Amino.getApplicationMetadataContext().getBean(StaffDAO.class); return Amino.getApplicationMetadataContext().getBean(StaffDAO.class);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment