package org.jeecg.modules.hotelorder.controller;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.hanHaiMember.entity.HanHaiMember;
import org.jeecg.modules.hanHaiMember.service.IHanHaiMemberService;
import org.jeecg.modules.hotelbalancelog.entity.HotelBalanceLog;
import org.jeecg.modules.hotelbalancelog.service.IHotelBalanceLogService;
import org.jeecg.modules.hotelconf.service.IHotelConfService;
import org.jeecg.modules.hotelleaselog.entity.HotelLeaseLog;
import org.jeecg.modules.hotelleaselog.service.IHotelLeaseLogService;
import org.jeecg.modules.hotelmemberaccount.entity.HotelMemberAccount;
import org.jeecg.modules.hotelmemberaccount.service.IHotelMemberAccountService;
import org.jeecg.modules.hotelorder.entity.HotelOrder;
import org.jeecg.modules.hotelorder.req.DamageAuditReq;
import org.jeecg.modules.hotelorder.service.IHotelOrderService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.modules.hotelorderdetail.entity.HotelOrderDetail;
import org.jeecg.modules.hotelorderdetail.service.IHotelOrderDetailService;
import org.jeecg.modules.hotelorderlog.entity.HotelOrderLog;
import org.jeecg.modules.hotelorderlog.service.IHotelOrderLogService;
import org.jeecg.modules.hotelshop.entity.HotelShop;
import org.jeecg.modules.hotelshop.service.IHotelShopService;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: hotel_order
 * @Author: jeecg-boot
 * @Date:   2024-09-11
 * @Version: V1.0
 */
@Api(tags="hotel_order")
@RestController
@RequestMapping("/hotelorder/hotelOrder")
@Slf4j
public class HotelOrderController extends JeecgController<HotelOrder, IHotelOrderService> {
	@Autowired
	private IHotelOrderService hotelOrderService;
	@Resource
	private IHotelShopService hotelShopService;
	@Resource
	private IHotelMemberAccountService hotelMemberAccountService;
	@Resource
	private IHotelConfService hotelConfService;
	@Resource
	private IHotelBalanceLogService hotelBalanceLogService;
	@Resource
	private IHotelLeaseLogService hotelLeaseLogService;
	@Resource
	private IHotelOrderDetailService hotelOrderDetailService;
	@Resource
	private IHanHaiMemberService hanHaiMemberService;
	@Resource
	private IHotelOrderLogService hotelOrderLogService;

	/**
	 * 分页列表查询
	 *
	 * @param hotelOrder
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "hotel_order-分页列表查询")
	@ApiOperation(value="hotel_order-分页列表查询", notes="hotel_order-分页列表查询")
	@GetMapping(value = "/list")
	public Result<IPage<HotelOrder>> queryPageList(HotelOrder hotelOrder,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<HotelOrder> queryWrapper = QueryGenerator.initQueryWrapper(hotelOrder, req.getParameterMap());
		Page<HotelOrder> page = new Page<HotelOrder>(pageNo, pageSize);
		IPage<HotelOrder> pageList = hotelOrderService.page(page, queryWrapper);
		return Result.OK(pageList);
	}


	 /**
	  * 水洗分页列表查询
	  *
	  * @param hotelOrder
	  * @param pageNo
	  * @param pageSize
	  * @param req
	  * @return
	  */
	 //@AutoLog(value = "hotel_order-分页列表查询")
	 @ApiOperation(value="水洗分页列表查询", notes="水洗分页列表查询")
	 @GetMapping(value = "/lease/list")
	 public Result<IPage<HotelOrder>> queryPageLeaseList(HotelOrder hotelOrder,
														@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
														@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
														HttpServletRequest req) {
		 QueryWrapper<HotelOrder> queryWrapper = QueryGenerator.initQueryWrapper(hotelOrder, req.getParameterMap());
		 queryWrapper.eq("type",0).eq("lease_flag",1);
		 Page<HotelOrder> page = new Page<HotelOrder>(pageNo, pageSize);
		 IPage<HotelOrder> pageList = hotelOrderService.page(page, queryWrapper);
		 return Result.OK(pageList);
	 }

