package com.bonus.zlpt.company.controller;
import com.bonus.zlpt.common.core.web.controller.BaseController;
import com.bonus.zlpt.common.core.web.domain.AjaxResult;
import com.bonus.zlpt.common.log.annotation.Log;
import com.bonus.zlpt.common.log.enums.BusinessType;
import com.bonus.zlpt.common.security.annotation.RequiresPermissions;
import com.bonus.zlpt.company.api.domain.MaUserCollect;
import com.bonus.zlpt.company.mapper.MaUserCollectMapper;
import com.bonus.zlpt.company.service.MaUserCollectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 我的收藏
 * (ma_user_collect)表控制层
 * @author 阮世耀
*/
@RestController
@RequestMapping("/user_collect")
@Api(value = "城市控制器",tags = {"城市管理"})
public class MaUserCollectController extends BaseController {

    /**
    * 服务对象
    */
    @Resource
    private MaUserCollectService maUserCollectService;

    @Resource
    private MaUserCollectMapper maUserCollectMapper;

    /**
     * 新增 -- 收藏设备
     */
    @RequiresPermissions("system:collect:add")
    @Log(title = "收藏设备", businessType = BusinessType.INSERT)
    @PostMapping("saveCollectedEquipment")
    @ApiOperation("新增 -- 收藏设备")
    public AjaxResult saveCollectedEquipment(@RequestBody MaUserCollect obj) {
        try {
            return toAjax(maUserCollectService.insertSelective(obj));
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 获取收藏列表
     */
    @RequiresPermissions("system:collect:list")
    @GetMapping("/getColletList")
    @ApiOperation("获取收藏列表")
    public AjaxResult getColletList(MaUserCollect obj) {
        try {
            List<MaUserCollect> list = maUserCollectMapper.selectAll(obj);
            return success(getDataTable(list));
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }

    /**
     * 删除 -- 取消收藏
     */
    @RequiresPermissions("system:collect:remove")
    @Log(title = "取消收藏", businessType = BusinessType.DELETE)
    @PostMapping("cancelCollet")
    @ApiOperation("删除 -- 取消收藏")
    public AjaxResult cancelCollet(@RequestBody MaUserCollect obj) {
        try {
            return toAjax(maUserCollectService.deleteByPrimaryKey(obj));
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }


    /**
     * 查询 -- 根据设备id获取信息
     */
    @RequiresPermissions("system:collect:list")
    @Log(title = "根据设备id查询信息", businessType = BusinessType.OTHER)
    @GetMapping("selectByMaId")
    @ApiOperation("查询 -- 根据设备id获取信息")
    public AjaxResult selectByMaId(Integer maId) {
        try {
            return success(maUserCollectService.selectByMaId(maId));
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }


    /**
    * 通过主键查询单条数据
    *
    * @param id 主键
    * @return 单条数据
    */
    @GetMapping("selectOne")
    @ApiOperation("通过主键查询单条数据")
    public MaUserCollect selectOne(Integer id) {
    return maUserCollectService.selectByPrimaryKey(id);
    }

}
