|
@ -52,6 +52,9 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
@Autowired
|
|
|
private MediicinecabinetInventoryDao inventoryDao;
|
|
|
|
|
|
@Autowired
|
|
|
private MedicineDrugInventoryRecordDao inventoryRecordDao;
|
|
|
|
|
|
@Autowired
|
|
|
MedicineServive medicineServive;
|
|
|
|
|
@ -1153,6 +1156,8 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
}
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("device",device);
|
|
|
//1补货,2换货,3上架,4下架
|
|
|
jsonObject.put("inventoryList",inventoryRecordDao.findMedicineDrugInventoryRecordsByDeviceIdAndEquNumAndType(device.getId(), device.getEquNum(),"1"));
|
|
|
result.put("response",ConstantUtils.SUCCESS);
|
|
|
result.put("msg",jsonObject);
|
|
|
return result;
|
|
@ -1976,6 +1981,202 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
}
|
|
|
|
|
|
|
|
|
public JSONObject getDeviceInventoryRecordListWithUserId(String userId, int page, int size) throws Exception {
|
|
|
JSONObject result = new JSONObject();
|
|
|
|
|
|
UserDO user = userDao.findOne(userId);
|
|
|
RoleDO role = roleDao.findOne(user.getRoleId());
|
|
|
List<Map<String, Object>> deviceList = null;
|
|
|
//查询控制语句
|
|
|
String conditionSql = "";
|
|
|
if ("replenisher".equals(role.getCode())) {
|
|
|
//补货员所分配的设备
|
|
|
String deviceIds = "";
|
|
|
{
|
|
|
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);
|
|
|
|
|
|
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();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//模拟补货员未绑定设备
|
|
|
// deviceIds = "";
|
|
|
|
|
|
conditionSql = "AND ',"+ deviceIds +",' LIKE CONCAT('%,',t.id,',%')\n";
|
|
|
} else {
|
|
|
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();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (!StringUtils.isEmpty(belongCommunitys)) {
|
|
|
conditionSql += "AND ',"+ belongCommunitys +",' LIKE CONCAT('%,',t.belong_community,',%')\n";
|
|
|
}
|
|
|
}
|
|
|
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" +
|
|
|
"FROM\n" +
|
|
|
" t_mediicine_device AS t\n" +
|
|
|
"WHERE 1=1 AND t.del = 1\n";
|
|
|
}
|
|
|
|
|
|
conditionSql += "AND t.belong_community IS NOT NULL\n";
|
|
|
sql = sql + conditionSql;
|
|
|
|
|
|
deviceList = hibenateUtils.createSQLQuery(sql, page, size);
|
|
|
Map<String, String> equTypeMap = new HashMap<>();
|
|
|
equTypeMap.put("1", "测试类型1");
|
|
|
equTypeMap.put("2", "测试类型2");
|
|
|
equTypeMap.put("3", "测试类型3");
|
|
|
for (Map<String, Object> stringObjectMap : deviceList) {
|
|
|
if(!StringUtils.isEmpty(stringObjectMap.get("equType"))){
|
|
|
stringObjectMap.put("equTypeName", equTypeMap.get(stringObjectMap.get("equType")));
|
|
|
}
|
|
|
if(!StringUtils.isEmpty(stringObjectMap.get("networkStatus"))){
|
|
|
if ("1".equals(stringObjectMap.get("networkStatus").toString())) {
|
|
|
stringObjectMap.put("networkStatusName", "在线");
|
|
|
}
|
|
|
if ("0".equals(stringObjectMap.get("networkStatus").toString())) {
|
|
|
stringObjectMap.put("networkStatusName", "离线");
|
|
|
}
|
|
|
}
|
|
|
if(!StringUtils.isEmpty(stringObjectMap.get("saleStatus"))){
|
|
|
if ("1".equals(stringObjectMap.get("saleStatus").toString())) {
|
|
|
stringObjectMap.put("saleStatusName", "在售");
|
|
|
}
|
|
|
if ("2".equals(stringObjectMap.get("saleStatus").toString())) {
|
|
|
stringObjectMap.put("saleStatusName", "停售");
|
|
|
}
|
|
|
if ("3".equals(stringObjectMap.get("saleStatus").toString())) {
|
|
|
stringObjectMap.put("saleStatusName", "故障");
|
|
|
}
|
|
|
}
|
|
|
if(!StringUtils.isEmpty(stringObjectMap.get("cardStatus"))){
|
|
|
if ("1".equals(stringObjectMap.get("cardStatus").toString())) {
|
|
|
stringObjectMap.put("cardStatusName", "正常");
|
|
|
}
|
|
|
if ("2".equals(stringObjectMap.get("cardStatus").toString())) {
|
|
|
stringObjectMap.put("cardStatusName", "到期");
|
|
|
}
|
|
|
if ("3".equals(stringObjectMap.get("cardStatus").toString())) {
|
|
|
stringObjectMap.put("cardStatusName", "未知");
|
|
|
}
|
|
|
}
|
|
|
stringObjectMap.put("children",
|
|
|
inventoryRecordDao.findMedicineDrugInventoryRecordsByDeviceIdAndEquNumAndType(
|
|
|
stringObjectMap.get("id").toString(),
|
|
|
stringObjectMap.get("equNum").toString(), "1"));
|
|
|
}
|
|
|
String countSql = " select " +
|
|
|
" COUNT(DISTINCT (t.id)) as count " +
|
|
|
" from " +
|
|
|
" t_mediicine_device t " +
|
|
|
" where " +
|
|
|
" 1=1 and t.del = 1 " +
|
|
|
conditionSql;
|
|
|
Logger.getAnonymousLogger().info("finalCountSql="+countSql);
|
|
|
int count = jdbcTemplate.queryForObject(countSql,Integer.class);
|
|
|
|
|
|
result.put("count", count);
|
|
|
result.put("msg", JavaBeanUtils.getInstance().mapListJson(deviceList));
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取初始化设备列表
|
|
|
* @param content
|
|
@ -2773,14 +2974,44 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public MediicinecabinetInventory updateMediicinecabineInventoryById(String id,String drugId,String qty) throws Exception {
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public MediicinecabinetInventory updateMediicinecabineInventoryById(String id,String drugId,String qty,String userId) throws Exception {
|
|
|
MediicinecabinetInventory inventory = inventoryDao.findOne(id);
|
|
|
if (inventory==null){
|
|
|
throw new Exception("不存在改货道!");
|
|
|
}
|
|
|
//记录补货or换货or上架(上货)信息
|
|
|
//上货
|
|
|
MedicineDrugInventoryRecord inventoryRecord = new MedicineDrugInventoryRecord();
|
|
|
inventoryRecord.setDeviceId(inventory.getIdDevice());
|
|
|
inventoryRecord.setEquNum(inventory.getEquNum());
|
|
|
inventoryRecord.setOldDrugId(inventory.getDrugId());
|
|
|
inventoryRecord.setDrugId(drugId);
|
|
|
inventoryRecord.setLayerNo(inventory.getLayerNo());
|
|
|
inventoryRecord.setWayerNo(inventory.getWayerNo());
|
|
|
inventoryRecord.setMergeState(inventory.getState());
|
|
|
inventoryRecord.setMergeCargo(inventory.getMerge());
|
|
|
inventoryRecord.setOldQuantity(inventory.getQty());
|
|
|
inventoryRecord.setQuantity(qty);
|
|
|
inventoryRecord.setCreateUser(userId);
|
|
|
//补货
|
|
|
if (inventory.getDrugId() != null && !StringUtils.isEmpty(inventory.getDrugId()) && drugId.equals(inventory.getDrugId())) {
|
|
|
inventoryRecord.setType("1");
|
|
|
}
|
|
|
//换货
|
|
|
if (inventory.getDrugId() != null && !StringUtils.isEmpty(inventory.getDrugId()) && !drugId.equals(inventory.getDrugId())) {
|
|
|
inventoryRecord.setType("2");
|
|
|
}
|
|
|
//上架(上货)
|
|
|
if (inventory.getDrugId() == null && StringUtils.isEmpty(inventory.getDrugId())) {
|
|
|
inventoryRecord.setType("3");
|
|
|
}
|
|
|
inventoryRecordDao.save(inventoryRecord);
|
|
|
|
|
|
Mediicinedrugs mediicinedrugs = mediicinedrugsDao.findOne(drugId);
|
|
|
inventory.setUpdateTime(new Date());
|
|
|
inventory.setDrugCode(mediicinedrugs.getDrugCode());
|
|
|
inventory.setOrgCode(mediicinedrugs.getOrgCode());
|
|
|
inventory.setDrugName(mediicinedrugs.getDrugName());
|
|
|
inventory.setPrice(mediicinedrugs.getPrice()+"");
|
|
|
inventory.setSku(mediicinedrugs.getDrugSku());
|
|
@ -2814,9 +3045,24 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
public MediicinecabinetInventory updateMediicinecabineInventoryInfoById(String id,String qty,String cargoCapacity,String status) throws Exception {
|
|
|
public MediicinecabinetInventory updateMediicinecabineInventoryInfoById(String id,String qty,String cargoCapacity,String status,String userId) throws Exception {
|
|
|
MediicinecabinetInventory inventory = inventoryDao.findOne(id);
|
|
|
if (org.apache.commons.lang3.StringUtils.isNoneBlank(qty)){
|
|
|
//有药品时的补货
|
|
|
MedicineDrugInventoryRecord inventoryRecord = new MedicineDrugInventoryRecord();
|
|
|
inventoryRecord.setDeviceId(inventory.getIdDevice());
|
|
|
inventoryRecord.setEquNum(inventory.getEquNum());
|
|
|
inventoryRecord.setOldDrugId(inventory.getDrugId());
|
|
|
inventoryRecord.setDrugId(inventory.getDrugId());
|
|
|
inventoryRecord.setLayerNo(inventory.getLayerNo());
|
|
|
inventoryRecord.setWayerNo(inventory.getWayerNo());
|
|
|
inventoryRecord.setMergeState(inventory.getState());
|
|
|
inventoryRecord.setMergeCargo(inventory.getMerge());
|
|
|
inventoryRecord.setOldQuantity(inventory.getQty());
|
|
|
inventoryRecord.setQuantity(qty);
|
|
|
inventoryRecord.setCreateUser(userId);
|
|
|
inventoryRecord.setType("1");
|
|
|
inventoryRecordDao.save(inventoryRecord);
|
|
|
//提升容量至库存数(修改的库存数大于容量时)
|
|
|
if (Integer.parseInt(qty) > Integer.parseInt(inventory.getCargoCapacity())) {
|
|
|
inventory.setCargoCapacity(qty);
|
|
@ -2832,6 +3078,20 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
inventory.setQty("0");
|
|
|
}
|
|
|
inventory.setShelfStatus(status);
|
|
|
MedicineDrugInventoryRecord inventoryRecord = new MedicineDrugInventoryRecord();
|
|
|
inventoryRecord.setDeviceId(inventory.getIdDevice());
|
|
|
inventoryRecord.setEquNum(inventory.getEquNum());
|
|
|
inventoryRecord.setOldDrugId(inventory.getDrugId());
|
|
|
inventoryRecord.setDrugId(inventory.getDrugId());
|
|
|
inventoryRecord.setLayerNo(inventory.getLayerNo());
|
|
|
inventoryRecord.setWayerNo(inventory.getWayerNo());
|
|
|
inventoryRecord.setMergeState(inventory.getState());
|
|
|
inventoryRecord.setMergeCargo(inventory.getMerge());
|
|
|
inventoryRecord.setOldQuantity(inventory.getQty());
|
|
|
inventoryRecord.setQuantity("0");
|
|
|
inventoryRecord.setCreateUser(userId);
|
|
|
inventoryRecord.setType("4");
|
|
|
inventoryRecordDao.save(inventoryRecord);
|
|
|
}
|
|
|
inventory.setUpdateTime(new Date());
|
|
|
return inventoryDao.save(inventory);
|