From 0849b4fd1ad5626710d0aebecd1f3e419573173a Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 18 九月 2024 21:03:35 +0800 Subject: [PATCH] 11 --- /dev/null | 35 --- docker/init/init.sql | 3 src/main/resources/mapper/SimuMapper.xml | 7 src/main/java/com/se/simu/domain/po/SimuPo.java | 80 ++++++++ src/main/java/com/se/simu/service/SimuService.java | 113 ++++++++++++ src/main/java/com/se/simu/domain/vo/SimuVo.java | 93 ++++++++++ src/main/java/com/se/simu/mapper/SimuMapper.java | 23 ++ src/main/java/com/se/simu/domain/vo/CreateSimuVo.java | 73 ++++++++ src/main/java/com/se/simu/controller/SimuController.java | 77 +++++++- 9 files changed, 455 insertions(+), 49 deletions(-) diff --git a/docker/init/init.sql b/docker/init/init.sql index 585366d..da96107 100644 --- a/docker/init/init.sql +++ b/docker/init/init.sql @@ -30,5 +30,4 @@ comment on column bs.simu.bak is '澶囨敞'; -- insert into bs.simu (pid, num, name, data, status, result, bak) values (0, 1, '浠跨湡01', null, 0, '', null); - -select * from bs.simu; +-- select * from bs.simu; diff --git a/src/main/java/com/se/simu/controller/SimuController.java b/src/main/java/com/se/simu/controller/SimuController.java index 60fdd44..2b113d3 100644 --- a/src/main/java/com/se/simu/controller/SimuController.java +++ b/src/main/java/com/se/simu/controller/SimuController.java @@ -1,13 +1,20 @@ package com.se.simu.controller; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.se.simu.domain.po.SimuPo; import com.se.simu.domain.vo.CreateSimuVo; import com.se.simu.domain.vo.R; +import com.se.simu.domain.vo.SimuVo; +import com.se.simu.helper.StringHelper; import com.se.simu.service.GedbService; +import com.se.simu.service.SimuService; import io.swagger.annotations.*; import lombok.extern.slf4j.Slf4j; +import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; +import java.util.Date; import java.util.List; /** @@ -25,16 +32,32 @@ @Resource GedbService gedbService; + @Resource + SimuService simuService; + @ApiOperation(value = "鍒涘缓") @PostMapping(value = "/create", produces = "application/json; charset=UTF-8") public R<Object> create(@RequestBody @ApiParam("鍒涘缓浠跨湡瑙嗗浘绫�") CreateSimuVo vo) { try { - // 469538.6536261877,4416744.922022615,469853.14714664617,4417049.378602433 - String bbox = "116.64388473935195,39.884315914604464,116.64754729082588,39.887069143903496"; - String taskName = "20240913"; - Object rs = gedbService.test(bbox, taskName); + if (null == vo.getTotal() || vo.getTotal() < 1 || vo.getTotal() > 1000) { + return fail("闄嶉洦閲忎笉鑳戒负绌猴紝涓斿彇鍊煎湪1~1000涔嬮棿"); + } + if (null == vo.getDuration() || vo.getDuration() < 1 || vo.getDuration() > 120) { + return fail("浠跨湡鏃堕暱涓嶈兘涓虹┖锛屼笖鍙栧�煎湪1~120涔嬮棿"); + } + if (null == vo.getMinx() || null == vo.getMiny() || null == vo.getMaxx() || null == vo.getMaxy()) { + return fail("閫夋嫨鑼冨洿涓嶈兘涓虹┖", false); + } + if (StringHelper.isEmpty(vo.getName())) { + vo.setName(StringHelper.YMDHMS2_FORMAT.format(new Date())); + } + if (null == vo.getNum() || vo.getNum() < 1) { + vo.setNum(simuService.getMaxId() + 1); + } - return success(rs); + boolean flag = simuService.create(vo); + + return success(flag, flag ? "鎴愬姛" : "澶辫触"); } catch (Exception ex) { return fail(ex, null); } @@ -42,14 +65,18 @@ @ApiOperation(value = "鍒犻櫎") @ApiImplicitParams({ - @ApiImplicitParam(name = "ids", value = "浠诲姟ID", dataType = "Integer", paramType = "query", allowMultiple = true, example = "2") + @ApiImplicitParam(name = "ids", value = "ID", dataType = "Integer", paramType = "query", allowMultiple = true, example = "0") }) @GetMapping(value = "/del") public R<Object> del(@RequestParam List<Integer> ids) { try { - // + if (ids == null || ids.isEmpty()) { + return fail("鏃ュ織ID涓嶈兘涓虹┖", null); + } - return success(0); + int count = simuService.del(ids); + + return success(count); } catch (Exception ex) { return fail(ex, null); } @@ -57,11 +84,39 @@ @ApiOperation(value = "鑾峰彇") @GetMapping("/get") - public R<Object> get(@ApiParam("浠诲姟瑙嗗浘绫�") Object vo) { + public R<Object> get(@ApiParam("浠跨湡瑙嗗浘绫�") SimuVo vo) { try { - // + if (null == vo) { + vo = new SimuVo(); + } + if (null == vo.getPageSize() || vo.getPageSize() < 1) { + vo.setPageSize(10); + } + if (null == vo.getPageIndex() || vo.getPageIndex() < 1) { + vo.setPageIndex(1); + } - return success(null, 0); + IPage<SimuPo> paged = simuService.get(vo); + if (null == paged) { + return success(null, 0); + } + + return success(paged.getRecords(), paged.getTotal()); + } catch (Exception ex) { + return fail(ex, null); + } + } + + @ApiOperation(value = "* Test *") + @GetMapping("/test") + public R<Object> test(@ApiParam("浠跨湡瑙嗗浘绫�") SimuVo vo) { + try { + // 469538.6536261877,4416744.922022615,469853.14714664617,4417049.378602433 + String bbox = "116.64388473935195,39.884315914604464,116.64754729082588,39.887069143903496"; + String taskName = "20240913"; + Object rs = gedbService.test(bbox, taskName); + + return success(rs); } catch (Exception ex) { return fail(ex, null); } diff --git a/src/main/java/com/se/simu/domain/po/SimuPo.java b/src/main/java/com/se/simu/domain/po/SimuPo.java index 035fdd6..22336af 100644 --- a/src/main/java/com/se/simu/domain/po/SimuPo.java +++ b/src/main/java/com/se/simu/domain/po/SimuPo.java @@ -46,4 +46,84 @@ @ApiModelProperty("澶囨敞") private String bak; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Integer getPid() { + return pid; + } + + public void setPid(Integer pid) { + this.pid = pid; + } + + public Integer getNum() { + return num; + } + + public void setNum(Integer num) { + this.num = num; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + public Short getStatus() { + return status; + } + + public void setStatus(Short status) { + this.status = status; + } + + public String getResult() { + return result; + } + + public void setResult(String result) { + this.result = result; + } + + public Timestamp getCreateTime() { + return createTime; + } + + public void setCreateTime(Timestamp createTime) { + this.createTime = createTime; + } + + public Timestamp getUpdateTime() { + return updateTime; + } + + public void setUpdateTime(Timestamp updateTime) { + this.updateTime = updateTime; + } + + public String getBak() { + return bak; + } + + public void setBak(String bak) { + this.bak = bak; + } } diff --git a/src/main/java/com/se/simu/domain/vo/CreateSimuVo.java b/src/main/java/com/se/simu/domain/vo/CreateSimuVo.java index 8284a78..e56310b 100644 --- a/src/main/java/com/se/simu/domain/vo/CreateSimuVo.java +++ b/src/main/java/com/se/simu/domain/vo/CreateSimuVo.java @@ -12,7 +12,6 @@ * @author WWW * @date 2024-09-18 */ -@Data @ToString @SuppressWarnings("ALL") @ApiModel(value = "鍒涘缓浠跨湡瑙嗗浘绫�") @@ -44,4 +43,76 @@ @ApiModelProperty("浠跨湡澶囨敞") private String bak; + + public Double getMinx() { + return minx; + } + + public void setMinx(Double minx) { + this.minx = minx; + } + + public Double getMiny() { + return miny; + } + + public void setMiny(Double miny) { + this.miny = miny; + } + + public Double getMaxx() { + return maxx; + } + + public void setMaxx(Double maxx) { + this.maxx = maxx; + } + + public Double getMaxy() { + return maxy; + } + + public void setMaxy(Double maxy) { + this.maxy = maxy; + } + + public Integer getNum() { + return num; + } + + public void setNum(Integer num) { + this.num = num; + } + + public Double getTotal() { + return total; + } + + public void setTotal(Double total) { + this.total = total; + } + + public Integer getDuration() { + return duration; + } + + public void setDuration(Integer duration) { + this.duration = duration; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getBak() { + return bak; + } + + public void setBak(String bak) { + this.bak = bak; + } } diff --git a/src/main/java/com/se/simu/domain/vo/SimuVo.java b/src/main/java/com/se/simu/domain/vo/SimuVo.java new file mode 100644 index 0000000..9f427e3 --- /dev/null +++ b/src/main/java/com/se/simu/domain/vo/SimuVo.java @@ -0,0 +1,93 @@ +package com.se.simu.domain.vo; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModelProperty; + +import java.util.List; + +/** + * 浠跨湡瑙嗗浘绫� + * + * @author WWW + * @date 2024-09-18 + */ +@TableName("bs.simu") +@SuppressWarnings("ALL") +public class SimuVo { + @ApiModelProperty("ID") + private Long id; + + @ApiModelProperty("鐖禝D") + private Integer pid; + + @ApiModelProperty("搴忓彿") + private Integer num; + + @ApiModelProperty("鍚嶇О") + private String name; + + @ApiModelProperty("鐘舵�侊細0-鍒涘缓浠跨湡锛�1-杩炴帴GEDB搴擄紝2-涓嬭浇绌洪棿鏁版嵁锛�3-涓嬭浇楂樼▼鏁版嵁锛�4-妯℃嫙鍐呮稘浠跨湡锛�5-澶勭悊浠跨湡鏁版嵁锛�10-瀹屾垚锛�-10-鍑洪敊") + private List<Short> status; + + @ApiModelProperty("鍒嗛〉澶у皬") + private Integer pageSize; + + @ApiModelProperty("褰撳墠椤电爜") + private Integer pageIndex; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public Integer getPid() { + return pid; + } + + public void setPid(Integer pid) { + this.pid = pid; + } + + public Integer getNum() { + return num; + } + + public void setNum(Integer num) { + this.num = num; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List<Short> getStatus() { + return status; + } + + public void setStatus(List<Short> status) { + this.status = status; + } + + public Integer getPageSize() { + return pageSize; + } + + public void setPageSize(Integer pageSize) { + this.pageSize = pageSize; + } + + public Integer getPageIndex() { + return pageIndex; + } + + public void setPageIndex(Integer pageIndex) { + this.pageIndex = pageIndex; + } +} diff --git a/src/main/java/com/se/simu/domain/vo/TaskVo.java b/src/main/java/com/se/simu/domain/vo/TaskVo.java deleted file mode 100644 index 4ba6ead..0000000 --- a/src/main/java/com/se/simu/domain/vo/TaskVo.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.se.simu.domain.vo; - -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiModelProperty; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.ToString; - -/** - * 浠诲姟瑙嗗浘绫� - * - * @author WWW - * @date 2024-09-18 - */ -@Data -@ToString -@SuppressWarnings("ALL") -@ApiModel(value = "浠诲姟瑙嗗浘绫�") -@EqualsAndHashCode(callSuper = false) -public class TaskVo { - @ApiModelProperty("搴忓彿") - private Integer num; - - @ApiModelProperty("鍚嶇О") - private String name; - - @ApiModelProperty("鍒嗛〉澶у皬") - private Integer pageSize; - - @ApiModelProperty("褰撳墠椤电爜") - private Integer pageIndex; - - public TaskVo() { - } -} diff --git a/src/main/java/com/se/simu/mapper/SimuMapper.java b/src/main/java/com/se/simu/mapper/SimuMapper.java new file mode 100644 index 0000000..84ae72b --- /dev/null +++ b/src/main/java/com/se/simu/mapper/SimuMapper.java @@ -0,0 +1,23 @@ +package com.se.simu.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.se.simu.domain.po.SimuPo; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Repository; + +/** + * 浠跨湡Mapper + * + * @author WWW + * @date 2024-09-18 + */ +@Mapper +@Repository +public interface SimuMapper extends BaseMapper<SimuPo> { + /** + * 鏌ヨ鏈�澶D + * + * @return 鏈�澶D + */ + Integer selectMaxId(); +} diff --git a/src/main/java/com/se/simu/service/SimuService.java b/src/main/java/com/se/simu/service/SimuService.java new file mode 100644 index 0000000..3ea9084 --- /dev/null +++ b/src/main/java/com/se/simu/service/SimuService.java @@ -0,0 +1,113 @@ +package com.se.simu.service; + +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.io.FileUtil; +import cn.hutool.json.JSONUtil; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.metadata.OrderItem; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.se.simu.domain.po.DataPo; +import com.se.simu.domain.po.SimuPo; +import com.se.simu.domain.vo.CreateSimuVo; +import com.se.simu.domain.vo.SimuVo; +import com.se.simu.helper.StringHelper; +import com.se.simu.mapper.SimuMapper; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; + +import javax.annotation.Resource; +import java.io.File; +import java.util.List; + +/** + * 浠跨湡鏈嶅姟绫� + * + * @author WWW + * @date 2024-09-18 + */ +@Slf4j +@Service +@SuppressWarnings("ALL") +public class SimuService { + @Value("${sys.path.in}") + String inPath; + + @Value("${sys.path.out}") + String outPath; + + @Resource + SimuMapper simuMapper; + + public Integer getMaxId() { + return simuMapper.selectMaxId(); + } + + public boolean create(CreateSimuVo vo) { + return true; + } + + public int del(List<Integer> ids) { + List<SimuPo> list = simuMapper.selectBatchIds(ids); + if (null != list && list.size() > 0) { + for (SimuPo po : list) { + try { + if (StringHelper.isEmpty(po.getData())) continue; + + DataPo dp = JSONUtil.toBean(po.getData(), DataPo.class); + if (null == dp) continue; + + delDir(inPath + File.separator + dp.getInPath()); + delDir(outPath + File.separator + dp.getOutPath()); + } catch (Exception ex) { + log.error(ex.getMessage(), ex); + } + } + } + + return simuMapper.deleteBatchIds(ids); + } + + private boolean delDir(String dir) { + File file = new File(dir); + if (!file.exists() || !file.isDirectory()) { + return false; + } + + return FileUtil.del(dir); + } + + public IPage<SimuPo> get(SimuVo vo) { + QueryWrapper<SimuPo> wrapper = getPageWrapper(vo); + + Page<SimuPo> page = new Page<>(vo.getPageIndex(), vo.getPageSize()); + page.addOrder(OrderItem.desc("id")); + + IPage<SimuPo> paged = simuMapper.selectPage(page, wrapper); + + return paged; + } + + private QueryWrapper<SimuPo> getPageWrapper(SimuVo vo) { + QueryWrapper<SimuPo> wrapper = new QueryWrapper<>(); + if (null != vo.getId()) { + wrapper.eq("id", vo.getId()); + } + if (null != vo.getPid()) { + wrapper.eq("pid", vo.getPid()); + } + if (null != vo.getNum()) { + wrapper.eq("num", vo.getNum()); + } + if (!StringUtils.isEmpty(vo.getName())) { + wrapper.like("lower(name)", vo.getName().trim().toLowerCase()); + } + if (!CollUtil.isEmpty(vo.getStatus())) { + wrapper.in("status", vo.getStatus()); + } + + return wrapper; + } +} diff --git a/src/main/resources/mapper/SimuMapper.xml b/src/main/resources/mapper/SimuMapper.xml new file mode 100644 index 0000000..e9ed9bb --- /dev/null +++ b/src/main/resources/mapper/SimuMapper.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="com.se.simu.mapper.SimuMapper"> + <select id="selectMaxId" resultType="java.lang.Integer"> + select coalesce(max(id), 0) from bs.simu; + </select> +</mapper> \ No newline at end of file -- Gitblit v1.9.3