|
@ -199,7 +199,7 @@ public class MedicineUserService extends BaseJpaService<Mediicineuser, Mediicine
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public JSONObject allotDevice(String userIds, String deviceIds, Boolean isAll) throws Exception {
|
|
|
public JSONObject allotDevice(String userIds, String deviceIds, Boolean isAll, String operator) throws Exception {
|
|
|
JSONObject result = new JSONObject();
|
|
|
if (StringUtils.isEmpty(userIds)) {
|
|
|
result.put("response", ConstantUtils.FAIL);
|
|
@ -210,28 +210,150 @@ public class MedicineUserService extends BaseJpaService<Mediicineuser, Mediicine
|
|
|
if (!StringUtils.isEmpty(userId)) {
|
|
|
//全部设备
|
|
|
if(isAll) {
|
|
|
Iterable<Mediicinedevice> lists = deviceDao.findAll();
|
|
|
Iterator iterator = lists.iterator();
|
|
|
while(iterator.hasNext()){
|
|
|
Mediicinedevice mediicinedevice = ((Mediicinedevice) iterator.next());
|
|
|
if (mediicinedevice != null) {
|
|
|
UserDO user = userDao.findOne(operator);
|
|
|
RoleDO role = roleDao.findOne(user.getRoleId());
|
|
|
String belongCommunitys = "";
|
|
|
String tempSql = "";
|
|
|
//获取管理员所在社区id字符串
|
|
|
{
|
|
|
//市管理员
|
|
|
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 (StringUtils.isEmpty(belongCommunitys)) {
|
|
|
belongCommunitys += stringObjectMap.get("community").toString();
|
|
|
} else {
|
|
|
belongCommunitys += "," + stringObjectMap.get("community").toString();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
String sql = "";
|
|
|
{
|
|
|
sql += "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" +
|
|
|
"t.humidity AS humidity,\n" +
|
|
|
"t.temperature AS temperature,\n" +
|
|
|
"t.humiditycontrol AS humiditycontrol,\n" +
|
|
|
"t.temperaturecontrol AS temperaturecontrol,\n" +
|
|
|
"t.heat AS heat,\n" +
|
|
|
"t.warning_temperature_height AS warningTemperatureHeight,\n" +
|
|
|
"t.waring_humidity_height AS waringHumidityHeight,\n" +
|
|
|
"t.warning_temperature_low AS warningTemperatureLow,\n" +
|
|
|
"t.waring_humidity_low AS waringHumidityLow\n" +
|
|
|
"FROM\n" +
|
|
|
"t_mediicine_device AS t WHERE t.del = 1 AND ',"+ belongCommunitys +",' LIKE CONCAT('%,',t.belong_community,',%')\n";
|
|
|
}
|
|
|
List<Map<String, Object>> list = hibenateUtils.createSQLQuery(sql);
|
|
|
for (Map<String, Object> stringObjectMap : list) {
|
|
|
if (stringObjectMap != null && stringObjectMap.get("id") != null && !StringUtils.isEmpty(stringObjectMap.get("id").toString())) {
|
|
|
String countSql = " select " +
|
|
|
" COUNT(DISTINCT (t.id)) as count " +
|
|
|
" from " +
|
|
|
" t_mediicine_device_user t " +
|
|
|
" where " +
|
|
|
" 1=1 AND t.del = 1 AND t.device_id = '" + mediicinedevice.getId() + "' AND t.user_id = '" + userId + "'";
|
|
|
" 1=1 AND t.del = 1 AND t.device_id = '" + stringObjectMap.get("id").toString() + "' AND t.user_id = '" + userId + "'";
|
|
|
int count = jdbcTemplate.queryForObject(countSql,Integer.class);
|
|
|
if (count > 0) {
|
|
|
continue;
|
|
|
}
|
|
|
MediicineDeviceUser deviceUser = new MediicineDeviceUser();
|
|
|
deviceUser.setDel("1");
|
|
|
deviceUser.setDeviceId(mediicinedevice.getId());
|
|
|
deviceUser.setDeviceId(stringObjectMap.get("id").toString());
|
|
|
deviceUser.setUserId(userId);
|
|
|
deviceUserDao.save(deviceUser);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// Iterable<Mediicinedevice> lists = deviceDao.findAll();
|
|
|
// Iterator iterator = lists.iterator();
|
|
|
// while(iterator.hasNext()){
|
|
|
// Mediicinedevice mediicinedevice = ((Mediicinedevice) iterator.next());
|
|
|
// if (mediicinedevice != null) {
|
|
|
// String countSql = " select " +
|
|
|
// " COUNT(DISTINCT (t.id)) as count " +
|
|
|
// " from " +
|
|
|
// " t_mediicine_device_user t " +
|
|
|
// " where " +
|
|
|
// " 1=1 AND t.del = 1 AND t.device_id = '" + mediicinedevice.getId() + "' AND t.user_id = '" + userId + "'";
|
|
|
// int count = jdbcTemplate.queryForObject(countSql,Integer.class);
|
|
|
// if (count > 0) {
|
|
|
// continue;
|
|
|
// }
|
|
|
// MediicineDeviceUser deviceUser = new MediicineDeviceUser();
|
|
|
// deviceUser.setDel("1");
|
|
|
// deviceUser.setDeviceId(mediicinedevice.getId());
|
|
|
// deviceUser.setUserId(userId);
|
|
|
// deviceUserDao.save(deviceUser);
|
|
|
// }
|
|
|
// }
|
|
|
} else {
|
|
|
//删除移除设备
|
|
|
String sql = "SELECT\n" +
|