package com.younike.admin;


import java.util.List;

import com.younike.common.utils.StringUtils;
import com.younike.framework.config.AnonymousAccess;
import com.younike.system.service.ISysTreatyService;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.younike.common.annotation.Log;
import com.younike.common.core.controller.BaseController;
import com.younike.common.core.domain.AjaxResult;
import com.younike.common.enums.BusinessType;
import com.younike.system.domain.SysTreaty;
import com.younike.common.utils.poi.ExcelUtil;
import com.younike.common.core.page.TableDataInfo;

/**
 * 隐私协议Controller
 *
 * @author elev
 * @date 2022-01-04
 */
@RestController
@RequestMapping("/admin/treaty")
public class AdminSysTreatyController extends BaseController {
    @Autowired
    private ISysTreatyService sysTreatyService;

    /**
     * 查询隐私协议列表
     */
    @PreAuthorize("@ss.hasPermi('basic:treaty:list')")
    @GetMapping("/list")
    public TableDataInfo list() {
        startPage();
        SysTreaty sysTreaty = new SysTreaty();
        List<SysTreaty> list = sysTreatyService.selectSysTreatyList(sysTreaty);
        return getDataTable(list);
    }

    /**
     * 导出隐私协议列表
     */
    @PreAuthorize("@ss.hasPermi('basic:treaty:export')")
    @Log(title = "隐私协议", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SysTreaty sysTreaty) {
        List<SysTreaty> list = sysTreatyService.selectSysTreatyList(sysTreaty);
        ExcelUtil<SysTreaty> util = new ExcelUtil<SysTreaty>(SysTreaty.class);
        return util.exportExcel(list, "隐私协议数据");
    }

    /**
     * 获取隐私协议详细信息
     */
    @PreAuthorize("@ss.hasPermi('basic:treaty:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sysTreatyService.selectSysTreatyById(id));
    }

    /**
     * 新增隐私协议
     */
    @PreAuthorize("@ss.hasPermi('basic:treaty:add')")
    @Log(title = "隐私协议", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysTreaty sysTreaty) {
        return toAjax(sysTreatyService.insertSysTreaty(sysTreaty));
    }

    /**
     * 修改隐私协议
     */

    @PreAuthorize("@ss.hasPermi('basic:treaty:edit')")
    @Log(title = "隐私协议", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody SysTreaty sysTreaty) {
        if(ObjectUtils.isEmpty(sysTreaty)){
            return AjaxResult.error("参数错误");
        }
        return toAjax(sysTreatyService.updateSysTreaty(sysTreaty));
    }

    /**
     * 删除隐私协议
     */
    @PreAuthorize("@ss.hasPermi('basic:treaty:remove')")
    @Log(title = "隐私协议", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysTreatyService.deleteSysTreatyByIds(ids));
    }
}

