wangzhinan 3 anos atrás
pai
commit
cd0f40db6a

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

@ -179,6 +179,8 @@ public class BaseRequestMapping {
        public static final String DOCINFO  = "/docInfo";
        public static final String DOCINFO  = "/docInfo";
        public static final String CREATE  = "/create";
        public static final String CREATE  = "/create";
        public static final String setWarrayRule  = "/setWarrayRule";
        public static final String setWarrayRule  = "/setWarrayRule";
        public static final String getMedicineWarrayRuleByDeviceId  = "/getMedicineWarrayRuleByDeviceId";
        public static final String getDrugInventoryCount  = "/getDrugInventoryCount";
        public static final String CREATEADDRESS  = "/createAddress";
        public static final String CREATEADDRESS  = "/createAddress";
        public static final String DELETEADDRESS  = "/deleteAddress";
        public static final String DELETEADDRESS  = "/deleteAddress";
        public static final String updateCommunity  = "/updateCommunity";
        public static final String updateCommunity  = "/updateCommunity";

+ 14 - 1
svr/svr-base/src/main/java/com/yihu/jw/base/dao/a2dao/MediicinecabinetInventoryDao.java

@ -29,7 +29,7 @@ public interface MediicinecabinetInventoryDao extends PagingAndSortingRepository
    List<MediicinecabinetInventory> findMediicinecabinetInventoriesByIdDeviceAndStateInAndDrugCodeNotNullAndAndOrgCodeNotNull(String deviceId, String[] states);
    List<MediicinecabinetInventory> findMediicinecabinetInventoriesByIdDeviceAndStateInAndDrugCodeNotNullAndAndOrgCodeNotNull(String deviceId, String[] states);
    @Query("select sum(qty) as qty, drugCode as drugCode, orgCode as orgCode, sum(ratedInventory) as ratedInventory from MediicinecabinetInventory where idDevice = ?1 and state in ?2 and drugCode is not null and orgCode is not null group by drugCode,orgCode")
    @Query("select sum(qty) as qty, drugId as drugId, drugCode as drugCode, orgCode as orgCode, sum(ratedInventory) as ratedInventory from MediicinecabinetInventory where idDevice = ?1 and state in ?2 and drugCode is not null and orgCode is not null group by drugCode,orgCode")
    List<Map<String, Object>> selectsomethingBysomeCondition(String deviceId, String[] states);
    List<Map<String, Object>> selectsomethingBysomeCondition(String deviceId, String[] states);
@ -45,4 +45,17 @@ public interface MediicinecabinetInventoryDao extends PagingAndSortingRepository
            "and orgCode is not null and drugCode is not null ")
            "and orgCode is not null and drugCode is not null ")
    Integer sumqty(String orgCode, String drugCode, String deviceId, String[] state);
    Integer sumqty(String orgCode, String drugCode, String deviceId, String[] state);
    @Query(" select a " +
            "from MediicinecabinetInventory a " +
            "where a.orgCode = ?1 " +
            "and a.drugCode = ?2 " +
            "and a.idDevice = ?3 " +
            "and a.state in ?4 " +
            "and a.orgCode is not null and a.drugCode is not null ")
    List<MediicinecabinetInventory> getMediicinecabinetInventoriesByOrgCodeAndDurgCode(String orgCode, String drugCode, String deviceId, String[] state);
    @Query("select sum(qty) as qty from MediicinecabinetInventory where equNum = ?1 and state in ?2 and drugCode is not null and orgCode is not null")
    Integer sumInventoryWithEquNum(String equNum, String[] states);
}
}

+ 26 - 5
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/a4endpoint/MedicineDeviceEndpoint.java

