package com.ruoyi.web.app;

import com.github.pagehelper.PageHelper;
import com.ruoyi.bst.agreement.domain.AgreementQuery;
import com.ruoyi.bst.agreement.domain.AgreementVO;
import com.ruoyi.bst.agreement.service.AgreementService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.collection.CollectionUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/app/agreement")
public class AppAgreementController extends BaseController {

    @Autowired
    private AgreementService agreementService;

    @ApiOperation("查询协议")
    @GetMapping("/agreementByType")
    @Anonymous
    public AjaxResult agreementByType(AgreementQuery query) {
        PageHelper.startPage(1, 1);
        PageHelper.orderBy("create_time desc");
        query.setAgreementType(query.getAgreementType());
        if (query.getAgreementType()==null) {
            return AjaxResult.error("协议类型不能为空");
        }
        if (query.getAppId()==null) {
            return error("小程序ID不能为空");
        }
        AgreementVO agreementVO = CollectionUtils.firstElement(agreementService.selectAgreementList(query));
        return success(agreementVO);
    }


}
