Commit c8568aa5 by 王衍超

完善库存预警代码;

parent 8945de1c
......@@ -109,7 +109,7 @@ public class BaseBusinessWarn {
boolean isWarning = false;
WarnSetting warnSetting = getWarnSetting();
if(warnSetting==null ) return false;//|| !warnSetting.isOpen()
if(warnSetting==null || !warnSetting.isOpen()) return false;//
if(warningCalculate == null && warnSetting.warnCalculator()!=null) {
warningCalculate = Amino.getApplicationMetadataContext().getBean(warnSetting.warnCalculator(),IWarningCalculator.class);
}
......
......@@ -43,7 +43,7 @@ public class WarningServiceImpl implements WarningService{
setting.set(WarnSettingConstant.max, warnSetting.getMax());
setting.set(WarnSettingConstant.memo, warnSetting.getMemo());
setting.set(WarnSettingConstant.warnCalculator, warnSetting.warnCalculator());
setting.set(WarnSettingConstant.isOpen, warnSetting.isOpen()==null? true:false);
setting.set(WarnSettingConstant.isOpen, warnSetting.isOpen()==null? true:warnSetting.isOpen());
String[] personnel = warnSetting.getPersonnel();
if (personnel!=null) {
String personnelStr = UuidArrayToString(personnel);
......
......@@ -5,4 +5,12 @@ public interface InventoryConstant {
public static String INVENTORY_ENTITY = "com.xyst.dinas.sales.datamodel.Inventory";
public static String LOG_ENTITY = "com.beecode.bap.log.datamodel.Log";
String dinasType = "dinasType";
String station = "station";
String amount = "amount";
}
......@@ -16,4 +16,12 @@ public interface InventoryDao {
KObject getItemByStationIdAndDinasTypeId(UUID stationId, UUID dinasTypeId);
List<KObject> queryLog(List<String> businessObjectId);
/**
* 查询某种砂石的库存量
* @param stationId
* @param dinasTypeName
* @return
*/
public Double getStockAmountByDinas(UUID stationId,String dinasTypeName);
}
......@@ -36,6 +36,22 @@ public class InventoryDaoImpl implements InventoryDao {
}
});
}
public Double getStockAmountByDinas(UUID stationId,String dinasTypeName) {
String hql = "from " + InventoryConstant.INVENTORY_ENTITY + " where station.id =:stationId and dinasType.dinasTypeName =:dinasTypeName";
return template.execute(session -> {
Query<KObject> query = session.createQuery(hql, KObject.class);
query.setParameter("stationId", stationId);
query.setParameter("dinasTypeName", dinasTypeName);
List<KObject> resultList = query.getResultList();
if(resultList.isEmpty()) return 0D;
KObject kObject = resultList.get(0);
double stockAmount = kObject.getDouble(InventoryConstant.amount);
return stockAmount;
});
}
@Override
public void update(KObject kobj) {
......
......@@ -246,4 +246,8 @@ public class InventoryServiceImpl implements InventoryService {
}
return result;
}
public Double getStockAmountByDinas(UUID stationId,String dinasTypeName) {
return inventoryDao.getStockAmountByDinas(stationId, dinasTypeName);
}
}
package com.xyst.dinas.sales.processor;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Autowired;
import com.xyst.dinas.biz.warn.IWarningCalculator;
import com.xyst.dinas.biz.warn.WarnSetting;
import com.xyst.dinas.sales.service.InventoryService;
/**
* 库存砂石余量 预警计算器
......@@ -11,15 +16,25 @@ import com.xyst.dinas.biz.warn.WarnSetting;
*/
public class StockAmountWarnCalculator implements IWarningCalculator{
@Autowired
private InventoryService inventoryService;
//砂石
//砂石库存
private double stockAmount;
private String warnMessage;
@Override
public boolean isWarning(WarnSetting warnSetting) {
//TODO
String min = warnSetting.getMin();
UUID stationId = warnSetting.getBillId();
String dinasTypeName = warnSetting.getTarget();
if(min==null || min.trim().length()==0) return false;
stockAmount = inventoryService.getStockAmountByDinas(stationId, dinasTypeName);
if (stockAmount < Double.valueOf(min)) {
warnMessage = "["+dinasTypeName+"]"+"的当前库存量为"+stockAmount+",已不足"+min+"吨!";
return true;
}
return false;
}
......
......@@ -13,4 +13,12 @@ public interface InventoryService {
public ResponseObj<String> modifyInventory(String body, boolean isLog, boolean autoCalculate);
public List<InventoryLog> queryLog(UUID regionalCompany);
/**
* 查询某种砂石的库存量
* @param regionalCompany
* @param stationId
* @param dinasTypeName
* @return
*/
public Double getStockAmountByDinas(UUID stationId,String dinasTypeName);
}
......@@ -39,7 +39,7 @@ public class SalesPlanAutoCreateTaskRegister implements ServiceInitializer{
// 每天凌晨12点执行调度,如测试可修改为每十五秒:*/15 * * * * ?(表达式由至少6个由空格分隔的时间元素,从左至右可分为秒,分,时,日,月,星期)
// scheduleService.scheduleTask(TaskDetail, "0 0 0 * * ?");
// 测试调度时进行调用
scheduleService.scheduleTask(TaskDetail, "0 */1 * * * ?");
scheduleService.scheduleTask(TaskDetail, "0 */5 * * * ?");
logger.info("销售计划自动创建任务初始化成功!");
}
......
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