package com.bonus.zlpt.company.controller;

import com.bonus.zlpt.common.core.utils.poi.ExcelUtil;
import com.bonus.zlpt.common.core.web.controller.BaseController;
import com.bonus.zlpt.common.core.web.domain.AjaxResult;
import com.bonus.zlpt.common.core.web.page.TableDataInfo;
import com.bonus.zlpt.common.security.utils.SecurityUtils;
import com.bonus.zlpt.company.api.domain.ServiceGreementInfo;
import com.bonus.zlpt.company.api.domain.dto.ServiceDto;
import com.bonus.zlpt.company.api.domain.vo.ServiceGreementVo;
import com.bonus.zlpt.company.service.ServiceGreementInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.UnsupportedEncodingException;
import java.util.List;

/**
 * 隐私服务协议表(ServiceGreementInfo)表控制层
 *
 * @author makejava
 * @since 2023-12-04 16:32:02
 */
@RestController
@RequestMapping("serviceGreementInfo")
@Api(value = "隐私服务协议表",tags = {"隐私服务协议管理"})
public class ServiceGreementInfoController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private ServiceGreementInfoService serviceGreementInfoService;

    /**
     * 获取隐私协议模板列表
     * @param dto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("获取隐私协议模板列表")
    public TableDataInfo getPrivacyAgreementTemplateList(@RequestBody ServiceDto dto)
    {
        startPage(dto.getPageNum(), dto.getPageSize());
        List<ServiceGreementVo> list = serviceGreementInfoService.selectGreementInfoList(dto);
        return getDataTable(list);
    }

    /**
     * 根据id查询隐私协议模板信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询隐私协议模板信息")
    public AjaxResult getListById(@PathVariable("id") int id)
    {
        ServiceGreementVo serviceGreementVo = serviceGreementInfoService.selectListById(id);
        return success(serviceGreementVo);
    }

    /**
     * 新增隐私协议模板信息
     * @param dto
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("新增隐私协议模板信息")
    public AjaxResult addPrivacyAgreementTemplateList(@RequestBody ServiceGreementInfo dto)
    {
        Long userId = SecurityUtils.getUserId();
        dto.getServiceGreementDto().setUserId(userId.intValue());
        return toAjax(serviceGreementInfoService.insertConfig(dto));
    }

    /**
     * 导出隐私协议模板信息
     * @param response
     * @param
     */
    @GetMapping("/export")
    @ApiOperation("导出隐私协议模板信息")
    public void expPrivacyAgreementTemplate(HttpServletResponse response) throws UnsupportedEncodingException {
        ExcelUtil<ServiceGreementVo> util = new ExcelUtil<>(ServiceGreementVo.class);
        util.exportExcel(response, serviceGreementInfoService.selectGreementInfoList(new ServiceDto()), "隐私协议模板信息", "","隐私协议模板信息");
    }

    /**
     * 编辑隐私协议模板信息
     * @param dto
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("编辑隐私协议模板信息")
    public AjaxResult updatePrivacyAgreementTemplateList(@RequestBody ServiceGreementInfo dto)
    {
        return toAjax(serviceGreementInfoService.update(dto));
    }

    /**
     * 根据id删除隐私协议模板
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除隐私协议模板")
    public AjaxResult delCarouselChartInfo(@PathVariable("id") int id)
    {
        serviceGreementInfoService.delete(id);
        return success();
    }
}

