|
@ -43,6 +43,7 @@ import org.apache.commons.collections4.IterableUtils;
|
|
|
import org.apache.http.NameValuePair;
|
|
|
import org.apache.http.message.BasicNameValuePair;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
@ -2316,43 +2317,58 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
|
|
|
map.put("statusName", "未取药");
|
|
|
//取得订单详情
|
|
|
List<Mediicineorderdetail> list = orderdetailDao.findMediicineorderdetailsByIdOrder(order.getId());
|
|
|
//未取药列表
|
|
|
List<Mediicineorderdetail> weiQuYaolist = new ArrayList<>();
|
|
|
|
|
|
//判断订单药品是否都有药(能出的药),货道关闭的不能用来判断是否库存充足
|
|
|
Boolean shifoudouyouyao = true;
|
|
|
map.put("orderStatus", "1");//默认都有药
|
|
|
for (Mediicineorderdetail mediicineorderdetail : list) {
|
|
|
//cargo_state = 1,货道开启的,药品才计入统计
|
|
|
String secondSql = "SELECT\n" +
|
|
|
"\tifnull(\n" +
|
|
|
"\t\t(\n" +
|
|
|
"\t\t\tSELECT\n" +
|
|
|
"\t\t\t\tcount(DISTINCT(t.id))\n" +
|
|
|
"\t\t\tFROM\n" +
|
|
|
"\t\t\t\tt_mediicinecabinet_inventory t WHERE t.drug_code = '" + mediicineorderdetail.getDrugCode() + "'\n" +
|
|
|
"\t\t\tAND t.org_code = '" + mediicineorderdetail.getOrgCode() + "'\n" +
|
|
|
"\t\t\tAND t.cargo_state = '1'\n" +
|
|
|
"\t\t\tAND CONCAT(IFNULL(t.`id_device`,''), IFNULL(t.`equ_num`,'')) like '%" + deviceId + "%'\n" +
|
|
|
"\t\t\tGROUP BY\n" +
|
|
|
"\t\t\t\tt.drug_code,\n" +
|
|
|
"\t\t\t\tt.org_code\n" +
|
|
|
"\t\t\tHAVING\n" +
|
|
|
"\t\t\t\tsum(t.qty) >= " + Integer.parseInt(mediicineorderdetail.getQuantity()) + "\n" +
|
|
|
"\t\t),\n" +
|
|
|
"\t\t0\n" +
|
|
|
"\t)";
|
|
|
int count = jdbcTemplate.queryForObject(secondSql, Integer.class);
|
|
|
//标记详情是否有药
|
|
|
mediicineorderdetail.setOrderState("1");
|
|
|
if (count == 0) {
|
|
|
//详情无药
|
|
|
mediicineorderdetail.setOrderState("0");
|
|
|
map.put("orderStatus", "0");
|
|
|
//求出该药品已出的数量
|
|
|
String yichuyaoSql = " select count(id) from t_medicine_shipment_log where order_id='"+order.getId()+"' " +
|
|
|
" and `status`=2 and drug_code='"+mediicineorderdetail.getDrugCode()+"' ";
|
|
|
Integer yichuyao = jdbcTemplate.queryForObject(yichuyaoSql,Integer.class);
|
|
|
Integer weiquyaoTotal = Integer.parseInt(mediicineorderdetail.getQuantity())-yichuyao;
|
|
|
if (weiquyaoTotal>0){
|
|
|
Mediicineorderdetail waitForTaking= new Mediicineorderdetail();
|
|
|
BeanUtils.copyProperties(mediicineorderdetail,waitForTaking);
|
|
|
waitForTaking.setQuantity(weiquyaoTotal+"");
|
|
|
weiQuYaolist.add(waitForTaking);
|
|
|
|
|
|
String secondSql = "SELECT\n" +
|
|
|
"\tifnull(\n" +
|
|
|
"\t\t(\n" +
|
|
|
"\t\t\tSELECT\n" +
|
|
|
"\t\t\t\tcount(DISTINCT(t.id))\n" +
|
|
|
"\t\t\tFROM\n" +
|
|
|
"\t\t\t\tt_mediicinecabinet_inventory t WHERE t.drug_code = '" + mediicineorderdetail.getDrugCode() + "'\n" +
|
|
|
"\t\t\tAND t.org_code = '" + mediicineorderdetail.getOrgCode() + "'\n" +
|
|
|
"\t\t\tAND t.cargo_state = '1'\n" +
|
|
|
"\t\t\tAND CONCAT(IFNULL(t.`id_device`,''), IFNULL(t.`equ_num`,'')) like '%" + deviceId + "%'\n" +
|
|
|
"\t\t\tGROUP BY\n" +
|
|
|
"\t\t\t\tt.drug_code,\n" +
|
|
|
"\t\t\t\tt.org_code\n" +
|
|
|
"\t\t\tHAVING\n" +
|
|
|
"\t\t\t\tsum(t.qty) >= " + weiquyaoTotal + "\n" +
|
|
|
"\t\t),\n" +
|
|
|
"\t\t0\n" +
|
|
|
"\t)";
|
|
|
int count = jdbcTemplate.queryForObject(secondSql, Integer.class);
|
|
|
//标记详情是否有药
|
|
|
mediicineorderdetail.setOrderState("1");
|
|
|
if (count == 0) {
|
|
|
//详情无药
|
|
|
mediicineorderdetail.setOrderState("0");
|
|
|
map.put("orderStatus", "0");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if ("1".equals(map.get("orderStatus"))) {
|
|
|
map.put("orderStatusName", "药柜有药");
|
|
|
//生成出货单
|
|
|
shipmentLogDao.deleteByOrderId(order.getId());
|
|
|
shipmentLogDao.deleteByOrderIdNotOut(order.getId());//删除未处药和出药失败的订单
|
|
|
// int count = jdbcTemplate.queryForObject(
|
|
|
// "SELECT\n" +
|
|
|
// "\tcount(DISTINCT(id))\n" +
|
|
@ -2403,8 +2419,13 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
|
|
|
//订单详情遍历
|
|
|
for (Mediicineorderdetail mediicineorderdetail : list) {
|
|
|
Mediicinedrugs mediicinedrugs = drugsDao.findByDrugCodeAndOrgCode(mediicineorderdetail.getDrugCode(), mediicineorderdetail.getOrgCode());
|
|
|
|
|
|
String yichuyaoSql = " select count(id) from t_medicine_shipment_log where order_id='"+order.getId()+"' " +
|
|
|
" and `status`=2 and drug_code='"+mediicineorderdetail.getDrugCode()+"' ";//求出该药品已出的数量
|
|
|
Integer yichuyao = jdbcTemplate.queryForObject(yichuyaoSql,Integer.class);
|
|
|
|
|
|
//订单药品数目
|
|
|
Integer qty = Integer.parseInt(String.valueOf(mediicineorderdetail.getQuantity()));
|
|
|
Integer qty = Integer.parseInt(String.valueOf(mediicineorderdetail.getQuantity()))-yichuyao;
|
|
|
//库存集合
|
|
|
List<Map<String, Object>> tempList = hibenateUtils.createSQLQuery(
|
|
|
"SELECT\n" +
|
|
@ -2518,7 +2539,7 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
|
|
|
}
|
|
|
if ("0".equals(map.get("orderStatus"))) {
|
|
|
map.put("orderStatusName", "药柜无药");
|
|
|
map.put("drugList", list);
|
|
|
map.put("drugList", weiQuYaolist);
|
|
|
}
|
|
|
orderList.add(map);
|
|
|
}
|