wangzhinan vor 3 Jahren
Ursprung
Commit
34dc10febd

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

@ -75,6 +75,24 @@ public class MediicinecabinetInventory extends UuidIdentityEntityWithOperator im
     */
    private String orgCode;
    /**
     * 药品名称
     */
    private String drugName;
    /**
     * 货道容量,默认5
     */
    private String cargoCapacity;
    /**
     * 上下架状态,0下架,1上架、
     */
    private String shelfStatus;
    private String price;
    public MediicinecabinetInventory() {
    }
@ -173,4 +191,36 @@ public class MediicinecabinetInventory extends UuidIdentityEntityWithOperator im
    public void setOrgCode(String orgCode) {
        this.orgCode = orgCode;
    }
    public String getDrugName() {
        return drugName;
    }
    public void setDrugName(String drugName) {
        this.drugName = drugName;
    }
    public String getCargoCapacity() {
        return cargoCapacity;
    }
    public void setCargoCapacity(String cargoCapacity) {
        this.cargoCapacity = cargoCapacity;
    }
    public String getShelfStatus() {
        return shelfStatus;
    }
    public void setShelfStatus(String shelfStatus) {
        this.shelfStatus = shelfStatus;
    }
    public String getPrice() {
        return price;
    }
    public void setPrice(String price) {
        this.price = price;
    }
}

+ 1 - 1
common/common-entity/src/main/java/com/yihu/jw/entity/a1entity/Mediicinedevice.java

@ -135,7 +135,7 @@ public class Mediicinedevice extends UuidIdentityEntityWithOperator implements S
    /**
     * 状态
     * 状态    0缺货,,,,,1不缺货
     */
    private String status;

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

