Commit 6205299f by 王衍超

解决错误;

parent 306ff2f9
package com.xyst.dinas.biz.config;
import com.xyst.dinas.biz.warn.WarnSettingDao;
/**
* 预警配置
*
* @author Jackpot
* @date 2021年4月1日
*/
import org.springframework.context.annotation.Bean;
public class WarningConfiguration {
@Bean
public WarnSettingDao warnSettingDao() {
return new WarnSettingDao();
}
}
......@@ -3,9 +3,13 @@ package com.xyst.dinas.biz.warn;
import java.util.List;
import java.util.UUID;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import com.beecode.amino.core.Amino;
import com.beecode.inz.message.service.RemindService;
/**
* 业务预警基类
*
......@@ -14,24 +18,37 @@ import org.springframework.util.Assert;
*/
public class BaseBusinessWarn {
/** 业务类型*/
protected String billType;
/** 业务ID*/
protected UUID billId;
/** 指标*/
protected String target;
private IWarningCalculate warningCalculate;
public BaseBusinessWarn(String billType, @Nullable UUID billId,String target) {
private WarnSettingDao warnSettingDao;
private RemindService remindService;
public BaseBusinessWarn(@NonNull String billType, @Nullable UUID billId, @Nullable String target) {
Assert.notNull(billType, "The billType must not be null!");
this.billType = billType;
this.billId = billId;
this.target = target;
remindService = getRemindService();
warnSettingDao = getWarnSettingDao();
}
/** 预警设置*/
protected WarnSetting getWarnSetting() {
//通过billType, billId, target 在数据库查询预警设置数据
warnSettingDao.getWarnSetting(billType, billId, target);
WarnSettingEntity warnSettingEntity = new WarnSettingEntity();
warnSettingEntity.setNoticePersons(null);
// warnSettingEntity.setNoticePersons(null);
return warnSettingEntity;
};
......@@ -46,20 +63,29 @@ public class BaseBusinessWarn {
boolean isWarning = false;
WarnSetting warnSetting = getWarnSetting();
if(warnSetting==null || !warnSetting.isWarning()) return false;
if(warnSetting==null || !warnSetting.isOpen()) return false;
Assert.notNull(warningCalculate, "The warningCalculate must not be null!");
//计算业务实际的值, 与预警设置中的值做比较, 计算是否预警
isWarning = warningCalculate.isWarning(warnSetting);
if(!isWarning) return false;
List<String> noticePerson = warnSetting.getNoticePersons();
for (String person : noticePerson) {
//TODO 通知所有人员
}
String[] noticePerson = warnSetting.getPersonnel();
notice(noticePerson);
//TODO 记录预警日志
return true;
};
public void notice(String[] noticePerson) {
//TODO 通知所有人员
// remindService.
}
private WarnSettingDao getWarnSettingDao() {
return Amino.getApplicationMetadataContext().getBean(WarnSettingDao.class);
}
private RemindService getRemindService() {
return Amino.getApplicationMetadataContext().getBean(RemindService.class);
}
}
package com.xyst.dinas.biz.warn;
/**
* 砂石余量预警计算器
*
* @author Jackpot
* @date 2021年4月1日
*/
public class DinasCountWarningCalculate implements IWarningCalculate{
//砂石余量
private int dinsaCount;
/**
*
* @param dinsaCount 砂石余量
*/
public DinasCountWarningCalculate(int dinsaCount) {
this.dinsaCount = dinsaCount;
}
@Override
public boolean isWarning(WarnSetting warnSetting) {
String min = warnSetting.getMin();
//业务数据与设置的阀值做比较,计算是否预警
if (dinsaCount <= Integer.valueOf(min)) {
return true;
}
return false;
}
public int getDinsaCount() {
return dinsaCount;
}
public void setDinsaCount(int dinsaCount) {
this.dinsaCount = dinsaCount;
}
}
......@@ -16,9 +16,8 @@ public interface WarnSetting {
//触发时机
/** 预警开关:是否预警*/
boolean isWarning();
boolean isOpen();
/** 预警设置ID*/
UUID getSettingId();
......@@ -30,17 +29,16 @@ public interface WarnSetting {
UUID getBillId();
/** 指标名称*/
String getTargetName();
String getTarget();
/** 阀值上限*/
String getCeilingLimit();
String getMax();
/** 阀值下限*/
String getFloorLimit();
String getMin();
/** 人员*/
List<String> getNoticePersons();
String[] getPersonnel();
}
......@@ -3,7 +3,7 @@ package com.xyst.dinas.biz.warn;
public class WarnSettingConstant {
/** 实体名:合同信息表 */
public static final String ENTITY = "com.xyst.dinas.contract.datamodel.WarnSetting";
public static final String ENTITY = "com.xyst.dinas.biz.datamodel.WarnSetting";
/** 项目 */
......
......@@ -43,54 +43,52 @@ public class WarnSettingDao {
public List<KObject> queryContractByCode(String contractCode) {
return (List<KObject>)template.execute((session)->{
Query<KObject> query = session.createQuery("from " + WarnSettingConstant.ENTITY + " where (discard is null or discard = 0) and contractCode =:contractCode", KObject.class);
Query<KObject> query = session.createQuery("from " + WarnSettingConstant.ENTITY + " where billType =:billType", KObject.class);
query.setParameter("contractCode", contractCode);
return query.getResultList();
});
}
private String QUERY_HQL = "from " + WarnSettingConstant.ENTITY + " where billType =:billType";
private String QUERY_HQL =
"from " + "" + " where contractState =:contractState and purchaseSandUnit.id =:purchaseSandUnit ";
public JSONArray getProjectListByPurSandId(UUID purchaseSandId,UUID projectType,String projectName) {
public WarnSetting getWarnSetting(String billType, UUID billId, String target) {
JSONArray result =
return
template.execute(session -> {
JSONArray jsonArray = new JSONArray();
StringBuilder hql = new StringBuilder(QUERY_HQL);
if(projectType!=null) hql.append(" and project.projectType.id =:projectType");
if(projectName!=null) hql.append(" and project.projectName like :projectName");
if(billId!=null) hql.append(" and billId =:billId");
if(target!=null) hql.append(" and target =:target");
Query<KObject> query = session.createQuery(hql.toString(), KObject.class);//KObject
query.setParameter("purchaseSandUnit", purchaseSandId);
query.setParameter("contractState", "");//只查询执行中状态的合同
if(projectType!=null) query.setParameter("projectType", projectType);
if(projectName!=null) query.setParameter("projectName", "%"+projectName+"%");
List<KObject> list = query.list();
query.setParameter("billType", billType);
if(billId!=null) query.setParameter("billId", billId);
if(target!=null) query.setParameter("target", target);
KObject singleResult = query.getSingleResult();
UUID settingId = singleResult.getUuid("id");
UUID billId2 = singleResult.getUuid("billId");
String target2 = singleResult.getString("target");
String max = singleResult.getString("max");
String min = singleResult.getString("min");
String personnel = singleResult.getString("personnel");
boolean isOpen = singleResult.getBoolean("isOpen");
WarnSettingEntity warnSettingEntity = new WarnSettingEntity();
warnSettingEntity.setBillType(billType);
warnSettingEntity.setBillId(billId2);
warnSettingEntity.setTarget(target2);
warnSettingEntity.setSettingId(settingId);
warnSettingEntity.setMin(min);
warnSettingEntity.setMax(max);
warnSettingEntity.setOpen(isOpen);
// List<String> personnel
String[] person = personnel.split(",");
warnSettingEntity.setPersonnel(person);
for (int i = 0; i < list.size(); i++) {
KObject contract = list.get(i);
KObject project = contract.get("project");
UUID projectId = project.getUuid("id");
String projectNameWhole = project.getString("projectName");
Date createTime = project.getDate("createTime");
String projectNum = project.getString("projectNum");
String projectTypeName = project.get("projectType").getString("name");
Map<String, Object> map = new HashMap<>();
map.put("projectId", projectId);
map.put("projectNameWhole", projectNameWhole);
map.put("projectTypeName", projectTypeName);
map.put("createTime", DateUtil.dateTime2String(createTime));
map.put("projectNum", projectNum);
jsonArray.put(map);
}
return jsonArray;
return warnSettingEntity;
});
return result;
}
public List<KObject> getProjectListByPurSand(UUID purchaseSandId,UUID projectType,String projectName) {
......
package com.xyst.dinas.biz.warn;
import java.util.List;
import java.util.UUID;
public class WarnSettingEntity implements WarnSetting{
private boolean isWarning;
private UUID settingId;
private String billType;
private UUID billId;
private String targetName;
private String target;
String ceilingLimit;
String floorLimit;
List<String> noticePersons;
public boolean isWarning() {
return isWarning;
}
private String max;
private String min;
private String[] personnel;
private boolean isOpen;
public UUID getSettingId() {
return settingId;
}
public void setSettingId(UUID settingId) {
this.settingId = settingId;
}
public String getBillType() {
return billType;
}
public void setBillType(String billType) {
this.billType = billType;
}
public UUID getBillId() {
return billId;
}
public String getTargetName() {
return targetName;
}
public String getCeilingLimit() {
return ceilingLimit;
}
public String getFloorLimit() {
return floorLimit;
public void setBillId(UUID billId) {
this.billId = billId;
}
public List<String> getNoticePersons() {
return noticePersons;
public String getTarget() {
return target;
}
public void setWarning(boolean isWarning) {
this.isWarning = isWarning;
public void setTarget(String target) {
this.target = target;
}
public void setSettingId(UUID settingId) {
this.settingId = settingId;
public String getMax() {
return max;
}
public void setBillType(String billType) {
this.billType = billType;
public void setMax(String max) {
this.max = max;
}
public void setBillId(UUID billId) {
this.billId = billId;
public String getMin() {
return min;
}
public void setTargetName(String targetName) {
this.targetName = targetName;
public void setMin(String min) {
this.min = min;
}
public void setCeilingLimit(String ceilingLimit) {
this.ceilingLimit = ceilingLimit;
public String[] getPersonnel() {
return personnel;
}
public void setFloorLimit(String floorLimit) {
this.floorLimit = floorLimit;
public void setPersonnel(String[] personnel) {
this.personnel = personnel;
}
public void setNoticePersons(List<String> noticePersons) {
this.noticePersons = noticePersons;
public boolean isOpen() {
return isOpen;
}
public void setOpen(boolean isOpen) {
this.isOpen = isOpen;
}
}
......@@ -14,16 +14,8 @@ public class WarnTest {
int count = 10000;//青砂余量
ContractBusinessWarn contractBusinessWarn = new ContractBusinessWarn(billType, billId,target);
contractBusinessWarn.setWarningCalculate((warnSetting)->{
//拿到预警设置信息
String floorLimit = warnSetting.getFloorLimit();
//业务数据与设置的阀值做比较,计算是否预警
if (count<=Integer.valueOf(floorLimit)) {
return true;
}
return false;
});
DinasCountWarningCalculate dinasCountWarningCalculate = new DinasCountWarningCalculate(count);
contractBusinessWarn.setWarningCalculate(dinasCountWarningCalculate);
contractBusinessWarn.warn();
}
......
......@@ -6,4 +6,5 @@ com.xyst.dinas.biz.config.ShipConfiguration,\
com.xyst.dinas.biz.config.SceneConfiguration,\
com.xyst.dinas.biz.config.DinasOrganizationConfig,\
com.xyst.dinas.biz.config.BizDataInitializerConfig,\
com.xyst.dinas.biz.config.DinasCommonConfiguration
\ No newline at end of file
com.xyst.dinas.biz.config.DinasCommonConfiguration,\
com.xyst.dinas.biz.config.WarningConfiguration
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<metadata xmlns="http://www.beecode.cn/schema/amino-metadata" xmlns:m="http://www.beecode.cn/schema/inz-query">
<specification>1.0</specification>
<id>7226bf7b-a061-4554-bef3-c7968b05fdba</id>
<name>com.xyst.dinas.contract.query.WarningExe</name>
<title>执行预警</title>
<define>inz.query.Query</define>
<define-version>1.0</define-version>
<dependency>com.xyst.dinas.biz.datamodel.WarningExe</dependency>
<content>
<m:query>
<m:type>com.xyst.dinas.biz.datamodel.WarningExe</m:type>
<m:dataProcessor>com.xyst.dinas.contract.query.processor.PerformWarningProcessor</m:dataProcessor>
<m:authorityItem></m:authorityItem>
<m:innerScenes>
<m:innerScene>
<m:id>fa6d9e0d-a774-4f90-b20a-b4b3d5b468a6</m:id>
<m:title>全部</m:title>
<m:javaImplement>com.beecode.inz.common.scene.CommonAllScene</m:javaImplement>
<m:defaultExecute></m:defaultExecute>
<m:hide></m:hide>
</m:innerScene>
<m:innerScene>
<m:id>12cb7e87-edde-4447-ac5f-53fcd2bdc163</m:id>
<m:title>已废弃</m:title>
<m:javaImplement>com.beecode.inz.common.scene.DefaultDiscardScene</m:javaImplement>
<m:defaultExecute></m:defaultExecute>
<m:hide></m:hide>
</m:innerScene>
</m:innerScenes>
<m:fields>
<m:field>
<m:name>id</m:name>
<m:title>id</m:title>
<m:type>uuid</m:type>
<m:ref>
<m:name></m:name>
<m:type></m:type>
</m:ref>
<m:desc></m:desc>
</m:field>
<m:field>
<m:name>startTime</m:name>
<m:title>开始时间</m:title>
<m:type>datetime</m:type>
<m:ref>
<m:name></m:name>
<m:type></m:type>
</m:ref>
<m:desc></m:desc>
</m:field>
<m:field>
<m:name>endTime</m:name>
<m:title>结束时间</m:title>
<m:type>datetime</m:type>
<m:ref>
<m:name></m:name>
<m:type></m:type>
</m:ref>
<m:desc></m:desc>
</m:field>
<m:field>
<m:name>purchaseSandUnitName</m:name>
<m:title>购砂单位</m:title>
<m:type>string</m:type>
<m:ref>
<m:name></m:name>
<m:type></m:type>
</m:ref>
<m:desc></m:desc>
</m:field>
<m:field>
<m:name>projectName</m:name>
<m:title>项目名称</m:title>
<m:type>string</m:type>
<m:ref>
<m:name></m:name>
<m:type></m:type>
</m:ref>
<m:desc></m:desc>
</m:field>
<m:field>
<m:name>contractName</m:name>
<m:title>合同名称</m:title>
<m:type>string</m:type>
<m:ref>
<m:name></m:name>
<m:type></m:type>
</m:ref>
<m:desc></m:desc>
</m:field>
<m:field>
<m:name>target</m:name>
<m:title>预警指标</m:title>
<m:type>string</m:type>
<m:ref>
<m:name></m:name>
<m:type></m:type>
</m:ref>
<m:desc></m:desc>
</m:field>
<m:field>
<m:name>min</m:name>
<m:title>实际值</m:title>
<m:type>string</m:type>
<m:ref>
<m:name></m:name>
<m:type></m:type>
</m:ref>
<m:desc></m:desc>
</m:field>
<m:field>
<m:name>createTime</m:name>
<m:title>创建时间</m:title>
<m:type>datetime</m:type>
<m:ref>
<m:name></m:name>
<m:type></m:type>
</m:ref>
<m:desc></m:desc>
</m:field>
<m:field>
<m:name>creator.name</m:name>
<m:title>创建人</m:title>
<m:type>string</m:type>
<m:ref>
<m:name></m:name>
<m:type></m:type>
</m:ref>
<m:desc></m:desc>
</m:field>
<m:field>
<m:name>modifyTime</m:name>
<m:title>修改时间</m:title>
<m:type>datetime</m:type>
<m:ref>
<m:name></m:name>
<m:type></m:type>
</m:ref>
<m:desc></m:desc>
</m:field>
<m:field>
<m:name>modifier.name</m:name>
<m:title>修改人</m:title>
<m:type>string</m:type>
<m:ref>
<m:name></m:name>
<m:type></m:type>
</m:ref>
<m:desc></m:desc>
</m:field>
</m:fields>
</m:query>
</content>
</metadata>
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