	 /**
	  * 水洗分页列表查询
	  *
	  * @param hotelOrder
	  * @param pageNo
	  * @param pageSize
	  * @param req
	  * @return
	  */
	 //@AutoLog(value = "hotel_order-分页列表查询")
	 @ApiOperation(value="水洗分页列表查询", notes="水洗分页列表查询")
	 @GetMapping(value = "/lease/flag/list")
	 public Result<IPage<HotelOrder>> queryPageLeaseFlagList(HotelOrder hotelOrder,
														 @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
														 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
														 HttpServletRequest req) {
		 QueryWrapper<HotelOrder> queryWrapper = QueryGenerator.initQueryWrapper(hotelOrder, req.getParameterMap());
		 queryWrapper.eq("type",0).eq("lease_flag",0);
		 Page<HotelOrder> page = new Page<HotelOrder>(pageNo, pageSize);
		 IPage<HotelOrder> pageList = hotelOrderService.page(page, queryWrapper);
		 return Result.OK(pageList);
	 }

	 /**
	  * 水洗分页列表查询
	  *
	  * @param hotelOrder
	  * @param pageNo
	  * @param pageSize
	  * @param req
	  * @return
	  */
	 //@AutoLog(value = "hotel_order-分页列表查询")
	 @ApiOperation(value="水洗分页列表查询", notes="水洗分页列表查询")
	 @GetMapping(value = "/wash/list")
	 public Result<IPage<HotelOrder>> queryPageWashList(HotelOrder hotelOrder,
													@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
													@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
													HttpServletRequest req) {
		 QueryWrapper<HotelOrder> queryWrapper = QueryGenerator.initQueryWrapper(hotelOrder, req.getParameterMap());
		 queryWrapper.eq("type",1);
		 Page<HotelOrder> page = new Page<HotelOrder>(pageNo, pageSize);
		 IPage<HotelOrder> pageList = hotelOrderService.page(page, queryWrapper);
		 return Result.OK(pageList);
	 }

	 /**
	  * 换货分页列表查询
	  *
	  * @param hotelOrder
	  * @param pageNo
	  * @param pageSize
	  * @param req
	  * @return
	  */
	 //@AutoLog(value = "hotel_order-分页列表查询")
	 @ApiOperation(value="换货分页列表查询", notes="换货分页列表查询")
	 @GetMapping(value = "/replace/list")
	 public Result<IPage<HotelOrder>> queryPageReplaceList(HotelOrder hotelOrder,
														@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
														@RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
														HttpServletRequest req) {
		 QueryWrapper<HotelOrder> queryWrapper = QueryGenerator.initQueryWrapper(hotelOrder, req.getParameterMap());
		 queryWrapper.eq("type",2);
		 Page<HotelOrder> page = new Page<HotelOrder>(pageNo, pageSize);
		 IPage<HotelOrder> pageList = hotelOrderService.page(page, queryWrapper);
		 return Result.OK(pageList);
	 }

	 /**
	  * 退货分页列表查询
	  *
	  * @param hotelOrder
	  * @param pageNo
	  * @param pageSize
	  * @param req
	  * @return
	  */
	 //@AutoLog(value = "hotel_order-分页列表查询")
	 @ApiOperation(value="退货分页列表查询", notes="退货分页列表查询")
	 @GetMapping(value = "/refund/list")
	 public Result<IPage<HotelOrder>> queryPageRefundList(HotelOrder hotelOrder,
														   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
														   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
														   HttpServletRequest req) {
		 QueryWrapper<HotelOrder> queryWrapper = QueryGenerator.initQueryWrapper(hotelOrder, req.getParameterMap());
		 queryWrapper.eq("type",3);
		 Page<HotelOrder> page = new Page<HotelOrder>(pageNo, pageSize);
		 IPage<HotelOrder> pageList = hotelOrderService.page(page, queryWrapper);
		 return Result.OK(pageList);
	 }

	/**
	 *   添加
	 *
	 * @param hotelOrder
	 * @return
	 */
	@AutoLog(value = "hotel_order-添加")
	@ApiOperation(value="hotel_order-添加", notes="hotel_order-添加")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody HotelOrder hotelOrder) {
		hotelOrderService.save(hotelOrder);
		return Result.OK("添加成功！");
	}

	/**
	 *  编辑
	 *
	 * @param hotelOrder
	 * @return
	 */
	@AutoLog(value = "hotel_order-编辑")
	@ApiOperation(value="hotel_order-编辑", notes="hotel_order-编辑")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody HotelOrder hotelOrder) {
		hotelOrderService.updateById(hotelOrder);
		return Result.OK("编辑成功!");
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "hotel_order-通过id删除")
	@ApiOperation(value="hotel_order-通过id删除", notes="hotel_order-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		hotelOrderService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "hotel_order-批量删除")
	@ApiOperation(value="hotel_order-批量删除", notes="hotel_order-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.hotelOrderService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "hotel_order-通过id查询")
	@ApiOperation(value="hotel_order-通过id查询", notes="hotel_order-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<HotelOrder> queryById(@RequestParam(name="id",required=true) String id) {
		HotelOrder hotelOrder = hotelOrderService.getById(id);
		if(hotelOrder==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(hotelOrder);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param hotelOrder
    */
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, HotelOrder hotelOrder) {
        return super.exportXls(request, hotelOrder, HotelOrder.class, "hotel_order");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, HotelOrder.class);
    }


	 /**
	  *  水洗破损上报审核
	  *
	  * @param hotelOrder3
	  * @return
	  */
	 @Transactional(rollbackFor = Exception.class)
	 @AutoLog(value = "水洗破损上报审核")
	 @ApiOperation(value="水洗破损上报审核", notes="水洗破损上报审核")
	 @RequestMapping(value = "/damage/audit2", method = {RequestMethod.PUT,RequestMethod.POST})
	 public Result<String> damageAudit(@RequestBody HotelOrder hotelOrder3) {
		 HotelOrder hotelOrder = new HotelOrder();
		 hotelOrder.setId(hotelOrder3.getId());

		 HotelLeaseLog hotelLeaseLog = hotelLeaseLogService.lambdaQuery()
				 .eq(HotelLeaseLog::getDelFlag, 0)
				 .eq(HotelLeaseLog::getId, hotelOrder3.getLeaseId())
				 .one();

		 HotelShop hotelShop = hotelShopService.lambdaQuery()
				 .eq(HotelShop::getDelFlag, 0)
				 .eq(HotelShop::getUserId, hotelOrder3.getShopId())
				 .one();
		 HotelLeaseLog hotelLeaseLog2 = new HotelLeaseLog();
		 if(hotelOrder3.getAudit() == 0){
		 	if(hotelOrder3.getNum() > hotelOrder3.getRefundNum()){
				hotelOrder.setStatus(6);



				hotelLeaseLog2.setUserId(hotelLeaseLog.getUserId());
				hotelLeaseLog2.setShopId(hotelLeaseLog.getShopId());
				hotelLeaseLog2.setOrderId(hotelLeaseLog.getOrderId());
				hotelLeaseLog2.setGoodsId(hotelLeaseLog.getGoodsId());
				hotelLeaseLog2.setSkuId(hotelLeaseLog.getSkuId());
				hotelLeaseLog2.setGoodsName(hotelLeaseLog.getGoodsName());
				hotelLeaseLog2.setGoodsPic(hotelLeaseLog.getGoodsPic());
				hotelLeaseLog2.setSku(hotelLeaseLog.getSku());
				hotelLeaseLog2.setStatus(1);
				hotelLeaseLog2.setNum(hotelOrder3.getRefundNum());
				hotelLeaseLog2.setPrice(hotelLeaseLog.getPrice());
				hotelLeaseLog2.setCategoryId(hotelLeaseLog.getCategoryId());
				hotelLeaseLogService.save(hotelLeaseLog2);

				HotelLeaseLog hotelLeaseLog1 = new HotelLeaseLog();
				hotelLeaseLog1.setId(hotelLeaseLog.getId());
				hotelLeaseLog1.setNum(hotelLeaseLog.getNum()-hotelOrder3.getRefundNum());
				hotelLeaseLogService.updateById(hotelLeaseLog1);





			}else{


				HotelMemberAccount hotelMemberAccount = hotelMemberAccountService.lambdaQuery()
						.eq(HotelMemberAccount::getDelFlag, 0)
						.eq(HotelMemberAccount::getUserId, hotelShop.getUserId())
						.one();


				BigDecimal platformServiceRate = new BigDecimal(hotelConfService.getConf("platformServiceRate"));
				BigDecimal platformServicePrice = hotelOrder.getOrderPay().multiply(platformServiceRate);
				BigDecimal shopPrice = hotelOrder.getOrderPay().multiply(hotelShop.getRate());
				BigDecimal price = hotelMemberAccount.getShopBalance().add(shopPrice);


				HotelMemberAccount hotelMemberAccount1 = new HotelMemberAccount();
				hotelMemberAccount1.setId(hotelMemberAccount.getId());
				hotelMemberAccount1.setShopBalance(price);
				hotelMemberAccountService.updateById(hotelMemberAccount1);


				HotelBalanceLog hotelBalanceLog = new HotelBalanceLog();
				hotelBalanceLog.setUserId(hotelShop.getUserId());
				hotelBalanceLog.setBalance(shopPrice);
				hotelBalanceLog.setUserBalance(hotelMemberAccount.getShopBalance());
				hotelBalanceLog.setType(2);
				hotelBalanceLog.setTitle("佣金到账");
				hotelBalanceLog.setPayType(1);
				hotelBalanceLog.setPlatformServicePrice(platformServicePrice);
				hotelBalanceLog.setOrderId(hotelOrder3.getId());
				hotelBalanceLogService.save(hotelBalanceLog);



				HotelLeaseLog hotelLeaseLog1 = new HotelLeaseLog();
				hotelLeaseLog1.setId(hotelLeaseLog.getId());
				hotelLeaseLog1.setStatus(1);
				hotelLeaseLogService.updateById(hotelLeaseLog1);


				hotelOrder.setStatus(15);
			}

			 HotelOrderDetail hotelOrderDetail = new HotelOrderDetail();

			 HotelOrder hotelOrder1 = new HotelOrder();
			 hotelOrder1.setReason(hotelOrder3.getReason());
			 hotelOrder1.setRefundNum(hotelOrder3.getRefundNum());
			 hotelOrder1.setReasonPrice(hotelOrder3.getReasonPrice());
			 hotelOrder1.setType(2);
			 hotelOrder1.setReasonInfo(hotelOrder3.getReasonInfo());
			 hotelOrder1.setReasonPic(hotelOrder3.getReasonPic());
			 hotelOrder1.setReasonPhone(hotelOrder3.getReasonPhone());
			 hotelOrder1.setUserId(hotelOrder3.getUserId());
			 hotelOrder1.setShopId(hotelLeaseLog.getShopId());
			 hotelOrderDetail.setGoodsId(hotelLeaseLog.getGoodsId());
			 hotelOrderDetail.setGoodsName(hotelLeaseLog.getGoodsName());
			 hotelOrderDetail.setSkuId(hotelLeaseLog.getSkuId());
			 hotelOrderDetail.setSku(hotelLeaseLog.getSku());
			 hotelOrderDetail.setPic(hotelLeaseLog.getGoodsPic());
			 hotelOrder1.setStatus(7);
			 hotelOrderDetail.setLeaseId(hotelOrder3.getNum() > hotelOrder3.getRefundNum()?hotelLeaseLog2.getId():hotelLeaseLog.getId());
			 hotelOrder1.setLeaseId(hotelOrder3.getNum() > hotelOrder3.getRefundNum()?hotelLeaseLog2.getId():hotelLeaseLog.getId());
			 hotelOrder1.setUserName(hotelShop.getUserName());
			 hotelOrder1.setUserPhone(hotelShop.getPhone());
			 hotelOrder1.setUserAddress(hotelShop.getAddress());
			 hotelOrder1.setShopId(hotelShop.getUserId());
			 hotelOrderService.save(hotelOrder1);
			 hotelOrderDetail.setOrderId(hotelOrder1.getId());
			 hotelOrderDetailService.save(hotelOrderDetail);
		 }else{
			 hotelOrder.setStatus(5);
		 }
		 hotelOrderService.updateById(hotelOrder);
		 return Result.OK("编辑成功!");
	 }

	 /**
	  *  水洗破损上报审核
	  *
	  * @param hotelOrder3
	  * @return
	  */
	 @Transactional(rollbackFor = Exception.class)
	 @AutoLog(value = "水洗破损上报审核")
	 @ApiOperation(value="水洗破损上报审核", notes="水洗破损上报审核")
	 @RequestMapping(value = "/damage/audit", method = {RequestMethod.PUT,RequestMethod.POST})
	 public Result<String> damageAudit2(@RequestBody HotelOrder hotelOrder3){

		 HotelOrder hotelOrder = hotelOrderService.lambdaQuery()
				 .eq(HotelOrder::getId, hotelOrder3.getId())
				 .one();
		 //新订单
		 HotelOrderDetail hotelOrderDetail = hotelOrderDetailService.lambdaQuery()
				 .eq(HotelOrderDetail::getDelFlag, 0)
				 .eq(HotelOrderDetail::getOrderId, hotelOrder.getId())
				 .one();

		 HotelOrder hotelOrder1 = new HotelOrder();
		 hotelOrder1.setId(hotelOrder.getId());
		 if(hotelOrder3.getAudit() == 0){
			 hotelOrder1.setStatus(8);
//			 hotelOrder1.setReasonPrice(hotelOrder3.getReasonPrice());
		 }else{
		 	//原订单详情
			 HotelOrderDetail hotelOrderDetail1 = hotelOrderDetailService.lambdaQuery()
					 .eq(HotelOrderDetail::getDelFlag, 0)
					 .eq(HotelOrderDetail::getId, hotelOrderDetail.getOrderDetailId())
					 .one();

			 HotelOrderDetail hotelOrderDetail2 = new HotelOrderDetail();
			 hotelOrderDetail2.setId(hotelOrderDetail1.getId());
			 hotelOrderDetail2.setStatus(0);
			 hotelOrderDetailService.updateById(hotelOrderDetail2);


			 hotelOrder1.setStatus(17);


		 }
		 hotelOrderService.updateById(hotelOrder1);
		 return Result.OK();
	 }

	 /**
	  * 租赁订单发货
	  * @param hotelOrder
	  * @return
	  */
	 @Transactional(rollbackFor = Exception.class)
	 @RequestMapping(value = "/lease/send", method = {RequestMethod.PUT,RequestMethod.POST})
	 public Result<?> leaseSendOrder(@RequestBody HotelOrder hotelOrder){
	 	//水洗店租赁订单
	 	if(hotelOrder.getWashShopFlag() == 1){
			HotelOrderLog hotelOrderLog = hotelOrderLogService.lambdaQuery()
					.eq(HotelOrderLog::getDelFlag, 0)
					.eq(HotelOrderLog::getId, hotelOrder.getOrderLogId())
					.one();

			List<HotelOrderDetail> hotelOrderDetails = hotelOrderDetailService.lambdaQuery()
					.eq(HotelOrderDetail::getDelFlag, 0)
					.eq(HotelOrderDetail::getOrderId, hotelOrder.getId())
					.list();
			HanHaiMember hanHaiMember = hanHaiMemberService.lambdaQuery()
					.eq(HanHaiMember::getId, hotelOrder.getUserId())
					.one();


			List<HotelLeaseLog> hotelLeaseLogs = new ArrayList<>();
			List<HotelOrderDetail> hotelOrderDetails1 = new ArrayList<>();
			for (HotelOrderDetail hotelOrderDetail:hotelOrderDetails){
				//水洗店
				HotelLeaseLog hotelLeaseLog = new HotelLeaseLog();
				hotelLeaseLog.setId(IdWorker.getIdStr());
				hotelLeaseLog.setUserId(hanHaiMember.getId());
				hotelLeaseLog.setOrderId(hotelOrder.getId());
				hotelLeaseLog.setOrderDetailId(hotelOrderDetail.getId());
				hotelLeaseLog.setGoodsId(hotelOrderDetail.getGoodsId());
				hotelLeaseLog.setSkuId(hotelOrderDetail.getSkuId());
				hotelLeaseLog.setGoodsName(hotelOrderDetail.getGoodsName());
				hotelLeaseLog.setGoodsPic(hotelOrderDetail.getPic());
				hotelLeaseLog.setSku(hotelOrderDetail.getSku());
				hotelLeaseLog.setStatus(0);
				hotelLeaseLog.setNum(hotelOrderDetail.getNum());
				hotelLeaseLog.setPrice(hotelOrderDetail.getDeposit());
				hotelLeaseLog.setFormUserId(hotelOrderLog.getUserId());
				hotelLeaseLog.setCategoryId(hotelOrderDetail.getCategoryId());

				HotelOrderDetail hotelOrderDetail1 = new HotelOrderDetail();
				hotelOrderDetail1.setId(hotelOrderDetail.getId());
				hotelOrderDetail1.setLeaseId(hotelLeaseLog.getId());

				hotelLeaseLogs.add(hotelLeaseLog);
				hotelOrderDetails1.add(hotelOrderDetail1);
			}
			hotelLeaseLogService.saveBatch(hotelLeaseLogs);
			hotelOrderDetailService.updateBatchById(hotelOrderDetails1);
		}
		 hotelOrder.setStatus(2);
		 hotelOrderService.updateById(hotelOrder);
		 return Result.OK();
	 }

	 /**
	  * 租赁订单不发货
	  * @param hotelOrder
	  * @return
	  */
	 @Transactional(rollbackFor = Exception.class)
	 @RequestMapping(value = "/lease/no/send", method = {RequestMethod.PUT,RequestMethod.POST})
	 public Result<?> leaseNotSendOrder(@RequestBody HotelOrder hotelOrder){
	 	if(hotelOrder.getWashShopFlag() == 0){
	 		throw new JeecgBootException("只有水洗店才可不发货");
		}
	 	hotelOrderService.removeById(hotelOrder.getId());
	 	return Result.OK();
	 }


	 /**
	  * 换货订单收货
	  * @param hotelOrder
	  * @return
	  */
	 @Transactional(rollbackFor = Exception.class)
	 @RequestMapping(value = "/take", method = {RequestMethod.PUT,RequestMethod.POST})
	 public Result<?> replaceTakeOrder(@RequestBody HotelOrder hotelOrder){
		 hotelOrder.setStatus(10);
		 hotelOrderService.updateById(hotelOrder);
		 return Result.OK();
	 }


	 /**
	  * 退货订单收货
	  * @param hotelOrder
	  * @return
	  */
	 @Transactional(rollbackFor = Exception.class)
	 @RequestMapping(value = "/refund/confirm", method = {RequestMethod.PUT,RequestMethod.POST})
	 public Result<?> refundConfirmOrder(@RequestBody HotelOrder hotelOrder){
		 hotelOrder.setStatus(14);
		 hotelOrderService.updateById(hotelOrder);
		 return Result.OK();
	 }

	 @RequestMapping(value = "/refund", method = {RequestMethod.PUT,RequestMethod.POST})
	 public Result<?> refundOrder(@RequestBody HotelOrder hotelOrder){
		 hotelOrder.setStatus(15);
		 hotelOrderService.updateById(hotelOrder);

		 HanHaiMember hanHaiMember = hanHaiMemberService.lambdaQuery()
				 .eq(HanHaiMember::getId, hotelOrder.getUserId())
				 .one();

		 HotelMemberAccount hotelMemberAccount = hotelMemberAccountService.lambdaQuery()
				 .eq(HotelMemberAccount::getDelFlag, 0)
				 .eq(HotelMemberAccount::getUserId, hanHaiMember.getId())
				 .one();

		 HotelMemberAccount hotelMemberAccount1 = new HotelMemberAccount();
		 hotelMemberAccount1.setId(hotelMemberAccount.getId());
		 hotelMemberAccount1.setDeposit(hotelMemberAccount.getDeposit().subtract(hotelOrder.getDeposit()));
		 hotelMemberAccountService.updateById(hotelMemberAccount1);

		 HotelBalanceLog hotelBalanceLog = new HotelBalanceLog();
		 hotelBalanceLog.setBalance(hotelOrder.getDeposit());
		 hotelBalanceLog.setUserBalance(hotelMemberAccount.getDeposit());
		 hotelBalanceLog.setOrderId(hotelOrder.getId());
		 hotelBalanceLog.setPayType(1);
		 hotelBalanceLog.setUserId(hanHaiMember.getId());
		 hotelBalanceLog.setTitle("租赁押金退还");
		 hotelBalanceLogService.save(hotelBalanceLog);

		 return Result.OK();
	 }

}
