package com.platform.controller;

import com.platform.annotation.CanUserUpdateRecord;
import com.platform.entity.HelpIssueEntity;
import com.platform.entity.Result;
import com.platform.service.HelpIssueService;
import com.platform.utils.PageUtils;
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("helpissue")
public class HelpIssueController {
    @Autowired
    private HelpIssueService helpIssueService;

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

        List<HelpIssueEntity> helpIssueList = helpIssueService.queryList(query);
        int total = helpIssueService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(helpIssueList, total, query.getLimit(), query.getPage());

        return Result.success(pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    
    @ResponseBody
    public Result info(@PathVariable("id") Integer id) {
        HelpIssueEntity helpIssue = helpIssueService.queryObject(id);

        return Result.success(helpIssue);
    }

    /**
     * 保存
     */
    @CanUserUpdateRecord
    @RequestMapping("/save")
    
    @ResponseBody
    public Result save(@RequestBody HelpIssueEntity helpIssue) {
        helpIssueService.save(helpIssue);

        return Result.success();
    }

    /**
     * 修改
     */
    @CanUserUpdateRecord
    @RequestMapping("/update")
    
    @ResponseBody
    public Result update(@RequestBody HelpIssueEntity helpIssue) {
        helpIssueService.update(helpIssue);

        return Result.success();
    }

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

        return Result.success();
    }

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

        List<HelpIssueEntity> list = helpIssueService.queryList(params);

        return Result.success( list);
    }
}
