package com.muchinfo.mtp3century.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.muchinfo.mtp3century.service.*;
import com.muchinfo.mtp3century.utils.CenturyDecryptUtil;
import com.muchinfo.mtp3common.enumtype.Constants;
import com.muchinfo.mtp3common.enumtype.MessageType;
import com.muchinfo.mtp3common.enumtype.SysConstants;
import com.muchinfo.mtp3century.utils.AjaxResult;
import com.muchinfo.mtp3common.utils.EncryptionUtils;
import com.muchinfo.mtp3common.utils.JsonUtils;
import com.muchinfo.mtp3common.vo.PageResult;
import com.muchinfo.mtp3interface.mapper.ISystemmanagerMapper;
import com.muchinfo.mtp3interface.mapper.ISystemparamMapper;
import com.muchinfo.mtp3interface.mapper.IUseraccountMapper;
import com.muchinfo.mtp3pojos.entity.*;
import com.muchinfo.mtp3pojos.vo.investor.*;
import com.muchinfo.mtp3pojos.vo.organ.son.OrganSonTransferAddParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;

/**
 * 子机构管理
 */
@RestController
@RequestMapping("/investor")
@Api(value = "交易商管理API", description = "交易商管理")
public class InvestorController {
    private final Logger log = LoggerFactory.getLogger(this.getClass());
    @Resource
    private ISystemmanagerMapper iSystemmanagerMapper;
    @Resource
    private ICommonService iCommonService;
    @Resource
    private IWskhUserinfoService iWskhUserinfoService;
    @Resource
    private IUseraccountService iUseraccountService;
    @Resource
    private ITaaccountService iTaaccountService;
    @Resource
    private IDealLoginService iDealLoginService;
    @Resource
    private IOrganService iOrganService;
    @Resource
    private IOrganSonService iOrganSonService;
    @Resource
    private ISystemparamMapper iSystemparamMapper;
    @Resource
    private IUseraccountMapper iUseraccountMapper;

    @ApiOperation("交易商管理-->开户管理-->交易商开户列表信息获取")
    @RequestMapping(method = RequestMethod.GET, value = "/query")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    public PageResult<InvestorQueryResult> query(InvestorQueryParam investorQueryParam, HttpServletRequest request) {
        Systemmanager systemmanager = iSystemmanagerMapper.selectOne(new QueryWrapper<Systemmanager>().eq("LOGINCODE", iCommonService.getUserLoginCode(request)));
        investorQueryParam.setUserTypes("1,5");
        if ("show".equals(investorQueryParam.getShow())) {
            //查询所有记录
            investorQueryParam.setUserState(0);
            if (systemmanager.getReletype().intValue() != SysConstants.SYS_TYPE_MANAGE.intValue()) {
                investorQueryParam.setAreaId(systemmanager.getAreauserid());
            }
        } else {
            if (systemmanager.getReletype().intValue() != SysConstants.SYS_TYPE_MANAGE.intValue()) {
                investorQueryParam.setAreaId(systemmanager.getAreauserid());
                investorQueryParam.setUserState(investorQueryParam.getUserState());
            }
        }
        return iWskhUserinfoService.queryInvestorPage(investorQueryParam, request);
    }

    @ApiOperation("交易商管理-->开户管理-->获取交易商开户详情信息")
    @RequestMapping(method = RequestMethod.GET, value = "/querySunDetail")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult<WskhUserinfo> querySunDetail(Long userId, HttpServletRequest request) {
        return iWskhUserinfoService.querySunDetail(userId, request);
    }

    @RequestMapping(method = RequestMethod.POST, value = "/dealSunOrgan")
    @ApiOperation("交易商管理-->开户管理-->交易商开户")
    public AjaxResult dealSunOrgan(@RequestBody String wskhUserInfo, HttpServletRequest request) {
        try {
            WskhUserinfo currentVo = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(wskhUserInfo, request), WskhUserinfo.class);
            Systemmanager systemmanager = iSystemmanagerMapper.selectOne(new QueryWrapper<Systemmanager>().eq("LOGINCODE", iCommonService.getUserLoginCode(request)));
            if (currentVo.getUserid() != null) {
                return iWskhUserinfoService.editWskhUserinfo(currentVo, systemmanager, request);
            } else {
                return iWskhUserinfoService.addWskhUserinfo(currentVo, systemmanager, request);
            }
        } catch (Exception e) {
            log.error("交易商开户失败，失败原因：" + Arrays.toString(e.getStackTrace()));
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }

