|
@ -4024,7 +4024,7 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
// @Transactional(rollbackFor = Exception.class)
|
|
|
@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){
|
|
@ -4059,6 +4059,17 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
inventoryRecordDao.save(inventoryRecord);
|
|
|
|
|
|
Mediicinedrugs mediicinedrugs = mediicinedrugsDao.findOne(drugId);
|
|
|
InventoryDO inventoryDO = new InventoryDO();
|
|
|
inventoryDO.setDrugCode(mediicinedrugs.getDrugCode());
|
|
|
inventoryDO.setOrgCode(mediicinedrugs.getOrgCode());
|
|
|
inventoryDO.setQty(Integer.parseInt(qty));
|
|
|
//换货,原额定库存跟该药品没关系
|
|
|
if ("2".equals(inventoryRecord.getType())) {
|
|
|
inventoryDO.setRatedInventory(0);
|
|
|
} else {
|
|
|
inventoryDO.setRatedInventory(inventory.getRatedInventory());
|
|
|
}
|
|
|
|
|
|
inventory.setUpdateTime(new Date());
|
|
|
inventory.setDrugCode(mediicinedrugs.getDrugCode());
|
|
|
inventory.setOrgCode(mediicinedrugs.getOrgCode());
|
|
@ -4078,9 +4089,11 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
//设置额定库存
|
|
|
inventory.setRatedInventory(Integer.parseInt(qty));
|
|
|
|
|
|
inventoryDao.save(inventory);
|
|
|
//更改设备缺货状态
|
|
|
updateDeviceState(inventory.getId());
|
|
|
updateDeviceState(inventory.getId(), inventoryDO);
|
|
|
|
|
|
inventoryDao.save(inventory);
|
|
|
|
|
|
//重算设备容量
|
|
|
if (cargoCapacityChanged) {
|
|
|
|
|
@ -4112,7 +4125,7 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
* 更新设备缺货状态,cargoId,货道id
|
|
|
* @param cargoId
|
|
|
*/
|
|
|
public void updateDeviceState(String cargoId) {
|
|
|
public void updateDeviceState(String cargoId, InventoryDO inventoryDO) {
|
|
|
//包含原来药品信息
|
|
|
MediicinecabinetInventory inventory = inventoryDao.findOne(cargoId);
|
|
|
String sql = "SELECT\n" +
|
|
@ -4126,6 +4139,7 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
"WHERE\n" +
|
|
|
"\tid_device = '"+inventory.getIdDevice()+"'\n" +
|
|
|
"AND (state = '1' OR state = '21')\n" +
|
|
|
"AND id != '"+ cargoId +"'\n" +
|
|
|
"AND drug_code IS NOT NULL\n" +
|
|
|
"AND org_code IS NOT NULL\n" +
|
|
|
"GROUP BY\n" +
|
|
@ -4133,56 +4147,18 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
"\torg_code";
|
|
|
// List<Map<String, Object>> collect = inventoryDao.selectsomethingBysomeCondition(inventory.getIdDevice(), "1", "21");
|
|
|
List<Map<String, Object>> collect = hibenateUtils.createSQLQuery(sql);
|
|
|
// //药品变更
|
|
|
// if (drugChanged) {
|
|
|
// //变更的目标药品
|
|
|
// Mediicinedrugs mediicinedrugs = mediicinedrugsDao.findOne(drugId);
|
|
|
// Iterator<Map<String, Object>> it = collect.iterator();
|
|
|
// //剔除旧药品的数量
|
|
|
// while (it.hasNext()) {
|
|
|
// Map<String, Object> stringObjectMap = it.next();
|
|
|
// if (String.valueOf(stringObjectMap.get("drugCode")).equals(inventory.getDrugCode()) &&
|
|
|
// String.valueOf(stringObjectMap.get("orgCode")).equals(inventory.getOrgCode())) {
|
|
|
// //说明只有一个货道是该种药品
|
|
|
// if (Integer.parseInt(stringObjectMap.get("qty") + "") - Integer.parseInt(inventory.getQty()) == 0) {
|
|
|
// it.remove();
|
|
|
// } else {
|
|
|
// stringObjectMap.put("qty", String.valueOf(Integer.parseInt(stringObjectMap.get("qty") + "") - Integer.parseInt(inventory.getQty())));
|
|
|
// }
|
|
|
//
|
|
|
// }
|
|
|
// }
|
|
|
// //
|
|
|
// Map<String, Object> tempMap = new HashMap<>();
|
|
|
// tempMap.put("drugCode", mediicinedrugs.getDrugCode());
|
|
|
// tempMap.put("orgCode", mediicinedrugs.getOrgCode());
|
|
|
// tempMap.put("qty", qty);
|
|
|
// tempMap.put("ratedInventory", Integer.parseInt(qty));
|
|
|
// collect.add(tempMap);
|
|
|
// } else {
|
|
|
// //数量变更
|
|
|
// if (qtyChanged) {
|
|
|
// Iterator<Map<String, Object>> it = collect.iterator();
|
|
|
// while (it.hasNext()) {
|
|
|
// Map<String, Object> stringObjectMap = it.next();
|
|
|
// if (String.valueOf(stringObjectMap.get("drugCode")).equals(inventory.getDrugCode()) &&
|
|
|
// String.valueOf(stringObjectMap.get("orgCode")).equals(inventory.getOrgCode())) {
|
|
|
// //下架
|
|
|
// if ("0".equals(qty)) {
|
|
|
// it.remove();
|
|
|
// }
|
|
|
//
|
|
|
// if (Integer.parseInt(qty) > Integer.parseInt(inventory.getQty())) {
|
|
|
// stringObjectMap.put("qty", qty);
|
|
|
// stringObjectMap.put("ratedInventory", Integer.parseInt(qty));
|
|
|
// } else if (Integer.parseInt(qty) < Integer.parseInt(inventory.getQty())) {
|
|
|
// it.remove();
|
|
|
// }
|
|
|
//
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// }
|
|
|
// //药品变更,true除当前货道还存在该药品
|
|
|
boolean isExit = collect.stream().filter(m -> m.get("drugCode").toString().equals(inventoryDO.getDrugCode())).findAny().isPresent();
|
|
|
if (collect == null || collect.size() == 0 || !isExit) {
|
|
|
Map<String, Object> tempMap = new HashMap<>();
|
|
|
tempMap.put("drugCode", inventoryDO.getDrugCode());
|
|
|
tempMap.put("orgCode", inventoryDO.getOrgCode());
|
|
|
tempMap.put("qty", inventoryDO.getQty());
|
|
|
tempMap.put("ratedInventory", inventoryDO.getRatedInventory());
|
|
|
tempMap.put("drugId", inventoryDO.getDrugId());
|
|
|
collect.add(tempMap);
|
|
|
}
|
|
|
|
|
|
|
|
|
Mediicinedevice mediicinedevice = deviceDao.findOne(inventory.getIdDevice());
|
|
|
//该设备库存预警规则
|
|
@ -4191,8 +4167,16 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
mediicinedevice.setStatus("1");
|
|
|
quit:for (MedicineWarrayRule rule : rules) {
|
|
|
for (Map<String, Object> stringObjectMap : collect) {
|
|
|
if (isExit) {
|
|
|
if (inventoryDO.getDrugCode() != null && inventoryDO.getOrgCode() != null) {
|
|
|
if (inventoryDO.getDrugCode().equals(stringObjectMap.get("drugCode")) && inventoryDO.getOrgCode().equals(stringObjectMap.get("orgCode"))) {
|
|
|
stringObjectMap.put("qty", (int) Double.parseDouble(stringObjectMap.get("qty") + "") + inventoryDO.getQty());
|
|
|
stringObjectMap.put("ratedInventory", (int) Double.parseDouble(stringObjectMap.get("ratedInventory") + "") + inventoryDO.getRatedInventory());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
Integer ratedInventory = (int) Double.parseDouble(stringObjectMap.get("ratedInventory") + "");
|
|
|
if (ratedInventory > rule.getLower() && ratedInventory < rule.getUpper()) {
|
|
|
if (ratedInventory >= rule.getLower() && ratedInventory <= rule.getUpper()) {
|
|
|
Integer tempQty = (int) Double.parseDouble(stringObjectMap.get("qty") + "");
|
|
|
if ("%".equals(rule.getMatchUnit())) {
|
|
|
Integer matchValue = (int) Math.ceil((rule.getUpper() * rule.getMatchValue()) / 100.0);
|
|
@ -4223,9 +4207,16 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
* @return
|
|
|
* @throws Exception
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public MediicinecabinetInventory updateMediicinecabineInventoryInfoById(String id,String qty,String cargoCapacity,String status,String userId) throws Exception {
|
|
|
MediicinecabinetInventory inventory = inventoryDao.findOne(id);
|
|
|
//更新设备缺货状态的该药品的已变动数量
|
|
|
InventoryDO inventoryDO = new InventoryDO();
|
|
|
inventoryDO.setDrugCode(inventory.getDrugCode());
|
|
|
inventoryDO.setOrgCode(inventory.getOrgCode());
|
|
|
inventoryDO.setRatedInventory(inventory.getRatedInventory());
|
|
|
boolean cargoCapacityChanged = false;
|
|
|
//库存变动
|
|
|
if (org.apache.commons.lang3.StringUtils.isNoneBlank(qty)){
|
|
|
if (Integer.parseInt(qty) > 99) {
|
|
|
throw new Exception("库存数量最多99个,请重新设置");
|
|
@ -4251,11 +4242,14 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
inventory.setCargoCapacity(qty);
|
|
|
}
|
|
|
inventory.setQty(qty);
|
|
|
//库存变更已变更的数量
|
|
|
inventoryDO.setQty(Integer.parseInt(qty));
|
|
|
//设置额定库存
|
|
|
inventory.setRatedInventory(Integer.parseInt(qty));
|
|
|
}
|
|
|
//更改货道容量-start
|
|
|
if (org.apache.commons.lang3.StringUtils.isNoneBlank(cargoCapacity)){
|
|
|
inventoryDO.setQty(Integer.parseInt(inventory.getQty()));
|
|
|
//2022-01-05-bug:13617-start
|
|
|
if (Integer.parseInt(inventory.getQty()) > Integer.parseInt(cargoCapacity)) {
|
|
|
//有药品时的补货
|
|
@ -4274,6 +4268,7 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
inventoryRecord.setType("1");
|
|
|
inventoryRecordDao.save(inventoryRecord);
|
|
|
inventory.setQty(cargoCapacity);
|
|
|
inventoryDO.setQty(Integer.parseInt(cargoCapacity));
|
|
|
//设置额定库存
|
|
|
inventory.setRatedInventory(Integer.parseInt(cargoCapacity));
|
|
|
}
|
|
@ -4285,10 +4280,12 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
cargoCapacityChanged = true;
|
|
|
}
|
|
|
//更改货道容量-end
|
|
|
//下架药品
|
|
|
if (org.apache.commons.lang3.StringUtils.isNoneBlank(status)){
|
|
|
//下架时,清空库存
|
|
|
if ("0".equals(status)) {
|
|
|
inventory.setQty("0");
|
|
|
inventoryDO.setQty(0);
|
|
|
inventory.setDrugCode(null);
|
|
|
inventory.setDrugId(null);
|
|
|
inventory.setDrugName(null);
|
|
@ -4313,9 +4310,11 @@ public class MedicinedeviceService extends BaseJpaService<Mediicinedevice, Medi
|
|
|
inventoryRecordDao.save(inventoryRecord);
|
|
|
}
|
|
|
inventory.setUpdateTime(new Date());
|
|
|
inventoryDao.save(inventory);
|
|
|
|
|
|
//更改设备缺货状态
|
|
|
updateDeviceState(inventory.getId());
|
|
|
updateDeviceState(inventory.getId(), inventoryDO);
|
|
|
|
|
|
inventoryDao.save(inventory);
|
|
|
//重算设备容量
|
|
|
if (cargoCapacityChanged) {
|
|
|
Mediicinedevice mediicinedevice = deviceDao.findOne(inventory.getIdDevice());
|