@ -6,10 +6,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.base.service.a3service.MedicineServive;
import com.yihu.jw.base.service.a3service.MedicineServive;
import com.yihu.jw.base.service.a3service.MedicinedeviceService;
import com.yihu.jw.base.service.a3service.MedicinedeviceService;
import com.yihu.jw.base.util.ConstantUtils;
import com.yihu.jw.base.util.ConstantUtils;
import com.yihu.jw.entity.a1entity.MedicineDeviceDelivery;
import com.yihu.jw.entity.a1entity.Mediicinedevice;
import com.yihu.jw.entity.a1entity.Mediicinedrugs;
import com.yihu.jw.entity.a1entity.Mediicineuser;
import com.yihu.jw.entity.a1entity.*;
import com.yihu.jw.entity.base.area.BaseCityDO;
import com.yihu.jw.entity.base.area.BaseCityDO;
import com.yihu.jw.restmodel.base.area.BaseCityVO;
import com.yihu.jw.restmodel.base.area.BaseCityVO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.Envelop;
@ -821,8 +818,32 @@ public class MedicineDeviceEndpoint extends EnvelopRestEndpoint {
            @RequestParam(value = "page") int page,
            @RequestParam(value = "page") int page,
            @ApiParam(name = "size", value = "分页大小", required = true, defaultValue = "15")
            @ApiParam(name = "size", value = "分页大小", required = true, defaultValue = "15")
            @RequestParam(value = "size") int size) throws Exception {
            @RequestParam(value = "size") int size) throws Exception {
        return success(deviceService.getDeviceOrderInfoPage(deviceId,startTime,endTime,page,size));
        return success(deviceService.getDeviceOrderInfoPage(deviceId, startTime, endTime, page, size));
    }
    }
    @GetMapping(value = BaseRequestMapping.BaseDevice.getMedicineWarrayRuleByDeviceId)
    @ApiOperation(value = "根据设备id获取该设备的药品库存预警规则" , notes="根据设备id获取该设备的药品库存预警规则")
    public ListEnvelop<MedicineWarrayRule> getMedicineWarrayRuleByDeviceId  (
            @ApiParam(name = "deviceId", value = "设备id", required = true)
            @RequestParam(value = "deviceId") String deviceId) throws Exception {
        JSONObject jsonObject = deviceService.getMedicineWarrayRuleByDeviceId(deviceId);
        List<MedicineWarrayRule> list = JSONObject.parseArray(jsonObject.getJSONArray("msg").toJSONString(), MedicineWarrayRule.class);
        return success(list, MedicineWarrayRule.class);
    }
    @GetMapping(value = BaseRequestMapping.BaseDevice.getDrugInventoryCount)
    @ApiOperation(value = "根据设备id获取该设备的药品库存预警规则" , notes="根据设备id获取该设备的药品库存预警规则")
    public ListEnvelop getDrugInventoryCount  (
            @ApiParam(name = "content", value = "设备id")
            @RequestParam(value = "content", required = false) String content,
            @ApiParam(name = "lowerQty", value = "设备id")
            @RequestParam(value = "lowerQty", required = false) Integer lowerQty,
            @ApiParam(name = "upperQty", value = "设备id")
            @RequestParam(value = "upperQty", required = false) Integer upperQty,
            @ApiParam(name = "deviceId", value = "设备id", required = true)
            @RequestParam(value = "deviceId") String deviceId) throws Exception {
        return success(deviceService.getDrugInventoryCount(content, lowerQty, upperQty, deviceId));
    }
}
}

+ 99 - 113
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicinedeviceService.java

@ -2352,6 +2352,12 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
            int inStock = jdbcTemplate.queryForObject(tempSql, Integer.class);
            int inStock = jdbcTemplate.queryForObject(tempSql, Integer.class);
            //在架库存数
            //在架库存数
            stringObjectMap.put("shangPinKuCun", inStock);
            stringObjectMap.put("shangPinKuCun", inStock);
            //商品庫存
            Integer inventoryNum = inventoryDao.sumInventoryWithEquNum(stringObjectMap.get("equNum")+"", new String[]{"1", "21"});
            if(inventoryNum == null) inventoryNum = 0;
            stringObjectMap.put("inventoryNum", inventoryNum);
            stringObjectMap.put("warningNum", getEarlyWaringNum(stringObjectMap.get("equNum") + ""));
        }
        }
        String countSql = " select " +
        String countSql = " select " +
                "     COUNT(DISTINCT (t.id)) as count " +
                "     COUNT(DISTINCT (t.id)) as count " +