    @RequestMapping(method = RequestMethod.GET, value = "/investorProcess")
    @ApiOperation("交易商管理-->开户管理-->交易商初审/复审")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult investorProcess(InvestorProcessParam param, HttpServletRequest request) {
        try {
            return iWskhUserinfoService.investorProcess(param, request);
        } catch (Exception e) {
            log.error("交易商初审/复审，失败原因：" + Arrays.toString(e.getStackTrace()));
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }

    @ApiOperation("交易商管理-->交易商管理-->获取交易商列表信息")
    @RequestMapping(method = RequestMethod.GET, value = "/initQuery")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    public PageResult<DealerQueryResult> initQuery(DealerQueryParam dealerQueryParam, HttpServletRequest request) {
        if (StringUtils.isNotBlank(dealerQueryParam.getCardNum())) {
            dealerQueryParam.setCardNum(EncryptionUtils.encryptByAES(dealerQueryParam.getCardNum()));
        }
        if (StringUtils.isNotBlank(dealerQueryParam.getMobilePhone())) {
            dealerQueryParam.setMobilePhone(EncryptionUtils.encryptByAES(dealerQueryParam.getMobilePhone()));
        }
        return iUseraccountService.queryOrganPage(dealerQueryParam, request);
    }

    @ApiOperation("交易商管理-->交易商管理-->获取交易商详情信息")
    @RequestMapping(method = RequestMethod.GET, value = "/initQueryDetail")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult<DealerQueryDetailResult> initQueryDetail(DealerQueryDetailParam dealerQueryDetailParam, HttpServletRequest request) {
        return iUseraccountService.initQueryDetail(dealerQueryDetailParam, request);
    }

    @ApiOperation("交易商管理-->交易商管理-->修改")
    @RequestMapping(method = RequestMethod.POST, value = "/investorEdit")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult investorEdit(@RequestBody String param, HttpServletRequest request) {
        try {
            DetailBeforeResult currentVo = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(param, request), DetailBeforeResult.class);
            return iUseraccountService.investorEdit(currentVo, request);
        } catch (Exception e) {
            log.error("交易商修改失败，失败原因：" + e);
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }

    @ApiOperation("交易商管理-->交易商管理-->查询个性化设置")
    @RequestMapping(method = RequestMethod.GET, value = "/accountQuery")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult<InvestorPersonalizationResult> accountQuery(Long goodsid, Long accountid, HttpServletRequest request) {
        return iUseraccountService.accountQuery(goodsid, accountid, request);
    }

    @ApiOperation("交易商管理-->交易商管理-->注销")
    @RequestMapping(method = RequestMethod.GET, value = "/logOff")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult logOff(Long areaid, HttpServletRequest request) {
        return iTaaccountService.logOff(areaid, request);
    }

    @ApiOperation("交易商管理-->交易商管理-->撤回变更")
    @RequestMapping(method = RequestMethod.GET, value = "/rebackChange")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult rebackChange(Long areaid, HttpServletRequest request) {
        return iTaaccountService.rebackChange(areaid, request);
    }

    @ApiOperation("交易商管理-->交易商管理-->恢复")
    @RequestMapping(method = RequestMethod.GET, value = "/recover")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult recover(Long areaid, HttpServletRequest request) {
        return iTaaccountService.recover(areaid, request);
    }

    @ApiOperation("交易商管理-->交易商管理-->资金账户、资金账户详情（userid不传）")
    @RequestMapping(method = RequestMethod.GET, value = "/showAccount")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    public PageResult<Taaccount> showAccount(Long userid, String accountid, Integer pageNum, Integer pageSize, HttpServletRequest request) {
        return iTaaccountService.showAccount(userid, accountid, pageNum, pageSize, request);
    }

    @ApiOperation("交易商管理-->交易商管理-->资金账户-->修改")
    @RequestMapping(method = RequestMethod.POST, value = "/edit")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult edit(@RequestBody String param, HttpServletRequest request) {
        try {
            InvestorTaAccountUpdateParam updateParam = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(param, request), InvestorTaAccountUpdateParam.class);
            return iTaaccountService.edit(updateParam, request);
        } catch (Exception e) {
            log.error("交易商资金账户修改失败，失败原因：" + e);
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }

    @ApiOperation("交易商管理-->交易商管理-->登录账户列表查询")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/queryInvestor")
    public PageResult<InvestorLoginQueryResult> queryInvestor(InvestorLoginQueryParam param, HttpServletRequest request) {
        return iDealLoginService.queryInvestor(param, request);
    }

    @ApiOperation("交易商管理-->交易商管理-->登录账户列表查询-->查看登录流水")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/queryLoginLog")
    public PageResult<Userloginflow> queryLoginLog(Long loginid, Integer pageNum, Integer pageSize, HttpServletRequest request) {
        return iDealLoginService.queryLoginLog(loginid, pageNum, pageSize, request);
    }

    @ApiOperation("交易商管理-->交易商管理-->登录账户列表查询-->重置密码")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/resetPwd")
    public AjaxResult resetPwd(Long loginid, HttpServletRequest request) {
        return iDealLoginService.resetPwd(loginid, request);
    }

    @ApiOperation("交易商管理-->交易商管理-->登录账户列表查询-->账号锁定、解锁")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/lockAccount")
    public AjaxResult lockAccount(Long loginid, Integer status, HttpServletRequest request) {
        return iDealLoginService.lockAccount(loginid, status, request);
    }

    @ApiOperation("交易商管理-->交易商管理-->登录账户列表查询-->注销停用")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/deleteAccount")
    public AjaxResult deleteAccount(Long loginid, HttpServletRequest request) {
        return iDealLoginService.deleteAccount(loginid, request);
    }

    @ApiOperation("交易商管理-->交易商管理-->登录账户列表查询-->恢复")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/restoreAccount")
    public AjaxResult restoreAccount(Long loginid, HttpServletRequest request) {
        return iDealLoginService.restoreAccount(loginid, request);
    }

    @ApiOperation("交易商管理-->交易商管理-->登录账户列表查询-->查看手机号")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/queryUserAuthInfo")
    public AjaxResult<Userauthinfo> queryUserAuthInfo(Long loginid, HttpServletRequest request) {
        return iDealLoginService.queryUserAuthInfo(loginid, request);
    }

    @ApiOperation("交易商管理-->交易商管理-->交易商管理导出")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/export")
    public AjaxResult export(HttpServletRequest request) {
        return iUseraccountService.export(request);
    }

    @ApiOperation("交易商管理-->交易商变更审核-->查询交易商变更审核列表")
    @RequestMapping(method = RequestMethod.GET, value = "/queryModifyPage")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    public PageResult<InvestorModifyResult> queryModifyPage(InvestorModifyParam param, HttpServletRequest request) {
        return iUseraccountService.queryModifyPage(param, request);
    }

    @ApiOperation("交易商管理-->交易商变更审核-->审核")
    @RequestMapping(method = RequestMethod.GET, value = "/modifyAudit")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult modifyAudit(InvestorModifyAuditParam param, HttpServletRequest request) {
        return iUseraccountService.modifyAudit(param, request);
    }

    @ApiOperation("交易商管理-->个性化管理-->交易商分组管理-->获取列表")
    @RequestMapping(method = RequestMethod.GET, value = "/queryPersonalized")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    public PageResult<InvestorPersonalizedResult> queryPersonalized(String groupname, Integer pageNum, Integer pageSize, HttpServletRequest request) {
        return iUseraccountService.queryPersonalized(groupname, pageNum, pageSize, request);
    }

    @ApiOperation("交易商管理-->个性化管理-->交易商分组管理-->获取所选客户信息对应风险率")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/getRiskRatioTypeForMarketer")
    public AjaxResult<Riskratiotype> getRiskRatioTypeForMarketer(Integer customertype, Integer riskcontrolmode, HttpServletRequest request) {
        return iUseraccountService.getRiskRatioTypeForMarketer(customertype, riskcontrolmode, request);
    }

    @ApiOperation("交易商管理-->个性化管理-->交易商分组管理-->新增/修改")
    @RequestMapping(method = RequestMethod.POST, value = "/addPersonalized")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult addPersonalized(@RequestBody String param, HttpServletRequest request) {
        try {
            InvestorPersonalizedAddParam updateParam = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(param, request), InvestorPersonalizedAddParam.class);
            return iUseraccountService.addPersonalized(updateParam, request);
        } catch (Exception e) {
            log.error("交易商分组新增失败，失败原因：" + e);
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }

    @ApiOperation("交易商管理-->个性化管理-->交易商分组管理-->分组交易商获取列表")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/queryPersonalizedDetail")
    public PageResult<InvestorPerDetailQueryResult> queryPersonalizedDetail(InvestorPerDetailQueryParam param, HttpServletRequest request) {
        return iUseraccountService.queryPersonalizedDetail(param, request);
    }

    @ApiOperation("交易商管理-->个性化管理-->交易商分组管理-->分组交易商获取列表-->初始化交易商")
    @RequestMapping(method = RequestMethod.GET, value = "/queryInvestorForPer")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    public AjaxResult<Useraccount> queryInvestorForPer(Long usergroupid, HttpServletRequest request) {
        return iUseraccountService.queryInvestorForPer(usergroupid, request);
    }

    @ApiOperation("交易商管理-->个性化管理-->交易商分组管理-->分组交易商获取列表-->新增")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.POST, value = "/addInvestorForPer")
    public AjaxResult addInvestorForPer(@RequestBody String param, HttpServletRequest request) {
        try {
            InvestorForPerAddParam updateParam = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(param, request), InvestorForPerAddParam.class);
            return iUseraccountService.addInvestorForPer(updateParam, request);
        } catch (Exception e) {
            log.error("分组交易商新增失败，失败原因：" + e);
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }

