wangzhinan 3 năm trước cách đây
mục cha
commit
aca08365dc

+ 0 - 2
svr/svr-base/src/main/java/com/yihu/jw/base/dao/a2dao/MediicinecabinetInventoryDao.java

@ -26,8 +26,6 @@ public interface MediicinecabinetInventoryDao extends PagingAndSortingRepository
    List<MediicinecabinetInventory> findMediicinecabinetInventoriesByLayerNoAndMerge(String layerNo, String merge);
//    List<MediicinecabinetInventory> findMediicinecabinetInventoriesByIdDeviceAndStateInAndDrugCodeNotNullAndAndOrgCodeNotNull(String deviceId, String[] states);
    @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 = ?2 or state = ?3) and drugCode is not null and orgCode is not null group by drugCode,orgCode")
    List<Map<String, Object>> selectsomethingBysomeCondition(String deviceId, String firstState, String secondState);

+ 20 - 39
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicineOrderService.java

@ -843,27 +843,8 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
                    medicineShipmentLog.getDeviceId(),              //equNum
                    medicineShipmentLog.getLayerNo(),
                    medicineShipmentLog.getWayerNo().split(",")[0]);
//            inventory.setQty(String.valueOf((Integer.parseInt(inventory.getQty()) - 1)<0 ? 0 :(Integer.parseInt(inventory.getQty()) - 1)));
            inventory.setQty((Integer.parseInt(inventory.getQty()) - 1<0 ? "0" :String.valueOf((Integer.parseInt(inventory.getQty()) - 1))));
            //判断设备是否还缺货不咯
            //库存中
            Mediicinedevice mediicinedevice = deviceDao.findOne(inventory.getIdDevice());
            String sql = "SELECT\n" +
                    "\tcount(DISTINCT(`id`))\n" +
                    "FROM\n" +
                    "\tt_mediicinecabinet_inventory\n" +
                    "WHERE\n" +
                    "\t`id_device` = '" + medicineShipmentLog.getDeviceId() + "'\n" +
                    "AND cast(`qty` AS UNSIGNED) < `num`";
            int count = jdbcTemplate.queryForObject(sql, Integer.class);
            if (count == 0) {
                mediicinedevice.setStatus("1");
            }
            if (Integer.parseInt(inventory.getQty()) < Integer.parseInt(inventory.getNum())) {
                //0缺货,1不缺货
                mediicinedevice.setStatus("0");
            }
            deviceDao.save(mediicinedevice);
            inventoryDao.save(inventory);
            //绑定订单跟出货设备的关系,
            Mediicineorder mediicineorder = orderDao.findOne(medicineShipmentLog.getOrderId());
@ -875,24 +856,6 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
            updateDeviceState(medicineShipmentLog);
        }
        //查询更新订单信息start
        //订单id
//        String orderId = medicineShipmentLog.getOrderId();
//        String sql = "SELECT\n" +
//                "\tcount(DISTINCT(id))\n" +
//                "FROM\n" +
//                "\tt_medicine_shipment_log\n" +
//                "WHERE\n" +
//                "\torder_id = '" + orderId + "'\n" +
//                "AND (`status` = 1\n" +
//                "OR `status` = 3)";
//        int count = jdbcTemplate.queryForObject(sql, Integer.class);
//        if (count == 0) {
//            Mediicineorder order = orderDao.findOne(orderId);
//            order.setSellState("1");
//            orderDao.save(order);
//        }
        //end
        result.put("msg", ConstantUtils.SUCCESS);
        result.put("response", ConstantUtils.SUCCESS);
        return result;
