package com.djhk.uav.plotting.controller;


import com.djhk.common.core.controller.BaseController;
import com.djhk.common.core.domain.AjaxResult;
import com.djhk.common.core.domain.entity.SysUser;
import com.djhk.common.core.page.TableDataInfo;
import com.djhk.common.utils.DateUtils;
import com.djhk.common.utils.SecurityUtils;
import com.djhk.system.service.ISysUserService;
import com.djhk.uav.plotting.modol.Plotting;
import com.djhk.uav.plotting.service.PlottingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 图上标绘Controller
 *
 * @author huangqg
 * @date 2024-04-09
 */
@RestController
@RequestMapping("/plotting")
public class PlottingController extends BaseController {

    @Autowired
    private PlottingService plottingService;

    @Autowired
    private ISysUserService userService;

    @Autowired
    private RedisTemplate redisTemplate;

    private List<Plotting> list;

    /**
     * 查询图上标会
     */
    @GetMapping("/list")
    public TableDataInfo getList()
    {
//        SysUser sysUser = userService.getUserInfoByUserId(SecurityUtils.getUserId(), SecurityConstants.INNER).getData();
        SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
        list = plottingService.selectPlottingList(sysUser.getDeptId());
        return getDataTable(list);
    }


    /**
     * 查询详情
     */
    @GetMapping(value = "/{plottingId}")
    public AjaxResult selectPlottingById(@PathVariable Long plottingId){
        return AjaxResult.success(plottingService.selectPlottingById(plottingId));
    }


    /**
     * 新增图上标绘
     */
    @PostMapping
    public AjaxResult add(@RequestBody Plotting plotting){
        logger.info("plotting数据为："+plotting.toString());
//        SysUser sysUser = userService.getUserInfoByUserId(SecurityUtils.getUserId(), SecurityConstants.INNER).getData();
        SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
        Date nowDate = DateUtils.getNowDate();
        plotting.setCreateTime(nowDate);
        plotting.setCreateBy(sysUser.getUserName());
        plotting.setSysDeptNo(sysUser.getDeptId());
        return AjaxResult.success(plottingService.insertPlotting(plotting));
    }

    /**
     * 修改
     */
    @PutMapping
    public  AjaxResult edit(@RequestBody Plotting plotting){
//        SysUser sysUser = userService.getUserInfoByUserId(SecurityUtils.getUserId(), SecurityConstants.INNER).getData();
        SysUser sysUser = userService.selectUserById(SecurityUtils.getUserId());
        Date nowDate = DateUtils.getNowDate();
        plotting.setUpdateTime(nowDate);
        plotting.setUpdateBy(sysUser.getUserName());
        return AjaxResult.success(plottingService.updatePlotting(plotting));
    }

    /**
     * 删除
     */
    @DeleteMapping(value = "/{plottingIds}")
    public  AjaxResult delete(@PathVariable Long[] plottingIds){
        return AjaxResult.success(plottingService.deletePlottingByIds(plottingIds));
    }


}
