77 lines
2.5 KiB
Java
77 lines
2.5 KiB
Java
package com.gunshi.project.xyt.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.gunshi.core.result.R;
|
|
import com.gunshi.project.xyt.entity.so.RotaLogPageSo;
|
|
import com.gunshi.project.xyt.model.RotaLog;
|
|
import com.gunshi.project.xyt.service.RotaLogService;
|
|
import com.gunshi.project.xyt.validate.markers.Insert;
|
|
import com.gunshi.project.xyt.validate.markers.Update;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import jakarta.annotation.Resource;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
/**
|
|
* Description:
|
|
* Created by wanyan on 2024/3/25
|
|
*
|
|
* @author wanyan
|
|
* @version 1.0
|
|
*/
|
|
@RestController
|
|
@RequestMapping("/rota/log")
|
|
@Tag(name = "值班日志")
|
|
public class RotaLogController {
|
|
|
|
@Resource
|
|
private RotaLogService service;
|
|
|
|
@Operation(summary = "新增")
|
|
@PostMapping("/insert")
|
|
public R<RotaLog> insert(@Validated(Insert.class) @RequestBody RotaLog dto) {
|
|
checkParam(dto);
|
|
dto.setId(IdWorker.getId());
|
|
boolean result = service.save(dto);
|
|
return R.ok(result ? dto : null);
|
|
}
|
|
|
|
@Operation(summary = "修改")
|
|
@PostMapping("/update")
|
|
public R<RotaLog> update(@Validated(Update.class) @RequestBody RotaLog dto) {
|
|
checkParam(dto);
|
|
boolean result = service.updateById(dto);
|
|
return R.ok(result ? dto : null);
|
|
}
|
|
|
|
@Operation(summary = "删除")
|
|
@GetMapping("/del/{id}")
|
|
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Long id) {
|
|
return R.ok(service.removeById(id));
|
|
}
|
|
|
|
private void checkParam(RotaLog dto) {
|
|
Long id = dto.getId();
|
|
LambdaQueryWrapper<RotaLog> queryWrapper = Wrappers.lambdaQuery();
|
|
queryWrapper.eq(RotaLog::getRotaDate,dto.getRotaDate());
|
|
if(id != null){
|
|
queryWrapper.ne(RotaLog::getId,id);
|
|
}
|
|
if(service.count(queryWrapper ) > 0){
|
|
throw new IllegalArgumentException("该日期已存在值班日志");
|
|
}
|
|
}
|
|
|
|
@Operation(summary = "分页")
|
|
@PostMapping("/page")
|
|
public R<Page<RotaLog>> page(@RequestBody RotaLogPageSo rotaLogPageSo) {
|
|
return R.ok(service.queryPage(rotaLogPageSo));
|
|
}
|
|
|
|
}
|