package com.se.nsl.controller;
|
|
import com.alibaba.fastjson.JSON;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.se.nsl.domain.po.Simu;
|
import com.se.nsl.domain.po.SimuData;
|
import com.se.nsl.domain.vo.R;
|
import com.se.nsl.domain.vo.SimuVo;
|
import com.se.nsl.service.ResolveService;
|
import com.se.nsl.service.SimuService;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.util.StringUtils;
|
import org.springframework.web.bind.annotation.*;
|
|
import javax.annotation.Resource;
|
import java.util.List;
|
|
@Api(tags = "03-推演模拟")
|
@Slf4j
|
@RestController
|
@RequestMapping("/simu")
|
@SuppressWarnings("ALL")
|
public class SimuController extends BaseController {
|
@Resource
|
SimuService simuService;
|
|
@Resource
|
ResolveService resolveService;
|
|
/**
|
* 分页查询推演模拟
|
*
|
* @param pageNum 页码
|
* @param pageSize 每页数量
|
* @return 分页后的推演模拟
|
*/
|
@ApiOperation(value = "selectPage")
|
@GetMapping("/selectPage")
|
public R<Object> selectPage(SimuVo vo, Integer pageNum, Integer pageSize) {
|
try {
|
if (null == pageNum || pageNum < 1) pageNum = 1;
|
if (null == pageSize || pageSize < 1) pageSize = 10;
|
if (pageSize > 1000) pageSize = 1000;
|
|
IPage<Simu> paged = simuService.selectPage(vo, pageNum, pageSize);
|
if (null == paged) {
|
return success(null, 0);
|
}
|
|
return success(paged.getRecords(), paged.getTotal());
|
} catch (Exception ex) {
|
return fail(ex, null);
|
}
|
}
|
|
/**
|
* 根据ID批量删除推演模拟
|
*
|
* @param ids 要删除的推演模拟ID列表
|
* @return 删除成功的记录数
|
*/
|
@ApiOperation(value = "deleteByIds")
|
@DeleteMapping("/deleteByIds")
|
public R<Object> deleteByIds(@RequestParam List<Integer> ids) {
|
try {
|
return success(simuService.deleteByIds(ids));
|
} catch (Exception ex) {
|
return fail(ex, null);
|
}
|
}
|
|
/**
|
* 新增推演模拟
|
*
|
* @param simu 推演模拟对象
|
* @return 新增成功的记录数
|
*/
|
@ApiOperation(value = "insert")
|
@PostMapping(value = "/insert", produces = "application/json; charset=UTF-8")
|
public R<Object> insert(@RequestBody Simu simu) {
|
try {
|
if (StringUtils.isEmpty(simu.getData())) return fail("data为空");
|
|
SimuData data = JSON.parseObject(simu.getData(), SimuData.class);
|
if (null == data) return fail("data数据格式(JSON)不正确");
|
|
int rows = simuService.insert(simu);
|
|
return success(rows);
|
} catch (Exception ex) {
|
return fail(ex, null);
|
}
|
}
|
|
@ApiOperation(value = "start")
|
@GetMapping(value = "/start", produces = "application/json; charset=UTF-8")
|
public R<Object> start(Integer id) {
|
try {
|
if (null == id || id < 1) return fail("id为空");
|
|
Simu simu = simuService.selectById(id);
|
if (null == simu) return fail("方案找不到");
|
if (StringUtils.isEmpty(simu.getData())) return fail("方案数据(JSON)为空");
|
|
SimuData data = JSON.parseObject(simu.getData(), SimuData.class);
|
if (null == data) return fail("方案数据格式(JSON)不正确");
|
|
//if (simu.getStatus() != 0) return fail("方案正在运行或已完成");
|
if (StringUtils.isEmpty(simu.getGeom())) return fail("方案的图形为空");
|
|
int rows = resolveService.start(simu);
|
|
return success("ok");
|
} catch (Exception ex) {
|
return fail(ex, null);
|
}
|
}
|
|
/**
|
* 修改推演模拟
|
*
|
* @param simu 推演模拟对象
|
* @return 修改成功的记录数
|
*/
|
@ApiOperation(value = "updateById")
|
@PutMapping(value = "/updateById", produces = "application/json; charset=UTF-8")
|
public R<Object> updateById(@RequestBody Simu simu) {
|
try {
|
return success(simuService.updateById(simu));
|
} catch (Exception ex) {
|
return fail(ex, null);
|
}
|
}
|
}
|