InspectController.java 2.11 KB
package vion.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.github.linpeilie.Converter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import vion.dto.InspectDTO;
import vion.model.Inspect;
import vion.service.IInspectService;
import vion.vo.InspectVO;

import java.util.Date;

@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
@Slf4j
public class InspectController {

    private final IInspectService inspectService;
    private final Converter converter;

    @GetMapping("/inspects")
    @SaCheckPermission(value = "inspect:list", orRole = "admin")
    public Page<InspectVO> getInspectList(InspectDTO data) {
        return inspectService.getInspectList(data);
    }

    @GetMapping("/inspect")
    @SaCheckPermission(value = "inspect:query", orRole = "admin")
    public InspectVO getById(@RequestParam(name = "id") Long id) {
        return inspectService.getById(id);
    }

    @PostMapping("/inspects")
    @SaCheckPermission(value = "inspect:editAndSave", orRole = "admin")
    public String saveOrUpdate(@RequestBody InspectDTO data) {
        Inspect inspect = converter.convert(data, Inspect.class);
        return inspectService.saveOrUpdate(inspect) ? "成功" : "失败";
    }

    @PostMapping("/updateInspectStatus")
    @SaCheckPermission(value = "inspect:editStatus", orRole = "admin")
    public String UpdateStatus(@RequestBody InspectDTO data) {
        boolean result = inspectService.lambdaUpdate()
                .eq(Inspect::getId, data.getId())
                .set(Inspect::getStatus, data.getStatus())
                .set(Inspect::getAuditDate, new Date())
                .set(Inspect::getReviewer, data.getReviewer())
                //审核状态为已完成的时候更新完成时间(0进行中、1待审核、2已完成、3、驳回)
                .set(data.getStatus() == 2, Inspect::getFinishDate, new Date())
                .update();
        return result ? "更新巡检状态成功" : "更新巡检状态失败";
    }
}