package com.sunxung.factoring.web.credit;


import com.sunxung.factoring.component.annotation.OperationLog;
import com.sunxung.factoring.component.enums.OperationTypeEnum;
import com.sunxung.factoring.entity.GridPage;
import com.sunxung.factoring.entity.ResponseJson;
import com.sunxung.factoring.entity.credit.CreditInfo;
import com.sunxung.factoring.entity.customerinformation.ElectronicSignaturePersonal;
import com.sunxung.factoring.entity.entprise.Enterprise;
import com.sunxung.factoring.entity.sys.FileStorage;
import com.sunxung.factoring.entity.sys.FileStorageDO;
import com.sunxung.factoring.service.credit.CreditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/creditInfo")
public class CreditController {


    @Autowired
    private CreditService creditService;

    /**
     * 列表接口
     * @param name
     * @return
     */
    @ResponseBody
    @RequestMapping("findByName")
    public GridPage findByName(String name, Integer type, Integer page, Integer rows){
        GridPage list = creditService.findByName(name,type,page,rows);
        return list;
    }


    @ResponseBody
    @RequestMapping("add")
    public ResponseJson add(@RequestBody CreditInfo creditInfo){
        creditService.add(creditInfo);
        return new ResponseJson("新增成功！");
    }


    @ResponseBody
    @RequestMapping("update")
    public ResponseJson update(@RequestBody CreditInfo creditInfo){
        creditService.update(creditInfo);
        return new ResponseJson("修改成功！");
    }


    /**
     * 查询详细信息
     * @param id
     * @return
     */
    @ResponseBody
    @RequestMapping("get")
    public ResponseJson get(Long id){
        CreditInfo creditInfo = creditService.get(id);
        return new ResponseJson(creditInfo);
    }

    /**
     * 查询授权书地址
     * @return
     */
    @ResponseBody
    @PostMapping("getAuthAddress")
    public ResponseJson getAuthAddress(String cardNo) throws Exception {
        FileStorage authAddress = creditService.getAuthAddress(cardNo);
        return new ResponseJson(authAddress);
    }


    /**
     * 根据关键字模糊查询企业   企查查886高级接口
     */
    @RequestMapping("getBusinessByKeyWord")
    public ResponseJson getBusinessByKeyWord(@RequestParam String keyword){
        List<Enterprise> enterpriseList = creditService.getBusinessByKeyWord(keyword);
        return new ResponseJson(enterpriseList);
    }



}
