package cc.iotkit.manager.controller;

import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging;
import cc.iotkit.common.api.Request;
import cc.iotkit.common.api.Response;
import cc.iotkit.manager.config.BeanUtils;
import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationPageReqVO;
import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationRespVO;
import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationSaveReqVO;
import cc.iotkit.manager.dto.vo.FeedBackEvaluation.FeedBackEvaluationVO;
import cc.iotkit.manager.dto.vo.worder.WorderPageReqVO;
import cc.iotkit.manager.dto.vo.worder.WorderRespVO;
import cc.iotkit.manager.dto.vo.worder.WorderSaveReqVO;
import cc.iotkit.manager.service.FeedBackEvaluationService;
import cc.iotkit.manager.service.IWorderService;
import cc.iotkit.model.FeedBackEvaluation.FeedBackEvaluationDO;
import cc.iotkit.model.worder.WorderDO;
import cn.hutool.db.PageResult;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static cc.iotkit.common.api.Response.success;

@Api(tags = {"工单"})
@Slf4j
@RestController
@RequestMapping("/dWorder")
public class WorderController {


  @Resource
    private IWorderService worderService;

  @PostMapping("/add")
  //@Operation(summary = "创建工单")
  //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:create')")
  public Long createWorder(@Valid @RequestBody Request<WorderSaveReqVO> createReqVO) {
    return worderService.createWorder(createReqVO.getData());
  }

  @PostMapping("/edit")
  //@Operation(summary = "更新工单")
 // @PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:update')")
  public Boolean updateFeedBackEvaluation(@Valid @RequestBody Request<WorderSaveReqVO> updateReqVO) {
    worderService.updateWorder(updateReqVO.getData());
    return true;
  }

  @PostMapping("/delete")
  //@Operation(summary = "删除工单")
  //@Parameter(name = "id", description = "编号", required = true)
  //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:delete')")
  public Boolean deleteFeedBackEvaluation(@Validated @RequestBody Request<Long> request) {
    worderService.deleteWorder(request.getData());
    return true;
  }

  @PostMapping("/getDetail")
  //@Operation(summary = "获得工单")
  //@Parameter(name = "id", description = "编号", required = true, example = "1024")
  //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:query')")
  public WorderDO getFeedBackEvaluation(@Validated @RequestBody Request<Long> request) {
    WorderDO worderDO = worderService.getWorder(request.getData());
    return worderDO;
  }

  @PostMapping("/list")
  //@Operation(summary = "获得工单分页")
  //@PreAuthorize("@ss.hasPermission('installEqu:feed-back-evaluation:query')")
  public Paging<WorderRespVO> getFeedBackEvaluationPage(@Validated @RequestBody PageRequest<WorderPageReqVO> pageReqVO) {
    Paging<WorderRespVO> pageResult = worderService.getWorderPage(pageReqVO);
    return pageResult;
  }


}
