package com.sunxung.factoring.web.fundmanagement;

import com.sunxung.factoring.component.annotation.OperationLog;
import com.sunxung.factoring.component.enums.OperationTypeEnum;
import com.sunxung.factoring.entity.ResponseJson;
import com.sunxung.factoring.entity.fundmanagement.vo.EnterpriseDisburseVo;
import com.sunxung.factoring.entity.fundmanagement.vo.EnterpriseVo;
import com.sunxung.factoring.entity.fundmanagement.vo.FinancialInstitutionDetailVo;
import com.sunxung.factoring.entity.fundmanagement.vo.FinancialInstitutionSearch;
import com.sunxung.factoring.entity.sys.User;
import com.sunxung.factoring.entity.sys.vo.SeachUser;
import com.sunxung.factoring.service.fundmanagement.FinancialInstitutionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description : 资方管理控制层
 * @Author : L.Jia
 * @Date: 2023-02-13 19:22
 */

@RestController
@RequestMapping("/financialInstitution")
public class FinancialInstitutionController {

    @Autowired
    private FinancialInstitutionService financialInstitutionService;

    /***
     * 列表页查询
     *
     * @param search
     * @return
     */
    @PostMapping("/doList")
    public Object doList(@RequestBody SeachUser search) {
        return new ResponseJson(financialInstitutionService.findBySearch(search));
    }

    /**
     * 获取详情信息列表
     *
     * @return
     */
    @PostMapping("/getDetailList")
    public Object doDetailList(@RequestBody FinancialInstitutionSearch search) {
        return new ResponseJson(financialInstitutionService.getDetailList(search));
    }

    /**
     * 关联企业
     *
     * @param enterpriseVo
     * @return
     */
    @PostMapping("/addEnterprise")
    @OperationLog(operationModule = "资方管理",operationType = OperationTypeEnum.OTHER,description = "关联企业")
    public Object doAddEnterpriseList(@RequestBody EnterpriseVo enterpriseVo) {
        financialInstitutionService.addEnterpriseList(enterpriseVo);
        return new ResponseJson("操作成功");
    }

    /**
     * 新增资方账号
     *
     * @param user
     * @return
     */
    @PostMapping("/addAccount")
    @OperationLog(operationModule = "资方管理",operationType = OperationTypeEnum.INSERT,description = "新增资方账号")
    public Object updateFinancialUser(@RequestBody User user) {
        financialInstitutionService.updateFinancialUser(user);
        return new ResponseJson("新增资方账号成功");
    }

    /**
     * 根据资方id获取用户所有支用信息
     *
     * @return
     */
    @GetMapping("/getQuotaDisburseList")
    public Object doGetQuotaDisburseList(Long institutionId) {
        return new ResponseJson(financialInstitutionService.getQuotaDisburseList(institutionId));
    }

    /**
     * 关联支用
     *
     * @param enterpriseDisburseVo
     * @return
     */
    @PostMapping("/addEnterpriseDisburse")
    @OperationLog(operationModule = "资方管理",operationType = OperationTypeEnum.OTHER,description = "关联支用")
    public Object doAddEnterpriseDisburseList(@RequestBody EnterpriseDisburseVo enterpriseDisburseVo) {
        financialInstitutionService.addEnterpriseDisburseList(enterpriseDisburseVo);
        return new ResponseJson("操作成功");
    }

    /**
     * 删除
     *
     * @param financialInstitutionDetailVo
     * @return
     */
    @PostMapping("/deleteEnterprise")
    @OperationLog(operationModule = "资方管理",operationType = OperationTypeEnum.DELETE,description = "删除")
    public ResponseJson doDeleteEnterprise(@RequestBody FinancialInstitutionDetailVo financialInstitutionDetailVo) {
        financialInstitutionService.deleteEnterprise(financialInstitutionDetailVo);
        return new ResponseJson("删除成功！");
    }


    /**
     * 批量添加资方用户 （历史数据治理）
     *
     * @return
     */
    @GetMapping("/addBackerUser")
    @OperationLog(operationModule = "资方管理",operationType = OperationTypeEnum.OTHER,description = "批量添加资方用户 （历史数据治理）")
    public ResponseJson addBackerUser() {
        financialInstitutionService.addBackerUser();
        return new ResponseJson("批量添加资方用户成功！");
    }

    /**
     * 重置密码
     * @param institutionName
     * @return
     */
    @GetMapping("/modifyPassword")
    @OperationLog(operationModule = "资方管理",operationType = OperationTypeEnum.OTHER,description = "重置密码")
    public ResponseJson modifyPassword(String institutionName){
        financialInstitutionService.modifyPassword(institutionName);
        return new ResponseJson("重置密码成功！！");
    }
}
