 package com.huimv.management.controller;

import java.util.Arrays;
import java.util.Map;

import com.huimv.management.entity.CameraInfoEntity;
import com.huimv.management.entity.SysUserEntity;
import com.huimv.management.util.GetUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.huimv.management.entity.UserAttentionEntity;
import com.huimv.management.service.UserAttentionService;
import com.huimv.common.utils.PageUtils;
import com.huimv.common.utils.R;

import javax.servlet.http.HttpServletRequest;


 /**
 * 
 *
 * @author yinhao
 * @version ${version}
 * @date 2021-07-13 15:48:41
 */
@RestController
@RequestMapping("management/userattention")
public class UserAttentionController {
    @Autowired
    private UserAttentionService userAttentionService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userAttentionService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		UserAttentionEntity userAttention = userAttentionService.getById(id);

        return R.ok().put("userAttention", userAttention);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody UserAttentionEntity userAttention){
		userAttentionService.save(userAttention);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody UserAttentionEntity userAttention){
		userAttentionService.updateById(userAttention);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		userAttentionService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

     //修改关注状态
     @RequestMapping("/updateAttention")
     private R updateAttention(@RequestParam Integer cameraId, HttpServletRequest request) {
         SysUserEntity user = GetUserUtil.getUser(request);
         if (user == null){
             return R.error("获取用户信息异常");
         }
         if (cameraId == null){
             return R.error("获取摄像头信息异常");
         }
        return userAttentionService.updateAttention(cameraId,user.getUserId());
     }
}
