package com.jkcredit.invoice.controller.interserver;

import com.jkcredit.invoice.annotation.LoginRequired;
import com.jkcredit.invoice.model.entity.customer.CustomerRec;
import com.jkcredit.invoice.model.entity.user.User;
import com.jkcredit.invoice.service.customer.CustomerService;
import com.jkcredit.invoice.service.lowerservice.CheckHasAuthRole;
import com.jkcredit.invoice.service.lowerservice.CustomeLowerService;
import com.jkcredit.invoice.util.RespR;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
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;

/**
 * 客户下游接口
 * @author mumuxigua
 */
@Api(tags = "客户下游接口")
@RestController
@RequestMapping(value = {"/lowerService"})
public class CustomerLowerServiceController {
    @Autowired
    CustomeLowerService lowerService;

    @Autowired
    CustomerService customerService;
    @Autowired
    private CheckHasAuthRole checkHasAuthRole;

    /**
     * @param customerRecs
     * @return
     */
    @PostMapping("/customeRec")
    @ApiOperation(value = "用户备案", notes = "用户备案")
    @LoginRequired
    public RespR customeRec(@RequestBody List<CustomerRec> customerRecs) {
        return lowerService.customeRec(customerRecs);
    }


    /**
     * @param customerRec
     * @return
     */
    @PostMapping("/customeRecQueryList")
    @ApiOperation(value = "用户备案列表查询", notes = "用户备案列表查询")
    @LoginRequired
    public RespR customeRecQueryList(@RequestBody CustomerRec customerRec, User user) {
        checkHasAuthRole.checkCustomerRole(user, customerRec.getCustomerName());
        return lowerService.customeRecQueryList(customerRec);
    }

    /**
     * @param customerRec
     * @return
     */
    @PostMapping("/customeRecQueryUpper")
    @ApiOperation(value = "企业备案信息上游查询", notes = "企业备案上游查询")
    @LoginRequired
    public RespR customeRecQueryUpper(@RequestBody CustomerRec customerRec, User user) {
        checkHasAuthRole.checkCustomerRole(user, customerRec.getCustomerName());
        return customerService.customerRecQuery(customerRec);
    }

    /**
     * @param customerRec
     * @return
     */
    @PostMapping("/customeRecQuery")
    @ApiOperation(value = "用户备案信息查询", notes = "用户备案信息查询")
    @LoginRequired
    public RespR customeRecQuery(@RequestBody CustomerRec customerRec, User user) {
        checkHasAuthRole.checkCustomerRole(user, customerRec.getCustomerName());
        return lowerService.customeRecQuery(customerRec);
    }


}
