package com.yh.saas.plugin.yiliangyiyun.controller;



import com.baomidou.mybatisplus.plugins.Page;
import com.winsea.svc.base.base.entity.CommonCompany;
import com.winsea.svc.base.base.service.ICommonCompanyService;
import com.winsea.svc.base.security.util.AuthSecurityUtils;
import com.yh.saas.plugin.yiliangyiyun.entity.IdentityAuthenticationInfo;
import com.yh.saas.plugin.yiliangyiyun.exception.AppServiceException;
import com.yh.saas.plugin.yiliangyiyun.exception.ServiceException;
import com.yh.saas.plugin.yiliangyiyun.service.IIdentityAuthenticationInfoService;
import com.yh.saas.plugin.yiliangyiyun.util.QRCodeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * <p>
 * 记录身份认证 前端控制器
 * </p>
 *
 * @author Gongdc
 * @since 2021-07-23
 */
@RestController
@RequestMapping("/identityAuthenticationInfo")
public class IdentityAuthenticationInfoController {

    @Autowired
    private IIdentityAuthenticationInfoService iIdentityAuthenticationInfoService;
    @Autowired
    private ICommonCompanyService companyService;
    @Autowired
    private QRCodeUtil qrCodeUtil ;
    /**
     * 粮商认证列表
     * @param identityAuthenticationInfo
     * @return
     */
    @GetMapping("/selectIdentityAuthenticationInfo")
    public Page<IdentityAuthenticationInfo> selectIdentityAuthenticationInfo(IdentityAuthenticationInfo identityAuthenticationInfo) {
        return iIdentityAuthenticationInfoService.selectIdentityAuthenticationInfo(identityAuthenticationInfo);
    }


    /**
     * 更改手机号
     * @param identityAuthenticationInfo
     * @return
     */
    @PostMapping("/api/modifyIdentityPhone")
    public String modifyIdentityPhone(@RequestBody IdentityAuthenticationInfo identityAuthenticationInfo) {
        return iIdentityAuthenticationInfoService.modifyIdentityPhone(identityAuthenticationInfo);
    }

    /**
     * 添加身份认证
     * @param identityAuthenticationInfo
     * @return
     */
    @PostMapping("/api/addIdentityAuthenticationInfo")
    public String addIdentityAuthenticationInfo(@RequestBody IdentityAuthenticationInfo identityAuthenticationInfo) throws ServiceException {
        return iIdentityAuthenticationInfoService.addIdentityAuthenticationInfo(identityAuthenticationInfo);
    }

    /**
     * 编辑身份认证
     * @param identityAuthenticationInfo
     * @return
     */
    @PostMapping("/api/editIdentityAuthenticationInfo")
    public String editIdentityAuthenticationInfo(@RequestBody IdentityAuthenticationInfo identityAuthenticationInfo){
        return iIdentityAuthenticationInfoService.editIdentityAuthenticationInfo(identityAuthenticationInfo);
    }
    /**
     * 查看身份认证
     * @param identityAuthenticationInfo
     * @return
     */
    @GetMapping("/api/getIdentityAuthenticationInfo")
    public IdentityAuthenticationInfo getIdentityAuthenticationInfo(IdentityAuthenticationInfo identityAuthenticationInfo){
        return iIdentityAuthenticationInfoService.getIdentityAuthenticationInfo(identityAuthenticationInfo.getId());
    }


    /**
     * 删除身份认证
     *  @param identityAuthenticationInfo
     * @return
     */
    @PostMapping("/api/deleteIdentityAuthenticationInfo")
    public void deleteIdentityAuthenticationInfo(@RequestBody IdentityAuthenticationInfo identityAuthenticationInfo) {
        iIdentityAuthenticationInfoService.deleteIdentityAuthenticationInfo(identityAuthenticationInfo.getId());
    }
    /**
     * 查看
     */
    @GetMapping("/getInfo")
    public IdentityAuthenticationInfo getInfo(@RequestParam String commonId) throws ServiceException {
        return iIdentityAuthenticationInfoService.getInfo(commonId);
    }
    /**
     * 审核
     * @param identityAuthenticationInfo
     * @return
     */
    @PostMapping("/api/examine")
    public String examine(@RequestBody IdentityAuthenticationInfo identityAuthenticationInfo){
        return iIdentityAuthenticationInfoService.examine(identityAuthenticationInfo);
    }

    /**
     * 设置默认
     * @param identityAuthenticationInfo
     * @return
     */
    @PostMapping("/api/setDefault")
    public String setDefault(@RequestBody IdentityAuthenticationInfo identityAuthenticationInfo){
        return iIdentityAuthenticationInfoService.setDefault(identityAuthenticationInfo);
    }

