|
@ -19,6 +19,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.logging.Logger;
|
|
@ -34,6 +35,9 @@ public class MedicineUserService extends BaseJpaService<Mediicineuser, Mediicine
|
|
|
|
|
|
@Autowired
|
|
|
private MediicineDeviceUserDao deviceUserDao;
|
|
|
|
|
|
@Autowired
|
|
|
private MediicineDeviceDao deviceDao;
|
|
|
@Autowired
|
|
|
private ObjectMapper objectMapper;
|
|
|
|
|
@ -218,7 +222,14 @@ public class MedicineUserService extends BaseJpaService<Mediicineuser, Mediicine
|
|
|
List<Map<String,Object>> list=null;
|
|
|
list = hibenateUtils.createSQLQuery(sql,page,size);
|
|
|
for (Map<String, Object> stringObjectMap : list) {
|
|
|
|
|
|
String countSql = " select " +
|
|
|
" COUNT(DISTINCT (t.id)) as count " +
|
|
|
" from " +
|
|
|
" t_mediicine_device_user t " +
|
|
|
" where " +
|
|
|
" 1=1 and t.del = 1 and t.user_id = '" + stringObjectMap.get("id").toString() + "'";
|
|
|
stringObjectMap.put("allocatedDevice", jdbcTemplate.queryForObject(countSql, Integer.class));
|
|
|
stringObjectMap.put("deviceQty", deviceDao.countAll());
|
|
|
}
|
|
|
String countSql = " select " +
|
|
|
" COUNT(DISTINCT (t.id)) as count " +
|
|
@ -242,66 +253,87 @@ public class MedicineUserService extends BaseJpaService<Mediicineuser, Mediicine
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public JSONObject allotDevice(String userIds, String deviceIds) throws Exception {
|
|
|
public JSONObject allotDevice(String userIds, String deviceIds, Boolean isAll) throws Exception {
|
|
|
JSONObject result = new JSONObject();
|
|
|
if (StringUtils.isEmpty(userIds) && StringUtils.isEmpty(deviceIds)) {
|
|
|
if (StringUtils.isEmpty(userIds)) {
|
|
|
result.put("response", ConstantUtils.FAIL);
|
|
|
return result;
|
|
|
}
|
|
|
//绑定设备
|
|
|
for (String userId : userIds.split(",")) {
|
|
|
if (!StringUtils.isEmpty(userId)) {
|
|
|
//移除不绑定设备
|
|
|
String sql = "SELECT\n" +
|
|
|
"\tt.id AS id,\n" +
|
|
|
"\tt.device_id AS deviceId,\n" +
|
|
|
"\tt.user_id AS userId,\n" +
|
|
|
"\tt.del AS del,\n" +
|
|
|
"\tt.create_time AS createTime,\n" +
|
|
|
"\tt.create_user AS createUser,\n" +
|
|
|
"\tt.create_user_name AS createUserName,\n" +
|
|
|
"\tt.update_time AS updateTime,\n" +
|
|
|
"\tt.update_user AS updateUser,\n" +
|
|
|
"\tt.update_user_name AS updateUserName\n" +
|
|
|
"FROM\n" +
|
|
|
"\tt_mediicine_device_user AS t\n" +
|
|
|
"WHERE\n" +
|
|
|
" t.user_id = '" + userId + "'\n" +
|
|
|
"AND '," + deviceIds + ",' NOT LIKE CONCAT('%,',t.device_id,',%')";
|
|
|
List<Map<String,Object>> list=null;
|
|
|
list = hibenateUtils.createSQLQuery(sql);
|
|
|
if (list != null && list.size() > 0) {
|
|
|
for (Map<String, Object> stringObjectMap : list) {
|
|
|
MediicineDeviceUser mediicineDeviceUser = deviceUserDao.findOne(stringObjectMap.get("id").toString());
|
|
|
mediicineDeviceUser.setDel("0");
|
|
|
deviceUserDao.save(mediicineDeviceUser);
|
|
|
//全部设备
|
|
|
if(isAll) {
|
|
|
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);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// if (list != null && list.size() > 0) {
|
|
|
// for (MediicineDeviceUser deviceUser : list) {
|
|
|
// deviceUser.setDel("0");
|
|
|
// deviceUserDao.save(deviceUser);
|
|
|
// }
|
|
|
// }
|
|
|
for (String deviceId : deviceIds.split(",")) {
|
|
|
if (!StringUtils.isEmpty(deviceId)) {
|
|
|
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 = '" + deviceId + "' AND t.user_id = '" + userId + "'";
|
|
|
int count = jdbcTemplate.queryForObject(countSql,Integer.class);
|
|
|
if (count > 0) {
|
|
|
continue;
|
|
|
} else {
|
|
|
//删除移除设备
|
|
|
String sql = "SELECT\n" +
|
|
|
"\tt.id AS id,\n" +
|
|
|
"\tt.device_id AS deviceId,\n" +
|
|
|
"\tt.user_id AS userId,\n" +
|
|
|
"\tt.del AS del,\n" +
|
|
|
"\tt.create_time AS createTime,\n" +
|
|
|
"\tt.create_user AS createUser,\n" +
|
|
|
"\tt.create_user_name AS createUserName,\n" +
|
|
|
"\tt.update_time AS updateTime,\n" +
|
|
|
"\tt.update_user AS updateUser,\n" +
|
|
|
"\tt.update_user_name AS updateUserName\n" +
|
|
|
"FROM\n" +
|
|
|
"\tt_mediicine_device_user AS t\n" +
|
|
|
"WHERE\n" +
|
|
|
" t.user_id = '" + userId + "' AND t.del = 1\n" +
|
|
|
"AND '," + deviceIds + ",' NOT LIKE CONCAT('%,',t.device_id,',%')";
|
|
|
List<Map<String,Object>> list=null;
|
|
|
list = hibenateUtils.createSQLQuery(sql);
|
|
|
if (list != null && list.size() > 0) {
|
|
|
for (Map<String, Object> stringObjectMap : list) {
|
|
|
MediicineDeviceUser mediicineDeviceUser = deviceUserDao.findOne(stringObjectMap.get("id").toString());
|
|
|
mediicineDeviceUser.setDel("0");
|
|
|
deviceUserDao.save(mediicineDeviceUser);
|
|
|
}
|
|
|
}
|
|
|
for (String deviceId : deviceIds.split(",")) {
|
|
|
if (!StringUtils.isEmpty(deviceId)) {
|
|
|
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 = '" + deviceId + "' 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(deviceId);
|
|
|
deviceUser.setUserId(userId);
|
|
|
deviceUserDao.save(deviceUser);
|
|
|
}
|
|
|
MediicineDeviceUser deviceUser = new MediicineDeviceUser();
|
|
|
deviceUser.setDel("1");
|
|
|
deviceUser.setDeviceId(deviceId);
|
|
|
deviceUser.setUserId(userId);
|
|
|
deviceUserDao.save(deviceUser);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
@ -348,7 +380,9 @@ public class MedicineUserService extends BaseJpaService<Mediicineuser, Mediicine
|
|
|
" t.aisles as aisles,\n" +
|
|
|
" t.capacity as capacity,\n" +
|
|
|
" t.ratio as ratio,\n" +
|
|
|
" t.cargo_capacity as cargoCapacity\n" +
|
|
|
" t.cargo_capacity as cargoCapacity,\n" +
|
|
|
" t.layer as layer,\n" +
|
|
|
" t.wayer as wayer\n" +
|
|
|
"FROM\n" +
|
|
|
" t_mediicine_device AS t where 1=1\n";
|
|
|
|
|
@ -472,12 +506,14 @@ public class MedicineUserService extends BaseJpaService<Mediicineuser, Mediicine
|
|
|
" t.aisles as aisles,\n" +
|
|
|
" t.capacity as capacity,\n" +
|
|
|
" t.ratio as ratio,\n" +
|
|
|
" t.cargo_capacity as cargoCapacity\n" +
|
|
|
" t.cargo_capacity as cargoCapacity,\n" +
|
|
|
" t.layer as layer,\n" +
|
|
|
" t.wayer as wayer\n" +
|
|
|
"FROM\n" +
|
|
|
" t_mediicine_device AS t where\n";
|
|
|
" t_mediicine_device AS t where t.del = 1\n";
|
|
|
|
|
|
// String conditionSql = " t.id in (select du.device_id from t_mediicine_device_user du where del = 1 and ',"+userId+",' LIKE CONCAT('%,',du.user_id,',%'))";
|
|
|
String conditionSql = " t.id in (select du.device_id from t_mediicine_device_user du where del = 1 and du.user_id = '" + userId + "'";
|
|
|
String conditionSql = " and t.id in (select du.device_id from t_mediicine_device_user du where del = 1 and du.user_id = '" + userId + "'";
|
|
|
|
|
|
sql = sql + conditionSql;
|
|
|
|
|
@ -600,7 +636,7 @@ public class MedicineUserService extends BaseJpaService<Mediicineuser, Mediicine
|
|
|
JSONObject result = new JSONObject();
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
|
String sql = "select count(1) from t_mediicine_device a";
|
|
|
String sql = "select count(1) from t_mediicine_device a where a.del = 1";
|
|
|
int count = jdbcTemplate.queryForObject(sql,Integer.class);
|
|
|
jsonObject.put("count", count);
|
|
|
result.put("response",ConstantUtils.SUCCESS);
|
|
@ -621,7 +657,7 @@ public class MedicineUserService extends BaseJpaService<Mediicineuser, Mediicine
|
|
|
*/
|
|
|
public JSONObject countOnline() throws Exception{
|
|
|
JSONObject result = new JSONObject();
|
|
|
String sql = "select count(1) from t_mediicine_device a where a.status = 1";
|
|
|
String sql = "select count(1) from t_mediicine_device a where a.del = 1 and a.status = 1";
|
|
|
int count = jdbcTemplate.queryForObject(sql,Integer.class);
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("count",count);
|
|
@ -732,11 +768,13 @@ public class MedicineUserService extends BaseJpaService<Mediicineuser, Mediicine
|
|
|
"\tt.aisles as aisles,\n" +
|
|
|
"\tt.capacity as capacity,\n" +
|
|
|
"\tt.ratio as ratio,\n" +
|
|
|
"\tt.cargo_capacity as cargoCapacity\n" +
|
|
|
"\tt.cargo_capacity as cargoCapacity,\n" +
|
|
|
"\tt.layer as layer,\n" +
|
|
|
"\tt.wayer as wayer\n" +
|
|
|
"FROM\n" +
|
|
|
"\tt_mediicine_device t\n" +
|
|
|
"LEFT JOIN t_mediicinecabinet_inventory tmi ON t.id = tmi.id_device\n" +
|
|
|
"WHERE 1=1\n" ;
|
|
|
"WHERE 1=1 and t.del = 1 \n" ;
|
|
|
if (!StringUtils.isEmpty(replenishEr)) {
|
|
|
sql +=" AND t.id in (select device_id from t_mediicine_device_user tmdu left join t_mediicine_user tmu on tmdu.user_id = tmu.id where tmdu.del = 1 and CONCAT(tmu.name,tmu.account) like '%" + replenishEr + "%')\n";
|
|
|
}
|
|
@ -816,9 +854,11 @@ public class MedicineUserService extends BaseJpaService<Mediicineuser, Mediicine
|
|
|
" t.aisles AS aisles,\n" +
|
|
|
" t.capacity AS capacity,\n" +
|
|
|
" t.ratio AS ratio,\n" +
|
|
|
" t.cargo_capacity AS cargoCapacity\n" +
|
|
|
" t.cargo_capacity AS cargoCapacity,\n" +
|
|
|
" t.layer AS layer,\n" +
|
|
|
" t.wayer AS wayer\n" +
|
|
|
"FROM\n" +
|
|
|
" t_mediicine_device AS t WHERE ',"+ ids +",' LIKE CONCAT('%,',t.id,',%')";
|
|
|
" t_mediicine_device AS t WHERE t.del = 1 and ',"+ ids +",' LIKE CONCAT('%,',t.id,',%')";
|
|
|
String sencordSql = "SELECT\n" +
|
|
|
"\ttmi.layer_no AS layerNo,\n" +
|
|
|
"\ttmi.wayer_no AS wayerNo,\n" +
|
|
@ -934,9 +974,11 @@ public class MedicineUserService extends BaseJpaService<Mediicineuser, Mediicine
|
|
|
" t.aisles AS aisles,\n" +
|
|
|
" t.capacity AS capacity,\n" +
|
|
|
" t.ratio AS ratio,\n" +
|
|
|
" t.cargo_capacity AS cargoCapacity\n" +
|
|
|
" t.cargo_capacity AS cargoCapacity,\n" +
|
|
|
" t.layer AS layer,\n" +
|
|
|
" t.wayer AS wayer\n" +
|
|
|
"FROM\n" +
|
|
|
" t_mediicine_device AS t WHERE 1=1";
|
|
|
" t_mediicine_device AS t WHERE 1=1 and t.del = 1";
|
|
|
|
|
|
if (!StringUtils.isEmpty(deviceId)) {
|
|
|
sql += " AND t.id = '" + deviceId + "'";
|