package com.jeeplus.business.useSeal.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.business.project.service.dto.JyProjectDTO;
import com.jeeplus.business.useSeal.domain.Signet;
import com.jeeplus.common.utils.ResponseUtil;
import com.jeeplus.business.useSeal.service.SignetService;
import com.jeeplus.business.useSeal.service.dto.SignetDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

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

@RestController
@Api(tags ="用印")
@RequestMapping(value = "/useSeal")
public class SignetController {

    @Resource
    private SignetService signetService;


    /**
     * 列表查询
     */
    @ApiOperation(value = "用印列表查询")
    @GetMapping("/findList")
    public ResponseEntity<IPage<SignetDTO>> findList(Page<SignetDTO> signetDTOPage, SignetDTO dto) throws Exception {
       IPage<SignetDTO> signetDTOS= signetService.findList(signetDTOPage,dto);
        return ResponseEntity.ok(signetDTOS);
    }


    /**
     * 新增/修改
     */
    @ApiOperation(value = "新增、修改")
    @PostMapping("/saveForm")
    public ResponseEntity save(@RequestBody SignetDTO dto) throws Exception{
        String id = signetService.save(dto);
        return ResponseUtil.newInstance().add("businessTable", "jy_user_signet").add("businessId", id).ok ("操作成功");
    }


    /**
     * 根据id查询
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id查询")
    @GetMapping(value = "/findById")
    public ResponseEntity<SignetDTO> save(@RequestParam String id){
        SignetDTO dto = signetService.findById(id);
        return ResponseEntity.ok(dto);
    }

    /**
     * 根据id修改状态status
     * @param jyProjectDTO
     */
    @ApiOperation(value = "根据id修改状态status")
    @PostMapping(value = "/updateStatusById")
    public void updateStatusById(String id,String status) {
        signetService.updateStatusById(id,status);
    }


    /**
     * 查询用印逾期信息
     */
    @ApiOperation(value = "查询用印信息")
    @GetMapping("/findSeal")
    public String findSeal(){
        List<Signet> signetList=signetService.findSeal();
        return JSON.toJSONString(signetList);
    }

    /**
     * 查询用印未逾期信息
     */
    @ApiOperation(value = "查询用印未逾期信息")
    @GetMapping("/findSealInTime")
    public String findSealInTime(){
        List<Signet> signetList=signetService.findSealInTime();
        return JSON.toJSONString(signetList);
    }


    /**
     * 修改用印逾期状态
     */
    @ApiOperation(value = "修改用印逾期状态")
    @GetMapping(value = "/updateSealStatus")
    public void updateSealStatus(@RequestParam String id,@RequestParam String status,@RequestParam String exceedTimeStatus) {
        signetService.updateOutInstanceStatus(id,status,exceedTimeStatus);

    }

    /**
     * 根据id删除
     * @param id
     * @return
     */
    @ApiOperation(value = "根据id删除")
    @GetMapping(value = "/deleteById")
    public ResponseEntity<String> deleteById(@RequestParam String id){
        String s = signetService.deleteById(id);
        return ResponseEntity.ok(s);
    }






}
