package com.xhkjedu.sapi.controller.system;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xhkjedu.annotation.Action;
import com.xhkjedu.sapi.model.system.TPicture;
import com.xhkjedu.sapi.service.system.PictureService;
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;

/**
 * @author ywx
 * @classname PictureController
 * @description
 * @date 2022/04/27 10:08
 **/
@RequestMapping("picture")
@RestController
public class PictureController {
    @Resource
    private PictureService pictureService;

    @PostMapping("/list")
    public ResultVo list(@RequestBody TPicture picture) {
        PageHelper.startPage(picture.getPage(), picture.getPageSize());
        List<Map> list = pictureService.listAll(picture);
        PageResult pageResult = PageUtil.getPageResult(new PageInfo(list));
        return new ResultVo(0,"获取图片列表成功",pageResult);
    }

    @PostMapping("/list_sel")
    public ResultVo listForSel(@RequestBody TPicture picture) {
        Integer pictype = picture.getPictype();
        N_Utils.validation(new Object[]{pictype,"图片类型",1});
        List<Map> list = pictureService.listForSel(pictype);
        return new ResultVo(0,"获取图片选择列表成功",list);
    }

    @PostMapping("/add")
    @Action("图片管理-增加")
    public ResultVo add(@RequestBody TPicture picture) {
        pictureService.add(picture);
        return new ResultVo(0,"添加成功");
    }

    @PostMapping("/del")
    @Action("图片管理-删除")
    public ResultVo del(@RequestBody TPicture picture) {
        Integer picid = picture.getPicid();
        N_Utils.validation(new Object[]{picid,"图片id",1});
        pictureService.del(picid);
        return new ResultVo(0,"删除成功");
    }
}
