package com.elephant.framework.galaxy.aroad.module.zhjg.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.elephant.framework.galaxy.aroad.module.zhjg.entity.ZhjgDckhRw;
import com.elephant.framework.galaxy.aroad.module.zhjg.service.ZhjgDckhRwService;
import com.elephant.framework.galaxy.aroad.response.R;
import com.elephant.framework.galaxy.aroad.module.common.annotation.SysLog;
import com.elephant.framework.galaxy.aroad.module.zhjg.entity.ZhjgDckhRwFk;
import com.elephant.framework.galaxy.aroad.module.zhjg.service.ZhjgDckhRwFkService;
import com.elephant.framework.galaxy.aroad.util.SecurityUtils;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.elephant.framework.galaxy.aroad.module.common.controller.BaseController;

import java.time.LocalDateTime;


/**
 * 督查任务反馈
 *
 * @author zyw
 * @date 2019-04-16 15:58:24
 */
@RestController
@AllArgsConstructor
@RequestMapping("/zhjg/zhjgdckhrwfk")
public class ZhjgDckhRwFkController extends BaseController  {

  private final  ZhjgDckhRwFkService zhjgDckhRwFkService;
  private final ZhjgDckhRwService zhjgDckhRwService;

  /**
   * 分页查询
   * @param page 分页对象
   * @param zhjgDckhRwFk 督查任务反馈
   * @return
   */
  @GetMapping("/page")
  public R getZhjgDckhRwFkPage(Page page, ZhjgDckhRwFk zhjgDckhRwFk) {
    return  new R<>(zhjgDckhRwFkService.page(page,Wrappers.query(zhjgDckhRwFk)));
  }


  /**
   * 通过id查询督查任务反馈
   * @param id id
   * @return R
   */
  @GetMapping("/{id}")
  public R getById(@PathVariable("id") Integer id){
    return new R<>(zhjgDckhRwFkService.getById(id));
  }

  /**
   * 新增督查任务反馈
   * @param zhjgDckhRwFk 督查任务反馈
   * @return R
   */
  @SysLog("新增督查任务反馈")
  @PostMapping
  public R save(@RequestBody ZhjgDckhRwFk zhjgDckhRwFk){
      Integer deptId = SecurityUtils.getUser().getDeptId();
      zhjgDckhRwFk.setFkdw(deptId);
      zhjgDckhRwFk.setFksj(LocalDateTime.now());
      ZhjgDckhRw  rw = zhjgDckhRwService.getById(zhjgDckhRwFk.getRwid());
      if (rw !=null){
        rw.setFkzt("1");
        zhjgDckhRwService.updateById(rw);
      }
    return new R<>(zhjgDckhRwFkService.save(zhjgDckhRwFk));
  }

  /**
   * 修改督查任务反馈
   * @param zhjgDckhRwFk 督查任务反馈
   * @return R
   */
  @SysLog("修改督查任务反馈")
  @PutMapping
  public R updateById(@RequestBody ZhjgDckhRwFk zhjgDckhRwFk){
    return new R<>(zhjgDckhRwFkService.updateById(zhjgDckhRwFk));
  }

  /**
   * 通过id删除督查任务反馈
   * @param id id
   * @return R
   */
  @SysLog("删除督查任务反馈")
  @DeleteMapping("/{id}")
  public R removeById(@PathVariable Integer id){
    return new R<>(zhjgDckhRwFkService.removeById(id));
  }

}