@ -905,7 +868,25 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
    public void updateDeviceState(MedicineShipmentLog medicineShipmentLog) {
        //包含原来药品信息
//        MediicinecabinetInventory inventory =  inventoryDao.findOne(cargoId);
        List<Map<String, Object>> collect = inventoryDao.selectsomethingBysomeConditionWithEquNum(medicineShipmentLog.getDeviceId(),"1,", "21");
        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 = '"+medicineShipmentLog.getDeviceId()+"'\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 = inventoryDao.selectsomethingBysomeConditionWithEquNum(medicineShipmentLog.getDeviceId(),"1,", "21");
        List<Map<String, Object>> collect = hibenateUtils.createSQLQuery(sql);
        Iterator<Map<String, Object>> it = collect.iterator();
        while (it.hasNext()) {
            Map<String, Object> stringObjectMap = it.next();

+ 16 - 4
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicineStockOutService.java

@ -484,10 +484,22 @@ public class MedicineStockOutService extends BaseJpaService<Mediicinestockout, M
        for (Mediicinestockoutdetail mediicinestockoutdetail : list) {
            MediicineStockoutDetailVO mediicineStockoutDetailVO = new MediicineStockoutDetailVO();
            BeanUtils.copyProperties(mediicinestockoutdetail, mediicineStockoutDetailVO);
            Integer inventoryNum = mediicinecabinetInventoryDao.sumqty(mediicinestockoutdetail.getOrgCode(),
                    mediicinestockoutdetail.getDrugCode(),
                    deviceId,
                    "1", "21");
            String sql = "select ifnull((SELECT\n" +
                    "\tsum(qty) AS qty\n" +
                    "FROM\n" +
                    "\tt_mediicinecabinet_inventory\n" +
                    "WHERE\n" +
                    "\torg_code = '"+mediicinestockoutdetail.getOrgCode()+"'\n" +
                    "AND drug_code = '"+mediicinestockoutdetail.getDrugCode()+"'\n" +
                    "AND id_device = '"+deviceId+"'\n" +
                    "AND (state = '1' OR state = '21')\n" +
                    "AND org_code IS NOT NULL\n" +
                    "AND drug_code IS NOT NULL), 0) as qty";
            Integer inventoryNum = jdbcTemplate.queryForObject(sql, Integer.class);
//            Integer inventoryNum = mediicinecabinetInventoryDao.sumqty(mediicinestockoutdetail.getOrgCode(),
//                    mediicinestockoutdetail.getDrugCode(),
//                    deviceId,
//                    "1", "21");
            if(inventoryNum == null) inventoryNum = 0;
            mediicineStockoutDetailVO.setInventoryNum(inventoryNum);
            Mediicinedrugs mediicinedrugs = drugsDao.findOne(mediicinestockoutdetail.getDrugId());

+ 127 - 10
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicinedeviceService.java

@ -2357,7 +2357,23 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
            //在架库存数
            stringObjectMap.put("shangPinKuCun", inStock);
            //商品庫存
            Integer inventoryNum = inventoryDao.sumInventoryWithEquNum(stringObjectMap.get("equNum")+"", "1", "21");
//            Integer inventoryNum = inventoryDao.sumInventoryWithEquNum(stringObjectMap.get("equNum")+"", "1", "21");
            String tempSqlTwo = "SELECT\n" +
                    "\tifnull(\n" +
                    "\t\t(\n" +
                    "\t\t\tSELECT\n" +
                    "\t\t\t\tsum(qty) AS qty\n" +
                    "\t\t\tFROM\n" +
                    "\t\t\t\tt_mediicinecabinet_inventory\n" +
                    "\t\t\tWHERE\n" +
                    "\t\t\t\tequ_num = '"+stringObjectMap.get("equNum")+""+"'\n" +
                    "\t\t\tAND (state = '1' OR state = '21')\n" +
                    "\t\t\tAND drug_code IS NOT NULL\n" +
                    "\t\t\tAND org_code IS NOT NULL\n" +
                    "\t\t),\n" +
                    "\t\t0\n" +
                    "\t) AS qty";
            Integer inventoryNum = jdbcTemplate.queryForObject(tempSqlTwo, Integer.class);
            if(inventoryNum == null) inventoryNum = 0;
            stringObjectMap.put("inventoryNum", inventoryNum);
            stringObjectMap.put("warningNum", getEarlyWaringNum(stringObjectMap.get("equNum") + ""));
@ -2597,7 +2613,24 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
        //
        List<Map<String, Integer>> drugIds = new ArrayList<>();
        //设备中所有药品列表
        List<Map<String, Object>> collect = inventoryDao.selectsomethingBysomeConditionWithEquNum(equNum, "1", "21");
        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 = inventoryDao.selectsomethingBysomeConditionWithEquNum(equNum, "1", "21");
        List<Map<String, Object>> collect = hibenateUtils.createSQLQuery(sql);
        Integer number = 0;
        //获取了所有缺货的药品id
        for (MedicineWarrayRule rule : rules) {
@ -3756,8 +3789,24 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
    public void updateDeviceState(String cargoId) {
        //包含原来药品信息
        MediicinecabinetInventory inventory =  inventoryDao.findOne(cargoId);
//        List<MediicinecabinetInventory> list = inventoryDao.findMediicinecabinetInventoriesByIdDeviceAndStateInAndDrugCodeNotNullAndAndOrgCodeNotNull(inventory.getIdDevice(), new String[]{"1", "21"});
        List<Map<String, Object>> collect = inventoryDao.selectsomethingBysomeCondition(inventory.getIdDevice(), "1", "21");
        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" +
                "\tid_device = '"+inventory.getIdDevice()+"'\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 = inventoryDao.selectsomethingBysomeCondition(inventory.getIdDevice(), "1", "21");
        List<Map<String, Object>> collect = hibenateUtils.createSQLQuery(sql);
//        //药品变更
//        if (drugChanged) {
//            //变更的目标药品
@ -4602,10 +4651,55 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
//         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, "1", "21"));
            String tempSql = "SELECT\n" +
                    "\ta.id AS id,\n" +
                    "\ta.id_device AS idDevice,\n" +
                    "\ta.num AS num,\n" +
                    "\ta.sku AS sku,\n" +
                    "\ta.state AS state,\n" +
                    "\ta.longtime AS longtime,\n" +
                    "\ta.drug_id AS drugId,\n" +
                    "\ta.drug_sku AS drugSku,\n" +
                    "\ta.drug_code AS drugCode,\n" +
                    "\ta.org_code AS orgCode,\n" +
                    "\ta.layer_no AS layerNo,\n" +
                    "\ta.wayer_no AS wayerNo,\n" +
                    "\ta.qty AS qty,\n" +
                    "\ta.create_time AS createTime,\n" +
                    "\ta.create_user AS createUser,\n" +
                    "\ta.create_user_name AS createUserName,\n" +
                    "\ta.update_time AS updateTime,\n" +
                    "\ta.update_user AS updateUser,\n" +
                    "\ta.update_user_name AS updateUserName,\n" +
                    "\ta.drug_name AS drugName,\n" +
                    "\ta.cargo_capacity AS cargoCapacity,\n" +
                    "\ta.shelf_status AS shelfStatus,\n" +
                    "\ta.price AS price,\n" +
                    "\ta.pic AS pic,\n" +
                    "\ta.equ_num AS equNum,\n" +
                    "\ta.`merge` AS `merge`,\n" +
                    "\ta.cargo_state AS cargoState,\n" +
                    "\ta.fault_state AS faultState,\n" +
                    "\ta.rated_inventory AS ratedInventory\n" +
                    "FROM\n" +
                    "\tt_mediicinecabinet_inventory a\n" +
                    "WHERE\n" +
                    "\ta.org_code = '"+stringObjectMap.get("orgCode") + ""+"'\n" +
                    "AND a.drug_code = '"+stringObjectMap.get("drugCode") + ""+"'\n" +
                    "AND a.id_device = '"+deviceId+"'\n" +
                    "AND (a.state = '1' OR a.state = '21')\n" +
                    "AND a.org_code IS NOT NULL\n" +
                    "AND a.drug_code IS NOT NULL";
            List<Map<String, Object>> list = hibenateUtils.createSQLQuery(tempSql);
//            stringObjectMap.put("detail", inventoryDao.getMediicinecabinetInventoriesByOrgCodeAndDurgCode(
//                    stringObjectMap.get("orgCode") + "",
//                    stringObjectMap.get("drugCode") + "",
//                    deviceId, "1", "21"));
            stringObjectMap.put("detail", list);
        }
        return collect;
    }
@ -4895,14 +4989,37 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
        Date startDate = null;
        String timeCondition = "";
        String endTime = DateUtil.getStringDate();
        if (day != null) {
            if (day == 1) {
                startDate = DateUtil.strToDateLong(DateUtil.getStringDateShort() + " 00:00:00");
            } else {
                startDate = DateUtil.getPreDays(new Date(), -day);
            }
            String endTime = DateUtil.getStringDate();
            timeCondition = " and o.shipping_time >='" + DateUtil.dateToStrLong(startDate) + "' and o.shipping_time <= '" + endTime + "'  ";
        } else {
            startDate = DateUtil.strToDateLong(DateUtil.getStringDateShort() + " 00:00:00");
            String sql = "SELECT\n" +
                    "\to.shipping_time AS shippingTime\n" +
                    "FROM\n" +
                    "\tt_mediicine_order o\n" +
                    "WHERE\n" +
                    "\t1 = 1\n" +
                    "AND o.shipping_time IS NOT NULL\n" +
                    "ORDER BY\n" +
                    "\to.shipping_time ASC LIMIT 1";
            Map<String,Object> totalMap = jdbcTemplate.queryForMap(sql);
            if (totalMap != null) {
                if (totalMap.get("shippingTime") != null) {
                    startDate = new Date(Long.parseLong(totalMap.get("shippingTime").toString()));
                } else {
                    startDate = DateUtil.getNowDate();
                }
            } else {
                startDate = DateUtil.getNowDate();
            }
            timeCondition = " and o.shipping_time >='" + DateUtil.dateToStrLong(startDate) + "' and o.shipping_time <= '" + endTime + "'  ";
        }
        String sql = "SELECT SUM(o.order_amount) as \"amount\" FROM t_mediicine_order o WHERE o.sell_state=1 "+condition+ timeCondition;