    /**
     * 粮商认证列表PC端
     * @param identityAuthenticationInfo
     * @return
     */
    @GetMapping("/selectIdentityAuthenticationInfoPc")
    public Page<IdentityAuthenticationInfo> selectIdentityAuthenticationInfoPc(IdentityAuthenticationInfo identityAuthenticationInfo) {
        return iIdentityAuthenticationInfoService.selectIdentityAuthenticationInfoPc(identityAuthenticationInfo);
    }
    /**
     * 查粮农身份
     * @param identityAuthenticationInfo
     * @return
     */
    @GetMapping("/selectCount")
    public IdentityAuthenticationInfo selectCount(IdentityAuthenticationInfo identityAuthenticationInfo) {
        return iIdentityAuthenticationInfoService.selectCount(identityAuthenticationInfo);
    }

    /**
     * 查手机号是否存在
     * @param identityAuthenticationInfo
     * @return
     */
    @GetMapping("/selectPhone")
    public IdentityAuthenticationInfo selectPhone(IdentityAuthenticationInfo identityAuthenticationInfo) throws AppServiceException {
        return iIdentityAuthenticationInfoService.selectPhone(identityAuthenticationInfo);
    }
    /**
     * 库内自采客户管理获取二维码
     * @param identityAuthenticationInfo
     * @return
     */
    @GetMapping("/generateQRCodeImage")
    public String generateQRCodeImage(IdentityAuthenticationInfo identityAuthenticationInfo) {
        identityAuthenticationInfo.setCompId(AuthSecurityUtils.getCurrentUserInfo().getCompId());
        CommonCompany commonCompany = companyService.selectById(identityAuthenticationInfo.getCompId());
        return qrCodeUtil.generateQRCodeImage(identityAuthenticationInfo.getCompId()+","+commonCompany.getCompName(),800,800,"company",identityAuthenticationInfo.getCompId());
    }
    /**
     * 手机端扫码成为公司客户
     * @param identityAuthenticationInfo
     * @return
     */
    @GetMapping("/saveCompanyIdentity")
    public String scanCode(IdentityAuthenticationInfo identityAuthenticationInfo) {
        return iIdentityAuthenticationInfoService.saveCompanyIdentity(identityAuthenticationInfo);
    }
    /**
     * 库内自采客户管理列表PC端
     * @param identityAuthenticationInfo
     * @return
     */
    @GetMapping("/selectIdentityAuthenticationInfoPurchase")
    public Page<IdentityAuthenticationInfo> selectIdentityAuthenticationInfoPurchase(IdentityAuthenticationInfo identityAuthenticationInfo) {
        return iIdentityAuthenticationInfoService.selectIdentityAuthenticationInfoPurchase(identityAuthenticationInfo);
    }
    /**
     * 库内自采客户管理删除身份认证
     *  @param identityAuthenticationInfo
     * @return
     */
    @PostMapping("/api/deleteCompanyIdentity")
    public void deleteCompanyIdentity(@RequestBody IdentityAuthenticationInfo identityAuthenticationInfo) {
        iIdentityAuthenticationInfoService.deleteCompanyIdentity(identityAuthenticationInfo);
    }

    /**
     * 自采客户下拉列表
     * @param identityAuthenticationInfo
     * @return
     */
    @GetMapping("/identityAuthenticationInfoCustomer")
    public List<IdentityAuthenticationInfo> identityAuthenticationInfoCustomer(IdentityAuthenticationInfo identityAuthenticationInfo) {
        return iIdentityAuthenticationInfoService.identityAuthenticationInfoCustomer(identityAuthenticationInfo);
    }

    /**
     * 送粮登记货主下拉列表
     * @param identityAuthenticationInfo
     * @return
     */
    @GetMapping("/identityAuthenticationInfoUser")
    public List<IdentityAuthenticationInfo> identityAuthenticationInfoUser(IdentityAuthenticationInfo identityAuthenticationInfo) throws AppServiceException {
        return iIdentityAuthenticationInfoService.identityAuthenticationInfoUser(identityAuthenticationInfo);
    }
    /**
     * 查看客户账户信息
     * @param identityAuthenticationInfo
     * @return
     */
    @GetMapping("/getPayeeInfo")
    public IdentityAuthenticationInfo getPayeeInfo(IdentityAuthenticationInfo identityAuthenticationInfo) {
        return iIdentityAuthenticationInfoService.getPayeeInfo(identityAuthenticationInfo);
    }
}