@ -2575,6 +2581,43 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
        return result;
        return result;
    }
    }
    /**
     * 获取设备预警品类数
     * @param equNum
     * @return
     */
    public Integer getEarlyWaringNum(String equNum) {
        //该设备库存预警规则
        List<MedicineWarrayRule> rules = medicineWarrayRuleDao.findMedicineWarrayRulesByEquNumAndDel(equNum, 1);
        //
        List<Map<String, Integer>> drugIds = new ArrayList<>();
        //设备中所有药品列表
        List<Map<String, Object>> collect = inventoryDao.selectsomethingBysomeConditionWithEquNum(equNum, new String[]{"1", "21"});
        Integer number = 0;
        //获取了所有缺货的药品id
        for (MedicineWarrayRule rule : rules) {
            for (Map<String, Object> stringObjectMap : collect) {
                Integer ratedInventory = Integer.parseInt(stringObjectMap.get("ratedInventory") + "");
                if (ratedInventory > rule.getLower() && ratedInventory < rule.getUpper()) {
                    Integer tempQty = Integer.parseInt(stringObjectMap.get("qty") + "");
                    if ("%".equals(rule.getMatchUnit())) {
                        Integer matchValue = (int) Math.ceil((rule.getUpper() * rule.getMatchValue()) / 100.0);
                        if (tempQty <= matchValue) {
                            number++;
                        }
                    }
                    if ("件".equals(rule.getMatchUnit())) {
                        if (tempQty <= rule.getMatchValue()) {
                            number++;
                        }
                    }
                }
            }
        }
        return number;
    }
    public PageEnvelop selectInventoryRecordByDeviceId(String id ,String deviceId, String layerNo, String wayerNo, String type, String startTime, String endTime, String drugName, int page, int size){
    public PageEnvelop selectInventoryRecordByDeviceId(String id ,String deviceId, String layerNo, String wayerNo, String type, String startTime, String endTime, String drugName, int page, int size){
        PageEnvelop listEnvelop = new PageEnvelop();
        PageEnvelop listEnvelop = new PageEnvelop();
        String sql = "SELECT\n" +
        String sql = "SELECT\n" +
@ -2990,9 +3033,9 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
                    "tmd.quantity_unit AS quantityUnit,\n" +
                    "tmd.quantity_unit AS quantityUnit,\n" +
                    "tmd.pack_unit AS packUnit,\n" +
                    "tmd.pack_unit AS packUnit,\n" +
                    "tmd.spell_code AS spellCode,\n" +
                    "tmd.spell_code AS spellCode,\n" +
                    "\tsum(tmi.qty) AS qty,\n" +
                    "\tIFNULL(sum(tmi.qty), 0) AS qty,\n" +
                    "\t(\n" +
                    "\t(\n" +
                    "\t\ttmi.rated_inventory - CAST(tmi.qty AS UNSIGNED)\n" +
                    "\t\tIFNULL(tmi.rated_inventory - CAST(tmi.qty AS UNSIGNED), 0)\n" +
                    "\t) AS daibukucun\n" +
                    "\t) AS daibukucun\n" +
                    "FROM\n" +
                    "FROM\n" +
                    "\tt_mediicinecabinet_inventory tmi LEFT JOIN t_mediicine_drugs tmd ON tmi.drug_id = tmd.id\n" +
                    "\tt_mediicinecabinet_inventory tmi LEFT JOIN t_mediicine_drugs tmd ON tmi.drug_id = tmd.id\n" +
@ -3023,6 +3066,9 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
                "\torg_code";
                "\torg_code";
        Logger.getAnonymousLogger().info("finalCountSql="+countSql);
        Logger.getAnonymousLogger().info("finalCountSql="+countSql);
        int count = jdbcTemplate.queryForObject(countSql,Integer.class);
        int count = jdbcTemplate.queryForObject(countSql,Integer.class);
        if (count == 0) {
            list = new ArrayList<>();
        }
        result.put("count", count);
        result.put("count", count);
        result.put("msg", JavaBeanUtils.getInstance().mapListJson(list));
        result.put("msg", JavaBeanUtils.getInstance().mapListJson(list));
@ -4504,121 +4550,61 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
    }
    }
    /**
     * 预警详情
     * @param deviceId
     * @param page
     * @param size
     * @return
     * @throws Exception
     */
    public JSONObject getEaringWarringInfoByDeviceWithPage(String deviceId, int page, int size) throws Exception {
    public JSONObject getMedicineWarrayRuleByDeviceId(String deviceId) throws Exception {
        JSONObject result = new JSONObject();
        JSONObject result = new JSONObject();
//        Mediicinedevice mediicinedevice = deviceDao.findOne(deviceId);
//
//        //该设备库存预警规则
//        List<MedicineWarrayRule> rules = medicineWarrayRuleDao.findMedicineWarrayRulesByEquNumAndDel(mediicinedevice.getEquNum(), 1);
//        //
//        List<Map<String, Integer>> drugIds = new ArrayList<>();
//        List<Map<String, Object>> collect = inventoryDao.selectsomethingBysomeConditionWithEquNum(mediicinedevice.getEquNum(), new String[]{"1", "21"});
//        //获取了所有缺货的药品id
//        for (MedicineWarrayRule rule : rules) {
//            for (Map<String, Object> stringObjectMap : collect) {
//                Integer ratedInventory = Integer.parseInt(stringObjectMap.get("ratedInventory") + "");
//                if (ratedInventory > rule.getLower() && ratedInventory < rule.getUpper()) {
//                    Integer tempQty = Integer.parseInt(stringObjectMap.get("qty") + "");
//                    if ("%".equals(rule.getMatchUnit())) {
//                        Integer matchValue = (int) Math.ceil((rule.getUpper() * rule.getMatchValue()) / 100.0);
//                        if (tempQty <= matchValue) {
//                            Map<String, Integer> tempMap = new HashMap<>();
//                            tempMap.put(stringObjectMap.get("drugId") + "", Integer.parseInt(stringObjectMap.get("qty") + ""));
//                            drugIds.add(tempMap);
//                        }
//                    }
//                    if ("件".equals(rule.getMatchUnit())) {
//                        if (tempQty <= rule.getMatchValue()) {
//                            Map<String, Integer> tempMap = new HashMap<>();
//                            tempMap.put(stringObjectMap.get("drugId") + "", Integer.parseInt(stringObjectMap.get("qty") + ""));
//                            drugIds.add(tempMap);
//                        }
//                    }
//                }
//            }
//        }
//        String sql = "";
//        {
//
//            sql = "SELECT\n" +
//                    "tmd.id,\n" +
//                    "tmd.approval_num,\n" +
//                    "tmd.barcode,\n" +
//                    "tmd.brand,\n" +
//                    "tmd.dos_form,\n" +
//                    "tmd.state,\n" +
//                    "tmd.drug_bar_code,\n" +
//                    "tmd.drug_class,\n" +
//                    "tmd.drug_class_code,\n" +
//                    "tmd.drug_code,\n" +
//                    "tmd.drug_name,\n" +
//                    "tmd.drug_name_alies,\n" +
//                    "tmd.drug_short_code,\n" +
//                    "tmd.drug_type_code,\n" +
//                    "tmd.earlywarningcate,\n" +
//                    "tmd.inventory,\n" +
//                    "tmd.manufactor,\n" +
//                    "tmd.med_cabinet,\n" +
//                    "tmd.pic,\n" +
//                    "tmd.price,\n" +
//                    "tmd.sale_volume,\n" +
//                    "tmd.self_code,\n" +
//                    "tmd.specif,\n" +
//                    "tmd.unit,\n" +
//                    "tmd.create_time,\n" +
//                    "tmd.create_user,\n" +
//                    "tmd.create_user_name,\n" +
//                    "tmd.update_time,\n" +
//                    "tmd.update_user,\n" +
//                    "tmd.update_user_name,\n" +
//                    "tmd.drug_sku,\n" +
//                    "tmd.drug_num,\n" +
//                    "tmd.use_num,\n" +
//                    "tmd.use_way,\n" +
//                    "tmd.use_rate,\n" +
//                    "tmd.use_dose,\n" +
//                    "tmd.use_way_add,\n" +
//                    "tmd.org_code,\n" +
//                    "tmd.org_name,\n" +
//                    "tmd.quantity_unit,\n" +
//                    "tmd.pack_unit,\n" +
//                    "tmd.spell_code\n" +
//                    "FROM\n" +
//                    "t_mediicine_drugs AS tmd\n" +
////                    "WHERE ',"+ drugIds.stream().map(item->item.keySet()).collect(Collectors.joining(",")) +",' LIKE CONCAT('%,',t.belong_community,',%')\n";
//
//        }
//        List<Map<String, Object>> list = null;
//        list = hibenateUtils.createSQLQuery(sql,page,size);
//        String countSql = "SELECT\n" +
//                "COUNT(DISTINCT(id))" +
//                "FROM\n" +
//                "\tt_mediicinecabinet_inventory\n" +
//                "WHERE" +
//                "\tid_device = '" + deviceId + "'\n" +
//                "AND CAST(qty as UNSIGNED) < rated_inventory\n" +
//                "AND drug_code IS NOT NULL\n" +
//                "AND org_code IS NOT NULL\n" +
//                "AND (state = 1 OR state = 21)\n" +
//                "ORDER BY\n" +
//                "\tdrug_code,\n" +
//                "\torg_code";
//        Logger.getAnonymousLogger().info("finalCountSql="+countSql);
//        int count = jdbcTemplate.queryForObject(countSql,Integer.class);
//
//        result.put("count", count);
//        result.put("msg", JavaBeanUtils.getInstance().mapListJson(list));
        Mediicinedevice mediicinedevice = deviceDao.findOne(deviceId);
        result.put("msg", JavaBeanUtils.getInstance().mapListJson(medicineWarrayRuleDao.findMedicineWarrayRulesByEquNumAndDel(mediicinedevice.getEquNum(), 1)));
        return result;
        return result;
    }
    }
    public List<Map<String, Object>> getDrugInventoryCount(String content, Integer lowerQty, Integer upperQty, String deviceId) throws Exception {
        JSONObject result = new JSONObject();
        String sql = "SELECT\n" +
                "\ttmd.specif as specif,\n" +
                "\ttmi.drug_name AS drugName,\n" +
                "\tsum(tmi.qty) AS qty,\n" +
                "\ttmi.drug_id AS drugId,\n" +
                "\ttmi.drug_code AS drugCode,\n" +
                "\ttmi.org_code AS orgCode,\n" +
                "\tIFNULL(sum(tmi.rated_inventory), 0) AS ratedInventory\n" +
                "FROM\n" +
                "\tt_mediicinecabinet_inventory tmi LEFT JOIN t_mediicine_drugs tmd on tmi.drug_id = tmd.id\n" +
                "WHERE\n" +
                "\ttmi.id_device = '" + deviceId + "'\n";
        if (content != null && !StringUtils.isEmpty(content)) {
            sql += "AND tmi.drug_name like '%" + content + "%'\n";
        }
        sql += "AND (tmi.state = '1' OR tmi.state = '21')\n" +
                "AND tmi.drug_code IS NOT NULL\n" +
                "AND tmi.org_code IS NOT NULL\n" +
                "GROUP BY\n" +
                "\ttmi.drug_code,\n" +
                "\ttmi.org_code\n";
        if (lowerQty != null) {
            sql += "HAVING  SUM(tmi.qty) >= " + lowerQty + "\n";
        }
        if (upperQty != null) {
            if (lowerQty != null) {
                sql += "AND SUM(tmi.qty) <= " + upperQty + "\n";
            } else {
                sql += "HAVING SUM(tmi.qty) <= " + upperQty + "\n";
            }
        }
//         List<Map<String, Object>> collect = inventoryDao.selectsomethingBysomeCondition(deviceId, new String[]{"1", "21"});
        List<Map<String, Object>> collect = hibenateUtils.createSQLQuery(sql);
        for (Map<String, Object> stringObjectMap : collect) {
            stringObjectMap.put("detail", inventoryDao.getMediicinecabinetInventoriesByOrgCodeAndDurgCode(
                    stringObjectMap.get("orgCode") + "",
                    stringObjectMap.get("drugCode") + "",
                    deviceId, new String[]{"1", "21"}));
        }
        return collect;
    }
}
}