package com.xhkjedu.suser.controller.system;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.annotation.Action;
import com.xhkjedu.suser.model.system.TUsecret;
import com.xhkjedu.suser.service.system.UsecretService;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.utils.PageUtil;
import com.xhkjedu.vo.PageResult;
import com.xhkjedu.vo.ResultVo;
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 javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("usecret")
public class UsecretController {
    @Resource
    private UsecretService usecretService;

    /**
      * 添加
      * @param [usecret]
      * @author ywx
      * @date 2022/3/30 11:33
      * @return com.xhkjedu.vo.ResultVo
      */
    @PostMapping("/add")
    @Action("密保管理-增加")
    public ResultVo add(@RequestBody TUsecret usecret) {
        usecretService.save(usecret);
        return new ResultVo(0,"保存成功");
    }

    /**
      * 修改
      * @param [usecret]
      * @author ywx
      * @date 2022/3/30 11:33
      * @return com.xhkjedu.vo.ResultVo
      */
    @PostMapping("/update")
    @Action("密保管理-修改")
    public ResultVo update(@RequestBody TUsecret usecret) {
        N_Utils.validation(new Object[]{usecret.getUsid(), "密保问题id", 1});
        return usecretService.update(usecret);
    }

    /**
      * 删除
      * @param [usecret]
      * @author ywx
      * @date 2022/3/30 11:33
      * @return com.xhkjedu.vo.ResultVo
      */
    @PostMapping("/delete")
    @Action("密保管理-删除")
    public ResultVo delete(@RequestBody TUsecret usecret) {
        Integer usid = usecret.getUsid();
        N_Utils.validation(new Object[]{usid, "密保问题id", 1});
        return usecretService.deleteById(usid, usecret.getSchoolid());
    }

    /**
      * 列表
      * @param [usecret]
      * @author ywx
      * @date 2022/3/30 11:34
      * @return com.xhkjedu.vo.ResultVo
      */
    @PostMapping("/list")
    public ResultVo list(@RequestBody TUsecret usecret) {
        N_Utils.validation(new Object[]{usecret.getPage(), "显示页码", 1, usecret.getPageSize(), "显示条数", 1});
        PageHelper.startPage(usecret.getPage(), usecret.getPageSize());
        List<Map> list = usecretService.findAll(usecret);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo<>(list));
        return new ResultVo(0,"获取列表成功",pageResult);
    }

    /**
     * 选择表
     * @param [usecret]
     * @author ywx
     * @date 2022/3/30 13:17
     * @return com.xhkjedu.vo.ResultVo
     */
    @PostMapping("/list_sel")
    public ResultVo listForSel(@RequestBody TUsecret usecret) {
        Integer schoolid = usecret.getSchoolid();
        List<Map> list = usecretService.listForSel(schoolid);
        return new ResultVo(0,"获取列表成功",list);
    }
}