    @ApiOperation("交易商管理-->个性化管理-->交易商分组管理-->分组交易商获取列表-->删除")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/delInvestorForPer")
    public AjaxResult delInvestorForPer(Long userid, HttpServletRequest request) {
        return iUseraccountService.delInvestorForPer(userid, request);
    }

    @ApiOperation("交易商管理-->个性化管理-->交易商分组管理-->删除")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/delInvest")
    public AjaxResult delInvest(Long autoid, HttpServletRequest request) {
        return iUseraccountService.delInvest(autoid, request);
    }

    @ApiOperation("交易商管理-->个性化管理-->风控个性化-->获取列表")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/queryAccountRiskConfig")
    public PageResult<AccountRiskConfigResult> queryAccountRiskConfig(AccountRiskConfigParam param, HttpServletRequest request) {
        return iUseraccountService.queryAccountRiskConfig(param, request);
    }

    @ApiOperation("交易商管理-->个性化管理-->风控个性化-->新增获取交易商资金账户信息")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/getTaaccountList")
    public AjaxResult getTaaccountList(Long userid, HttpServletRequest request) {
        return iUseraccountService.getTaaccountList(userid, request);
    }

    @ApiOperation("交易商管理-->个性化管理-->风控个性化-->新增/修改")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.POST, value = "/addAccountRiskConfig")
    public AjaxResult addAccountRiskConfig(@RequestBody String param, HttpServletRequest request) {
        try {
            AccountRiskConfigAddParam updateParam = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(param, request), AccountRiskConfigAddParam.class);
            return iUseraccountService.addAccountRiskConfig(updateParam, request);
        } catch (Exception e) {
            log.error("风控个性化新增或修改失败，失败原因：" + e);
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }

    @ApiOperation("交易商管理-->个性化管理-->风控个性化-->详情")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/view")
    public AjaxResult<Accountriskconfig> view(Long accountid, HttpServletRequest request) {
        return iUseraccountService.view(accountid, request);
    }

    @ApiOperation("交易商管理-->个性化管理-->风控个性化-->删除")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/deleteConfig")
    public AjaxResult deleteConfig(Long accountid, HttpServletRequest request) {
        return iUseraccountService.deleteConfig(accountid, request);
    }

    @ApiOperation("交易商管理-->个性化管理-->交易商个性化-->获取树结构")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/getTree")
    public AjaxResult<UserGroupTreeResult> getTree(HttpServletRequest request) {
        return iUseraccountService.getTree(request);
    }

    @ApiOperation("交易商管理-->个性化管理-->交易商个性化-->新增-->初始化交易商个性化信息")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/initInvestorPerson")
    public AjaxResult<InvestorInitPerAddResult> initGoodsAndBZ(Long usergroupid, Long marketid, Long goodsid, HttpServletRequest request) {
        return iUseraccountService.initGoodsAndBZ(usergroupid, marketid, goodsid, request);
    }

    @ApiOperation("交易商管理-->个性化管理-->交易商个性化-->修改-->初始化保证金类别")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/initBZList")
    public AjaxResult<InvestorInitBZResult> initBZList(Long goodsid, HttpServletRequest request) {
        return iUseraccountService.initBZList(goodsid, request);
    }

    @ApiOperation("交易商管理-->个性化管理-->交易商个性化-->新增/修改")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.POST, value = "/traderPersonAdd")
    public AjaxResult traderPersonAdd(@RequestBody String param, HttpServletRequest request) {
        try {
            InvestorPersonAddParam updateParam = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(param, request), InvestorPersonAddParam.class);
            return iUseraccountService.traderPersonAdd(updateParam, request);
        } catch (Exception e) {
            log.error("交易商个性化新增或修改失败，失败原因：" + e);
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }

    @ApiOperation("交易商管理-->个性化管理-->交易商个性化-->删除")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.POST, value = "/deleteTraderConfig")
    public AjaxResult deleteTraderConfig(@RequestBody String param, HttpServletRequest request) {
        try {
            InvestorPersonDeleteParam updateParam = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(param, request), InvestorPersonDeleteParam.class);
            return iUseraccountService.deleteTraderConfig(updateParam, request);
        } catch (Exception e) {
            log.error("交易商个性化删除失败，失败原因：" + e);
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }

    @ApiOperation("交易商管理-->个性化管理-->交易商个性化-->详情")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/tradeConfigView")
    public AjaxResult<UserGroupTradeConfigVo> tradeConfigView(PersonalizationDelParam param, HttpServletRequest request) {
        return iUseraccountService.tradeConfigView(param, request);
    }


    @ApiOperation("交易商管理-->个性化管理-->资金账户个性化-->获取树结构")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/getAccTradeTree")
    public AjaxResult<AccountTradeConfigTreeVo> getAccTradeTree(HttpServletRequest request) {
        return iUseraccountService.getAccTradeTree(request);
    }

    @ApiOperation("交易商管理-->个性化管理-->资金账户个性化--> 详情")
    @RequestMapping(method = RequestMethod.GET, value = "/accTradeConfigView")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult<Accounttradeconfig> accTradeConfigView(PersonalizationDelParam param, HttpServletRequest request) {
        //这个是投资者的userid ,获取投资者的分组ID
        param.setMemberuserid(1L);
        return iOrganService.tradeConfigView(param, request);
    }

    @ApiOperation("交易商管理-->个性化管理-->资金账户个性化--> 删除")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/accTradeConfigDelete")
    public AjaxResult accTradeConfigDelete(PersonalizationDelParam param, HttpServletRequest request) {
        return iOrganService.tradeConfigDelete(param, request);
    }

    @ApiOperation("交易商管理-->个性化管理-->资金账户个性化--> 新增初始化交易商信息")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/initAccTrade")
    public AjaxResult<InitInvestorTradeResult> initAccTrade(String searchName, HttpServletRequest request) {
        return iOrganService.initAccTrade(searchName, request);
    }

    @ApiOperation("交易商管理-->交易商批量转移-->新增")
    @RequestMapping(method = RequestMethod.POST, value = "/organSonTransferAdd")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    private AjaxResult organSonTransferAdd(@RequestBody String param, HttpServletRequest request) {
        Systemmanager systemmanager = iSystemmanagerMapper.selectOne(new QueryWrapper<Systemmanager>().eq("LOGINCODE", iCommonService.getUserLoginCode(request)));
        try {
            OrganSonTransferAddParam current = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(param, request), OrganSonTransferAddParam.class);
            Systemparam p = iSystemparamMapper.selectOne(new QueryWrapper<Systemparam>().eq("PARAMCODE", SysConstants.SYPAMAM_CODE_TRANSFER_MEMBER));
            if (p != null && "0".equals(p.getParamvalue())) {
                //如果不允许转 会员，那么admin没有操作权限
                if (systemmanager.getReletype() == 1) {
                    return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM003.getCode(), request.getHeader("Accept-Language"));
                }
            }
            if (current.getDiversiontype() == 0) {
                // 交易商单个转移时 更新转出会员、机构
                Useraccount userAccount = iUseraccountMapper.selectOne(new QueryWrapper<Useraccount>().eq("userid", current.getOutinvestor()));
                if (userAccount != null) {
                    current.setOutmemberuserid(userAccount.getMemberuserid());
                    current.setOutparentuserid(userAccount.getParentuserid());
                }
            }
            return iOrganSonService.organSonTransferAdd(current, request);
        } catch (Exception e) {
            log.error("子机构管理修改失败，失败原因：" + Arrays.toString(e.getStackTrace()));
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }

    @ApiOperation("交易商管理-->交易商销户审核-->获取列表")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/usercancelapply")
    public PageResult<InvestorCancelApplyResult> usercancelapply(InvestorCancelApplyParam param, HttpServletRequest request) {
        return iUseraccountService.usercancelapply(param, request);
    }

    @ApiOperation("交易商管理-->交易商销户审核-->详情")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/cancelview")
    public AjaxResult<Usercancelapply> cancelview(Long autoid, HttpServletRequest request) {
        return iUseraccountService.cancelview(autoid, request);
    }

    @ApiOperation("交易商管理-->交易商批量转移-->新增初始化")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/getUserAccountDetail")
    public AjaxResult<UserAccountDetailVo> getUserAccountDetail(Long userid, HttpServletRequest request) {
        return iUseraccountService.getUserAccountDetail(userid, request);
    }

    @ApiOperation("交易商管理-->交易商销户审核-->审核")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/cancelaudit")
    public AjaxResult cancelaudit(Long autoid, Integer auditflag, String msg, HttpServletRequest request) {
        return iUseraccountService.cancelaudit(autoid, auditflag, msg, request);
    }
}
