wangzhinan il y a 3 ans
Parent
commit
581c02f94d

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

@ -187,6 +187,7 @@ public class BaseRequestMapping {
        public static final String getDetialOutOfStock  = "/getDetialOutOfStock";
        public static final String getDevInventory  = "/getDevInventory";
        public static final String countall  = "/countall";
        public static final String countAllDevice  = "/countAllDevice";
        public static final String countOnline  = "/countOnline";
        public static final String getDevicesByMoreContent  = "/getDevicesByMoreContent";
        public static final String getOrderDetailListById  = "/getOrderDetailListById";

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

@ -281,6 +281,18 @@ public class MedicineDeviceEndpoint extends EnvelopRestEndpoint {
    }
    @GetMapping(value = BaseRequestMapping.BaseDevice.countAllDevice)
    @ApiOperation(value = "获取设备总计" , notes="参数未添加通过数据区域查询获取")
    public Envelop countAllDevice(@ApiParam(name = "userId", value = "用户id", required = true)
                                      @RequestParam(value = "userId") String userId) throws Exception {
        JSONObject jsonObject = deviceService.countAllDevice(userId);
        if (jsonObject.getString("response").equalsIgnoreCase(ConstantUtils.FAIL)) {
            return failed(jsonObject.getString("msg"));
        }
        return success(jsonObject.getJSONObject("msg"));
    }
//    @ApiOperation(value = "获取设备总数量", notes="参数未添加通过数据区域查询获取")
//    @GetMapping("/countall")

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

@ -8,15 +8,21 @@ 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.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.base.role.RoleDO;
import com.yihu.jw.entity.base.user.UserDO;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.restmodel.ResponseContant;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.jw.utils.StringUtil;
import com.yihu.jw.utils.hibernate.HibenateUtils;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
@ -48,6 +54,14 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
    @Autowired
    private ObjectMapper objectMapper;
    @Autowired
    private UserDao userDao;
    @Autowired
    private RoleDao roleDao;
    @Autowired
    private UserAgent userAgent;
    @Autowired
    private HibenateUtils hibenateUtils;
@ -874,7 +888,87 @@ public class MedicinedeviceService  extends BaseJpaService<Mediicinedevice, Medi
        return result;
    }
    //获取当前设备数量
    /**
     * 获取设备总计
     * @return
     * @throws Exception
     */
    public  JSONObject countAllDevice(String userId) throws Exception {
        JSONObject result = new JSONObject();
        JSONObject jsonObject = new JSONObject();
//        String userId = userAgent.getUID();
        UserDO user = userDao.findOne(userId);
        RoleDO role = roleDao.findOne(user.getRoleId());
        int count = 0;
        int onlineCount = 0;
        int saleCount = 0;
        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 count(distinct(id)) from t_mediicine_device a where a.del = 1 and ',"+ deviceIds +",' LIKE CONCAT('%,',a.id,',%')";
            count = jdbcTemplate.queryForObject(sencodSql,Integer.class);
            jsonObject.put("total", count);
            sencodSql = "select count(distinct(id)) from t_mediicine_device a where a.del = 1 and a.network_status = 1 and ',"+ deviceIds +",' LIKE CONCAT('%,',a.id,',%')";
            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" +
                    "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);
            String belongCommunitys = "";
            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();
                    }
                }
            }
            //多个社区
            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);
            sencodSql = "select count(distinct(id)) from t_mediicine_device a where a.del = 1 and a.network_status = 1 and ',"+ belongCommunitys +",' LIKE CONCAT('%,',a.belong_community,',%')";
            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);
        }
        jsonObject.put("total", count);
        jsonObject.put("onlineTotal", onlineCount);
        jsonObject.put("saleTotal", saleCount);
        jsonObject.put("onlineRate", onlineCount * 1.0 / count);
        result.put("response",ConstantUtils.SUCCESS);
        result.put("msg", jsonObject);
        return result;
    }
    //获取当前设备数量countAllDevice
//    public  long countAll() {
//        return deviceDao.countAll();
//    }