Browse Source

预警规则,&,增加额定库存,初始化、解绑设备归0

wangzhinan 3 years ago
parent
commit
25311620bf

+ 94 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/a1entity/MedicineWarrayRule.java

@ -0,0 +1,94 @@
package com.yihu.jw.entity.a1entity;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
@Entity
@Table(name="t_medicine_warray_rule")
public class MedicineWarrayRule extends UuidIdentityEntityWithOperator implements Serializable {
    /**
     * 设备编号
     */
    private String equNum;
    /**
     * 是否生效,1生效,0失效
     */
    private Integer del;
    /**
     * 上限
     */
    private Integer  upper;
    /**
     * 下限
     */
    private Integer  lower;
    /**
     * 匹配值
     */
    @Column
    private Integer matchValue;
    /**
     * 匹配单位
     */
    private String matchUnit;
    public MedicineWarrayRule() {
    }
    public String getEquNum() {
        return equNum;
    }
    public void setEquNum(String equNum) {
        this.equNum = equNum;
    }
    public Integer getDel() {
        return del;
    }
    public void setDel(Integer del) {
        this.del = del;
    }
    public Integer getUpper() {
        return upper;
    }
    public void setUpper(Integer upper) {
        this.upper = upper;
    }
    public Integer getLower() {
        return lower;
    }
    public void setLower(Integer lower) {
        this.lower = lower;
    }
    public Integer getMatchValue() {
        return matchValue;
    }
    public void setMatchValue(Integer matchValue) {
        this.matchValue = matchValue;
    }
    public String getMatchUnit() {
        return matchUnit;
    }
    public void setMatchUnit(String matchUnit) {
        this.matchUnit = matchUnit;
    }
}

+ 15 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/a1entity/MediicinecabinetInventory.java

@ -124,6 +124,13 @@ public class MediicinecabinetInventory extends UuidIdentityEntityWithOperator im
     */
    private String faultState;
    /**
     * 2021-12-29 额定库存,用于设备药品库存预警,
     * 初始化为0,+
     * 重置设备(解绑设备)为0,+
     */
    private Integer ratedInventory;
    public MediicinecabinetInventory() {
    }
@ -294,4 +301,12 @@ public class MediicinecabinetInventory extends UuidIdentityEntityWithOperator im
    public void setFaultState(String faultState) {
        this.faultState = faultState;
    }
    public Integer getRatedInventory() {
        return ratedInventory;
    }
    public void setRatedInventory(Integer ratedInventory) {
        this.ratedInventory = ratedInventory;
    }
}

+ 1 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/base/BaseRequestMapping.java

@ -176,6 +176,7 @@ public class BaseRequestMapping {
        public static final String PREFIX  = "/baseDevice";
        public static final String DOCINFO  = "/docInfo";
        public static final String CREATE  = "/create";
        public static final String setWarrayRule  = "/setWarrayRule";
        public static final String CREATEADDRESS  = "/createAddress";
        public static final String DELETEADDRESS  = "/deleteAddress";
        public static final String updateCommunity  = "/updateCommunity";

+ 11 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/a2dao/MedicineWarrayRuleDao.java

@ -0,0 +1,11 @@
package com.yihu.jw.base.dao.a2dao;
import com.yihu.jw.entity.a1entity.MedicineWarrayRule;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface MedicineWarrayRuleDao extends PagingAndSortingRepository<MedicineWarrayRule, String> {
    MedicineWarrayRule findMedicineWarrayRuleByEquNumAndDel(String equNum, Integer del);
}

+ 3 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/dao/a2dao/MediicineDeviceDao.java

@ -47,4 +47,7 @@ public interface MediicineDeviceDao extends PagingAndSortingRepository<Mediicine
    Mediicinedevice findByBelongCommunity(String belongCommunity);
    Mediicinedevice findByBelongCommunityAndEquNum(String belongCommunity,String equNum);
    List<Mediicinedevice> findMediicinedevicesByBelongCommunityInAndDel(String[] belongCommunitys, String del);
}

+ 30 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/a4endpoint/MedicineDeviceEndpoint.java

@ -19,6 +19,7 @@ import com.yihu.jw.rm.base.BaseRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
@ -748,4 +749,33 @@ public class MedicineDeviceEndpoint extends EnvelopRestEndpoint {
    }
    @PostMapping(value = BaseRequestMapping.BaseDevice.setWarrayRule)
    @ApiOperation(value = "设置设备药品库存报警规则")
    public Envelop setWarrayRule(
            @ApiParam(name = "isAll", value = "是否全部设备", required = true)
            @RequestParam(value = "isAll") Boolean isAll,
            @ApiParam(name = "equNums", value = "设备编号串,多个用英文逗号隔开")
            @RequestParam(value = "equNums", required = false) String equNums,
            @ApiParam(name = "rule1", value = "规则1")
            @RequestParam(value = "rule1", required = false ) String rule1,
            @ApiParam(name = "rule2", value = "规则2")
            @RequestParam(value = "rule2", required = false) String rule2
            ,@ApiParam(name = "userId", value = "用户id", required = true)
            @RequestParam(value = "userId") String userId) throws Exception {
        if (StringUtils.isEmpty(rule1) && StringUtils.isEmpty(rule2)) {
            return failed("预警规则为空");
        }
        if (!isAll && StringUtils.isEmpty(equNums)) {
            return failed("未选择设备");
        }
        String str = deviceService.setMedicineWarrayRule(isAll, equNums, rule1, rule2, userId);
        JSONObject jsonObject = JSONObject.parseObject(str);
        if (jsonObject.getString("response").equalsIgnoreCase(ConstantUtils.FAIL)) {
            return failed(jsonObject.getString("msg"));
        }
        return success(jsonObject.getString("response"));
    }
}

+ 198 - 1
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicinedeviceService.java

@ -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();
    }
}