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; ...@@ -3,9 +3,13 @@ package com.xyst.dinas.biz.warn;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import org.springframework.lang.NonNull;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.util.Assert; 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; ...@@ -14,24 +18,37 @@ import org.springframework.util.Assert;
*/ */
public class BaseBusinessWarn { public class BaseBusinessWarn {
/** 业务类型*/
protected String billType; protected String billType;
/** 业务ID*/
protected UUID billId; protected UUID billId;
/** 指标*/
protected String target; protected String target;
private IWarningCalculate warningCalculate; 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.billType = billType;
this.billId = billId; this.billId = billId;
this.target = target; this.target = target;
remindService = getRemindService();
warnSettingDao = getWarnSettingDao();
} }
/** 预警设置*/ /** 预警设置*/
protected WarnSetting getWarnSetting() { protected WarnSetting getWarnSetting() {
//通过billType, billId, target 在数据库查询预警设置数据 //通过billType, billId, target 在数据库查询预警设置数据
warnSettingDao.getWarnSetting(billType, billId, target);
WarnSettingEntity warnSettingEntity = new WarnSettingEntity(); WarnSettingEntity warnSettingEntity = new WarnSettingEntity();
warnSettingEntity.setNoticePersons(null); // warnSettingEntity.setNoticePersons(null);
return warnSettingEntity; return warnSettingEntity;
}; };
...@@ -46,20 +63,29 @@ public class BaseBusinessWarn { ...@@ -46,20 +63,29 @@ public class BaseBusinessWarn {
boolean isWarning = false; boolean isWarning = false;
WarnSetting warnSetting = getWarnSetting(); 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!"); Assert.notNull(warningCalculate, "The warningCalculate must not be null!");
//计算业务实际的值, 与预警设置中的值做比较, 计算是否预警 //计算业务实际的值, 与预警设置中的值做比较, 计算是否预警
isWarning = warningCalculate.isWarning(warnSetting); isWarning = warningCalculate.isWarning(warnSetting);
if(!isWarning) return false; if(!isWarning) return false;
List<String> noticePerson = warnSetting.getNoticePersons(); String[] noticePerson = warnSetting.getPersonnel();
for (String person : noticePerson) { notice(noticePerson);
//TODO 通知所有人员
}
//TODO 记录预警日志 //TODO 记录预警日志
return true; 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 { ...@@ -16,9 +16,8 @@ public interface WarnSetting {
//触发时机 //触发时机
/** 预警开关:是否预警*/ /** 预警开关:是否预警*/
boolean isWarning(); boolean isOpen();
/** 预警设置ID*/ /** 预警设置ID*/
UUID getSettingId(); UUID getSettingId();
...@@ -30,17 +29,16 @@ public interface WarnSetting { ...@@ -30,17 +29,16 @@ public interface WarnSetting {
UUID getBillId(); 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; ...@@ -3,7 +3,7 @@ package com.xyst.dinas.biz.warn;
public class WarnSettingConstant { 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 { ...@@ -43,54 +43,52 @@ public class WarnSettingDao {
public List<KObject> queryContractByCode(String contractCode) { public List<KObject> queryContractByCode(String contractCode) {
return (List<KObject>)template.execute((session)->{ 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); query.setParameter("contractCode", contractCode);
return query.getResultList(); return query.getResultList();
}); });
} }
private String QUERY_HQL = "from " + WarnSettingConstant.ENTITY + " where billType =:billType";
private String QUERY_HQL = public WarnSetting getWarnSetting(String billType, UUID billId, String target) {
"from " + "" + " where contractState =:contractState and purchaseSandUnit.id =:purchaseSandUnit ";
public JSONArray getProjectListByPurSandId(UUID purchaseSandId,UUID projectType,String projectName) {
JSONArray result = return
template.execute(session -> { template.execute(session -> {
JSONArray jsonArray = new JSONArray();
StringBuilder hql = new StringBuilder(QUERY_HQL); StringBuilder hql = new StringBuilder(QUERY_HQL);
if(projectType!=null) hql.append(" and project.projectType.id =:projectType"); if(billId!=null) hql.append(" and billId =:billId");
if(projectName!=null) hql.append(" and project.projectName like :projectName"); if(target!=null) hql.append(" and target =:target");
Query<KObject> query = session.createQuery(hql.toString(), KObject.class);//KObject Query<KObject> query = session.createQuery(hql.toString(), KObject.class);//KObject
query.setParameter("purchaseSandUnit", purchaseSandId); query.setParameter("billType", billType);
query.setParameter("contractState", "");//只查询执行中状态的合同 if(billId!=null) query.setParameter("billId", billId);
if(projectType!=null) query.setParameter("projectType", projectType); if(target!=null) query.setParameter("target", target);
if(projectName!=null) query.setParameter("projectName", "%"+projectName+"%"); KObject singleResult = query.getSingleResult();
List<KObject> list = query.list();
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++) { return warnSettingEntity;
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 result;
} }
public List<KObject> getProjectListByPurSand(UUID purchaseSandId,UUID projectType,String projectName) { public List<KObject> getProjectListByPurSand(UUID purchaseSandId,UUID projectType,String projectName) {
......
package com.xyst.dinas.biz.warn; package com.xyst.dinas.biz.warn;
import java.util.List;
import java.util.UUID; import java.util.UUID;
public class WarnSettingEntity implements WarnSetting{ public class WarnSettingEntity implements WarnSetting{
private boolean isWarning;
private UUID settingId; private UUID settingId;
private String billType; private String billType;
private UUID billId; private UUID billId;
private String targetName; private String target;
String ceilingLimit; private String max;
String floorLimit; private String min;
List<String> noticePersons; private String[] personnel;
private boolean isOpen;
public boolean isWarning() {
return isWarning;
}
public UUID getSettingId() { public UUID getSettingId() {
return settingId; return settingId;
} }
public void setSettingId(UUID settingId) {
this.settingId = settingId;
}
public String getBillType() { public String getBillType() {
return billType; return billType;
} }
public void setBillType(String billType) {
this.billType = billType;
}
public UUID getBillId() { public UUID getBillId() {
return billId; return billId;
} }
public String getTargetName() {
return targetName; public void setBillId(UUID billId) {
} this.billId = billId;
public String getCeilingLimit() {
return ceilingLimit;
}
public String getFloorLimit() {
return floorLimit;
} }
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 { ...@@ -14,16 +14,8 @@ public class WarnTest {
int count = 10000;//青砂余量 int count = 10000;//青砂余量
ContractBusinessWarn contractBusinessWarn = new ContractBusinessWarn(billType, billId,target); ContractBusinessWarn contractBusinessWarn = new ContractBusinessWarn(billType, billId,target);
contractBusinessWarn.setWarningCalculate((warnSetting)->{ DinasCountWarningCalculate dinasCountWarningCalculate = new DinasCountWarningCalculate(count);
contractBusinessWarn.setWarningCalculate(dinasCountWarningCalculate);
//拿到预警设置信息
String floorLimit = warnSetting.getFloorLimit();
//业务数据与设置的阀值做比较,计算是否预警
if (count<=Integer.valueOf(floorLimit)) {
return true;
}
return false;
});
contractBusinessWarn.warn(); contractBusinessWarn.warn();
} }
......
...@@ -6,4 +6,5 @@ com.xyst.dinas.biz.config.ShipConfiguration,\ ...@@ -6,4 +6,5 @@ com.xyst.dinas.biz.config.ShipConfiguration,\
com.xyst.dinas.biz.config.SceneConfiguration,\ com.xyst.dinas.biz.config.SceneConfiguration,\
com.xyst.dinas.biz.config.DinasOrganizationConfig,\ com.xyst.dinas.biz.config.DinasOrganizationConfig,\
com.xyst.dinas.biz.config.BizDataInitializerConfig,\ com.xyst.dinas.biz.config.BizDataInitializerConfig,\
com.xyst.dinas.biz.config.DinasCommonConfiguration com.xyst.dinas.biz.config.DinasCommonConfiguration,\
\ No newline at end of file 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