package com.platform.controller;

import com.platform.annotation.CanUserUpdateRecord;
import com.platform.entity.HelpTypeEntity;
import com.platform.entity.Result;
import com.platform.service.HelpTypeService;
import com.platform.utils.PageUtils;
import com.platform.utils.PageUtilsPlus;
import com.platform.utils.Query;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Controller
 *
 * @author lipengjun
 * @email 939961241@qq.com
 * @date 2018-11-07 10:09:54
 */
@Controller
@RequestMapping("helptype")
public class HelpTypeController {
    @Autowired
    private HelpTypeService helpTypeService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    
    @ResponseBody
    public Result list(@RequestBody Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<HelpTypeEntity> helpTypeList = helpTypeService.queryList(query);
        int total = helpTypeService.queryTotal(query);

        return Result.success(PageUtilsPlus.page(helpTypeList,(long)total,(long)query.getLimit(),(long)query.getPage()));
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info")
    
    @ResponseBody
    public Result info(@RequestParam("id") Integer id) {
        HelpTypeEntity helpType = helpTypeService.queryObject(id);

        return Result.success( helpType);
    }

    /**
     * 保存
     */
    @CanUserUpdateRecord
    @RequestMapping("/save")
    
    @ResponseBody
    public Result save(@RequestBody HelpTypeEntity helpType) {
        helpTypeService.save(helpType);

        return Result.success();
    }

    /**
     * 修改
     */
    @CanUserUpdateRecord
    @RequestMapping("/update")
    
    @ResponseBody
    public Result update(@RequestBody HelpTypeEntity helpType) {
        helpTypeService.update(helpType);

        return Result.success();
    }

    /**
     * 删除
     */
    @CanUserUpdateRecord
    @RequestMapping("/delete")
    
    @ResponseBody
    public Result delete(@RequestBody Integer[]ids) {
        helpTypeService.deleteBatch(ids);

        return Result.success();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public Result queryAll(@RequestBody Map<String, Object> params) {

        List<HelpTypeEntity> list = helpTypeService.queryList(params);

        return Result.success(list);
    }
}
