| 
					
				 | 
			
			
				@ -24,6 +24,7 @@ import org.springframework.util.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.IOException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.logging.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.stream.Collectors; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Created by Bing on 2021/9/23. 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -1213,4 +1214,256 @@ public class MedicineOrderService extends BaseJpaService<Mediicineorder, Mediici 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 检查订单并且返回订单列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param deviceId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param pickUpNum 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param cardNum 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Transactional(rollbackFor = Exception.class) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject checkOrderAndReturnOrderList(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; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //订单列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Mediicineorder> orders = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (!StringUtils.isEmpty(pickUpNum)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            mediicineorder = orderDao.findMediicineorderByPickUpNum(pickUpNum); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            orders.add(mediicineorder); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (!StringUtils.isEmpty(cardNum)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            orders.addAll(orderDao.findMediicineordersBySocialSecurityCardNum(cardNum)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        orders = orders.stream().distinct().collect(Collectors.toList()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (orders == null && orders.size() == 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("msg", "order doesn't exist"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("response", ConstantUtils.FAIL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String , Object>> orderList = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //遍历所有订单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Boolean shifoucunzaikeyiquyaode = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for (Mediicineorder order : orders) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Map<String, Object> map = new HashMap<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            DmHospitalDO dmHospitalDO = hospitalDao.findByCode(order.getBelongCommunity()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("order", order); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("orderId", order.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("prescribeNum", order.getPrescribeNum()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("community", dmHospitalDO == null ? "" : dmHospitalDO.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("phone", "123456"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("num", order.getPrescribeNum()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("date", DateUtil.dateToStr(new Date(), "yyyy-MM-dd")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("time", DateUtil.dateToStr(new Date(), "HH:mm:ss")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("remark", "若未取到货物,请您扫描小票二维码申请退款。\n谢谢慢走,祝您生活愉快!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("qrCodeContent", "谢谢慢走,祝您生活愉快!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if ("1".equals(order.getSellState())) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                map.put("status", 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                map.put("statusName", "已取药"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                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" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "\tt.drug_bar_code AS drugBarCode,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "\tt.drug_code AS drugCode,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "\tt.drug_name AS drugName,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "\tt.pic AS pic,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "\tt.price AS price,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "\tt.specif AS specif,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "\tt.unit AS unit,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "\tt.org_code AS orgCode,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "\tt.org_name AS orgName,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "                t.equ_name AS equName,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "                t.dos_form AS dosForm\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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                map.put("drugList", tempList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                orderList.add(map); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("status", 0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("statusName", "未取药"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //取得订单详情 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<Mediicineorderdetail> list = orderdetailDao.findMediicineorderdetailsByIdOrder(order.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //判断订单药品是否都有药(能出的药),货道关闭的不能用来判断是否库存充足 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Boolean shifoudouyouyao = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("orderStatus", "1");//默认都有药 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (Mediicineorderdetail mediicineorderdetail : 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 = '" + mediicineorderdetail.getDrugCode() + "'\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "\t\t\tAND t.org_code = '" + mediicineorderdetail.getOrgCode() + "'\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"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if ("1".equals(map.get("orderStatus"))) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                map.put("orderStatusName", "药柜有药"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //生成出货单 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                int count = jdbcTemplate.queryForObject( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        "SELECT\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                "\tcount(DISTINCT(id))\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                "FROM\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                "\tt_medicine_shipment_log\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                "WHERE\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                "\torder_id = '" + order.getId() + "'", 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" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "\tt.drug_bar_code AS drugBarCode,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "\tt.drug_code AS drugCode,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "\tt.drug_name AS drugName,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "\tt.pic AS pic,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "\tt.price AS price,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "\tt.specif AS specif,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "\tt.unit AS unit,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "\tt.org_code AS orgCode,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "\tt.org_name AS orgName,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "                t.equ_name AS equName,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            "                t.dos_form AS dosForm\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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    map.put("drugList", tempList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    orderList.add(map); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    continue; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //未生成 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                List<MedicineShipmentLog> shipmentLogs = new ArrayList<>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //订单详情遍历 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                for (Mediicineorderdetail mediicineorderdetail : list) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Mediicinedrugs mediicinedrugs = drugsDao.findByDrugCodeAndOrgCode(mediicineorderdetail.getDrugCode(), mediicineorderdetail.getOrgCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //订单药品数目 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Integer qty = Integer.parseInt(String.valueOf(mediicineorderdetail.getQuantity())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //库存集合 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    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.merge AS merge,\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    "    t.qty\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    "FROM\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    "\tt_mediicinecabinet_inventory t\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    "WHERE\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    "\tt.drug_code = '" + mediicineorderdetail.getDrugCode() + "'\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    "AND t.org_code = '" + mediicineorderdetail.getOrgCode() + "'\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    "AND CONCAT(IFNULL(t.`id_device`,''), IFNULL(t.`equ_num`,'')) like '%" + deviceId + "%'\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    "AND ( t.state = '1' or t.state = '21')\n" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    "and t.qty > 0" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    Mediicinedevice mediicinedevice = deviceDao.findMediicinedeviceByEquNum(deviceId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    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(mediicineorderdetail.getIdOrder()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                shipmentLog.setDrugId(mediicinedrugs.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                shipmentLog.setStatus("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                shipmentLog.setLayerNo(objectMap.get("layerNo").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                shipmentLog.setWayerNo(objectMap.get("merge").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                shipmentLog.setDrugBarCode(mediicinedrugs.getDrugBarCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                shipmentLog.setDrugCode(mediicinedrugs.getDrugCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                shipmentLog.setDrugName(mediicinedrugs.getDrugName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                shipmentLog.setOrgCode(mediicinedrugs.getOrgCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                shipmentLog.setOrgName(mediicinedrugs.getOrgName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                shipmentLog.setPic(mediicinedrugs.getPic()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                shipmentLog.setPrice(mediicinedrugs.getPrice()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                shipmentLog.setSpecif(mediicinedrugs.getSpecif()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                shipmentLog.setUnit(mediicinedrugs.getUnit()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                shipmentLog.setEquName(mediicinedevice.getEquName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                shipmentLog.setEquNum(mediicinedevice.getEquNum()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                shipmentLog.setDosForm(mediicinedrugs.getDosForm()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                shipmentLogDao.save(shipmentLog); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                shipmentLogs.add(shipmentLog); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                map.put("drugList", shipmentLogs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if ("0".equals(map.get("orderStatus"))) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                map.put("orderStatusName", "药柜无药"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                map.put("drugList", list); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            orderList.add(map); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jsonObject = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        jsonObject.put("orderList", orderList); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("response", ConstantUtils.SUCCESS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("msg", jsonObject); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |