package com.yunzhi.marketing.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunzhi.marketing.base.BaseController;
import com.yunzhi.marketing.base.ResponseBean;
import com.yunzhi.marketing.bo.request.HousingRaiseRequestBO;
import com.yunzhi.marketing.bo.request.RaiseOrderRequestBO;
import com.yunzhi.marketing.bo.request.RaiseRecordRequestBO;
import com.yunzhi.marketing.center.taUser.entity.TaUser;
import com.yunzhi.marketing.center.taUser.service.ITaUserService;
import com.yunzhi.marketing.common.CommConstant;
import com.yunzhi.marketing.entity.*;
import com.yunzhi.marketing.service.*;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 认筹单(认筹记录表)  前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-02-26
 */
@RestController
@RequestMapping("/api")
public class TaRaiseRecordController extends BaseController {

    private final Logger logger = LoggerFactory.getLogger(TaRaiseRecordController.class);

    @Autowired
    public ITaRaiseRecordService iTaRaiseRecordService;

    @Autowired
    public ITaRaiseHouseService taRaiseHouseService;

    @Autowired
    public ITaHousingResourcesService taHousingResourcesService;

    @Autowired
    public ITaOrderService taOrderService;

    @Autowired
    public ITaBuildingImgService taBuildingImgService;

    @Autowired
    public ITaRaiseService taRaiseService;

    @Autowired
    public ITaBuildingApartmentService taBuildingApartmentService;

    @Autowired
    public ITaUserService taUserService;

    @Autowired
    public ITaPersonService taPersonService;

    /**
     * 条件查询房源认筹记录
     *
     * @param requestBO
     * @param pageNumber
     * @param pageSize
     * @param request
     * @return
     */
    @RequestMapping(value = "/admin/listHousingRaiseByCondition", method = RequestMethod.GET)
    public ResponseBean listHousingRaiseByCondition(HousingRaiseRequestBO requestBO,
                                                    @RequestParam(value = "pageNumber", defaultValue = "1") Integer pageNumber,
                                                    @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                    HttpServletRequest request) {
        logger.info("TaRaiseRecordController.listHousingRaiseByCondition 接收参数：bo:{},pageNumber:{},pageSize:{}", JSONObject.toJSONString(requestBO), pageNumber, pageSize);

        ResponseBean responseBean = new ResponseBean();
        try {
            requestBO.setOrgId(getOrgId(request));
            responseBean = iTaRaiseRecordService.listHousingRaiseByCondition(requestBO, pageNumber, pageSize);
            logger.info("TaRaiseRecordController.listHousingRaiseByCondition 返回：{}", JSONObject.toJSONString(responseBean));
        } catch (Exception e) {
            logger.error("TaRaiseRecordController.listHousingRaiseByCondition -=- {}", e);
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 条件查询认筹单
     *
     * @param recordRequestBO
     * @param pageNumber
     * @param pageSize
     * @param request
     * @return
     */
    @RequestMapping(value = "/admin/listRaiseRecordByCondition", method = RequestMethod.GET)
    public ResponseBean listRaiseRecordByCondition(RaiseRecordRequestBO recordRequestBO,
                                                   @RequestParam(value = "pageNumber", defaultValue = "1") Integer pageNumber,
                                                   @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                   HttpServletRequest request) {
        logger.info("TaRaiseRecordController.listRaiseRecordByCondition 接收参数：bo:{},pageNumber:{},pageSize:{}", JSONObject.toJSONString(recordRequestBO), pageNumber, pageSize);

        ResponseBean responseBean = new ResponseBean();
        try {
            recordRequestBO.setOrgId(getOrgId(request));
            responseBean = iTaRaiseRecordService.listRaiseRecordByCondition(recordRequestBO, pageNumber, pageSize);
            logger.info("TaRaiseRecordController.listRaiseRecordByCondition 返回：{}", JSONObject.toJSONString(responseBean));
        } catch (Exception e) {
            logger.error("TaRaiseRecordController.taRaiseRecordList -=- {}", e);
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 条件查询缴费单/退费单
     * 备注：
     * 缴费单：payStatus传 paid
     * 退费单：payStatus传 refunded
     *
     * @param orderRequestBO
     * @param pageNumber
     * @param pageSize
     * @param request
     * @return
     */
    @RequestMapping(value = "/admin/listRaiseOrderByCondition", method = RequestMethod.GET)
    public ResponseBean listRaiseOrderByCondition(RaiseOrderRequestBO orderRequestBO,
                                                  @RequestParam(value = "pageNumber", defaultValue = "1") Integer pageNumber,
                                                  @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                                  HttpServletRequest request) {
        logger.info("TaRaiseRecordController.listOrderByCondition 接收参数：bo:{},pageNumber:{},pageSize:{}", JSONObject.toJSONString(orderRequestBO), pageNumber, pageSize);

        ResponseBean responseBean = new ResponseBean();
        try {
            orderRequestBO.setOrgId(getOrgId(request));
            responseBean = iTaRaiseRecordService.listRaiseOrderByCondition(orderRequestBO, pageNumber, pageSize);
            logger.info("TaRaiseRecordController.listOrderByCondition 返回：{}", JSONObject.toJSONString(responseBean));
        } catch (Exception e) {
            logger.error("TaRaiseRecordController.listOrderByCondition -=- {}", e);
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 批量作废前校验
     *
     * @param raiseRecord
     * @return
     */
    @RequestMapping(value = "/admin/raise/checkBeforeInvalidRecord", method = RequestMethod.POST)
    public ResponseBean checkBeforeInvalidRecord(@RequestBody TaRaiseRecord raiseRecord) {
        ResponseBean responseBean = new ResponseBean();
        try {
            Integer fitNum = 0;
            Integer notFitNum = 0;
            Integer totalNum = raiseRecord.getTaRaiseRecords().size();
            for (TaRaiseRecord record : raiseRecord.getTaRaiseRecords()) {
                TaRaiseRecord r = iTaRaiseRecordService.getById(record.getRaiseRecordId());
                if (CommConstant.STATUS_NORMAL != r.getStatus()) {
                    notFitNum++;
                } else {
                    fitNum++;
                }
            }

            // 组装反参
            JSONObject resultObj = new JSONObject();
            resultObj.put("totalNum", totalNum);
            resultObj.put("fitNum", fitNum);
            resultObj.put("notFitNum", notFitNum);
            responseBean.addSuccess(resultObj);
        } catch (Exception e) {
            logger.error("checkBeforeInvalidRecord 异常：", e);
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 批量作废
     *
     * @param raiseRecord
     * @return
     */
    @RequestMapping(value = "/admin/batchInvalidRaiseRecord", method = RequestMethod.PUT)
    public ResponseBean batchInvalidRaiseRecord(@RequestBody TaRaiseRecord raiseRecord, HttpServletRequest request) {

        logger.info("TaRaiseRecordController.batchInvalidRaiseRecord 接收参数：TaRaiseRecord:{}", JSONObject.toJSONString(raiseRecord));

        ResponseBean responseBean = new ResponseBean();
        try {
            // 校验参数
            if (CollectionUtils.isEmpty(raiseRecord.getTaRaiseRecords()) || StringUtils.isBlank(raiseRecord.getInvalidReason())) {
                responseBean.addError("参数错误");
                return responseBean;
            }

            // 获取用户信息
            TaUser taUser = taUserService.getUserInfoById(getUserId(request), getOrgId(request));
            raiseRecord.getTaRaiseRecords().stream().forEach(record -> {
                if (taUser != null) {
                    record.setUpdateUserName(taUser.getUserName());
                }
                record.setInvalidReason(raiseRecord.getInvalidReason());
                record.setUpdateDate(LocalDateTime.now());
                record.setStatus(CommConstant.STATUS_UNACCALIMED);

                // 更新房源认筹热度
                iTaRaiseRecordService.updateForSubtractRaiseHeat(record.getRaiseRecordId());

                // 修改房源锁定状态为未锁定
                record.setHouseLockingStatus(CommConstant.HOUSE_LOCKING_STATUS_UNLOCKED);
                iTaRaiseRecordService.updateHouseLockingStatus(record.getRaiseRecordId(), CommConstant.HOUSE_LOCKING_STATUS_UNLOCKED, record.getPersonId());

                // 发送订阅消息
                iTaRaiseRecordService.sendRaiseMsg(record.getRaiseRecordId(), record.getPersonId(), "认筹通知", "认筹单已作废", "点击详情查看认筹单", "具体原因查看详情", false);
            });

            if (iTaRaiseRecordService.updateBatchById(raiseRecord.getTaRaiseRecords())) {
                responseBean.addSuccess("success");
            } else {
                responseBean.addError("fail");
            }
        } catch (Exception e) {
            logger.error("TaRaiseRecordController.taRaiseRecordList -=- {}", e);
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 批量删除
     *
     * @param raiseRecord
     * @return
     */
    @RequestMapping(value = "/admin/batchDeleteRaiseRecord", method = RequestMethod.PUT)
    public ResponseBean batchDeleteRaiseRecord(@RequestBody TaRaiseRecord raiseRecord, HttpServletRequest request) {
        logger.info("TaRaiseRecordController.batchDeleteRaiseRecord 接收参数：{}", JSONObject.toJSONString(raiseRecord));

        ResponseBean responseBean = new ResponseBean();
        try {
            // 参数校验
            if (CollectionUtils.isEmpty(raiseRecord.getTaRaiseRecords())) {
                responseBean.addError("参数错误");
                return responseBean;
            }

            // 获取用户信息
            TaUser taUser = taUserService.getUserInfoById(getUserId(request), getOrgId(request));

            raiseRecord.getTaRaiseRecords().stream().forEach(record -> {
                if (taUser != null) {
                    record.setUpdateUserName(taUser.getUserName());
                }
                record.setStatus(CommConstant.STATUS_DELETE);
                record.setUpdateDate(LocalDateTime.now());

                // 更新房源认筹热度
                iTaRaiseRecordService.updateForSubtractRaiseHeat(record.getRaiseRecordId());

                // 修改房源锁定状态为未锁定
                record.setHouseLockingStatus(CommConstant.HOUSE_LOCKING_STATUS_UNLOCKED);
                iTaRaiseRecordService.updateHouseLockingStatus(record.getRaiseRecordId(), CommConstant.HOUSE_LOCKING_STATUS_UNLOCKED, record.getPersonId());

                // 发送订阅消息
                iTaRaiseRecordService.sendRaiseMsg(record.getRaiseRecordId(), record.getPersonId(), "认筹通知", "认筹单已作废", "点击详情查看认筹单", "具体原因查看详情", false);
            });

            if (iTaRaiseRecordService.updateBatchById(raiseRecord.getTaRaiseRecords())) {
                responseBean.addSuccess("success");
            } else {
                responseBean.addError("fail");
            }
        } catch (Exception e) {
            logger.error("TaRaiseRecordController.taRaiseRecordList -=- {}", e);
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 批量线下缴费前校验
     *
     * @param raiseRecord
     * @param request
     * @return
     */
    @RequestMapping(value = "/admin/raise/checkBeforePayOfflineRecord", method = RequestMethod.POST)
    public ResponseBean checkBeforePayOfflineRecord(@RequestBody TaRaiseRecord raiseRecord, HttpServletRequest request) {
        ResponseBean responseBean = new ResponseBean();
        try {
            Integer fitNum = 0;
            Integer notFitNum = 0;
            Integer totalNum = raiseRecord.getTaRaiseRecords().size();
            // 获取该认筹缴费方式
            TaRaise taRaise = taRaiseService.getById(raiseRecord.getRaiseId());
            if (taRaise == null) {
                responseBean.addError("当前批次不存在");
                return responseBean;
            }
            // 校验缴费方式
            if (CommConstant.PAY_TYPE_ONLINE == taRaise.getPayType()) {
                responseBean.addError("当前批次只支持线上缴费，请稍后再试");
                return responseBean;
            }
            for (TaRaiseRecord record : raiseRecord.getTaRaiseRecords()) {
                TaRaiseRecord r = iTaRaiseRecordService.getById(record.getRaiseRecordId());
                // 校验是否作废
                if (CommConstant.STATUS_NORMAL != r.getStatus()) {
                    notFitNum++;
                    continue;
                }
                // 校验缴费状态
                if (!CommConstant.PAY_STATUS_UNPAID.equals(r.getPayStatus())) {
                    notFitNum++;
                    continue;
                }
                fitNum++;
            }
            // 组装反参
            JSONObject resultObj = new JSONObject();
            resultObj.put("totalNum", totalNum);
            resultObj.put("fitNum", fitNum);
            resultObj.put("notFitNum", notFitNum);
            responseBean.addSuccess(resultObj);
        } catch (Exception e) {
            logger.error("checkBeforePayOfflineRecord 异常：", e);
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 批量线下缴费
     *
     * @param raiseRecord
     * @return
     */
    @RequestMapping(value = "/admin/batchPayOfflineRaiseRecord", method = RequestMethod.PUT)
    public ResponseBean batchPayOfflineRaiseRecord(@RequestBody TaRaiseRecord raiseRecord, HttpServletRequest request) {
        logger.info("TaRaiseRecordController.batchPayOfflineRaiseRecord 接收参数：{}", JSONObject.toJSONString(raiseRecord));

        ResponseBean responseBean = new ResponseBean();
        try {
            // 参数校验
            if (CollectionUtils.isEmpty(raiseRecord.getTaRaiseRecords())) {
                responseBean.addError("参数错误");
                return responseBean;
            }

            Integer orgId = getOrgId(request);
            TaRaiseRecord tr;
            QueryWrapper<TaRaiseRecord> queryWrapper;
            for (TaRaiseRecord record : raiseRecord.getTaRaiseRecords()) {
                queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("org_id", orgId);
                queryWrapper.eq("raise_record_id", record.getRaiseRecordId());
                tr = iTaRaiseRecordService.getOne(queryWrapper);
                if (tr == null) {
                    responseBean.addError(String.format("未找到认筹单编号为%s的记录", record.getRaiseRecordId()));
                    return responseBean;
                }
                if (-1 == tr.getStatus()) {
                    responseBean.addError(String.format("认筹单编号为%s的记录已作废，请重新选择", record.getRaiseRecordId()));
                    return responseBean;
                }
                if (!CommConstant.PAY_STATUS_UNPAID.equals(tr.getPayStatus())) {
                    responseBean.addError(String.format("认筹单编号为%s的记录为已缴费或已退费状态 ，请重新选择", record.getRaiseRecordId()));
                    return responseBean;
                }
            }

            // 获取用户信息
            TaUser taUser = taUserService.getUserInfoById(getUserId(request), orgId);

            // 设置缴费状态为已缴费
            raiseRecord.getTaRaiseRecords().stream().forEach(record -> {
                if (taUser != null) {
                    record.setUpdateUserName(taUser.getUserName());
                }
                record.setPayStatus(CommConstant.PAY_STATUS_PAID);
                record.setUpdateDate(LocalDateTime.now());
                //发送订阅消息
                iTaRaiseRecordService.sendRaiseMsg(record.getRaiseRecordId(), record.getPersonId(), "认筹通知", "认筹已缴费", "点击详情查看认筹单", "您的认筹已成功缴费", false);
            });

            if (iTaRaiseRecordService.updateBatchById(raiseRecord.getTaRaiseRecords())) {
                responseBean.addSuccess("success");
            } else {
                responseBean.addError("fail");
            }
        } catch (Exception e) {
            logger.error("TaRaiseRecordController.batchPayOfflineRaiseRecord -=- {}", e);
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 批量线下退费前校验
     *
     * @param raiseRecord
     * @return
     */
    @RequestMapping(value = "/admin/raise/checkBeforeRefundOfflineRecord", method = RequestMethod.POST)
    public ResponseBean checkBeforeRefundOfflineRecord(@RequestBody TaRaiseRecord raiseRecord) {
        ResponseBean responseBean = new ResponseBean();
        try {
            Integer fitNum = 0;
            Integer notFitNum = 0;
            Integer totalNum = raiseRecord.getTaRaiseRecords().size();
            for (TaRaiseRecord record : raiseRecord.getTaRaiseRecords()) {
                TaRaiseRecord r = iTaRaiseRecordService.getById(record.getRaiseRecordId());
                // 校验缴费状态
                if (CommConstant.PAY_STATUS_PAID.equals(r.getPayStatus())) {
                    fitNum++;
                    continue;
                }
                notFitNum++;
            }

            // 组装反参
            JSONObject resultObj = new JSONObject();
            resultObj.put("totalNum", totalNum);
            resultObj.put("fitNum", fitNum);
            resultObj.put("notFitNum", notFitNum);
            responseBean.addSuccess(resultObj);
        } catch (Exception e) {
            logger.error("checkBeforeRefundOfflineRecord 异常：", e);
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 批量线下退费
     *
     * @param raiseRecord
     * @param refundReason 退款原因
     * @return
     */
    @RequestMapping(value = "/admin/batchRefundOfflineRaiseRecord", method = RequestMethod.PUT)
    public ResponseBean batchRefundOfflineRaiseRecord(@RequestBody TaRaiseRecord raiseRecord, String refundReason,
                                                      HttpServletRequest request) {
        logger.info("TaRaiseRecordController.batchRefundOfflineRaiseRecord 接收参数：{},refundReason:{}", JSONObject.toJSONString(raiseRecord), refundReason);

        ResponseBean responseBean = new ResponseBean();
        try {
            // 参数校验
            if (CollectionUtils.isEmpty(raiseRecord.getTaRaiseRecords())) {
                responseBean.addError("参数错误");
                return responseBean;
            }

            Integer orgId = getOrgId(request);
            TaRaiseRecord tr;
            QueryWrapper<TaRaiseRecord> queryWrapper;
            for (TaRaiseRecord record : raiseRecord.getTaRaiseRecords()) {
                queryWrapper = new QueryWrapper<>();
                queryWrapper.eq("org_id", orgId);
                queryWrapper.eq("raise_record_id", record.getRaiseRecordId());
                tr = iTaRaiseRecordService.getOne(queryWrapper);
                if (tr == null) {
                    responseBean.addError(String.format("未找到认筹单编号为%s的记录", record.getRaiseRecordId()));
                    return responseBean;
                }
                if (-1 == tr.getStatus()) {
                    responseBean.addError(String.format("认筹单编号为%s的记录已作废，请重新选择", record.getRaiseRecordId()));
                    return responseBean;
                }
                if (CommConstant.PAY_STATUS_UNPAID.equals(tr.getPayStatus())) {
                    responseBean.addError(String.format("认筹单编号为%s的未缴费，请重新选择", record.getRaiseRecordId()));
                    return responseBean;
                }
                if (CommConstant.PAY_STATUS_REFUNDED.equals(tr.getPayStatus())) {
                    responseBean.addError(String.format("认筹单编号为%s的记录已退费，请重新选择", record.getRaiseRecordId()));
                    return responseBean;
                }
            }

            // 获取用户信息
            TaUser taUser = taUserService.getUserInfoById(getUserId(request), orgId);

            raiseRecord.getTaRaiseRecords().stream().forEach(record -> {
                if (taUser != null) {
                    record.setUpdateUserName(taUser.getUserName());
                }
                record.setPayStatus(CommConstant.PAY_STATUS_REFUNDED);
                record.setRefundReason(raiseRecord.getRefundReason());
                record.setUpdateDate(LocalDateTime.now());
                //发送订阅消息
                iTaRaiseRecordService.sendRaiseMsg(record.getRaiseRecordId(), record.getPersonId(), "认筹通知", "认筹已退费", "点击详情查看认筹单", "您的认筹已成功退费", false);
            });

            if (iTaRaiseRecordService.updateBatchById(raiseRecord.getTaRaiseRecords())) {
                responseBean.addSuccess("success");
            } else {
                responseBean.addError("fail");
            }
        } catch (Exception e) {
            logger.error("TaRaiseRecordController.batchRefundOfflineRaiseRecord -=- {}", e);
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 保存对象
     *
     * @param taRaiseRecord 实体对象
     * @return
     */
    @RequestMapping(value = "/taRaiseRecord", method = RequestMethod.POST)
    public ResponseBean taRaiseRecordAdd(@RequestBody TaRaiseRecord taRaiseRecord) {
        ResponseBean responseBean = new ResponseBean();
        try {
            if (iTaRaiseRecordService.save(taRaiseRecord)) {
                responseBean.addSuccess(taRaiseRecord);
            } else {
                responseBean.addError("fail");
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("taRaiseRecordAdd -=- {}", e.toString());
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     */
    @ResponseBody
    @RequestMapping(value = "/taRaiseRecord/{id}", method = RequestMethod.DELETE)
    public ResponseBean taRaiseRecordDelete(@PathVariable Integer id) {
        ResponseBean responseBean = new ResponseBean();
        try {
            if (iTaRaiseRecordService.removeById(id)) {
                responseBean.addSuccess("success");
            } else {
                responseBean.addError("fail");
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("taRaiseRecordDelete -=- {}", e.toString());
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 修改对象
     *
     * @param id            实体ID
     * @param taRaiseRecord 实体对象
     * @return
     */
    @RequestMapping(value = "/taRaiseRecord/{id}", method = RequestMethod.PUT)
    public ResponseBean taRaiseRecordUpdate(@PathVariable Integer id,
                                            @RequestBody TaRaiseRecord taRaiseRecord) {
        ResponseBean responseBean = new ResponseBean();
        try {
            if (iTaRaiseRecordService.updateById(taRaiseRecord)) {
                responseBean.addSuccess(taRaiseRecord);
            } else {
                responseBean.addError("fail");
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("taRaiseRecordUpdate -=- {}", e.toString());
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 根据id查询对象
     *
     * @param id 实体ID
     */
    @RequestMapping(value = "/taRaiseRecord/{id}", method = RequestMethod.GET)
    public ResponseBean taRaiseRecordGet(@PathVariable Integer id) {
        ResponseBean responseBean = new ResponseBean();
        try {
            responseBean.addSuccess(iTaRaiseRecordService.getById(id));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("taRaiseRecordDelete -=- {}", e.toString());
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 条件查询认筹单
     *
     * @param request
     * @return
     */
    @RequestMapping(value = "/admin/getUserInfo", method = RequestMethod.GET)
    public ResponseBean getUserInfo(@RequestParam("raiseRecordId") Integer raiseRecordId,
                                    @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                    @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                                    HttpServletRequest request) {
        ResponseBean responseBean = new ResponseBean();
        try {
            responseBean.addSuccess(iTaRaiseRecordService.getUserInfo(raiseRecordId, getOrgId(request)));
        } catch (Exception e) {
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 微信端下认筹单
     *
     * @param taRaiseRecord 实体对象
     * @return
     */
    @RequestMapping(value = "/wx/taRaiseRecord", method = RequestMethod.POST)
    public ResponseBean wxRaiseRecordAdd(@RequestBody TaRaiseRecord taRaiseRecord, HttpServletRequest request) {
        ResponseBean responseBean = new ResponseBean();
        try {
            responseBean.addSuccess(iTaRaiseRecordService.saveRaiseInfo(taRaiseRecord, getOrgId(request), getPersonId(request)));
        } catch (Exception e) {
            logger.error("微信端下认筹单 -=- {}", e.toString());
            return ResponseBean.error(e.getMessage(), ResponseBean.ERROR_MISSING_PARAMS);
        }
        return responseBean;
    }


    /**
     * 微信端获取认筹单详细信息
     *
     * @param raiseRecordId 认筹旦id
     * @return
     */
    @RequestMapping(value = "/wx/taRaiseRecord/{raiseRecordId}", method = RequestMethod.GET)
    public ResponseBean wxGetRaiseRecordById(@PathVariable Integer raiseRecordId, HttpServletRequest request) {
        ResponseBean responseBean = new ResponseBean();
        try {
            responseBean = iTaRaiseRecordService.wxGetRaiseRecordById(raiseRecordId, getPersonId(request), getOrgId(request));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("微信端获取认筹单详细信息 -=- {}", e.toString());
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 微信端获取认筹单列表信息
     *
     * @return
     */
    @RequestMapping(value = "/wx/taRaiseRecord/list", method = RequestMethod.GET)
    public ResponseBean wxGetRaiseRecordList(@RequestParam(value = "buildingId", required = false) String buildingId,
                                             @RequestParam(value = "salesBatchId", required = false) Integer salesBatchId,
                                             @RequestParam(value = "houseLockingStatus", required = false) String houseLockingStatus,
                                             @RequestParam(value = "pageNumber", defaultValue = "1") Integer pageNumber,
                                             @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize, HttpServletRequest request) {
        ResponseBean responseBean = new ResponseBean();
        try {
            IPage<TaRaiseRecord> pg = new Page<>(pageNumber, pageSize);
            //获取认筹单列表信息
            QueryWrapper<TaRaiseRecord> taRaiseRecordQueryWrapper = new QueryWrapper<>();
            taRaiseRecordQueryWrapper.eq("org_id", getOrgId(request));
            taRaiseRecordQueryWrapper.eq("person_id", getPersonId(request));
            taRaiseRecordQueryWrapper.eq(StringUtils.isNotEmpty(buildingId), "building_id", buildingId);
            taRaiseRecordQueryWrapper.eq(null != salesBatchId, "sales_batch_id", salesBatchId);
            taRaiseRecordQueryWrapper.eq(StringUtils.isNotEmpty(houseLockingStatus), "house_locking_status", houseLockingStatus);
            taRaiseRecordQueryWrapper.ne("status", CommConstant.STATUS_DELETE);
            taRaiseRecordQueryWrapper.orderByDesc("create_date");
            IPage<TaRaiseRecord> page = iTaRaiseRecordService.page(pg, taRaiseRecordQueryWrapper);
            List<TaRaiseRecord> list = page.getRecords();
            list.forEach(e -> {
                //房源与认筹单关系图
                List<TaRaiseHouse> taRaiseHouseList = taRaiseHouseService.list(new QueryWrapper<TaRaiseHouse>().eq("raise_record_id", e.getRaiseRecordId()));
                //房源信息
                List<TaHousingResources> houseList = (List<TaHousingResources>) taHousingResourcesService.listByIds(taRaiseHouseList.stream().map(TaRaiseHouse::getHouseId).collect(Collectors.toList()));
                //户型图列表
                List<TaBuildingImg> apartMentList = taBuildingImgService.getAparemnetList(houseList.stream().map(TaHousingResources::getApartmentId).collect(Collectors.toList()));
                e.setTaHousingResourcesList(houseList);
                e.setTaHousingResourcesSize(houseList.size());
                e.setBuildingImgList(apartMentList);
            });

            responseBean.addSuccess(page);
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("微信端获取认筹单列表信息 -=- {}", e.toString());
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }

    /**
     * 微信端客户选择线下缴费就需要把此人的认筹单的缴费状态改为线下缴费
     */
    @RequestMapping(value = "/wx/taRaiseRecord/{raiseRecordId}", method = RequestMethod.PUT)
    public ResponseBean taRaiseRecordUpdate(@PathVariable Integer raiseRecordId,
                                            HttpServletRequest request) {
        ResponseBean responseBean = new ResponseBean();
        try {
            TaRaiseRecord taRaiseRecord = new TaRaiseRecord();
            taRaiseRecord.setRaiseRecordId(raiseRecordId);
            taRaiseRecord.setPayType(CommConstant.PAY_TYPE_OFFLINE);
            if (iTaRaiseRecordService.updateById(taRaiseRecord)) {
                responseBean.addSuccess(taRaiseRecord);
            } else {
                responseBean.addError("fail");
            }
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("taRaiseRecordUpdate -=- {}", e.toString());
            responseBean.addError(e.getMessage());
        }
        return responseBean;
    }
}
