package com.muchinfo.mtp3century.controller;

import com.muchinfo.mtp3century.service.ITaaccountService;
import com.muchinfo.mtp3century.utils.CenturyDecryptUtil;
import com.muchinfo.mtp3common.enumtype.Constants;
import com.muchinfo.mtp3common.enumtype.MessageType;
import com.muchinfo.mtp3century.utils.AjaxResult;
import com.muchinfo.mtp3common.utils.JsonUtils;
import com.muchinfo.mtp3common.vo.PageResult;
import com.muchinfo.mtp3pojos.vo.taaccount.*;
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;

@RestController
@RequestMapping("/taAccount")
@Api(value = "资金账户API", description = "资金账户管理")
public class TaAccountController {

    private final Logger log = LoggerFactory.getLogger(this.getClass());
    @Resource
    private ITaaccountService iTaaccountService;

    @ApiOperation("资金账户管理-->资金账户管理查询")
    @ApiResponse(code = 200, message = "成功", response = PageResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/query")
    public PageResult<TaAccountQueryResult> query(TaAccountQueryParam taAccountQueryParam, HttpServletRequest request) {
        return iTaaccountService.queryUserMsg(request, taAccountQueryParam);
    }

    @ApiOperation("资金账户管理-->资金账户详情信息")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/queryDetail")
    public AjaxResult<TaAccountQueryResultDetail> queryDetail(Long accountId, HttpServletRequest request) {
        return iTaaccountService.queryDetail(request, accountId);
    }

    @ApiOperation("资金账户管理-->资金账户信息修改--> 初始化")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/updateTaAccountInit")
    public AjaxResult<TaAccountInitResultDetail> updateTaAccountInit(Long accountId, HttpServletRequest request,String orgztypes) {
        return iTaaccountService.updateTaAccountInit(request, accountId,orgztypes);
    }

    @ApiOperation("资金账户管理-->资金账户信息修改")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.POST, value = "/updateTaAccount")
    public AjaxResult updateTaAccount(@RequestBody String param, HttpServletRequest request) {
        try {
            TaAccountUpdateParam taAccountPwd = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(param, request), TaAccountUpdateParam.class);
            return iTaaccountService.updateTaAccount(taAccountPwd, 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 = "/queryAmountStream")
    public PageResult<TaAccountAmountStreamResult> queryAmountStream(TaAccountAmountStreamParam taAccountAmountStreamParam, HttpServletRequest request) {
        return iTaaccountService.queryAmountStream(request, taAccountAmountStreamParam);
    }

    @ApiOperation("资金账户管理-->资金流水信息导出")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.GET, value = "/queryAmountStreamExport")
    public AjaxResult queryAmountStreamExport(TaAccountAmountStreamParam taAccountAmountStreamParam, HttpServletRequest request) {
        return iTaaccountService.queryAmountStreamExport(taAccountAmountStreamParam, request);
    }

    @ApiOperation("资金账户管理-->资金账户修改密码")
    @ApiResponse(code = 200, message = "成功", response = AjaxResult.class)
    @RequestMapping(method = RequestMethod.POST, value = "/updatePwd")
    public AjaxResult updatePwd(@RequestBody String pwd, HttpServletRequest request) {
        try {
            TaAccountPwd taAccountPwd = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(pwd, request), TaAccountPwd.class);
            return iTaaccountService.updatePwd(request, taAccountPwd);
        } 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 = "/inOrOutAmount")
    public AjaxResult inOrOutAmount(@RequestBody String param, HttpServletRequest request) {
        try {
            TaAccountInOrOutAmountParam taAccountPwd = JsonUtils.toBean(CenturyDecryptUtil.decryptForJson(param, request), TaAccountInOrOutAmountParam.class);
            return iTaaccountService.inOrOutAmount(taAccountPwd, request);
        } catch (Exception e) {
            log.error("网上出入金申请，失败原因：" + e);
            return AjaxResult.error(Constants.Error_Code_Design, MessageType.MESSAGE_ERROR_CODE_SYSTEM002.getCode(), request.getHeader("Accept-Language"));
        }
    }
}
