|
@ -1,19 +1,15 @@
|
|
|
package com.yihu.jw.base.service.a3service;
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.jw.base.dao.a2dao.*;
|
|
|
import com.yihu.jw.base.util.ConstantUtils;
|
|
|
import com.yihu.jw.base.util.JavaBeanUtils;
|
|
|
import com.yihu.jw.entity.a1entity.*;
|
|
|
import com.yihu.jw.entity.patient.Message;
|
|
|
import com.yihu.jw.util.date.DateUtil;
|
|
|
import com.yihu.jw.utils.StringUtil;
|
|
|
import com.yihu.jw.utils.hibernate.HibenateUtils;
|
|
|
import com.yihu.mysql.query.BaseJpaService;
|
|
|
import org.elasticsearch.common.recycler.Recycler;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@ -638,4 +634,238 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 检查订单&返回订单出货单列表
|
|
|
* @param deviceId
|
|
|
* @param pickUpNum
|
|
|
* @param cardNum
|
|
|
* @return
|
|
|
*/
|
|
|
public JSONObject checkOrderAndReturn(String deviceId, String pickUpNum, String cardNum) {
|
|
|
JSONObject result = new JSONObject();
|
|
|
if (deviceId == null || StringUtils.isEmpty(deviceId)) {
|
|
|
result.put("msg","parameter deviceId is null or empty");
|
|
|
result.put("response", ConstantUtils.FAIL);
|
|
|
return result;
|
|
|
}
|
|
|
if (pickUpNum == null && cardNum == null) {
|
|
|
result.put("msg","parameter packUpNum or cardNum is null");
|
|
|
result.put("response", ConstantUtils.FAIL);
|
|
|
return result;
|
|
|
}
|
|
|
if (StringUtils.isEmpty(pickUpNum) && StringUtils.isEmpty(cardNum)) {
|
|
|
result.put("msg","parameter pickUpNum or cardNum is empty");
|
|
|
result.put("response", ConstantUtils.FAIL);
|
|
|
return result;
|
|
|
}
|
|
|
Mediicineorder mediicineorder = null;
|
|
|
if (!StringUtils.isEmpty(pickUpNum)) {
|
|
|
mediicineorder = orderDao.findMediicineorderByPickUpNum(pickUpNum);
|
|
|
}
|
|
|
if (!StringUtils.isEmpty(cardNum)) {
|
|
|
mediicineorder = orderDao.findMediicineorderBySocialSecurityCardNum(cardNum);
|
|
|
}
|
|
|
if (mediicineorder == null) {
|
|
|
result.put("msg","order doesn't exist");
|
|
|
result.put("response", ConstantUtils.FAIL);
|
|
|
return result;
|
|
|
}
|
|
|
//订单详细内容--备用方案
|
|
|
// List<Mediicineorderdetail> list = orderdetailDao.findMediicineorderdetailsByIdOrder(mediicineorder.getId());
|
|
|
String sql = "SELECT\n" +
|
|
|
" t.id AS id,\n" +
|
|
|
" t.batch_num AS batchNum,\n" +
|
|
|
" t.cargo_info AS cargoInfo,\n" +
|
|
|
" t.drug_code AS drugCode,\n" +
|
|
|
" t.id_order AS idOrder,\n" +
|
|
|
" t.med_info AS medInfo,\n" +
|
|
|
" t.order_no AS orderNo,\n" +
|
|
|
" t.price AS price,\n" +
|
|
|
" t.quantity AS quantity,\n" +
|
|
|
" t.address AS address,\n" +
|
|
|
" t.age AS age,\n" +
|
|
|
" t.amount AS amount,\n" +
|
|
|
" t.contact AS contact,\n" +
|
|
|
" t.dispensing_window AS dispensingWindow,\n" +
|
|
|
" t.equ_address AS equAddress,\n" +
|
|
|
" t.equ_num AS equNum,\n" +
|
|
|
" t.goods_name AS goodsName,\n" +
|
|
|
" t.goods_total_amount AS goodsTotalAmount,\n" +
|
|
|
" t.id_num AS idNum,\n" +
|
|
|
" t.info_access AS infoAccess,\n" +
|
|
|
" t.`name` AS `name`,\n" +
|
|
|
" t.net_sale_amount AS netSaleAmount,\n" +
|
|
|
" t.order_amount AS orderAmount,\n" +
|
|
|
" t.order_num AS orderNum,\n" +
|
|
|
" t.order_source AS orderSource,\n" +
|
|
|
" t.order_state AS orderState,\n" +
|
|
|
" t.order_type AS orderType,\n" +
|
|
|
" t.pay_time AS payTime,\n" +
|
|
|
" t.pick_up_num AS pickUpNum,\n" +
|
|
|
" t.prescribe_num AS prescribeNum,\n" +
|
|
|
" t.prescribe_time AS prescribeTime,\n" +
|
|
|
" t.sell_state AS sellState,\n" +
|
|
|
" t.sex AS sex,\n" +
|
|
|
" t.shipping_equ AS shippingEqu,\n" +
|
|
|
" t.shipping_time AS shippingTime,\n" +
|
|
|
" t.socialinsurpayment AS socialinsurpayment,\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.drug_sku AS drugSku,\n" +
|
|
|
" t.drug_num AS drugNum,\n" +
|
|
|
" t.specif AS specif,\n" +
|
|
|
" t.use_num AS useNum,\n" +
|
|
|
" t.use_way AS useWay,\n" +
|
|
|
" t.use_rate AS useRate,\n" +
|
|
|
" t.use_dose AS useDose,\n" +
|
|
|
" t.unit AS unit,\n" +
|
|
|
" t.use_way_add AS useWayAdd,\n" +
|
|
|
" t.manufactor AS manufactor,\n" +
|
|
|
" t.social_security_card_num AS socialSecurityCardNum,\n" +
|
|
|
" t.org_code AS orgCode\n" +
|
|
|
"FROM\n" +
|
|
|
" t_mediicine_order_detail AS t\n";
|
|
|
if (!StringUtils.isEmpty(pickUpNum)) {
|
|
|
sql += "WHERE t.pick_up_num = '" + pickUpNum + "'";
|
|
|
}
|
|
|
if (!StringUtils.isEmpty(cardNum)) {
|
|
|
if (!StringUtils.isEmpty(pickUpNum)) {
|
|
|
sql += "AND t.social_security_card_num = '" + cardNum + "'";
|
|
|
} else {
|
|
|
sql += "WHERE t.social_security_card_num = '" + cardNum + "'";
|
|
|
}
|
|
|
}
|
|
|
List<Map<String,Object>> list = null;
|
|
|
//订单详细内容
|
|
|
list = hibenateUtils.createSQLQuery(sql);
|
|
|
//没有订单信息
|
|
|
Boolean isInStock = true;
|
|
|
for (Map<String, Object> stringObjectMap : list) {
|
|
|
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 = '" + stringObjectMap.get("drugCode") + "'\n" +
|
|
|
"\t\t\tAND t.org_code = '" + stringObjectMap.get("orgCode") + "'\n" +
|
|
|
"\t\t\tAND t.id_device = '"+ 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(String.valueOf(stringObjectMap.get("quantity"))) + "\n" +
|
|
|
"\t\t),\n" +
|
|
|
"\t\t0\n" +
|
|
|
"\t)";
|
|
|
int count = jdbcTemplate.queryForObject(secondSql,Integer.class);
|
|
|
stringObjectMap.put("status", 1);
|
|
|
if (count == 0) {
|
|
|
isInStock = false;
|
|
|
stringObjectMap.put("status", 0);
|
|
|
// result.put("response", ConstantUtils.FAIL);
|
|
|
// return result;
|
|
|
}
|
|
|
}
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
jsonObject.put("status", 0);
|
|
|
if (!isInStock) {
|
|
|
jsonObject.put("list", list);
|
|
|
result.put("response", ConstantUtils.SUCCESS);
|
|
|
result.put("msg", jsonObject);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
//生成出货单
|
|
|
int count = jdbcTemplate.queryForObject(
|
|
|
"SELECT\n" +
|
|
|
"\tcount(DISTINCT(id))\n" +
|
|
|
"FROM\n" +
|
|
|
"\tt_medicine_shipment_log\n" +
|
|
|
"WHERE\n" +
|
|
|
"\torder_id = '" + list.get(0).get("idOrder") + "'",Integer.class);
|
|
|
if (count > 0) {
|
|
|
String tempSql = "SELECT\n" +
|
|
|
"\tt.id AS id,\n" +
|
|
|
"\tt.device_id AS deviceId,\n" +
|
|
|
"\tt.order_id AS orderId,\n" +
|
|
|
"\tt.drug_id AS drugId,\n" +
|
|
|
"\tt.`status` AS `status`,\n" +
|
|
|
"\tt.out_time AS outTime,\n" +
|
|
|
"\tt.layer_no AS layerNo,\n" +
|
|
|
"\tt.wayer_no AS wayerNo,\n" +
|
|
|
"\tt.description AS description,\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_medicine_shipment_log AS t\n" +
|
|
|
"WHERE \n" +
|
|
|
"\tt.order_id = '" + mediicineorder.getId()+"'";
|
|
|
List<Map<String, Object>> tempList = hibenateUtils.createSQLQuery(tempSql);
|
|
|
jsonObject.put("list", tempList);
|
|
|
jsonObject.put("status", 1);
|
|
|
result.put("response", ConstantUtils.SUCCESS);
|
|
|
result.put("msg", jsonObject);
|
|
|
return result;
|
|
|
}
|
|
|
List<MedicineShipmentLog> shipmentLogs = new ArrayList<>();
|
|
|
//订单详情遍历
|
|
|
for (Map<String, Object> stringObjectMap : list) {
|
|
|
Mediicinedrugs mediicinedrugs = drugsDao.findByDrugCodeAndOrgCode(stringObjectMap.get("drugCode").toString(), stringObjectMap.get("orgCode").toString());
|
|
|
//订单药品数目
|
|
|
Integer qty = Integer.parseInt(String.valueOf(stringObjectMap.get("quantity")));
|
|
|
//库存集合
|
|
|
List<Map<String, Object>> tempList = hibenateUtils.createSQLQuery(
|
|
|
"SELECT\n" +
|
|
|
" t.id,\n" +
|
|
|
" t.layer_no AS layerNo,\n" +
|
|
|
" t.wayer_no AS wayerNo,\n" +
|
|
|
" t.qty\n" +
|
|
|
"FROM\n" +
|
|
|
"\tt_mediicinecabinet_inventory t\n" +
|
|
|
"WHERE\n" +
|
|
|
"\tt.drug_code = '"+ stringObjectMap.get("drugCode") +"'\n" +
|
|
|
"AND t.org_code = '" + stringObjectMap.get("orgCode") +"'\n" +
|
|
|
"AND t.id_device = '" + deviceId + "'\n" +
|
|
|
"and t.qty > 0"
|
|
|
);
|
|
|
for (int i = 0; i < qty; i++) {
|
|
|
for (Map<String, Object> objectMap : tempList) {
|
|
|
if (Integer.parseInt(String.valueOf(objectMap.get("qty"))) >0) {
|
|
|
objectMap.put("qty",Integer.parseInt(String.valueOf(objectMap.get("qty"))) - 1 );
|
|
|
MedicineShipmentLog shipmentLog = new MedicineShipmentLog();
|
|
|
shipmentLog.setDeviceId(deviceId);
|
|
|
shipmentLog.setOrderId(stringObjectMap.get("idOrder").toString());
|
|
|
shipmentLog.setDrugId(mediicinedrugs.getId());
|
|
|
shipmentLog.setStatus("1");
|
|
|
shipmentLog.setLayerNo(objectMap.get("layerNo").toString());
|
|
|
shipmentLog.setWayerNo(objectMap.get("wayerNo").toString());
|
|
|
shipmentLogDao.save(shipmentLog);
|
|
|
shipmentLogs.add(shipmentLog);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//只生成出货单,不扣减药柜库存
|
|
|
// for (Map<String, Object> objectMap : tempList) {
|
|
|
// MediicinecabinetInventory inventory = inventoryDao.findOne(objectMap.get("id").toString());
|
|
|
// inventory.setQty(String.valueOf(objectMap.get("qty")));
|
|
|
// inventoryDao.save(inventory);
|
|
|
// }
|
|
|
}
|
|
|
jsonObject.put("list", shipmentLogs);
|
|
|
jsonObject.put("status", 1);
|
|
|
result.put("response", ConstantUtils.SUCCESS);
|
|
|
result.put("msg", jsonObject);
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
}
|