|
@ -95,6 +95,10 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
@Autowired
|
|
|
private MedicineShipmentLogDao medicineShipmentLogDao;
|
|
|
|
|
|
@Autowired
|
|
|
private MedicineWarrayRuleDao medicineWarrayRuleDao;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 设备出货服务,创建设备,创建库存内容
|
|
@ -164,6 +168,8 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
inventory.setCargoState("1");
|
|
|
//设备初始化库存,默认货道是正常的
|
|
|
inventory.setFaultState("0");
|
|
|
//设备库存初始化,额定库存归0
|
|
|
inventory.setRatedInventory(0);
|
|
|
inventoryDao.save(inventory);
|
|
|
}
|
|
|
}
|
|
@ -688,6 +694,8 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
inventory.setNum("3");
|
|
|
inventory.setLongtime(null);
|
|
|
inventory.setOrgCode(null);
|
|
|
//额定 库存归0
|
|
|
inventory.setRatedInventory(0);
|
|
|
inventoryDao.save(inventory);
|
|
|
}
|
|
|
}
|
|
@ -3540,8 +3548,9 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
inventory.setCargoCapacity(qty);
|
|
|
}
|
|
|
inventoryDao.save(inventory);
|
|
|
//重算设备容量
|
|
|
if (cargoCapacityChanged) {
|
|
|
//重算设备容量
|
|
|
|
|
|
Mediicinedevice mediicinedevice = deviceDao.findOne(inventory.getIdDevice());
|
|
|
String tempSql = "SELECT\n" +
|
|
|
"\tsum(t.cargo_capacity)\n" +
|
|
@ -4023,5 +4032,193 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
return deviceDao.findMediicinedeviceByEquNum(equNum);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 设置设备药品库存预警规则,rule1,规则1,rule2,规则2
|
|
|
* @param isAll
|
|
|
* @param equNums
|
|
|
* @param rule1
|
|
|
* @param rule2
|
|
|
* @return
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public String setMedicineWarrayRule(Boolean isAll,String equNums, String rule1, String rule2, String userId){
|
|
|
JSONObject result = new JSONObject();
|
|
|
if (!StringUtils.isEmpty(rule1)) {
|
|
|
if (rule1.split(",").length != 4 ) {
|
|
|
result.put("msg","rule1 doesn't right");
|
|
|
result.put("response", ConstantUtils.FAIL);
|
|
|
return result.toJSONString();
|
|
|
}
|
|
|
}
|
|
|
if (!StringUtils.isEmpty(rule2)) {
|
|
|
if (rule2.split(",").length != 4 ) {
|
|
|
result.put("msg","rule2 doesn't right");
|
|
|
result.put("response", ConstantUtils.FAIL);
|
|
|
return result.toJSONString();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
UserDO user = userDao.findOne(userId);
|
|
|
RoleDO role = roleDao.findOne(user.getRoleId());
|
|
|
String belongCommunitys = "";
|
|
|
String tempSql = "";
|
|
|
//获取管理员所在社区code字符串
|
|
|
{
|
|
|
//市管理员
|
|
|
if ("saasAdmin".equals(role.getCode())) {
|
|
|
tempSql = "SELECT\n" +
|
|
|
"\t`code`\tas community\n" +
|
|
|
"FROM\n" +
|
|
|
"\tdm_hospital\n" +
|
|
|
"WHERE\n" +
|
|
|
"\tdel = 1";
|
|
|
}
|
|
|
//区域管理员
|
|
|
if ("regionAdmin".equals(role.getCode())) {
|
|
|
tempSql = "SELECT\n" +
|
|
|
"\tdh.`code` AS community\n" +
|
|
|
"FROM\n" +
|
|
|
"\twlyy_user_area t\n" +
|
|
|
"LEFT JOIN dm_hospital dh ON t.town = dh.town\n" +
|
|
|
"WHERE\n" +
|
|
|
"\tt.user_id = '" + userId + "'\n" +
|
|
|
"AND t.del = 1\n" +
|
|
|
"AND dh.del = 1";
|
|
|
}
|
|
|
//社区管理员
|
|
|
if ("communityAdmin".equals(role.getCode())) {
|
|
|
tempSql = "SELECT\n" +
|
|
|
"t.hospital AS community\n" +
|
|
|
"FROM\n" +
|
|
|
"wlyy_user_area AS t\n" +
|
|
|
"WHERE\n" +
|
|
|
"t.user_id = '" + userId + "'\n" +
|
|
|
"AND t.del = 1";
|
|
|
}
|
|
|
List<Map<String, Object>> list = hibenateUtils.createSQLQuery(tempSql);
|
|
|
for (Map<String, Object> stringObjectMap : list) {
|
|
|
if (stringObjectMap.get("community") != null && !StringUtils.isEmpty(stringObjectMap.get("community").toString())) {
|
|
|
if (belongCommunitys.indexOf(stringObjectMap.get("community") + "") == -1) {
|
|
|
if (StringUtils.isEmpty(belongCommunitys)) {
|
|
|
belongCommunitys += stringObjectMap.get("community").toString();
|
|
|
} else {
|
|
|
belongCommunitys += "," + stringObjectMap.get("community").toString();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//所有设备
|
|
|
if (isAll) {
|
|
|
{
|
|
|
tempSql = "SELECT\n" +
|
|
|
"\tt.id,\n" +
|
|
|
"\tt.equ_num,\n" +
|
|
|
"\tt.del,\n" +
|
|
|
"\tt.upper,\n" +
|
|
|
"\tt.lower,\n" +
|
|
|
"\tt.match_value,\n" +
|
|
|
"\tt.match_unit,\n" +
|
|
|
"\tt.create_time,\n" +
|
|
|
"\tt.create_user,\n" +
|
|
|
"\tt.create_user_name,\n" +
|
|
|
"\tt.update_time,\n" +
|
|
|
"\tt.update_user,\n" +
|
|
|
"\tt.update_user_name\n" +
|
|
|
"FROM\n" +
|
|
|
"\tt_medicine_warray_rule AS t\n" +
|
|
|
"LEFT JOIN t_mediicine_device tmd ON t.equ_num = tmd.equ_num\n" +
|
|
|
"WHERE\n" +
|
|
|
"\tt.del = 1\n" +
|
|
|
"AND ',"+ belongCommunitys +",' LIKE CONCAT('%,',tmd.belong_community,',%')\n";
|
|
|
}
|
|
|
List<Map<String,Object>> list = hibenateUtils.createSQLQuery(tempSql);
|
|
|
//失效原来规则
|
|
|
for (Map<String, Object> stringObjectMap : list) {
|
|
|
MedicineWarrayRule medicineWarrayRule = medicineWarrayRuleDao.findOne(stringObjectMap.get("id")+"");
|
|
|
medicineWarrayRule.setDel(0);
|
|
|
medicineWarrayRule.setUpdateTime(new Date());
|
|
|
medicineWarrayRule.setUpdateUser(userId);
|
|
|
medicineWarrayRuleDao.save(medicineWarrayRule);
|
|
|
}
|
|
|
List<Mediicinedevice> deviceList = deviceDao.findMediicinedevicesByBelongCommunityInAndDel(belongCommunitys.split(","), "1");
|
|
|
for (Mediicinedevice mediicinedevice : deviceList) {
|
|
|
if (!StringUtils.isEmpty(rule1)) {
|
|
|
MedicineWarrayRule medicineWarrayRule = new MedicineWarrayRule();
|
|
|
medicineWarrayRule.setDel(1);
|
|
|
medicineWarrayRule.setEquNum(mediicinedevice.getEquNum());
|
|
|
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 medicineWarrayRule = new MedicineWarrayRule();
|
|
|
medicineWarrayRule.setDel(1);
|
|
|
medicineWarrayRule.setEquNum(mediicinedevice.getEquNum());
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
}
|
|
|
result.put("response", ConstantUtils.SUCCESS);
|
|
|
result.put("msg", ConstantUtils.SUCCESS);
|
|
|
return result.toJSONString();
|
|
|
}
|
|
|
for (String equNum : equNums.split(",")) {
|
|
|
if (!StringUtils.isEmpty(equNum)) {
|
|
|
MedicineWarrayRule medicineWarrayRule = medicineWarrayRuleDao.findMedicineWarrayRuleByEquNumAndDel(equNum, 1);
|
|
|
if (medicineWarrayRule != null) {
|
|
|
medicineWarrayRule.setDel(0);
|
|
|
medicineWarrayRule.setUpdateTime(new Date());
|
|
|
medicineWarrayRule.setUpdateUser(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);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
result.put("response", ConstantUtils.SUCCESS);
|
|
|
result.put("msg", ConstantUtils.SUCCESS);
|
|
|
return result.toJSONString();
|
|
|
}
|
|
|
|
|
|
}
|