package com.xhpc.general.controller;

import com.xhpc.common.core.web.controller.BaseController;
import com.xhpc.common.core.web.domain.AjaxResult;
import com.xhpc.common.core.web.page.TableDataInfo;
import com.xhpc.general.domain.XhpcAgreement;
import com.xhpc.general.service.IXhpcAgreementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 协议管理controller
 * program: ruoyi
 * User: HongYun
 * Date:2021-08-03 09
 */
@RestController
@RequestMapping("/agreement")
public class XhpcAgreementController extends BaseController {

    @Autowired
    IXhpcAgreementService iXhpcAgreementService;
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody XhpcAgreement xhpcAgreement){

        return iXhpcAgreementService.deleteAgreementItem(xhpcAgreement.getAgreementId());
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody XhpcAgreement xhpcAgreement){

        return iXhpcAgreementService.insertAgreementItem(xhpcAgreement.getTitle(),xhpcAgreement.getType(),xhpcAgreement.getContent());
    }

    @PostMapping("/update")
    public AjaxResult update(@RequestBody XhpcAgreement xhpcAgreement){

        return iXhpcAgreementService.updateAgreementItem(xhpcAgreement.getAgreementId(),xhpcAgreement.getTitle(),xhpcAgreement.getType(),xhpcAgreement.getContent()
        );
    }

    @GetMapping("/listAll")
    public TableDataInfo listAll( String title,String createBy,Integer type){

        startPage();
        return getDataTable(iXhpcAgreementService.selectAgreementItems(title,createBy,type));
    }

    @GetMapping("/listOne")
    public AjaxResult listOne(@RequestParam Long agreementId){

        return AjaxResult.success(iXhpcAgreementService.selectAgreementItem(agreementId));
    }
    @GetMapping("/getContent")
    public AjaxResult getContent(@RequestParam Integer type){

        return AjaxResult.success(iXhpcAgreementService.selectContent(type));
    }

}