@ -183,6 +183,7 @@ public class BaseRequestMapping {
        public static final String getDeviceListByUserId  = "/getDeviceListByUserId";
        public static final String getUserListByDeviceId  = "/getUserListByDeviceId";
        public static final String getOutOfStockDeviceList  = "/getOutOfStockDeviceList";
        public static final String getOutOfStockDeviceListByUserId  = "/getOutOfStockDeviceListByUserId";
        public static final String getDevicesDeliveryList  = "/getDevicesDeliveryList";
        public static final String getDetialOutOfStock  = "/getDetialOutOfStock";
        public static final String getDevInventory  = "/getDevInventory";

+ 37 - 8
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/a4endpoint/MedicineDeviceEndpoint.java

@ -41,22 +41,38 @@ public class MedicineDeviceEndpoint extends EnvelopRestEndpoint {
    @Value("${wechat.id}")
    private String wechatId;
    @PostMapping(value = BaseRequestMapping.BaseDevice.CREATE)
    @ApiOperation(value = "新增设备信息")
    public Envelop create(
            @ApiParam(name = "jsonData", value = "Json数据", required = true)
            @RequestParam String jsonData) throws Exception {
        JSONObject jsonObject = null;
        String str = deviceService.createDevice(jsonData);
        jsonObject = JSONObject.parseObject(str);
    public Envelop createDevice(@ApiParam(name = "deviceId", value = "deviceId", required = true)
                                    @RequestParam(value = "deviceId") String deviceId,
                                @ApiParam(name = "layer", value = "层, 默认6", required = true)
                                @RequestParam(value = "layer", required = true, defaultValue = "6") String layer,
                                @ApiParam(name = "wayer", value = "列, 默认40", required = true)
                                    @RequestParam(value = "wayer", required = true, defaultValue = "40") String wayer){
        JSONObject jsonObject = new JSONObject();
        String str = deviceService.createDevice(deviceId, layer, wayer);
        if (jsonObject.getString("response").equalsIgnoreCase(ConstantUtils.FAIL)) {
            return failed(jsonObject.getString("msg"));
        }
        return success(jsonObject.getString("msg"));
        return success(jsonObject.getString("response"));
    }
//    @PostMapping(value = BaseRequestMapping.BaseDevice.CREATE)
//    @ApiOperation(value = "新增设备信息")
//    public Envelop create(
//            @ApiParam(name = "jsonData", value = "Json数据", required = true)
//            @RequestParam String jsonData) throws Exception {
//        JSONObject jsonObject = null;
//        String str = deviceService.createDevice(jsonData);
//        jsonObject = JSONObject.parseObject(str);
//        if (jsonObject.getString("response").equalsIgnoreCase(ConstantUtils.FAIL)) {
//            return failed(jsonObject.getString("msg"));
//        }
//        return success(jsonObject.getString("msg"));
//    }
    @PostMapping(value = BaseRequestMapping.BaseDevice.CREATEADDRESS)
    @ApiOperation(value = "新增设备投放地址")
    public Envelop createAddress(
@ -65,6 +81,8 @@ public class MedicineDeviceEndpoint extends EnvelopRestEndpoint {
        JSONObject jsonObject = null;
        String str = deviceService.createDeviceAddress(jsonData);
        jsonObject = JSONObject.parseObject(str);
        if (jsonObject.getString("response").equalsIgnoreCase(ConstantUtils.FAIL)) {
            return failed(jsonObject.getString("msg"));
        }
@ -331,6 +349,17 @@ public class MedicineDeviceEndpoint extends EnvelopRestEndpoint {
    }
    @GetMapping(value = BaseRequestMapping.BaseDevice.getOutOfStockDeviceListByUserId)
    @ApiOperation(value = "获取缺货设备列表夹带userId" , notes="获取缺货设备列表")
    public Envelop getOutOfStockDeviceListByUserId( @ApiParam(name = "userId", value = "用户id")
                                            @RequestParam(value = "userId", required = true) String userId,
                                            @ApiParam(name = "content", value = "搜索内容")
                                            @RequestParam(value = "content", required = false) String content) throws Exception {
        JSONObject jsonObject = deviceService.getOutOfStockDeviceListByUserId(userId, content);
        return success(jsonObject.getJSONArray("msg"));
    }
    @PostMapping(value = BaseRequestMapping.BaseDevice.getDetialOutOfStock)
    @ApiOperation(value = "获取缺货信息")

+ 310 - 48
svr/svr-base/src/main/java/com/yihu/jw/base/service/a3service/MedicinedeviceService.java

@ -4,19 +4,13 @@ package com.yihu.jw.base.service.a3service;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.jw.base.dao.a2dao.MedicineDeviceDeliveryDao;
import com.yihu.jw.base.dao.a2dao.MediicineDeviceDao;
import com.yihu.jw.base.dao.a2dao.MediicineDeviceUserDao;
import com.yihu.jw.base.dao.a2dao.MediicinedrugsDao;
import com.yihu.jw.base.dao.a2dao.*;
import com.yihu.jw.base.dao.role.RoleDao;
import com.yihu.jw.base.dao.user.UserDao;
import com.yihu.jw.base.useragent.UserAgent;
import com.yihu.jw.base.util.ConstantUtils;
import com.yihu.jw.base.util.JavaBeanUtils;
import com.yihu.jw.entity.a1entity.MedicineDeviceDelivery;
import com.yihu.jw.entity.a1entity.MediicineDeviceUser;
import com.yihu.jw.entity.a1entity.Mediicinedevice;
import com.yihu.jw.entity.a1entity.Mediicinedrugs;
import com.yihu.jw.entity.a1entity.*;
import com.yihu.jw.entity.base.role.RoleDO;
import com.yihu.jw.entity.base.user.UserDO;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
@ -51,6 +45,9 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
    @Autowired
    private MedicineDeviceDeliveryDao deviceDeliveryDao;
    @Autowired
    private MediicinecabinetInventoryDao inventoryDao;
    @Autowired
    private ObjectMapper objectMapper;
@ -67,50 +64,87 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
    private HibenateUtils hibenateUtils;
    /**
     * 新增设备
     * @param jsonData
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public String createDevice(String jsonData) {
    @Transactional(rollbackFor = Exception.class)
    public String createDevice(String deviceId, String layer, String wayer) {
        JSONObject result = new JSONObject();
        if(StringUtils.isEmpty(jsonData)){
        if(StringUtils.isEmpty(deviceId)){
            result.put("msg","jsonData is null");
            result.put("response", ConstantUtils.FAIL);
            return result.toJSONString();
        }
        JSONObject device = JSONObject.parseObject(jsonData);
        if(null == device){
            result.put("msg","parameter device of jsonData is null");
            result.put("response", ConstantUtils.FAIL);
            return result.toJSONString();
        }
        //判断设备id是否存在
//        if(StringUtils.isEmpty(device.getString("id"))){
//            result.put("msg","parameter id for device is null when update device");
//            result.put("response", ConstantUtils.FAIL);
//            return result.toJSONString();
//        }
        Mediicinedevice mediicinedevice = null;
        try {
            mediicinedevice = objectMapper.readValue(device.toJSONString(), Mediicinedevice.class);
        } catch (IOException e) {
            result.put("msg", "convert device jsonObject to BaseDoctorDO failed," + e.getCause());
            result.put("response", ConstantUtils.FAIL);
            return result.toJSONString();
        } catch (Exception e) {
            result.put("msg", "convert device birth failed," + e.getCause());
            result.put("response", ConstantUtils.FAIL);
            return result.toJSONString();
        Mediicinedevice mediicinedevice = new Mediicinedevice();
        mediicinedevice.setEquNum(deviceId);
        mediicinedevice.setLayer(layer);
        mediicinedevice.setWayer(wayer);
        mediicinedevice.setCargoCapacity("5");
        deviceDao.save(mediicinedevice);
        for (int i = 0; i < Integer.parseInt(layer); i++) {
            for (int i1 = 0; i1 < Integer.parseInt(wayer); i1++) {
                MediicinecabinetInventory inventory = new MediicinecabinetInventory();
                inventory.setQty("0");
                inventory.setLayerNo(String.valueOf(i+1));
                inventory.setWayerNo(String.valueOf(i1+1));
                //到底要存什么,deviceId device表中equNum
                inventory.setIdDevice(deviceId);
                inventory.setState("0");
                inventory.setCargoCapacity(mediicinedevice.getCargoCapacity());
                inventory.setShelfStatus("0");
                inventoryDao.save(inventory);
            }
        }
        this.save(mediicinedevice);
        result.put("response",ConstantUtils.SUCCESS);
        result.put("msg",mediicinedevice);
        return result.toJSONString();
    }
    /**
     * 新增设备
     * @param jsonData
     * @return
     */
//    @Transactional(rollbackFor = Exception.class)
//    public String createDevice(String jsonData) {
//
//        JSONObject result = new JSONObject();
//        if(StringUtils.isEmpty(jsonData)){
//            result.put("msg","jsonData is null");
//            result.put("response", ConstantUtils.FAIL);
//            return result.toJSONString();
//        }
//        JSONObject device = JSONObject.parseObject(jsonData);
//        if(null == device){
//            result.put("msg","parameter device of jsonData is null");
//            result.put("response", ConstantUtils.FAIL);
//            return result.toJSONString();
//        }
//        //判断设备id是否存在
////        if(StringUtils.isEmpty(device.getString("id"))){
////            result.put("msg","parameter id for device is null when update device");
////            result.put("response", ConstantUtils.FAIL);
////            return result.toJSONString();
////        }
//        Mediicinedevice mediicinedevice = null;
//        try {
//            mediicinedevice = objectMapper.readValue(device.toJSONString(), Mediicinedevice.class);
//        } catch (IOException e) {
//            result.put("msg", "convert device jsonObject to BaseDoctorDO failed," + e.getCause());
//            result.put("response", ConstantUtils.FAIL);
//            return result.toJSONString();
//        } catch (Exception e) {
//            result.put("msg", "convert device birth failed," + e.getCause());
//            result.put("response", ConstantUtils.FAIL);
//            return result.toJSONString();
//        }
//        this.save(mediicinedevice);
//        //t_mediicinecabinet_inventory
//
//        result.put("response",ConstantUtils.SUCCESS);
//        result.put("msg",mediicinedevice);
//        return result.toJSONString();
//    }
    @Transactional(rollbackFor = Exception.class)
    public String createDeviceAddress(String jsonData) {
@ -899,9 +933,14 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
//        String userId = userAgent.getUID();
        UserDO user = userDao.findOne(userId);
        RoleDO role = roleDao.findOne(user.getRoleId());
        //设备总数
        int count = 0;
        //在线设备
        int onlineCount = 0;
        //在售设备
        int saleCount = 0;
        //缺货设备数
        int outCount = 0;
        if ("replenisher".equals(role.getCode())) {
            String sql = "SELECT\n" +
                    "\tdevice_id\n" +
@ -929,16 +968,72 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
            onlineCount = jdbcTemplate.queryForObject(sencodSql, Integer.class);
            sencodSql = "select count(distinct(id)) from t_mediicine_device a where a.del = 1 and a.sale_status = 1 and ',"+ deviceIds +",' LIKE CONCAT('%,',a.id,',%')";
            saleCount = jdbcTemplate.queryForObject(sencodSql, Integer.class);
        } else {
            String sql = "SELECT\n" +
                    "t.hospital AS community\n" +
            sencodSql = "SELECT\n" +
                    "\tcount(DISTINCT(id))\n" +
                    "FROM\n" +
                    "wlyy_user_area AS t\n" +
                    "\tt_mediicine_device\n" +
                    "WHERE\n" +
                    "t.user_id = '" + userId + "'\n" +
                    "AND t.del = 1";
            List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql);
                    "\tdel = 1\n" +
                    "AND `status` = 0 and ',"+ deviceIds +",' LIKE CONCAT('%,',a.id,',%')";
//            sencodSql = "SELECT\n" +
//                    "\tcount(DISTINCT(t.id))\n" +
//                    "FROM\n" +
//                    "\tt_mediicine_device t\n" +
//                    "LEFT JOIN (\n" +
//                    "\tSELECT\n" +
//                    "\t\tid_device,\n" +
//                    "\t\tsum(qty) AS qty\n" +
//                    "\tFROM\n" +
//                    "\t\tt_mediicinecabinet_inventory\n" +
//                    "\tGROUP BY\n" +
//                    "\t\tid_device\n" +
//                    ") AS tmi ON t.id = tmi.id_device\n" +
//                    "WHERE\n" +
//                    "\tt.del = 1\n" +
//                    "AND tmi.qty < (t.capacity * t.ratio) and ',"+ deviceIds +",' LIKE CONCAT('%,',a.id,',%')";
            outCount = jdbcTemplate.queryForObject(sencodSql, Integer.class);
        } else {
            String belongCommunitys = "";
            String sql = "";
            //市管理员
            if ("saasAdmin".equals(role.getCode())) {
                sql = "SELECT\n" +
                        "\tid\tas community\n" +
                        "FROM\n" +
                        "\tdm_hospital\n" +
                        "WHERE\n" +
                        "\tdel = 1";
            }
            //区域管理员
            if ("regionAdmin".equals(role.getCode())) {
                sql = "SELECT\n" +
                        "\tdh.id 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())) {
                sql = "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(sql);
            for (Map<String, Object> stringObjectMap : list) {
                if (stringObjectMap.get("community") != null && !StringUtils.isEmpty(stringObjectMap.get("community").toString())) {
                    if (StringUtils.isEmpty(belongCommunitys)) {
@ -949,7 +1044,6 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
                }
            }
            //多个社区
            String sencodSql = "select count(1) from t_mediicine_device a where a.del = 1 and ',"+ belongCommunitys +",' LIKE CONCAT('%,',a.belong_community,',%')";
            count = jdbcTemplate.queryForObject(sencodSql,Integer.class);
            jsonObject.put("total", count);
@ -957,17 +1051,32 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
            onlineCount = jdbcTemplate.queryForObject(sencodSql, Integer.class);
            sencodSql = "select count(distinct(id)) from t_mediicine_device a where a.del = 1 and a.sale_status = 1 and ',"+ belongCommunitys +",' LIKE CONCAT('%,',a.belong_community,',%')";
            saleCount = jdbcTemplate.queryForObject(sencodSql, Integer.class);
            sencodSql = "SELECT\n" +
                    "\tcount(DISTINCT(id))\n" +
                    "FROM\n" +
                    "\tt_mediicine_device\n" +
                    "WHERE\n" +
                    "\tdel = 1\n" +
                    "AND `status` = 0  and ',"+ belongCommunitys +",' LIKE CONCAT('%,',a.belong_community,',%')";
            outCount = jdbcTemplate.queryForObject(sencodSql, Integer.class);
        }
        jsonObject.put("total", count);
        jsonObject.put("onlineTotal", onlineCount);
        jsonObject.put("saleTotal", saleCount);
        jsonObject.put("onlineRate", onlineCount * 1.0 / count);
        jsonObject.put("outCount", outCount);
        result.put("response",ConstantUtils.SUCCESS);
        result.put("msg", jsonObject);
        return result;
    }
    //获取当前设备数量countAllDevice
//    public  long countAll() {
//        return deviceDao.countAll();
@ -1164,6 +1273,159 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
    }
    /**
     * 获取缺货设备,夹带userId,用于数据隔离
     * @param userId
     * @param content
     * @return
     * @throws Exception
     */
    public JSONObject getOutOfStockDeviceListByUserId(String userId, String content) throws Exception {
        JSONObject result = new JSONObject();
        if (StringUtils.isEmpty(userId)) {
            return result;
        }
        UserDO user = userDao.findOne(userId);
        RoleDO role = roleDao.findOne(user.getRoleId());
        List<Map<String, Object>> deviceList = null;
        if ("replenisher".equals(role.getCode())) {
            //补货员所分配的设备
            String sql = "SELECT\n" +
                    "\tdevice_id\n" +
                    "FROM\n" +
                    "\tt_mediicine_device_user\n" +
                    "WHERE\n" +
                    "\tuser_id = '" + userId +"'\n" +
                    "AND del = 1";
            //设备列表
            List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql);
            String deviceIds = "";
            for (Map<String, Object> stringObjectMap : list) {
                if (stringObjectMap.get("device_id") != null && !StringUtils.isEmpty(stringObjectMap.get("device_id").toString())) {
                    if (StringUtils.isEmpty(deviceIds)) {
                        deviceIds += stringObjectMap.get("device_id").toString();
                    } else {
                        deviceIds += "," +  stringObjectMap.get("device_id").toString();
                    }
                }
            }
            String sencodSql = "SELECT\n" +
                    "    t.id AS id,\n" +
                    "    t.belong_community AS belongCommunity,\n" +
                    "    t.community AS community,\n" +
                    "    t.del AS del,\n" +
                    "    t.delivery_address AS deliveryAddress,\n" +
                    "    t.detail_address AS detailAddress,\n" +
                    "    t.equ_area AS equArea,\n" +
                    "    t.equ_class AS equClass,\n" +
                    "    t.equ_info AS equInfo,\n" +
                    "    t.equ_name AS equName,\n" +
                    "    t.equ_num AS equNum,\n" +
                    "    t.equ_type AS equType,\n" +
                    "    t.fbelong_community AS fbelongCommunity,\n" +
                    "    t.machine_code AS machineCode,\n" +
                    "    t.network_status AS networkStatus,\n" +
                    "    t.poweron_test AS poweronTest,\n" +
                    "    t.reg_date AS regDate,\n" +
                    "    t.sale_status AS saleStatus,\n" +
                    "    t.signalintensity AS signalintensity,\n" +
                    "    t.upgr_adesit AS upgrAdesit,\n" +
                    "    t.`status` AS `status`,\n" +
                    "    t.card_status AS cardStatus,\n" +
                    "    t.operator AS operator,\n" +
                    "    t.pack_age AS packAge,\n" +
                    "    t.usage_flow AS usageFlow,\n" +
                    "    t.flow AS flow,\n" +
                    "    t.create_time AS createTime,\n" +
                    "    t.create_user AS createUser,\n" +
                    "    t.create_user_name AS createUserName,\n" +
                    "    t.update_time AS updateTime,\n" +
                    "    t.update_user AS updateUser,\n" +
                    "    t.update_user_name AS updateUserName,\n" +
                    "    t.aisles AS aisles,\n" +
                    "    t.capacity AS capacity,\n" +
                    "    t.ratio AS ratio,\n" +
                    "    t.cargo_capacity AS cargoCapacity,\n" +
                    "    t.layer AS layer,\n" +
                    "    t.wayer AS wayer\n" +
                    "FROM\n" +
                    "    t_mediicine_device AS t\n" +
                    "WHERE\n" +
                    "t.del = 1 AND  \n" +
                    "t.`status` = 0 and ',"+ deviceIds +",' LIKE CONCAT('%,',a.id,',%')";
             deviceList = hibenateUtils.createSQLQuery(sencodSql);
        } else {
            String belongCommunitys = "";
            String sql = "";
            //市管理员
            if ("saasAdmin".equals(role.getCode())) {
                sql = "SELECT\n" +
                        "\tid\tas community\n" +
                        "FROM\n" +
                        "\tdm_hospital\n" +
                        "WHERE\n" +
                        "\tdel = 1";
            }
            //区域管理员
            if ("regionAdmin".equals(role.getCode())) {
                sql = "SELECT\n" +
                        "\tdh.id 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())) {
                sql = "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(sql);
            for (Map<String, Object> stringObjectMap : list) {
                if (stringObjectMap.get("community") != null && !StringUtils.isEmpty(stringObjectMap.get("community").toString())) {
                    if (StringUtils.isEmpty(belongCommunitys)) {
                        belongCommunitys += stringObjectMap.get("community").toString();
                    } else {
                        belongCommunitys += "," +  stringObjectMap.get("community").toString();
                    }
                }
            }
//            sencodSql = "SELECT\n" +
//                    "\tcount(DISTINCT(id))\n" +
//                    "FROM\n" +
//                    "\tt_mediicine_device\n" +
//                    "WHERE\n" +
//                    "\tdel = 1\n" +
//                    "AND `status` = 0  and ',"+ belongCommunitys +",' LIKE CONCAT('%,',a.belong_community,',%')";
//
//            outCount = jdbcTemplate.queryForObject(sencodSql, Integer.class);
        }
        result.put("response", ConstantUtils.SUCCESS);
        result.put("msg",deviceList);
        return result;
    }
    /**
     * 获取所属id的缺货信息
     * @param ids