133 lines
4.8 KiB
Java
133 lines
4.8 KiB
Java
package com.gunshi.project.hsz.controller;
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.gunshi.core.result.R;
|
|
import com.gunshi.core.session.entity.SessionUser;
|
|
import com.gunshi.project.hsz.entity.so.WaterDispatchPageSo;
|
|
import com.gunshi.project.hsz.entity.so.XlPlanPageSo;
|
|
import com.gunshi.project.hsz.entity.vo.WdCountVo;
|
|
import com.gunshi.project.hsz.model.IaCDanad;
|
|
import com.gunshi.project.hsz.model.WaterDispatch;
|
|
import com.gunshi.project.hsz.model.XlPlan;
|
|
import com.gunshi.project.hsz.service.FileAssociationsService;
|
|
import com.gunshi.project.hsz.service.WaterDispatchService;
|
|
import com.gunshi.project.hsz.validate.markers.Insert;
|
|
import com.gunshi.project.hsz.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.servlet.http.HttpServletRequest;
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.io.Serializable;
|
|
import java.time.LocalDateTime;
|
|
import java.util.Objects;
|
|
|
|
@Tag(name = "水量调度")
|
|
@RestController
|
|
@RequestMapping(value="/waterDis")
|
|
public class WaterDispatchController extends AbstractCommonFileController {
|
|
|
|
@Autowired
|
|
private WaterDispatchService waterDispatchService;
|
|
|
|
@Autowired
|
|
private FileAssociationsService fileService;
|
|
|
|
@Operation(summary = "新增")
|
|
@PostMapping("/insert")
|
|
public R<WaterDispatch> insert(@Validated(Insert.class) @RequestBody WaterDispatch dto) {
|
|
dto.setId(IdWorker.getId());
|
|
boolean flag = waterDispatchService.saveData(dto);
|
|
if(flag){
|
|
fileService.saveFile(dto.getFiles(),getGroupId(),dto.getId().toString());
|
|
}
|
|
return R.ok(dto);
|
|
}
|
|
|
|
@Operation(summary = "下发")
|
|
@GetMapping("/distribute/{id}")
|
|
public R<Boolean> distribute(@PathVariable("id") String id) {
|
|
WaterDispatch byId = waterDispatchService.getById(id);
|
|
if(byId == null){
|
|
throw new IllegalArgumentException("抱歉,该调度不存在,无法下发");
|
|
}
|
|
byId.setExeStatus(2);
|
|
boolean flag = waterDispatchService.updateById(byId);
|
|
return R.ok(flag);
|
|
}
|
|
|
|
@Operation(summary = "反馈")
|
|
@PostMapping("/feedback")
|
|
public R<WaterDispatch> feedback(@RequestBody WaterDispatch dto, HttpServletRequest request) {
|
|
SessionUser sessionUser = checkLogin(request);
|
|
if(sessionUser != null){
|
|
dto.setResPerson(sessionUser.getUserId().toString());
|
|
dto.setResPersonName(sessionUser.getUserName());
|
|
}
|
|
boolean flag = waterDispatchService.feedBack(dto);
|
|
if(flag){
|
|
fileService.saveFile(dto.getResFiles(),getResGroupId(),dto.getId().toString());
|
|
}
|
|
return R.ok(dto);
|
|
}
|
|
|
|
@Operation(summary = "更新")
|
|
@PostMapping("/update")
|
|
public R<WaterDispatch> update(@Validated(Update.class) @RequestBody WaterDispatch dto) {
|
|
boolean flag = waterDispatchService.update(dto);
|
|
if(flag){
|
|
fileService.saveFile(dto.getFiles(),getGroupId(),dto.getId().toString());
|
|
}
|
|
return R.ok(dto);
|
|
}
|
|
|
|
@Operation(summary = "删除")
|
|
@GetMapping("/del/{id}")
|
|
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
|
WaterDispatch byId = waterDispatchService.getById(id);
|
|
if(Objects.isNull(byId)){
|
|
throw new IllegalArgumentException("该计划不存在");
|
|
}
|
|
boolean flag = waterDispatchService.removeById(id);
|
|
if(flag){
|
|
fileService.deleteFile(getGroupId(),byId.getId().toString());
|
|
fileService.deleteFile(getResGroupId(),byId.getId().toString());
|
|
}
|
|
return R.ok(true);
|
|
}
|
|
|
|
@Operation(summary = "分页")
|
|
@PostMapping("/page")
|
|
public R<Page<WaterDispatch>> page(@RequestBody WaterDispatchPageSo pageSo) {
|
|
Page<WaterDispatch> res = waterDispatchService.pageQuery(pageSo);
|
|
if(!CollectionUtils.isEmpty(res.getRecords())){
|
|
res.getRecords().stream().forEach(o ->{
|
|
o.setFiles(fileService.getFiles(getGroupId(),o.getId().toString()));
|
|
o.setResFiles(fileService.getFiles2(getResGroupId(),o.getId().toString()));
|
|
});
|
|
}
|
|
return R.ok(res);
|
|
}
|
|
|
|
@Operation(summary = "统计当年完成调度次数")
|
|
@GetMapping("/count")
|
|
public R<WdCountVo> getCount(){
|
|
WdCountVo vo = waterDispatchService.getCount();
|
|
return R.ok(vo);
|
|
}
|
|
|
|
@Override
|
|
public String getGroupId() {
|
|
return "waterDispatch";
|
|
}
|
|
|
|
public String getResGroupId(){
|
|
return "waterDispatchRes";
|
|
}
|
|
}
|