|
@ -4300,13 +4300,83 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
Integer tempQty = (int) Double.parseDouble(stringObjectMap.get("qty") + "");
|
|
|
if ("%".equals(rule.getMatchUnit())) {
|
|
|
Integer matchValue = (int) Math.ceil((rule.getUpper() * rule.getMatchValue()) / 100.0);
|
|
|
if (tempQty <= matchValue) {
|
|
|
if (tempQty < matchValue) {
|
|
|
mediicinedevice.setStatus("0");
|
|
|
break quit;
|
|
|
}
|
|
|
}
|
|
|
if ("件".equals(rule.getMatchUnit())) {
|
|
|
if (tempQty <= rule.getMatchValue()) {
|
|
|
if (tempQty < rule.getMatchValue()) {
|
|
|
mediicinedevice.setStatus("0");
|
|
|
break quit;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
deviceDao.save(mediicinedevice);
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 更新设备缺货信息,没有货道信息,单纯更新设备的缺货信息
|
|
|
* @param cargoId
|
|
|
* @param inventoryDO
|
|
|
*/
|
|
|
public void updateDeviceStateWithoutCargo(String equNum) {
|
|
|
//所有药品及药品数量
|
|
|
String sql = "SELECT\n" +
|
|
|
"\tsum(qty) AS qty,\n" +
|
|
|
"\tdrug_id AS drugId,\n" +
|
|
|
"\tdrug_code AS drugCode,\n" +
|
|
|
"\torg_code AS orgCode,\n" +
|
|
|
"\tsum(rated_inventory) AS ratedInventory\n" +
|
|
|
"FROM\n" +
|
|
|
"\tt_mediicinecabinet_inventory\n" +
|
|
|
"WHERE\n" +
|
|
|
"\tequ_num = '"+equNum+"'\n" +
|
|
|
"AND (state = '1' OR state = '21')\n" +
|
|
|
"AND drug_code IS NOT NULL\n" +
|
|
|
"AND org_code IS NOT NULL\n" +
|
|
|
"GROUP BY\n" +
|
|
|
"\tdrug_code,\n" +
|
|
|
"\torg_code";
|
|
|
List<Map<String, Object>> collect = hibenateUtils.createSQLQuery(sql);
|
|
|
//更新设备
|
|
|
Mediicinedevice mediicinedevice = deviceDao.findMediicinedeviceByEquNum(equNum);
|
|
|
//该设备库存预警规则
|
|
|
List<MedicineWarrayRule> rules = medicineWarrayRuleDao.findMedicineWarrayRulesByEquNumAndDel(equNum, 1);
|
|
|
//不缺货
|
|
|
mediicinedevice.setStatus("1");
|
|
|
//bug:13663
|
|
|
if (rules == null || rules.size() == 0) {
|
|
|
int isZeroNum = 0;
|
|
|
for (Map<String, Object> stringObjectMap : collect) {
|
|
|
Integer tempQty = (int) Double.parseDouble(stringObjectMap.get("qty") + "");
|
|
|
if (tempQty == 0) {
|
|
|
isZeroNum++;
|
|
|
}
|
|
|
}
|
|
|
if (isZeroNum == collect.size()) {
|
|
|
mediicinedevice.setStatus("0");
|
|
|
}
|
|
|
deviceDao.save(mediicinedevice);
|
|
|
}
|
|
|
//bug:end
|
|
|
quit:for (MedicineWarrayRule rule : rules) {
|
|
|
for (Map<String, Object> stringObjectMap : collect) {
|
|
|
Integer ratedInventory = (int) Double.parseDouble(stringObjectMap.get("ratedInventory") + "");
|
|
|
if (ratedInventory >= rule.getLower() && ratedInventory <= rule.getUpper()) {
|
|
|
Integer tempQty = (int) Double.parseDouble(stringObjectMap.get("qty") + "");
|
|
|
if ("%".equals(rule.getMatchUnit())) {
|
|
|
Integer matchValue = (int) Math.ceil((rule.getUpper() * rule.getMatchValue()) / 100.0);
|
|
|
if (tempQty < matchValue) {
|
|
|
mediicinedevice.setStatus("0");
|
|
|
break quit;
|
|
|
}
|
|
|
}
|
|
|
if ("件".equals(rule.getMatchUnit())) {
|
|
|
if (tempQty < rule.getMatchValue()) {
|
|
|
mediicinedevice.setStatus("0");
|
|
|
break quit;
|
|
|
}
|
|
@ -5181,28 +5251,7 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
medicineWarrayRule.setCreateUser(userId);
|
|
|
medicineWarrayRuleDao.save(medicineWarrayRule);
|
|
|
}
|
|
|
// for (Object obj : ruleArray) {
|
|
|
// RuleDO ruleDO = null;
|
|
|
// try {
|
|
|
// ruleDO = objectMapper.readValue(obj.toString(), RuleDO.class);
|
|
|
// } catch (IOException e) {
|
|
|
// result.put("msg", "convert org jsonObject to RuleDO failed," + e.getCause());
|
|
|
// result.put("response", ConstantUtils.FAIL);
|
|
|
// return result.toJSONString();
|
|
|
// }
|
|
|
// MedicineWarrayRule medicineWarrayRule = new MedicineWarrayRule();
|
|
|
// medicineWarrayRule.setDel(1);
|
|
|
// medicineWarrayRule.setEquNum(mediicinedevice.getEquNum());
|
|
|
// medicineWarrayRule.setLower(ruleDO.getLower());
|
|
|
// medicineWarrayRule.setUpper(ruleDO.getUpper());
|
|
|
// medicineWarrayRule.setMatchValue(ruleDO.getMatchValue());
|
|
|
// medicineWarrayRule.setMatchUnit(ruleDO.getMatchUnit());
|
|
|
// medicineWarrayRule.setUpdateUser(userId);
|
|
|
// medicineWarrayRule.setUpdateTime(new Date());
|
|
|
// medicineWarrayRule.setCreateTime(new Date());
|
|
|
// medicineWarrayRule.setCreateUser(userId);
|
|
|
// medicineWarrayRuleDao.save(medicineWarrayRule);
|
|
|
// }
|
|
|
updateDeviceStateWithoutCargo(mediicinedevice.getEquNum());
|
|
|
}
|
|
|
result.put("response", ConstantUtils.SUCCESS);
|
|
|
result.put("msg", ConstantUtils.SUCCESS);
|
|
@ -5240,35 +5289,8 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
medicineWarrayRule.setCreateUser(userId);
|
|
|
medicineWarrayRuleDao.save(medicineWarrayRule);
|
|
|
}
|
|
|
// if (!StringUtils.isEmpty(rule1)) {
|
|
|
// medicineWarrayRule = new MedicineWarrayRule();
|
|
|
// medicineWarrayRule.setDel(1);
|
|
|
// medicineWarrayRule.setEquNum(equNum);
|
|
|
// medicineWarrayRule.setLower(Integer.parseInt(rule1.split(",")[0]));
|
|
|
// medicineWarrayRule.setUpper(Integer.parseInt(rule1.split(",")[1]));
|
|
|
// medicineWarrayRule.setMatchValue(Integer.parseInt(rule1.split(",")[2]));
|
|
|
// medicineWarrayRule.setMatchUnit(rule1.split(",")[3]);
|
|
|
// medicineWarrayRule.setUpdateUser(userId);
|
|
|
// medicineWarrayRule.setUpdateTime(new Date());
|
|
|
// medicineWarrayRule.setCreateTime(new Date());
|
|
|
// medicineWarrayRule.setCreateUser(userId);
|
|
|
// medicineWarrayRuleDao.save(medicineWarrayRule);
|
|
|
// }
|
|
|
// if (!StringUtils.isEmpty(rule2)) {
|
|
|
// medicineWarrayRule = new MedicineWarrayRule();
|
|
|
// medicineWarrayRule.setDel(1);
|
|
|
// medicineWarrayRule.setEquNum(equNum);
|
|
|
// medicineWarrayRule.setLower(Integer.parseInt(rule2.split(",")[0]));
|
|
|
// medicineWarrayRule.setUpper(Integer.parseInt(rule2.split(",")[1]));
|
|
|
// medicineWarrayRule.setMatchValue(Integer.parseInt(rule2.split(",")[2]));
|
|
|
// medicineWarrayRule.setMatchUnit(rule2.split(",")[3]);
|
|
|
// medicineWarrayRule.setUpdateUser(userId);
|
|
|
// medicineWarrayRule.setUpdateTime(new Date());
|
|
|
// medicineWarrayRule.setCreateTime(new Date());
|
|
|
// medicineWarrayRule.setCreateUser(userId);
|
|
|
// medicineWarrayRuleDao.save(medicineWarrayRule);
|
|
|
// }
|
|
|
}
|
|
|
updateDeviceStateWithoutCargo(equNum);
|
|
|
}
|
|
|
result.put("response", ConstantUtils.SUCCESS);
|
|
|
result.put("msg", ConstantUtils.SUCCESS);
|