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