Commit 337f46a0 by 高晓磊

散户预警功能

parent d5568749
...@@ -7,6 +7,8 @@ import com.xyst.dinas.biz.constant.RetailInfoConstant; ...@@ -7,6 +7,8 @@ import com.xyst.dinas.biz.constant.RetailInfoConstant;
import com.xyst.dinas.biz.dao.RetailInfoDao; import com.xyst.dinas.biz.dao.RetailInfoDao;
import com.xyst.dinas.biz.internal.dao.RetailInfoDaoImpl; import com.xyst.dinas.biz.internal.dao.RetailInfoDaoImpl;
import com.xyst.dinas.biz.internal.service.RetailInfoServiceImpl; import com.xyst.dinas.biz.internal.service.RetailInfoServiceImpl;
import com.xyst.dinas.biz.processor.RetailInfoBuyAmountWarningCalculator;
import com.xyst.dinas.biz.processor.RetailInfoBuyCountWarningCalculator;
import com.xyst.dinas.biz.service.RetailInfoService; import com.xyst.dinas.biz.service.RetailInfoService;
import com.xyst.dinas.biz.web.RetailInfoController; import com.xyst.dinas.biz.web.RetailInfoController;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -44,5 +46,14 @@ public class RetailInfoConfiguration { ...@@ -44,5 +46,14 @@ public class RetailInfoConfiguration {
new ClassPathResource("/com/xyst/dinas/biz/datamodel/RetailInfo.jmx", KClass.class)); new ClassPathResource("/com/xyst/dinas/biz/datamodel/RetailInfo.jmx", KClass.class));
} }
@Bean("com.xyst.dinas.biz.processor.RetailInfoBuyCountWarningCalculator")
public RetailInfoBuyCountWarningCalculator retailInfoBuyCountWarningCalculator () {
return new RetailInfoBuyCountWarningCalculator();
}
@Bean("com.xyst.dinas.biz.processor.RetailInfoBuyAmountWarningCalculator")
public RetailInfoBuyAmountWarningCalculator retailInfoBuyAmountWarningCalculator () {
return new RetailInfoBuyAmountWarningCalculator();
}
} }
...@@ -5,5 +5,35 @@ public interface RetailInfoConstant { ...@@ -5,5 +5,35 @@ public interface RetailInfoConstant {
* 实体名 * 实体名
*/ */
String ENTITY = "com.xyst.dinas.biz.datamodel.RetailInfo"; String ENTITY = "com.xyst.dinas.biz.datamodel.RetailInfo";
/**
* 实体名
*/
String DETAIL_ENTITY = "com.xyst.dinas.biz.datamodel.RetailInfoAssociatedDinasTypeDetail";
/**
* 散客购买预警类型
*/
public static final String RETAIL_INFO_WARN_BILL_TYPE = "散客购买";
/**
* 散客购买预警指标-购买次数
*/
public static final String RETAIL_INFO_WARN_BUY_COUNT = "购买次数";
/**
* 散客购买预警指标-购买重量
*/
public static final String RETAIL_INFO_WARN_BUY_AMOUNT = "购买重量";
/**
* 购买次数预警计算器
*/
public static final String RETAIL_INFO_BUY_COUNT_WARNING_CALCULATOR = "com.xyst.dinas.biz.processor.RetailInfoBuyCountWarningCalculator";
/**
* 购买重量(总量)预警计算器
*/
public static final String RETAIL_INFO_BUY_AMOUNT_WARNING_CALCULATOR = "com.xyst.dinas.biz.processor.RetailInfoBuyAmountWarningCalculator";
} }
...@@ -4,6 +4,7 @@ import com.beecode.bap.attachment.common.Page; ...@@ -4,6 +4,7 @@ import com.beecode.bap.attachment.common.Page;
import com.beecode.bcp.type.KObject; import com.beecode.bcp.type.KObject;
import com.beecode.inz.basis.dao.BaseDao; import com.beecode.inz.basis.dao.BaseDao;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
...@@ -23,6 +24,11 @@ public interface RetailInfoDao extends BaseDao { ...@@ -23,6 +24,11 @@ public interface RetailInfoDao extends BaseDao {
List<KObject> getByName(String name, UUID id); List<KObject> getByName(String name, UUID id);
void modify(KObject kobject); void modify(KObject kobject, KObject oldKObject);
void deleteDetailByMasterId(UUID uuid);
Long selectBuyCountByIdCard(String idCard, UUID uuid);
BigDecimal selectBuyAmountByIdCard(String idCard, UUID fromString);
} }
...@@ -5,20 +5,26 @@ import com.beecode.bap.attachment.common.Page; ...@@ -5,20 +5,26 @@ import com.beecode.bap.attachment.common.Page;
import com.beecode.bcp.core.context.AminoContextHolder; import com.beecode.bcp.core.context.AminoContextHolder;
import com.beecode.bcp.type.KClass; import com.beecode.bcp.type.KClass;
import com.beecode.bcp.type.KObject; import com.beecode.bcp.type.KObject;
import com.beecode.inz.basis.context.warehouse.WarehouseUserContextHolder;
import com.beecode.inz.basis.dao.WarehouseUserDao;
import com.beecode.inz.basis.internal.dao.AbstractBaseDao; import com.beecode.inz.basis.internal.dao.AbstractBaseDao;
import com.beecode.inz.basis.pojo.WarehouseUser;
import com.beecode.inz.common.BaseConstants; import com.beecode.inz.common.BaseConstants;
import com.xyst.dinas.biz.constant.ProductionLineConstant;
import com.xyst.dinas.biz.constant.RetailInfoConstant; import com.xyst.dinas.biz.constant.RetailInfoConstant;
import com.xyst.dinas.biz.dao.DinasTypeDao; import com.xyst.dinas.biz.dao.DinasTypeDao;
import com.xyst.dinas.biz.dao.RetailInfoDao; import com.xyst.dinas.biz.dao.RetailInfoDao;
import com.xyst.dinas.biz.dao.StationDao;
import org.hibernate.criterion.DetachedCriteria; import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order; import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions; import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate; import org.springframework.orm.hibernate5.HibernateTemplate;
import java.math.BigDecimal;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.UUID; import java.util.UUID;
public class RetailInfoDaoImpl extends AbstractBaseDao implements RetailInfoDao, RetailInfoConstant { public class RetailInfoDaoImpl extends AbstractBaseDao implements RetailInfoDao, RetailInfoConstant {
...@@ -29,6 +35,12 @@ public class RetailInfoDaoImpl extends AbstractBaseDao implements RetailInfoDao, ...@@ -29,6 +35,12 @@ public class RetailInfoDaoImpl extends AbstractBaseDao implements RetailInfoDao,
@Autowired @Autowired
private DinasTypeDao dinasTypeDao; private DinasTypeDao dinasTypeDao;
@Autowired
private StationDao stationDao;
@Autowired
private WarehouseUserDao warehouseUserDao;
@Override @Override
public KObject load(UUID id) { public KObject load(UUID id) {
return (KObject) template.load(ENTITY, id); return (KObject) template.load(ENTITY, id);
...@@ -38,9 +50,8 @@ public class RetailInfoDaoImpl extends AbstractBaseDao implements RetailInfoDao, ...@@ -38,9 +50,8 @@ public class RetailInfoDaoImpl extends AbstractBaseDao implements RetailInfoDao,
public Page<KObject> listRetailInfoInfoPaging(Page<KObject> page, Integer retailInfoStatus) { public Page<KObject> listRetailInfoInfoPaging(Page<KObject> page, Integer retailInfoStatus) {
KClass bean = Amino.getStaticMetadataContext().getBean(RetailInfoConstant.ENTITY, KClass.class); KClass bean = Amino.getStaticMetadataContext().getBean(RetailInfoConstant.ENTITY, KClass.class);
DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName()); DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName());
// detachedCriteria.add(Restrictions.eq("department.id", departmentId));
detachedCriteria.add(Restrictions.eq("del", false)); detachedCriteria.add(Restrictions.eq("del", false));
if(null!=retailInfoStatus){ if (null != retailInfoStatus) {
detachedCriteria.add(Restrictions.eq("retailInfoStatus", retailInfoStatus)); detachedCriteria.add(Restrictions.eq("retailInfoStatus", retailInfoStatus));
} }
dinasTypeDao.addRegionalCompanyFilter(detachedCriteria); dinasTypeDao.addRegionalCompanyFilter(detachedCriteria);
...@@ -48,7 +59,7 @@ public class RetailInfoDaoImpl extends AbstractBaseDao implements RetailInfoDao, ...@@ -48,7 +59,7 @@ public class RetailInfoDaoImpl extends AbstractBaseDao implements RetailInfoDao,
detachedCriteria.addOrder(Order.desc("sortOrder")); detachedCriteria.addOrder(Order.desc("sortOrder"));
int offset = page.getPageSize() * (page.getPageNo() - 1); int offset = page.getPageSize() * (page.getPageNo() - 1);
page.setTotal(template.findByCriteria(detachedCriteria).size()); page.setTotal(template.findByCriteria(detachedCriteria).size());
List<KObject> list = (List<KObject>) template.findByCriteria(detachedCriteria,offset,page.getPageSize()); List<KObject> list = (List<KObject>) template.findByCriteria(detachedCriteria, offset, page.getPageSize());
page.setDatas(list); page.setDatas(list);
return page; return page;
} }
...@@ -57,17 +68,16 @@ public class RetailInfoDaoImpl extends AbstractBaseDao implements RetailInfoDao, ...@@ -57,17 +68,16 @@ public class RetailInfoDaoImpl extends AbstractBaseDao implements RetailInfoDao,
public List<KObject> listRetailInfoInfoByRegionalCompany(UUID regionalCompanyId) { public List<KObject> listRetailInfoInfoByRegionalCompany(UUID regionalCompanyId) {
KClass bean = Amino.getStaticMetadataContext().getBean(RetailInfoConstant.ENTITY, KClass.class); KClass bean = Amino.getStaticMetadataContext().getBean(RetailInfoConstant.ENTITY, KClass.class);
DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName()); DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName());
// detachedCriteria.add(Restrictions.eq("department.id", departmentId));
detachedCriteria.add(Restrictions.eq("del", false)); detachedCriteria.add(Restrictions.eq("del", false));
if(null==regionalCompanyId){ if (null == regionalCompanyId) {
KObject currentLoginRegionalCompany = dinasTypeDao.getCurrentLoginRegionalCompany(); KObject currentLoginRegionalCompany = dinasTypeDao.getCurrentLoginRegionalCompany();
if(null!=currentLoginRegionalCompany){ if (null != currentLoginRegionalCompany) {
regionalCompanyId=currentLoginRegionalCompany.getUuid("id"); regionalCompanyId = currentLoginRegionalCompany.getUuid("id");
} }
} }
if(null!=regionalCompanyId){ if (null != regionalCompanyId) {
detachedCriteria.add(Restrictions.eq("regionalCompany.id",regionalCompanyId)); detachedCriteria.add(Restrictions.eq("regionalCompany.id", regionalCompanyId));
} }
detachedCriteria.addOrder(Order.desc("sortOrder")); detachedCriteria.addOrder(Order.desc("sortOrder"));
return (List<KObject>) template.findByCriteria(detachedCriteria); return (List<KObject>) template.findByCriteria(detachedCriteria);
...@@ -76,7 +86,6 @@ public class RetailInfoDaoImpl extends AbstractBaseDao implements RetailInfoDao, ...@@ -76,7 +86,6 @@ public class RetailInfoDaoImpl extends AbstractBaseDao implements RetailInfoDao,
@Override @Override
public List<KObject> getByName(String name, UUID id) { public List<KObject> getByName(String name, UUID id) {
// UUID departmentId = AminoContextHolder.getContext().getStaff().get("department").getUuid("id");
KClass bean = Amino.getStaticMetadataContext().getBean(RetailInfoConstant.ENTITY, KClass.class); KClass bean = Amino.getStaticMetadataContext().getBean(RetailInfoConstant.ENTITY, KClass.class);
DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName()); DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName());
...@@ -84,7 +93,7 @@ public class RetailInfoDaoImpl extends AbstractBaseDao implements RetailInfoDao, ...@@ -84,7 +93,7 @@ public class RetailInfoDaoImpl extends AbstractBaseDao implements RetailInfoDao,
detachedCriteria.add(Restrictions.eq("del", false)); detachedCriteria.add(Restrictions.eq("del", false));
detachedCriteria.add(Restrictions.eq("retailInfoName", name)); detachedCriteria.add(Restrictions.eq("retailInfoName", name));
if(id!=null){ if (id != null) {
detachedCriteria.add(Restrictions.ne("id", id)); detachedCriteria.add(Restrictions.ne("id", id));
} }
...@@ -92,56 +101,62 @@ public class RetailInfoDaoImpl extends AbstractBaseDao implements RetailInfoDao, ...@@ -92,56 +101,62 @@ public class RetailInfoDaoImpl extends AbstractBaseDao implements RetailInfoDao,
} }
@Override @Override
public void modify(KObject kobject) { public void modify(KObject kobject, KObject oldKObject) {
KObject id = load(kobject.getUuid("id")); kobject.set("createUser", oldKObject.get("createUser"));
kobject.set(BaseConstants.CREATOR,id.get(BaseConstants.CREATOR)); kobject.set(BaseConstants.CREATE_TIME, oldKObject.getDate(BaseConstants.CREATE_TIME));
kobject.set(BaseConstants.CREATE_TIME,id.getDate(BaseConstants.CREATE_TIME)); WarehouseUser warehouseUser = WarehouseUserContextHolder.getContext().getWarehouseUser();
KObject staff = AminoContextHolder.getContext().getStaff();
kobject.set("regionalCompany", dinasTypeDao.getCurrentLoginRegionalCompany()); kobject.set("regionalCompany", dinasTypeDao.getCurrentLoginRegionalCompany());
kobject.set(BaseConstants.MODIFY_TIME,new Date()); kobject.set("station", stationDao.load(kobject.get("station").getUuid(BaseConstants.ID)));
kobject.set(BaseConstants.MODIFIER,staff); kobject.set(BaseConstants.MODIFY_TIME, new Date());
kobject.set(BaseConstants.DEL,false); kobject.set("updateUser",warehouseUserDao.findById(warehouseUser.getId()));
template.deleteAll(id.get("productionLines").toList()); kobject.set(BaseConstants.DEL, false);
KObject productions = kobject.get("productionLines"); template.merge(kobject);
if(null!=productions){
List<KObject> kObjects = productions.toList();
for (KObject object : kObjects) {
if(null==object.getUuid("id")){
object.set("id",UUID.randomUUID());
}
object.set("retailInfo",kobject);
template.save(ProductionLineConstant.ENTITY,object);
} }
@Override
public void deleteDetailByMasterId(UUID uuid) {
template.execute(session ->
session.createQuery("delete from " + DETAIL_ENTITY + " where master.id = :id").setParameter("id", uuid).executeUpdate()
);
} }
template.merge(kobject);
@Override
public Long selectBuyCountByIdCard(String idCard, UUID uuid) {
KClass bean = Amino.getStaticMetadataContext().getBean(RetailInfoConstant.ENTITY, KClass.class);
DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName());
detachedCriteria.add(Restrictions.eq("del",false));
detachedCriteria.add(Restrictions.eq("idCard",idCard));
detachedCriteria.add(Restrictions.eq("station.id",uuid));
return (Long) detachedCriteria.setProjection(Projections.rowCount()).getExecutableCriteria(Objects.requireNonNull(template.getSessionFactory()).getCurrentSession()).setFirstResult(0).setMaxResults(1).uniqueResult();
} }
@Override
public BigDecimal selectBuyAmountByIdCard(String idCard, UUID fromString) {
KClass bean = Amino.getStaticMetadataContext().getBean(RetailInfoConstant.DETAIL_ENTITY, KClass.class);
DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName());
detachedCriteria.createAlias("master","master");
detachedCriteria.add(Restrictions.eq("master.del",false));
detachedCriteria.add(Restrictions.eq("master.idCard",idCard));
detachedCriteria.add(Restrictions.eq("master.station.id",fromString));
return (BigDecimal) detachedCriteria.setProjection(Projections.sum("purchaseAmount")).getExecutableCriteria(Objects.requireNonNull(template.getSessionFactory()).getCurrentSession()).setFirstResult(0).setMaxResults(1).uniqueResult();
}
@Override @Override
public UUID create(KObject kObject) { public UUID create(KObject kObject) {
KObject staff = AminoContextHolder.getContext().getStaff();
if(null==kObject.getUuid("id")){ WarehouseUser warehouseUser = WarehouseUserContextHolder.getContext().getWarehouseUser();
kObject.set("id",UUID.randomUUID());
if (null == kObject.getUuid("id")) {
kObject.set("id", UUID.randomUUID());
} }
kObject.set("station", stationDao.load(kObject.get("station").getUuid(BaseConstants.ID)));
kObject.set("createUser",warehouseUserDao.findById(warehouseUser.getId()));
kObject.set("regionalCompany", dinasTypeDao.getCurrentLoginRegionalCompany()); kObject.set("regionalCompany", dinasTypeDao.getCurrentLoginRegionalCompany());
kObject.set(BaseConstants.CREATOR,staff);
kObject.set(BaseConstants.CREATE_TIME, new Date()); kObject.set(BaseConstants.CREATE_TIME, new Date());
kObject.set(BaseConstants.DEL,false); kObject.set(BaseConstants.DEL, false);
UUID save = (UUID) template.save(kObject); return (UUID) template.save(kObject);
KObject productions = kObject.get("productionLines");
if(null!=productions){
List<KObject> kObjects = productions.toList();
for (KObject object : kObjects) {
if(null==object.getUuid("id")){
object.set("id",UUID.randomUUID());
}
object.set("retailInfo",kObject);
template.save(ProductionLineConstant.ENTITY,object);
}
}
return save;
} }
@Override @Override
...@@ -152,11 +167,12 @@ public class RetailInfoDaoImpl extends AbstractBaseDao implements RetailInfoDao, ...@@ -152,11 +167,12 @@ public class RetailInfoDaoImpl extends AbstractBaseDao implements RetailInfoDao,
@Override @Override
public void deleteById(UUID id) { public void deleteById(UUID id) {
KObject staff = AminoContextHolder.getContext().getStaff(); WarehouseUser warehouseUser = WarehouseUserContextHolder.getContext().getWarehouseUser();
KObject kobject = (KObject) template.load(ENTITY, id); KObject kobject = (KObject) template.load(ENTITY, id);
kobject.set(BaseConstants.MODIFY_TIME,new Date()); kobject.set(BaseConstants.MODIFY_TIME, new Date());
kobject.set(BaseConstants.MODIFIER,staff); kobject.set("updateUser",warehouseUser);
kobject.set(BaseConstants.DEL,true); kobject.set(BaseConstants.DEL, true);
kobject.set(BaseConstants.DISCARD, true);
template.update(kobject); template.update(kobject);
} }
......
...@@ -2,12 +2,25 @@ package com.xyst.dinas.biz.internal.service; ...@@ -2,12 +2,25 @@ package com.xyst.dinas.biz.internal.service;
import com.beecode.bap.attachment.common.Page; import com.beecode.bap.attachment.common.Page;
import com.beecode.bcp.type.KObject; import com.beecode.bcp.type.KObject;
import com.beecode.bcp.type.json.JSONObjectUtils;
import com.beecode.inz.common.BaseConstants;
import com.xyst.dinas.biz.constant.RetailInfoConstant;
import com.xyst.dinas.biz.dao.DinasTypeDao;
import com.xyst.dinas.biz.dao.RetailInfoDao; import com.xyst.dinas.biz.dao.RetailInfoDao;
import com.xyst.dinas.biz.processor.RetailInfoBuyAmountWarningCalculate;
import com.xyst.dinas.biz.processor.RetailInfoBuyCountWarningCalculate;
import com.xyst.dinas.biz.service.RetailInfoService; import com.xyst.dinas.biz.service.RetailInfoService;
import com.xyst.dinas.biz.warn.BaseBusinessWarn;
import com.xyst.dinas.biz.warn.WarnSetting;
import com.xyst.dinas.biz.warn.WarnSettingEntity;
import com.xyst.dinas.biz.warn.WarnTargetTypeEnum;
import com.xyst.dinas.biz.warn.service.WarningService;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
...@@ -17,6 +30,11 @@ public class RetailInfoServiceImpl implements RetailInfoService { ...@@ -17,6 +30,11 @@ public class RetailInfoServiceImpl implements RetailInfoService {
@Autowired @Autowired
private RetailInfoDao retailInfoDao; private RetailInfoDao retailInfoDao;
@Autowired
private DinasTypeDao dinasTypeDao;
@Autowired
private WarningService warningService;
@Override @Override
public Page<KObject> queryByPaging(Page<KObject> page, Integer retailInfoStatus) throws Exception { public Page<KObject> queryByPaging(Page<KObject> page, Integer retailInfoStatus) throws Exception {
if(page.getPageNo()==0||page.getPageSize()==0) { if(page.getPageNo()==0||page.getPageSize()==0) {
...@@ -25,13 +43,88 @@ public class RetailInfoServiceImpl implements RetailInfoService { ...@@ -25,13 +43,88 @@ public class RetailInfoServiceImpl implements RetailInfoService {
return retailInfoDao.listRetailInfoInfoPaging(page,retailInfoStatus); return retailInfoDao.listRetailInfoInfoPaging(page,retailInfoStatus);
} }
@Override @Override
public List<KObject> listRetailInfoInfoByRegionalCompany(UUID regionalCompanyId) throws Exception { public List<KObject> listRetailInfoInfoByRegionalCompany(UUID regionalCompanyId) {
return retailInfoDao.listRetailInfoInfoByRegionalCompany(regionalCompanyId); return retailInfoDao.listRetailInfoInfoByRegionalCompany(regionalCompanyId);
} }
@Override @Override
public UUID addRetailInfo(KObject kObject) { public UUID addRetailInfo(KObject newKobject) {
return retailInfoDao.create(kObject); UUID uuid = retailInfoDao.create(newKobject);
setDetail(newKobject, uuid);
//新增散户信息触发预警设置和预警记录
String newRetailInfoName = newKobject.getString("retailInfoName");
String newIdCard = newKobject.getString("idCard");
UUID newStation = newKobject.get("station").getUuid(BaseConstants.ID);
setWarnInfo(newKobject, uuid, newRetailInfoName, newIdCard, newStation);
return uuid;
}
private void setWarnInfo(KObject newKobject, UUID uuid, String retailInfoName, String idCard, UUID station) {
//购买次数预警
//查询场站是否有对应的预警模板
WarnSetting templateCount = warningService.queryOneWarnSettingsByMemoAndType(RetailInfoConstant.RETAIL_INFO_WARN_BUY_COUNT, station.toString(),"template");
if(templateCount==null){
templateCount = setWarningSettingEntity(newKobject, UUID.randomUUID(), RetailInfoConstant.RETAIL_INFO_WARN_BUY_COUNT, RetailInfoConstant.RETAIL_INFO_BUY_COUNT_WARNING_CALCULATOR,"0",true,false);
}
WarnSetting warnSetting = warningService.queryOneWarnSettingsByMemoAndType(RetailInfoConstant.RETAIL_INFO_WARN_BUY_COUNT, idCard, station.toString());
if (warnSetting != null) {
BaseBusinessWarn warn = warningService.createWarn(warnSetting.getSettingId());
warn.setWarningCalculate(new RetailInfoBuyCountWarningCalculate(retailInfoName, idCard, station, selectBuyCountByIdCard(idCard, station)));
warn.warn(false);
} else {
setWarningSettingEntity(newKobject, uuid, RetailInfoConstant.RETAIL_INFO_WARN_BUY_COUNT, RetailInfoConstant.RETAIL_INFO_BUY_COUNT_WARNING_CALCULATOR,templateCount.getMax(),false,true);
}
//购买重量预警
//查询场站是否有对应的预警模板
templateCount = warningService.queryOneWarnSettingsByMemoAndType(RetailInfoConstant.RETAIL_INFO_WARN_BUY_AMOUNT, station.toString(),"template");
if(templateCount==null){
templateCount = setWarningSettingEntity(newKobject, UUID.randomUUID(), RetailInfoConstant.RETAIL_INFO_WARN_BUY_AMOUNT, RetailInfoConstant.RETAIL_INFO_BUY_AMOUNT_WARNING_CALCULATOR,"0",true,false);
}
warnSetting = warningService.queryOneWarnSettingsByMemoAndType(RetailInfoConstant.RETAIL_INFO_WARN_BUY_AMOUNT, idCard, station.toString());
if (warnSetting != null) {
BaseBusinessWarn warn = warningService.createWarn(warnSetting.getSettingId());
warn.setWarningCalculate(new RetailInfoBuyAmountWarningCalculate(retailInfoName, idCard, selectBuyAmountByIdCard(idCard, station).doubleValue()));
warn.warn(false);
} else {
setWarningSettingEntity(newKobject, uuid, RetailInfoConstant.RETAIL_INFO_WARN_BUY_AMOUNT, RetailInfoConstant.RETAIL_INFO_BUY_AMOUNT_WARNING_CALCULATOR,templateCount.getMax(),false,true);
}
}
private WarnSettingEntity setWarningSettingEntity(KObject kObject, UUID uuid,String target,String warnCalculator,String max,boolean isTemplate,boolean isOpen) {
WarnSettingEntity warnSettingEntity = new WarnSettingEntity();
warnSettingEntity.setBillType(RetailInfoConstant.RETAIL_INFO_WARN_BILL_TYPE);
warnSettingEntity.setBillId(uuid);
warnSettingEntity.setTarget(target);
warnSettingEntity.setMax(max);
warnSettingEntity.setTargetType(WarnTargetTypeEnum.INT_TYPE.name());
warnSettingEntity.setOpen(isOpen);
HashMap<String, String> stringStringHashMap = new HashMap<>();
stringStringHashMap.put("stationId", kObject.get("station").getString(BaseConstants.ID));
if(isTemplate){
stringStringHashMap.put("template", "template");
}else{
stringStringHashMap.put("idCard", kObject.getString("idCard"));
stringStringHashMap.put("retailInfoName", kObject.getString("retailInfoName"));
}
warnSettingEntity.setMemo(JSONObjectUtils.toJson(stringStringHashMap).toString());
warnSettingEntity.setWarnCalculator(warnCalculator);
warningService.insertWarnSettingToIsNotice(warnSettingEntity,false);
return warnSettingEntity;
}
private void setDetail(KObject kObject, UUID uuid) {
KObject kObject1 = kObject.get("dinasTypeDetails");
List<KObject> kObjects = kObject1.toList();
for (KObject object : kObjects) {
object.set("master",retailInfoDao.load(uuid));
object.set("dinasType",dinasTypeDao.load(object.get("dinasType").getUuid(BaseConstants.ID)));
object.set(BaseConstants.ID,UUID.randomUUID());
retailInfoDao.saveOrUpdate(object);
}
} }
@Override @Override
...@@ -54,9 +147,27 @@ public class RetailInfoServiceImpl implements RetailInfoService { ...@@ -54,9 +147,27 @@ public class RetailInfoServiceImpl implements RetailInfoService {
} }
@Override @Override
public void update(KObject kobject) { public void update(KObject newKobject) {
UUID uuid = newKobject.getUuid(BaseConstants.ID);
KObject oldKObject = retailInfoDao.load(uuid);
retailInfoDao.modify(newKobject,oldKObject);
retailInfoDao.deleteDetailByMasterId(uuid);
setDetail(newKobject, uuid);
//新增散户信息触发预警设置和预警记录
String newRetailInfoName = newKobject.getString("retailInfoName");
String newIdCard = newKobject.getString("idCard");
UUID newStation = newKobject.get("station").getUuid(BaseConstants.ID);
String oldRetailInfoName = oldKObject.getString("retailInfoName");
String oldIdCard = oldKObject.getString("idCard");
UUID oldStation = oldKObject.get("station").getUuid(BaseConstants.ID);
retailInfoDao.modify(kobject); //购买预警
setWarnInfo(newKobject, uuid, newRetailInfoName, newIdCard, newStation);
if(!oldIdCard.equals(newIdCard)){
//旧的购买预警
setWarnInfo(oldKObject, uuid, oldRetailInfoName, oldIdCard, oldStation);
}
} }
@Override @Override
...@@ -64,5 +175,16 @@ public class RetailInfoServiceImpl implements RetailInfoService { ...@@ -64,5 +175,16 @@ public class RetailInfoServiceImpl implements RetailInfoService {
retailInfoDao.deleteById(id); retailInfoDao.deleteById(id);
} }
@Override
public Long selectBuyCountByIdCard(String idCard, UUID uuid) {
return retailInfoDao.selectBuyCountByIdCard(idCard,uuid);
}
@Override
public BigDecimal selectBuyAmountByIdCard(String idCard, UUID fromString) {
return retailInfoDao.selectBuyAmountByIdCard(idCard,fromString);
}
} }
package com.xyst.dinas.biz.processor;
import com.xyst.dinas.biz.warn.IWarningCalculator;
import com.xyst.dinas.biz.warn.WarnSetting;
import java.util.UUID;
/**
* retail散客购买重量(总量)预警
*
* @author
* @date 2021年4月1日
*/
public class RetailInfoBuyAmountWarningCalculate implements IWarningCalculator{
private String warnMessage;
private final String retailInfoName;
private final String idCard;
private final double buyAmount;
/**
* 散客购买次数预警
* @param buyAmount 购买次数
*/
public RetailInfoBuyAmountWarningCalculate(String retailInfoName, String idCard, double buyAmount) {
this.retailInfoName = retailInfoName;
this.idCard = idCard;
this.buyAmount = buyAmount;
}
@Override
public boolean isWarning(WarnSetting warnSetting) {
String max = warnSetting.getMax();
String target = warnSetting.getTarget();
if(max==null || max.trim().length()==0) {
return false;
}
//业务数据与设置的阀值做比较,计算是否预警
if (buyAmount >= Integer.parseInt(max)) {
warnMessage = "["+target+"]"+retailInfoName+":"+idCard+"购买总量:"+buyAmount+",超出预警值"+max;
return true;
}
return false;
}
@Override
public String warnMessage() {
return warnMessage;
}
@Override
public String getActualValue() {
return buyAmount+"";
}
}
package com.xyst.dinas.biz.processor;
import com.beecode.bcp.type.json.JSONObjectUtils;
import com.xyst.dinas.biz.service.RetailInfoService;
import com.xyst.dinas.biz.warn.IWarningCalculator;
import com.xyst.dinas.biz.warn.WarnSetting;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Map;
import java.util.UUID;
/**
* retail散客购买重量预警
*
* @author
* @date 2021年4月23日
*/
public class RetailInfoBuyAmountWarningCalculator implements IWarningCalculator{
/**重量
*
*/
private double buyAmount;
private String message;
@Autowired
private RetailInfoService retailInfoService;
@Override
public boolean isWarning(WarnSetting warnSetting) {
String max = warnSetting.getMax();
String target = warnSetting.getTarget();
if(max==null || max.trim().length()==0) {
return false;
}
Map<String, Object> stringObjectMap = JSONObjectUtils.toMap(warnSetting.getMemo());
if(!stringObjectMap.containsKey("idCard")){
return false;
}
Object idCard = stringObjectMap.get("idCard");
Object stationId = stringObjectMap.get("stationId");
Object retailInfoName = stringObjectMap.get("retailInfoName");
this.buyAmount = retailInfoService.selectBuyAmountByIdCard(idCard.toString(),UUID.fromString(stationId.toString())).doubleValue();
//业务数据与设置的阀值做比较,计算是否预警
double i = Double.parseDouble(max);
if (i>0 && buyAmount >= i) {
message = "["+target+"]"+retailInfoName+":"+idCard+",购买总量:"+buyAmount+",超出预警值"+max;
return true;
}
return false;
}
/**
* 预警消息
*
* @return
*/
@Override
public String warnMessage() {
return this.message;
}
/**
* 实际值
*
* @return
*/
@Override
public String getActualValue() {
return this.buyAmount+"";
}
}
package com.xyst.dinas.biz.processor;
import com.xyst.dinas.biz.warn.IWarningCalculator;
import com.xyst.dinas.biz.warn.WarnSetting;
import java.util.UUID;
/**
* retail散客购买次数预警
*
* @author
* @date 2021年4月1日
*/
public class RetailInfoBuyCountWarningCalculate implements IWarningCalculator{
private String warnMessage;
private final String retailInfoName;
private final String idCard;
private final long buyCount;
/**
* 散客购买次数预警
* @param buyCount 购买次数
*/
public RetailInfoBuyCountWarningCalculate(String retailInfoName, String idCard, UUID stationId, Long buyCount) {
this.retailInfoName = retailInfoName;
this.idCard = idCard;
this.buyCount = buyCount;
}
@Override
public boolean isWarning(WarnSetting warnSetting) {
String max = warnSetting.getMax();
String target = warnSetting.getTarget();
if(max==null || max.trim().length()==0) {
return false;
}
//业务数据与设置的阀值做比较,计算是否预警
int i = (int)Double.parseDouble(max);
if (i>0&&buyCount >= i ) {
warnMessage = "["+target+"]"+retailInfoName+":"+idCard+"购买次数"+buyCount+",超出预警值"+max;
return true;
}
return false;
}
@Override
public String warnMessage() {
return warnMessage;
}
@Override
public String getActualValue() {
return buyCount+"";
}
}
package com.xyst.dinas.biz.processor;
import com.beecode.bcp.type.json.JSONObjectUtils;
import com.xyst.dinas.biz.service.RetailInfoService;
import com.xyst.dinas.biz.warn.IWarningCalculator;
import com.xyst.dinas.biz.warn.WarnSetting;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Map;
import java.util.UUID;
/**
* retail散客购买次数预警
*
* @author
* @date 2021年4月23日
*/
public class RetailInfoBuyCountWarningCalculator implements IWarningCalculator{
/**
* 购买次数
*/
private long buyCount;
private String message;
@Autowired
private RetailInfoService retailInfoService;
@Override
public boolean isWarning(WarnSetting warnSetting) {
String max = warnSetting.getMax();
String target = warnSetting.getTarget();
if(max==null || max.trim().length()==0) {
return false;
}
Map<String, Object> stringObjectMap = JSONObjectUtils.toMap(warnSetting.getMemo());
if(!stringObjectMap.containsKey("idCard")){
return false;
}
Object idCard = stringObjectMap.get("idCard");
Object stationId = stringObjectMap.get("stationId");
Object retailInfoName = stringObjectMap.get("retailInfoName");
this.buyCount = retailInfoService.selectBuyCountByIdCard(idCard.toString(),UUID.fromString(stationId.toString()));
//业务数据与设置的阀值做比较,计算是否预警
int i = (int)Double.parseDouble(max);
if (i>0 && buyCount >= i) {
message = "["+target+"]"+retailInfoName+":"+idCard+"购买次数"+buyCount+",超出预警值"+max;
return true;
}
return false;
}
/**
* 预警消息
*
* @return
*/
@Override
public String warnMessage() {
return this.message;
}
/**
* 实际值
*
* @return
*/
@Override
public String getActualValue() {
return this.buyCount+"";
}
}
...@@ -3,6 +3,7 @@ package com.xyst.dinas.biz.service; ...@@ -3,6 +3,7 @@ package com.xyst.dinas.biz.service;
import com.beecode.bap.attachment.common.Page; import com.beecode.bap.attachment.common.Page;
import com.beecode.bcp.type.KObject; import com.beecode.bcp.type.KObject;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
...@@ -23,4 +24,8 @@ public interface RetailInfoService { ...@@ -23,4 +24,8 @@ public interface RetailInfoService {
void update(KObject kobject); void update(KObject kobject);
void deleteById(UUID id); void deleteById(UUID id);
Long selectBuyCountByIdCard(String toString, UUID uuid);
BigDecimal selectBuyAmountByIdCard(String idCard, UUID fromString);
} }
...@@ -3,6 +3,7 @@ package com.xyst.dinas.biz.warn; ...@@ -3,6 +3,7 @@ package com.xyst.dinas.biz.warn;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import com.xyst.dinas.biz.constant.RetailInfoConstant;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.Nullable; import org.springframework.lang.Nullable;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -20,7 +21,7 @@ import com.xyst.dinas.biz.warn.service.WarningService; ...@@ -20,7 +21,7 @@ import com.xyst.dinas.biz.warn.service.WarningService;
import com.xyst.dinas.biz.web.request.WarnSettingReq; import com.xyst.dinas.biz.web.request.WarnSettingReq;
@Transactional @Transactional
public class WarningServiceImpl implements WarningService{ public class WarningServiceImpl implements WarningService {
@Autowired @Autowired
private WarnSettingDao warnSettingDao; private WarnSettingDao warnSettingDao;
...@@ -32,6 +33,11 @@ public class WarningServiceImpl implements WarningService{ ...@@ -32,6 +33,11 @@ public class WarningServiceImpl implements WarningService{
@Override @Override
public UUID insertWarnSetting(WarnSetting warnSetting) { public UUID insertWarnSetting(WarnSetting warnSetting) {
return insertWarnSettingToIsNotice(warnSetting, true);
}
@Override
public UUID insertWarnSettingToIsNotice(WarnSetting warnSetting, boolean isNotice) {
String billType = warnSetting.getBillType(); String billType = warnSetting.getBillType();
String warnCalculator = warnSetting.warnCalculator(); String warnCalculator = warnSetting.warnCalculator();
Assert.notNull(billType, "The billType must not be null!"); Assert.notNull(billType, "The billType must not be null!");
...@@ -46,19 +52,19 @@ public class WarningServiceImpl implements WarningService{ ...@@ -46,19 +52,19 @@ public class WarningServiceImpl implements WarningService{
setting.set(WarnSettingConstant.max, warnSetting.getMax()); setting.set(WarnSettingConstant.max, warnSetting.getMax());
setting.set(WarnSettingConstant.memo, warnSetting.getMemo()); setting.set(WarnSettingConstant.memo, warnSetting.getMemo());
setting.set(WarnSettingConstant.warnCalculator, warnCalculator); setting.set(WarnSettingConstant.warnCalculator, warnCalculator);
setting.set(WarnSettingConstant.isOpen, warnSetting.isOpen()==null? true:warnSetting.isOpen()); setting.set(WarnSettingConstant.isOpen, warnSetting.isOpen() == null || warnSetting.isOpen());
String[] personnel = warnSetting.getPersonnel(); String[] personnel = warnSetting.getPersonnel();
if (personnel!=null) { if (personnel != null) {
String personnelStr = UuidArrayToString(personnel); String personnelStr = UuidArrayToString(personnel);
setting.set(WarnSettingConstant.personnel, personnelStr); setting.set(WarnSettingConstant.personnel, personnelStr);
} }
setting.set(BaseConstants.CREATE_TIME, LocalDateTime.now()); setting.set(BaseConstants.CREATE_TIME, LocalDateTime.now());
setting.set(BaseConstants.DEL,false); setting.set(BaseConstants.DEL, false);
setting.set(BaseConstants.DISCARD,false); setting.set(BaseConstants.DISCARD, false);
UUID warSettingId = warnSettingDao.create(setting); UUID warSettingId = warnSettingDao.create(setting);
//新增后触发预警 //新增后触发预警
BaseBusinessWarn baseBusinessWarn = new BaseBusinessWarn(warSettingId); BaseBusinessWarn baseBusinessWarn = new BaseBusinessWarn(warSettingId);
baseBusinessWarn.warn(); baseBusinessWarn.warn(isNotice);
return warSettingId; return warSettingId;
} }
...@@ -74,16 +80,16 @@ public class WarningServiceImpl implements WarningService{ ...@@ -74,16 +80,16 @@ public class WarningServiceImpl implements WarningService{
KObject warSettingIdObj = warnSettingDao.queryWarnSettingById(warSettingId); KObject warSettingIdObj = warnSettingDao.queryWarnSettingById(warSettingId);
List<UUID> personnel = warnSetting.getPersonnel(); List<UUID> personnel = warnSetting.getPersonnel();
if (personnel!=null) { if (personnel != null) {
String personnelStr = UuidListToString(personnel); String personnelStr = UuidListToString(personnel);
warSettingIdObj.set("personnel", personnelStr); warSettingIdObj.set("personnel", personnelStr);
} }
String min = warnSetting.getMin(); String min = warnSetting.getMin();
if(min != null) warSettingIdObj.set(WarnSettingConstant.min, min); if (min != null) warSettingIdObj.set(WarnSettingConstant.min, min);
String max = warnSetting.getMax(); String max = warnSetting.getMax();
if(max != null) warSettingIdObj.set(WarnSettingConstant.max, max); if (max != null) warSettingIdObj.set(WarnSettingConstant.max, max);
Boolean isOpen = warnSetting.isOpen(); Boolean isOpen = warnSetting.isOpen();
if(isOpen != null) warSettingIdObj.set(WarnSettingConstant.isOpen, isOpen); if (isOpen != null) warSettingIdObj.set(WarnSettingConstant.isOpen, isOpen);
warnSettingDao.update(warSettingIdObj); warnSettingDao.update(warSettingIdObj);
//修改后触发预警 //修改后触发预警
BaseBusinessWarn baseBusinessWarn = new BaseBusinessWarn(warSettingId); BaseBusinessWarn baseBusinessWarn = new BaseBusinessWarn(warSettingId);
...@@ -92,6 +98,7 @@ public class WarningServiceImpl implements WarningService{ ...@@ -92,6 +98,7 @@ public class WarningServiceImpl implements WarningService{
/** /**
* 新增预警执行记录 * 新增预警执行记录
*
* @param warnExeRecord * @param warnExeRecord
* @return * @return
*/ */
...@@ -114,15 +121,16 @@ public class WarningServiceImpl implements WarningService{ ...@@ -114,15 +121,16 @@ public class WarningServiceImpl implements WarningService{
@Override @Override
public void updateWarnExe(WarnExeRecord warnExeRecord) { public void updateWarnExe(WarnExeRecord warnExeRecord) {
KObject object = warnSettingDao.queryWarningExeById(warnExeRecord.getId()); KObject object = warnSettingDao.queryWarningExeById(warnExeRecord.getId());
if(warnExeRecord.getRecentlyTime()!=null) object.set("recentlyTime", warnExeRecord.getRecentlyTime()); if (warnExeRecord.getRecentlyTime() != null) object.set("recentlyTime", warnExeRecord.getRecentlyTime());
if(warnExeRecord.getEndTime()!=null) object.set("endTime", warnExeRecord.getEndTime()); if (warnExeRecord.getEndTime() != null) object.set("endTime", warnExeRecord.getEndTime());
if(warnExeRecord.getWarnState()!=null) object.set("warnState", warnExeRecord.getWarnState()); if (warnExeRecord.getWarnState() != null) object.set("warnState", warnExeRecord.getWarnState());
if(warnExeRecord.getActualValue()!=null) object.set("actualValue", warnExeRecord.getActualValue()); if (warnExeRecord.getActualValue() != null) object.set("actualValue", warnExeRecord.getActualValue());
warnSettingDao.update(object); warnSettingDao.update(object);
} }
/** /**
* 结束一条预警设置的预警执行记录 * 结束一条预警设置的预警执行记录
*
* @param warnSettingId * @param warnSettingId
*/ */
@Override @Override
...@@ -142,7 +150,7 @@ public class WarningServiceImpl implements WarningService{ ...@@ -142,7 +150,7 @@ public class WarningServiceImpl implements WarningService{
return warnSettingDao.getWarnSetting(billType, billId, target); return warnSettingDao.getWarnSetting(billType, billId, target);
} }
public List<KObject> queryWarnSettings(String billType, @Nullable UUID billId,@Nullable String target){ public List<KObject> queryWarnSettings(String billType, @Nullable UUID billId, @Nullable String target) {
return warnSettingDao.queryWarnSettings(billType, billId, target); return warnSettingDao.queryWarnSettings(billType, billId, target);
} }
...@@ -165,7 +173,7 @@ public class WarningServiceImpl implements WarningService{ ...@@ -165,7 +173,7 @@ public class WarningServiceImpl implements WarningService{
@Override @Override
public HashMap<String, Object> warnRecodeGroupInfo(List<UUID> regionalCompanyIds, List<String> targets) { public HashMap<String, Object> warnRecodeGroupInfo(List<UUID> regionalCompanyIds, List<String> targets) {
return warnSettingDao.warnRecodeGroupInfo(regionalCompanyIds,targets); return warnSettingDao.warnRecodeGroupInfo(regionalCompanyIds, targets);
} }
...@@ -184,8 +192,8 @@ public class WarningServiceImpl implements WarningService{ ...@@ -184,8 +192,8 @@ public class WarningServiceImpl implements WarningService{
@Override @Override
public void deleteWarnSetting(UUID warnSettingId) { public void deleteWarnSetting(UUID warnSettingId) {
KObject kObject = warnSettingDao.queryWarnSettingById(warnSettingId); KObject kObject = warnSettingDao.queryWarnSettingById(warnSettingId);
kObject.set(BaseConstants.DEL,true); kObject.set(BaseConstants.DEL, true);
kObject.set("discard",true); kObject.set("discard", true);
warnSettingDao.update(kObject); warnSettingDao.update(kObject);
//结束预警执行记录 //结束预警执行记录
KObject warnExeRecord = warnSettingDao.queryWarnExeRecordBySettingId(warnSettingId); KObject warnExeRecord = warnSettingDao.queryWarnExeRecordBySettingId(warnSettingId);
...@@ -194,20 +202,22 @@ public class WarningServiceImpl implements WarningService{ ...@@ -194,20 +202,22 @@ public class WarningServiceImpl implements WarningService{
/** /**
* 开启或关闭预警设置; 可重复开启或关闭 * 开启或关闭预警设置; 可重复开启或关闭
*
* @param warnSettingId 预警设置ID * @param warnSettingId 预警设置ID
* @param isOpen 开启true/关闭false * @param isOpen 开启true/关闭false
*/ */
public void onOffWarnSetting(UUID warnSettingId,boolean isOpen) { @Override
public void onOffWarnSetting(UUID warnSettingId, boolean isOpen) {
KObject warnSetting = warnSettingDao.queryWarnSettingById(warnSettingId); KObject warnSetting = warnSettingDao.queryWarnSettingById(warnSettingId);
boolean isOpen2 = warnSetting.getBoolean(WarnSettingConstant.isOpen); boolean isOpen2 = warnSetting.getBoolean(WarnSettingConstant.isOpen);
if(isOpen == isOpen2) return; if (isOpen == isOpen2) return;
warnSetting.set(WarnSettingConstant.isOpen,isOpen); warnSetting.set(WarnSettingConstant.isOpen, isOpen);
warnSettingDao.update(warnSetting); warnSettingDao.update(warnSetting);
if(isOpen) { if (isOpen) {
//再次开启,触发预警 //再次开启,触发预警
BaseBusinessWarn baseBusinessWarn = new BaseBusinessWarn(warnSettingId); BaseBusinessWarn baseBusinessWarn = new BaseBusinessWarn(warnSettingId);
baseBusinessWarn.warn(); baseBusinessWarn.warn();
}else { } else {
//关闭预警,结束预警执行记录 //关闭预警,结束预警执行记录
KObject warnExeRecord = warnSettingDao.queryWarnExeRecordBySettingId(warnSettingId); KObject warnExeRecord = warnSettingDao.queryWarnExeRecordBySettingId(warnSettingId);
warnSettingDao.endWarnRecordState(warnExeRecord); warnSettingDao.endWarnRecordState(warnExeRecord);
...@@ -215,7 +225,6 @@ public class WarningServiceImpl implements WarningService{ ...@@ -215,7 +225,6 @@ public class WarningServiceImpl implements WarningService{
} }
private String UuidListToString(List<UUID> uuids) { private String UuidListToString(List<UUID> uuids) {
StringBuilder str = new StringBuilder(); StringBuilder str = new StringBuilder();
for (int i = 0; i < uuids.size(); i++) { for (int i = 0; i < uuids.size(); i++) {
...@@ -227,6 +236,7 @@ public class WarningServiceImpl implements WarningService{ ...@@ -227,6 +236,7 @@ public class WarningServiceImpl implements WarningService{
} }
return str.toString(); return str.toString();
} }
private String UuidArrayToString(String[] uuids) { private String UuidArrayToString(String[] uuids) {
StringBuilder str = new StringBuilder(); StringBuilder str = new StringBuilder();
for (int i = 0; i < uuids.length; i++) { for (int i = 0; i < uuids.length; i++) {
...@@ -250,7 +260,6 @@ public class WarningServiceImpl implements WarningService{ ...@@ -250,7 +260,6 @@ public class WarningServiceImpl implements WarningService{
} }
@Override @Override
public ArrayList<String> getExistedWarningSettingPersonnelByBillType(UUID id) { public ArrayList<String> getExistedWarningSettingPersonnelByBillType(UUID id) {
WarnSetting warnSetting = warnSettingDao.getWarnSetting(id); WarnSetting warnSetting = warnSettingDao.getWarnSetting(id);
...@@ -266,4 +275,55 @@ public class WarningServiceImpl implements WarningService{ ...@@ -266,4 +275,55 @@ public class WarningServiceImpl implements WarningService{
return new ArrayList<>(strings); return new ArrayList<>(strings);
} }
@Override
public WarnSetting queryOneWarnSettingsByMemoAndType(String target, String... memo) {
return warnSettingDao.queryOneWarnSettingsByMemoAndType(target, memo);
}
@Override
public void updateRetailInfoWarnSettingAllByTypeAndMemo(String target, String toString, Double max) {
List<?> objects = warnSettingDao.queryWarnSettingsListByMemoAndType(target, toString);
if (objects.size() < 1) {
String warnCalculator;
if(target.equals(RetailInfoConstant.RETAIL_INFO_WARN_BUY_AMOUNT)){
warnCalculator=RetailInfoConstant.RETAIL_INFO_BUY_AMOUNT_WARNING_CALCULATOR;
}else {
warnCalculator=RetailInfoConstant.RETAIL_INFO_BUY_COUNT_WARNING_CALCULATOR;
}
setRetailInfoWarningSettingTemplateEntity(toString,UUID.randomUUID(),target,warnCalculator,max);
}
for (Object object : objects) {
KObject object1 = (KObject) object;
UUID uuid = object1.getUuid(BaseConstants.ID);
Assert.notNull(uuid, "The warSettingId must not be null");
KObject warSettingIdObj = warnSettingDao.queryWarnSettingById(uuid);
warSettingIdObj.set(WarnSettingConstant.max, max);
warnSettingDao.update(warSettingIdObj);
//修改后触发预警
BaseBusinessWarn baseBusinessWarn = new BaseBusinessWarn(uuid);
baseBusinessWarn.warn(false);
}
}
private void setRetailInfoWarningSettingTemplateEntity(String stationId, UUID billId, String target, String warnCalculator, Double max) {
WarnSettingEntity warnSettingEntity = new WarnSettingEntity();
warnSettingEntity.setBillType(RetailInfoConstant.RETAIL_INFO_WARN_BILL_TYPE);
warnSettingEntity.setBillId(billId);
warnSettingEntity.setTarget(target);
if(target.equals(RetailInfoConstant.RETAIL_INFO_WARN_BUY_AMOUNT)){
warnSettingEntity.setTargetType(WarnTargetTypeEnum.NUMBER_TYPE.name());
}else if(target.equals(RetailInfoConstant.RETAIL_INFO_WARN_BUY_COUNT)){
warnSettingEntity.setTargetType(WarnTargetTypeEnum.INT_TYPE.name());
}
warnSettingEntity.setOpen(false);
HashMap<String, String> stringStringHashMap = new HashMap<>();
stringStringHashMap.put("stationId", stationId);
stringStringHashMap.put("template","template");
warnSettingEntity.setMax(max+"");
warnSettingEntity.setMemo(JSONObjectUtils.toJson(stringStringHashMap).toString());
warnSettingEntity.setWarnCalculator(warnCalculator);
insertWarnSettingToIsNotice(warnSettingEntity, false);
}
} }
...@@ -293,4 +293,25 @@ public class WarnSettingDao { ...@@ -293,4 +293,25 @@ public class WarnSettingDao {
detachedCriteria.add(dis); detachedCriteria.add(dis);
} }
} }
public WarnSetting queryOneWarnSettingsByMemoAndType(String retailInfoWarnBuyCount, String ...memo) {
List<?> byCriteria = queryWarnSettingsListByMemoAndType(retailInfoWarnBuyCount, memo);
if(!byCriteria.isEmpty()){
Object o = byCriteria.get(0);
return warnSettingToEntity((KObject) o);
}
return null;
}
public List<?> queryWarnSettingsListByMemoAndType(String retailInfoWarnBuyCount, String... memo) {
KClass bean = Amino.getStaticMetadataContext().getBean(WarnSettingConstant.ENTITY_WARNSETTING, KClass.class);
DetachedCriteria detachedCriteria = DetachedCriteria.forEntityName(bean.getName());
for (String s : memo) {
detachedCriteria.add(Restrictions.like(WarnSettingConstant.memo,s,MatchMode.ANYWHERE));
}
detachedCriteria.add(Restrictions.eq(WarnSettingConstant.target, retailInfoWarnBuyCount));
return template.findByCriteria(detachedCriteria);
}
} }
...@@ -45,6 +45,8 @@ public interface WarningService { ...@@ -45,6 +45,8 @@ public interface WarningService {
*/ */
KObject queryWarnSettingById(UUID id); KObject queryWarnSettingById(UUID id);
UUID insertWarnSettingToIsNotice(WarnSetting warnSetting, boolean isNotice);
/** /**
* 更新预警设置 * 更新预警设置
* @param warnSetting * @param warnSetting
...@@ -98,4 +100,8 @@ public interface WarningService { ...@@ -98,4 +100,8 @@ public interface WarningService {
HashMap<String, Object> warnRecodeGroupInfo(List<UUID> regionalCompanyIds, List<String> targets); HashMap<String, Object> warnRecodeGroupInfo(List<UUID> regionalCompanyIds, List<String> targets);
ArrayList<String> getExistedWarningSettingPersonnelByBillType(UUID id); ArrayList<String> getExistedWarningSettingPersonnelByBillType(UUID id);
WarnSetting queryOneWarnSettingsByMemoAndType(String target, String ... memo);
void updateRetailInfoWarnSettingAllByTypeAndMemo(String target, String toString, Double max);
} }
...@@ -9,6 +9,8 @@ import com.beecode.inz.basis.team.pojo.ResponseObj; ...@@ -9,6 +9,8 @@ import com.beecode.inz.basis.team.pojo.ResponseObj;
import com.beecode.nlib.utils.StringUtils; import com.beecode.nlib.utils.StringUtils;
import com.xyst.dinas.biz.constant.RetailInfoConstant; import com.xyst.dinas.biz.constant.RetailInfoConstant;
import com.xyst.dinas.biz.service.RetailInfoService; import com.xyst.dinas.biz.service.RetailInfoService;
import com.xyst.dinas.biz.warn.WarnSetting;
import com.xyst.dinas.biz.warn.service.WarningService;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -28,6 +30,8 @@ public class RetailInfoController { ...@@ -28,6 +30,8 @@ public class RetailInfoController {
@Autowired @Autowired
private RetailInfoService retailInfoService; private RetailInfoService retailInfoService;
@Autowired
private WarningService warningService;
@RequestMapping(value = "list/page", method = RequestMethod.GET) @RequestMapping(value = "list/page", method = RequestMethod.GET)
public ResponseObj getListPage( public ResponseObj getListPage(
...@@ -122,4 +126,38 @@ public class RetailInfoController { ...@@ -122,4 +126,38 @@ public class RetailInfoController {
return ResponseObj.success(); return ResponseObj.success();
} }
/**
* 修改预警设置
* @param target
* @return
*/
@PutMapping("/updateWarnSetting")
public ResponseObj updateWarnSetting(@RequestParam("target") String target,@RequestParam(value = "max") String max,@RequestParam(value = "stationId") UUID stationId){
if(StringUtils.isEmpty(target)){
return ResponseObj.error(400,"指标错误");
}
warningService.updateRetailInfoWarnSettingAllByTypeAndMemo(target,stationId.toString(),Double.parseDouble(max));
return ResponseObj.success();
}
/**
* 获取预警设置模板
* @param target
* @return
*/
@GetMapping("/getWarnSetting")
public ResponseObj updateWarnSetting(@RequestParam("target") String target,@RequestParam(value = "stationId",required = false) UUID stationId){
if(StringUtils.isEmpty(target)){
return ResponseObj.error(400,"指标错误");
}
WarnSetting warnSetting = warningService.queryOneWarnSettingsByMemoAndType(target, stationId.toString(), "template");
return ResponseObj.success("查询成功",warnSetting);
}
} }
\ No newline at end of file
<model>
<header>
<type>inz.query.Query</type>
<package>com.xyst.dinas.biz.query</package>
<name>RetailInfoWarningExe</name>
<title>散户预警记录</title>
<tags></tags>
<description></description>
</header>
<content>
<customQuery id='a68b7ed6-e37c-447b-8f70-342afa606607'>
<kclass>com.xyst.dinas.biz.datamodel.WarningExe</kclass>
<innerScene title='全部'>
<id>8376206c-b50c-4c52-bb5a-e0c9f6696056</id>
<javaImplement>com.beecode.inz.common.scene.CommonAllScene</javaImplement>
<defaultExecute></defaultExecute>
<hide></hide>
</innerScene>
<innerScene title='已废弃'>
<id>7840dd0d-0c7b-413d-85c7-89e4a4a7957f</id>
<javaImplement>com.beecode.inz.common.scene.DefaultDiscardScene</javaImplement>
<defaultExecute></defaultExecute>
<hide></hide>
</innerScene>
<field title='id'>
<name>id</name>
<type>uuid</type>
<ref>
<type></type>
<name></name>
</ref>
<description></description>
</field>
<field title='开始时间'>
<name>startTime</name>
<type>datetime</type>
<ref>
<type></type>
<name></name>
</ref>
<description></description>
</field>
<field title='结束时间'>
<name>endTime</name>
<type>datetime</type>
<ref>
<type></type>
<name></name>
</ref>
<description></description>
</field>
<field title='业务id'>
<name>billId</name>
<type>uuid</type>
<ref>
<type></type>
<name></name>
</ref>
<description></description>
</field>
<field title='预警指标'>
<name>target</name>
<type>string</type>
<ref>
<type></type>
<name></name>
</ref>
<description></description>
</field>
<field title='预警消息'>
<name>message</name>
<type>string</type>
<ref>
<type></type>
<name></name>
</ref>
<description></description>
</field>
<field title='备注'>
<name>memo</name>
<type>string</type>
<ref>
<type></type>
<name></name>
</ref>
<description></description>
</field>
<field title='预警值'>
<name>max</name>
<type>string</type>
<ref>
<type></type>
<name></name>
</ref>
<description></description>
</field>
<field title='实际值'>
<name>actualValue</name>
<type>string</type>
<ref>
<type></type>
<name></name>
</ref>
<description></description>
</field>
<field title='创建时间'>
<name>createTime</name>
<type>datetime</type>
<ref>
<type></type>
<name></name>
</ref>
<description></description>
</field>
<field title='修改时间'>
<name>modifyTime</name>
<type>datetime</type>
<ref>
<type></type>
<name></name>
</ref>
<description></description>
</field>
</customQuery>
</content>
</model>
\ 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>a68b7ed6-e37c-447b-8f70-342afa606607</id>
<name>com.xyst.dinas.biz.query.RetailInfoWarningExe</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></m:dataProcessor>
<m:authorityItem></m:authorityItem>
<m:innerScenes>
<m:innerScene>
<m:id>8376206c-b50c-4c52-bb5a-e0c9f6696056</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>7840dd0d-0c7b-413d-85c7-89e4a4a7957f</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>billId</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>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>memo</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>max</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>actualValue</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>message</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>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: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