diff --git a/src/main/java/com/gunshi/project/xyt/Main.java b/src/main/java/com/gunshi/project/xyt/Main.java index a5bbb69..ff27575 100644 --- a/src/main/java/com/gunshi/project/xyt/Main.java +++ b/src/main/java/com/gunshi/project/xyt/Main.java @@ -7,6 +7,7 @@ import io.swagger.v3.oas.annotations.servers.Server; import lombok.extern.slf4j.Slf4j; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; +import org.springframework.cache.annotation.EnableCaching; @OpenAPIDefinition( servers = { @@ -24,6 +25,7 @@ import org.springframework.boot.SpringApplication; @MapperScan(basePackages = {"com.gunshi.**.mapper", "com.gunshi.**.model"}) @Slf4j @EnableMPP +@EnableCaching public class Main { public static void main(String[] args) { SpringApplication.run(Main.class, args); diff --git a/src/main/java/com/gunshi/project/xyt/controller/AttCctvBaseController.java b/src/main/java/com/gunshi/project/xyt/controller/AttCctvBaseController.java index a7dfce2..c148e41 100644 --- a/src/main/java/com/gunshi/project/xyt/controller/AttCctvBaseController.java +++ b/src/main/java/com/gunshi/project/xyt/controller/AttCctvBaseController.java @@ -1,6 +1,10 @@ package com.gunshi.project.xyt.controller; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gunshi.core.result.R; +import com.gunshi.project.xyt.entity.so.AttCctvBasePage; import com.gunshi.project.xyt.model.AttCctvBase; import com.gunshi.project.xyt.service.AttCctvBaseService; import com.gunshi.project.xyt.validate.markers.Insert; @@ -56,8 +60,21 @@ public class AttCctvBaseController { @Operation(summary = "分页") @PostMapping("/page") - public R> page() { - return R.ok(service.page(null,null)); + public R> page(@RequestBody @Validated AttCctvBasePage page) { + LambdaQueryChainWrapper query = service.lambdaQuery(); + if (ObjectUtils.isNotNull(page.getCode())) { + query.like(AttCctvBase::getIndexCode, page.getCode()); + } + if (ObjectUtils.isNotNull(page.getMenuId())) { + query.like(AttCctvBase::getMenuId, page.getMenuId()); + } + if (ObjectUtils.isNotNull(page.getName())) { + query.like(AttCctvBase::getName, page.getName()); + } + if (ObjectUtils.isNotNull(page.getType())) { + query.eq(AttCctvBase::getType, Integer.valueOf(page.getType())); + } + return R.ok(service.page(page.getPageSo().toPage(), query)); } } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/controller/AttDamBaseController.java b/src/main/java/com/gunshi/project/xyt/controller/AttDamBaseController.java index 3f2f90f..71aea5c 100644 --- a/src/main/java/com/gunshi/project/xyt/controller/AttDamBaseController.java +++ b/src/main/java/com/gunshi/project/xyt/controller/AttDamBaseController.java @@ -1,6 +1,10 @@ package com.gunshi.project.xyt.controller; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gunshi.core.result.R; +import com.gunshi.project.xyt.entity.so.GeneralDataPage; import com.gunshi.project.xyt.model.AttDamBase; import com.gunshi.project.xyt.service.AttDamBaseService; import com.gunshi.project.xyt.validate.markers.Insert; @@ -14,6 +18,8 @@ import org.springframework.web.bind.annotation.*; import java.io.Serializable; import java.util.List; +import java.util.Objects; + /** * 描述: 大坝表 * author: xusan @@ -38,6 +44,9 @@ public class AttDamBaseController { @Operation(summary = "修改") @PostMapping("/update") public R update(@Validated(Update.class) @RequestBody AttDamBase dto) { + if (Objects.isNull(service.getById(dto.getDamCode()))) { + throw new RuntimeException("当前数据不存在"); + } boolean result = service.updateById(dto); return R.ok(result ? dto : null); } @@ -45,6 +54,9 @@ public class AttDamBaseController { @Operation(summary = "删除") @GetMapping("/del/{id}") public R del(@Schema(name = "id") @PathVariable("id") Serializable id) { + if (Objects.isNull(service.getById(id))) { + throw new RuntimeException("当前数据不存在"); + } return R.ok(service.removeById(id)); } @@ -56,8 +68,15 @@ public class AttDamBaseController { @Operation(summary = "分页") @PostMapping("/page") - public R> page() { - return R.ok(service.page(null,null)); + public R> page(@RequestBody @Validated GeneralDataPage page) { + LambdaQueryChainWrapper query = service.lambdaQuery(); + if (ObjectUtils.isNotNull(page.getCode())){ + query.like(AttDamBase::getDamCode, page.getCode()); + } + if (ObjectUtils.isNotNull(page.getName())){ + query.like(AttDamBase::getDamName, page.getName()); + } + return R.ok(service.page(page.getPageSo().toPage(),query)); } } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/controller/AttDamProfileController.java b/src/main/java/com/gunshi/project/xyt/controller/AttDamProfileController.java index 113b552..57483db 100644 --- a/src/main/java/com/gunshi/project/xyt/controller/AttDamProfileController.java +++ b/src/main/java/com/gunshi/project/xyt/controller/AttDamProfileController.java @@ -1,9 +1,14 @@ package com.gunshi.project.xyt.controller; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gunshi.core.result.R; +import com.gunshi.project.xyt.entity.so.GeneralDataPage; import com.gunshi.project.xyt.entity.vo.ProfilePressTreeVo; import com.gunshi.project.xyt.model.AttDamProfile; import com.gunshi.project.xyt.service.AttDamProfileService; +import com.gunshi.project.xyt.service.FileAssociationsService; import com.gunshi.project.xyt.validate.markers.Insert; import com.gunshi.project.xyt.validate.markers.Update; import io.swagger.v3.oas.annotations.Operation; @@ -15,6 +20,7 @@ import org.springframework.web.bind.annotation.*; import java.io.Serializable; import java.util.List; +import java.util.Objects; /** * 描述: 监测断面信息表 @@ -24,29 +30,46 @@ import java.util.List; @Tag(name = "监测断面信息表") @RestController @RequestMapping(value="/attDamProfile") -public class AttDamProfileController { +public class AttDamProfileController extends AbstractCommonFileController{ @Autowired private AttDamProfileService service; + @Autowired + private FileAssociationsService fileService; @Operation(summary = "新增") @PostMapping("/insert") public R insert(@Validated(Insert.class) @RequestBody AttDamProfile dto) { + if (Objects.nonNull(service.lambdaQuery().eq(AttDamProfile::getProfileName,dto.getProfileName()))) { + throw new RuntimeException("当前名称已存在"); + } boolean result = service.save(dto); + if (result){ + fileService.saveFile(dto.getFiles(), getGroupId(), dto.getProfileCode()); + } return R.ok(result ? dto : null); } @Operation(summary = "修改") @PostMapping("/update") public R update(@Validated(Update.class) @RequestBody AttDamProfile dto) { + if (Objects.isNull(service.getById(dto.getProfileCode()))) { + throw new RuntimeException("当前数据不存在"); + } boolean result = service.updateById(dto); + if (result){ + fileService.saveFile(dto.getFiles(), getGroupId(), dto.getProfileCode()); + } return R.ok(result ? dto : null); } @Operation(summary = "删除") @GetMapping("/del/{id}") public R del(@Schema(name = "id") @PathVariable("id") Serializable id) { + if (Objects.isNull(service.getById(id))) { + throw new RuntimeException("当前数据不存在"); + } return R.ok(service.removeById(id)); } @@ -64,9 +87,18 @@ public class AttDamProfileController { @Operation(summary = "分页") @PostMapping("/page") - public R> page() { - return R.ok(service.page(null,null)); + public R> page(@RequestBody @Validated GeneralDataPage page) { + LambdaQueryChainWrapper query = service.lambdaQuery(); + if (ObjectUtils.isNotNull(page.getName())) { + query.like(AttDamProfile::getProfileName, page.getName()); + } + + return R.ok(service.page(page.getPageSo().toPage(), query)); } + @Override + public String getGroupId() { + return "AttDamProfile"; + } } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/controller/AttGateValveController.java b/src/main/java/com/gunshi/project/xyt/controller/AttGateValveController.java index 93bf532..369440d 100644 --- a/src/main/java/com/gunshi/project/xyt/controller/AttGateValveController.java +++ b/src/main/java/com/gunshi/project/xyt/controller/AttGateValveController.java @@ -1,6 +1,10 @@ package com.gunshi.project.xyt.controller; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gunshi.core.result.R; +import com.gunshi.project.xyt.entity.so.GeneralDataPage; import com.gunshi.project.xyt.model.AttGateValve; import com.gunshi.project.xyt.service.AttGateValveService; import com.gunshi.project.xyt.validate.markers.Insert; @@ -14,6 +18,8 @@ import org.springframework.web.bind.annotation.*; import java.io.Serializable; import java.util.List; +import java.util.Objects; + /** * 描述: 闸阀信息表 * author: xusan @@ -38,6 +44,9 @@ public class AttGateValveController { @Operation(summary = "修改") @PostMapping("/update") public R update(@Validated(Update.class) @RequestBody AttGateValve dto) { + if (Objects.isNull(service.getById(dto.getValveCode()))) { + throw new RuntimeException("当前数据不存在"); + } boolean result = service.updateById(dto); return R.ok(result ? dto : null); } @@ -45,6 +54,9 @@ public class AttGateValveController { @Operation(summary = "删除") @GetMapping("/del/{id}") public R del(@Schema(name = "id") @PathVariable("id") Serializable id) { + if (Objects.isNull(service.getById(id))) { + throw new RuntimeException("当前数据不存在"); + } return R.ok(service.removeById(id)); } @@ -56,8 +68,15 @@ public class AttGateValveController { @Operation(summary = "分页") @PostMapping("/page") - public R> page() { - return R.ok(service.page(null,null)); + public R> page(@RequestBody @Validated GeneralDataPage page) { + LambdaQueryChainWrapper query = service.lambdaQuery(); + if (ObjectUtils.isNotNull(page.getCode())){ + query.like(AttGateValve::getValveCode, page.getCode()); + } + if (ObjectUtils.isNotNull(page.getName())){ + query.like(AttGateValve::getValveName, page.getName()); + } + return R.ok(service.page(page.getPageSo().toPage(),query)); } } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/controller/AttMeaWeirController.java b/src/main/java/com/gunshi/project/xyt/controller/AttMeaWeirController.java index 9b30093..be8cf15 100644 --- a/src/main/java/com/gunshi/project/xyt/controller/AttMeaWeirController.java +++ b/src/main/java/com/gunshi/project/xyt/controller/AttMeaWeirController.java @@ -1,6 +1,10 @@ package com.gunshi.project.xyt.controller; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gunshi.core.result.R; +import com.gunshi.project.xyt.entity.so.GeneralDataPage; import com.gunshi.project.xyt.model.AttMeaWeir; import com.gunshi.project.xyt.service.AttMeaWeirService; import com.gunshi.project.xyt.validate.markers.Insert; @@ -14,6 +18,8 @@ import org.springframework.web.bind.annotation.*; import java.io.Serializable; import java.util.List; +import java.util.Objects; + /** * 描述: 量水堰表 * author: xusan @@ -38,6 +44,9 @@ public class AttMeaWeirController { @Operation(summary = "修改") @PostMapping("/update") public R update(@Validated(Update.class) @RequestBody AttMeaWeir dto) { + if (Objects.isNull(service.getById(dto.getWeirCode()))) { + throw new RuntimeException("当前数据不存在"); + } boolean result = service.updateById(dto); return R.ok(result ? dto : null); } @@ -45,6 +54,9 @@ public class AttMeaWeirController { @Operation(summary = "删除") @GetMapping("/del/{id}") public R del(@Schema(name = "id") @PathVariable("id") Serializable id) { + if (Objects.isNull(service.getById(id))) { + throw new RuntimeException("当前数据不存在"); + } return R.ok(service.removeById(id)); } @@ -56,8 +68,14 @@ public class AttMeaWeirController { @Operation(summary = "分页") @PostMapping("/page") - public R> page() { - return R.ok(service.page(null,null)); + public R> page(@RequestBody @Validated GeneralDataPage page) { + LambdaQueryChainWrapper query = service.lambdaQuery(); + if (ObjectUtils.isNotNull(page.getCode())) { + query.like(AttMeaWeir::getWeirCode, page.getCode()); + } + if (ObjectUtils.isNotNull(page.getName())) { + query.like(AttMeaWeir::getWeirName, page.getName()); + } + return R.ok(service.page(page.getPageSo().toPage(), query)); } - } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/controller/AttSpillwayBaseController.java b/src/main/java/com/gunshi/project/xyt/controller/AttSpillwayBaseController.java index 9c444dc..d6a55b9 100644 --- a/src/main/java/com/gunshi/project/xyt/controller/AttSpillwayBaseController.java +++ b/src/main/java/com/gunshi/project/xyt/controller/AttSpillwayBaseController.java @@ -1,6 +1,10 @@ package com.gunshi.project.xyt.controller; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gunshi.core.result.R; +import com.gunshi.project.xyt.entity.so.GeneralDataPage; import com.gunshi.project.xyt.model.AttSpillwayBase; import com.gunshi.project.xyt.service.AttSpillwayBaseService; import com.gunshi.project.xyt.validate.markers.Insert; @@ -14,6 +18,8 @@ import org.springframework.web.bind.annotation.*; import java.io.Serializable; import java.util.List; +import java.util.Objects; + /** * 描述: 溢洪道 * author: xusan @@ -38,6 +44,9 @@ public class AttSpillwayBaseController { @Operation(summary = "修改") @PostMapping("/update") public R update(@Validated(Update.class) @RequestBody AttSpillwayBase dto) { + if (Objects.isNull(service.getById(dto.getCode()))) { + throw new RuntimeException("当前数据不存在"); + } boolean result = service.updateById(dto); return R.ok(result ? dto : null); } @@ -45,6 +54,9 @@ public class AttSpillwayBaseController { @Operation(summary = "删除") @GetMapping("/del/{id}") public R del(@Schema(name = "id") @PathVariable("id") Serializable id) { + if (Objects.isNull(service.getById(id))) { + throw new RuntimeException("当前数据不存在"); + } return R.ok(service.removeById(id)); } @@ -56,8 +68,14 @@ public class AttSpillwayBaseController { @Operation(summary = "分页") @PostMapping("/page") - public R> page() { - return R.ok(service.page(null,null)); + public R> page(@RequestBody @Validated GeneralDataPage page) { + LambdaQueryChainWrapper query = service.lambdaQuery(); + if (ObjectUtils.isNotNull(page.getCode())){ + query.like(AttSpillwayBase::getCode, page.getCode()); + } + if (ObjectUtils.isNotNull(page.getName())){ + query.like(AttSpillwayBase::getName, page.getName()); + } + return R.ok(service.page(page.getPageSo().toPage(),query)); } - } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/controller/CctvBMenuController.java b/src/main/java/com/gunshi/project/xyt/controller/CctvBMenuController.java index 17ed590..d544d70 100644 --- a/src/main/java/com/gunshi/project/xyt/controller/CctvBMenuController.java +++ b/src/main/java/com/gunshi/project/xyt/controller/CctvBMenuController.java @@ -54,6 +54,12 @@ public class CctvBMenuController { return R.ok(service.lambdaQuery().list()); } + @Operation(summary = "树") + @GetMapping("/tree") + public R> tree() { + return R.ok(service.tree()); + } + @Operation(summary = "分页") @PostMapping("/page") public R> page() { diff --git a/src/main/java/com/gunshi/project/xyt/controller/FileAssociationsController.java b/src/main/java/com/gunshi/project/xyt/controller/FileAssociationsController.java new file mode 100644 index 0000000..3f29fbc --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/controller/FileAssociationsController.java @@ -0,0 +1,63 @@ +package com.gunshi.project.xyt.controller; + +import com.gunshi.core.result.R; +import com.gunshi.project.xyt.model.FileAssociations; +import com.gunshi.project.xyt.service.FileAssociationsService; +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 org.springframework.beans.factory.annotation.Autowired; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; + +import java.io.Serializable; +import java.util.List; +/** + * 描述: 文件关联业务表 + * author: xusan + * date: 2024-07-17 10:09:40 + */ +@Tag(name = "文件关联业务表") +@RestController +@RequestMapping(value="/fileAssociations") +public class FileAssociationsController { + + @Autowired + private FileAssociationsService service; + + + @Operation(summary = "新增") + @PostMapping("/insert") + public R insert(@Validated(Insert.class) @RequestBody FileAssociations dto) { + boolean result = service.save(dto); + return R.ok(result ? dto : null); + } + + @Operation(summary = "修改") + @PostMapping("/update") + public R update(@Validated(Update.class) @RequestBody FileAssociations dto) { + boolean result = service.updateById(dto); + return R.ok(result ? dto : null); + } + + @Operation(summary = "删除") + @GetMapping("/del/{id}") + public R del(@Schema(name = "id") @PathVariable("id") Serializable id) { + return R.ok(service.removeById(id)); + } + + @Operation(summary = "列表") + @PostMapping("/list") + public R> list() { + return R.ok(service.lambdaQuery().list()); + } + + @Operation(summary = "分页") + @PostMapping("/page") + public R> page() { + return R.ok(service.page(null,null)); + } + +} \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/controller/IaCBsnssinfoController.java b/src/main/java/com/gunshi/project/xyt/controller/IaCBsnssinfoController.java index ef6d939..70a95d0 100644 --- a/src/main/java/com/gunshi/project/xyt/controller/IaCBsnssinfoController.java +++ b/src/main/java/com/gunshi/project/xyt/controller/IaCBsnssinfoController.java @@ -3,18 +3,22 @@ package com.gunshi.project.xyt.controller; import com.gunshi.core.result.R; import com.gunshi.project.xyt.entity.vo.HomeIaCBsnssinfoVo; import com.gunshi.project.xyt.model.IaCBsnssinfo; +import com.gunshi.project.xyt.service.FileAssociationsService; import com.gunshi.project.xyt.service.IaCBsnssinfoService; 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 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.util.List; +import java.util.Objects; + /** * 描述: 防治区企事业单位汇总表 * author: xusan @@ -23,30 +27,50 @@ import java.util.List; @Tag(name = "防治区企事业单位汇总表") @RestController @RequestMapping(value="/iaCBsnssinfo") -public class IaCBsnssinfoController { +public class IaCBsnssinfoController extends AbstractCommonFileController{ @Autowired private IaCBsnssinfoService service; + @Autowired + private FileAssociationsService fileService; @Operation(summary = "新增") @PostMapping("/insert") public R insert(@Validated(Insert.class) @RequestBody IaCBsnssinfo dto) { boolean result = service.save(dto); + if (result){ + fileService.saveFile(dto.getFiles(), getGroupId(), dto.getEicd()); + } return R.ok(result ? dto : null); } @Operation(summary = "修改") @PostMapping("/update") public R update(@Validated(Update.class) @RequestBody IaCBsnssinfo dto) { + if (Objects.isNull(service.getById(dto.getEicd()))) { + throw new RuntimeException("当前数据不存在"); + } boolean result = service.updateById(dto); + if (result){ + fileService.saveFile(dto.getFiles(), getGroupId(), dto.getEicd()); + } return R.ok(result ? dto : null); } @Operation(summary = "删除") @GetMapping("/del/{id}") public R del(@Schema(name = "id") @PathVariable("id") Serializable id) { - return R.ok(service.removeById(id)); + if (Objects.isNull(service.getById(id))) { + throw new RuntimeException("当前数据不存在"); + } + boolean data = service.removeById(id); + + if (data){ + fileService.deleteFile(getGroupId(),id.toString()); + } + + return R.ok(data); } @Operation(summary = "列表") @@ -64,6 +88,15 @@ public class IaCBsnssinfoController { @Operation(summary = "详情和行政区划数据查询") @PostMapping("/getDetailsAndAddvcdDataList") public R> getDetailsAndMonitoringDataList() { - return R.ok(service.getDetailsAndMonitoringDataLis()); + List list = service.getDetailsAndMonitoringDataLis(); + if (CollectionUtils.isNotEmpty(list)){ + list.forEach(o -> o.setFiles(fileService.getFiles(getGroupId(),o.getEicd()))); + } + return R.ok(list); + } + + @Override + public String getGroupId() { + return "iaCBsnssinfo"; } } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/controller/ResPlanBController.java b/src/main/java/com/gunshi/project/xyt/controller/ResPlanBController.java index e4e74bd..0c0bd9e 100644 --- a/src/main/java/com/gunshi/project/xyt/controller/ResPlanBController.java +++ b/src/main/java/com/gunshi/project/xyt/controller/ResPlanBController.java @@ -3,19 +3,22 @@ package com.gunshi.project.xyt.controller; import com.gunshi.core.result.R; import com.gunshi.project.xyt.entity.so.ResCodeSo; import com.gunshi.project.xyt.model.ResPlanB; -import com.gunshi.project.xyt.model.ResSafePersonB; +import com.gunshi.project.xyt.service.FileAssociationsService; import com.gunshi.project.xyt.service.ResPlanBService; 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 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.util.List; +import java.util.Objects; + /** * 描述: 水库预案表 * author: xusan @@ -24,36 +27,67 @@ import java.util.List; @Tag(name = "水库预案表") @RestController @RequestMapping(value="/resPlanB") -public class ResPlanBController { +public class ResPlanBController extends AbstractCommonFileController{ @Autowired private ResPlanBService service; + @Autowired + private FileAssociationsService fileService; + @Operation(summary = "新增") @PostMapping("/insert") public R insert(@Validated(Insert.class) @RequestBody ResPlanB dto) { boolean result = service.save(dto); + + if (result){ + fileService.saveFile(dto.getFiles(), getGroupId(), String.valueOf( dto.getId())); + } + return R.ok(result ? dto : null); } @Operation(summary = "修改") @PostMapping("/update") public R update(@Validated(Update.class) @RequestBody ResPlanB dto) { + if (Objects.isNull(service.getById(dto.getId()))) { + throw new RuntimeException("当前数据不存在"); + } boolean result = service.updateById(dto); + + if (result) { + fileService.saveFile(dto.getFiles(), getGroupId(), String.valueOf( dto.getId())); + } + return R.ok(result ? dto : null); } @Operation(summary = "删除") @GetMapping("/del/{id}") public R del(@Schema(name = "id") @PathVariable("id") Serializable id) { - return R.ok(service.removeById(id)); + if (Objects.isNull(service.getById(id))) { + throw new RuntimeException("当前数据不存在"); + } + boolean data = service.removeById(id); + + if (data){ + fileService.deleteFile(getGroupId(),id.toString()); + } + + return R.ok(data); } @Operation(summary = "列表") @PostMapping("/list") public R> list(@Validated @RequestBody ResCodeSo so) { - return R.ok(service.lambdaQuery().eq(ResPlanB::getResCode,so.getResCode()).list()); + List list = service.lambdaQuery().eq(ResPlanB::getResCode, so.getResCode()).list(); + + if (CollectionUtils.isNotEmpty(list)){ + list.forEach(o -> o.setFiles(fileService.getFiles(getGroupId(),String.valueOf( o.getId())))); + } + + return R.ok(list); } @Operation(summary = "分页") @PostMapping("/page") @@ -61,4 +95,8 @@ public class ResPlanBController { return R.ok(service.page(null,null)); } + @Override + public String getGroupId() { + return "ResPlanB"; + } } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/controller/ResProjectImgController.java b/src/main/java/com/gunshi/project/xyt/controller/ResProjectImgController.java index 4922b28..e2220ed 100644 --- a/src/main/java/com/gunshi/project/xyt/controller/ResProjectImgController.java +++ b/src/main/java/com/gunshi/project/xyt/controller/ResProjectImgController.java @@ -3,18 +3,22 @@ package com.gunshi.project.xyt.controller; import com.gunshi.core.result.R; import com.gunshi.project.xyt.entity.so.ResCodeSo; import com.gunshi.project.xyt.model.ResProjectImg; +import com.gunshi.project.xyt.service.FileAssociationsService; import com.gunshi.project.xyt.service.ResProjectImgService; 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 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.util.List; +import java.util.Objects; + /** * 描述: 水库工程图片 * author: xusan @@ -23,36 +27,61 @@ import java.util.List; @Tag(name = "水库工程图片") @RestController @RequestMapping(value="/resProjectImg") -public class ResProjectImgController { +public class ResProjectImgController extends AbstractCommonFileController{ @Autowired private ResProjectImgService service; + @Autowired + private FileAssociationsService fileService; + @Operation(summary = "新增") @PostMapping("/insert") public R insert(@Validated(Insert.class) @RequestBody ResProjectImg dto) { boolean result = service.save(dto); + if (result){ + fileService.saveFile(dto.getFiles(), getGroupId(), String.valueOf( dto.getId())); + } return R.ok(result ? dto : null); } @Operation(summary = "修改") @PostMapping("/update") public R update(@Validated(Update.class) @RequestBody ResProjectImg dto) { + if (Objects.isNull(service.getById(dto.getId()))) { + throw new RuntimeException("当前数据不存在"); + } boolean result = service.updateById(dto); + if (result) { + fileService.saveFile(dto.getFiles(), getGroupId(), String.valueOf( dto.getId())); + } return R.ok(result ? dto : null); } @Operation(summary = "删除") @GetMapping("/del/{id}") public R del(@Schema(name = "id") @PathVariable("id") Serializable id) { - return R.ok(service.removeById(id)); + if (Objects.isNull(service.getById(id))) { + throw new RuntimeException("当前数据不存在"); + } + boolean data = service.removeById(id); + + if (data){ + fileService.deleteFile(getGroupId(),id.toString()); + } + + return R.ok(data); } @Operation(summary = "列表") @PostMapping("/list") public R> list(@Validated @RequestBody ResCodeSo so) { - return R.ok(service.lambdaQuery().eq(ResProjectImg::getResCode,so.getResCode()).list()); + List list = service.lambdaQuery().eq(ResProjectImg::getResCode, so.getResCode()).list(); + if (CollectionUtils.isNotEmpty(list)){ + list.forEach(o -> o.setFiles(fileService.getFiles(getGroupId(),String.valueOf( o.getId())))); + } + return R.ok(list); } @Operation(summary = "分页") @PostMapping("/page") @@ -60,4 +89,8 @@ public class ResProjectImgController { return R.ok(service.page(null,null)); } + @Override + public String getGroupId() { + return "ResProjectImg"; + } } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/controller/StStbprpBController.java b/src/main/java/com/gunshi/project/xyt/controller/StStbprpBController.java index 93af29a..5da58b9 100644 --- a/src/main/java/com/gunshi/project/xyt/controller/StStbprpBController.java +++ b/src/main/java/com/gunshi/project/xyt/controller/StStbprpBController.java @@ -1,8 +1,11 @@ package com.gunshi.project.xyt.controller; +import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.gunshi.core.result.R; import com.gunshi.project.xyt.entity.so.HomeStStbprpBSo; +import com.gunshi.project.xyt.entity.so.StStbprpBPage; import com.gunshi.project.xyt.entity.so.StStbprpBSo; import com.gunshi.project.xyt.entity.vo.HomeStStbprpBVo; import com.gunshi.project.xyt.entity.vo.StStatusListVo; @@ -70,8 +73,18 @@ public class StStbprpBController { @Operation(summary = "分页") @PostMapping("/page") - public R> page() { - return R.ok(service.page(null,null)); + public R> page(@RequestBody @Validated StStbprpBPage page) { + LambdaQueryChainWrapper query = service.lambdaQuery(); + if (ObjectUtils.isNotNull(page.getCode())) { + query.like(StStbprpB::getStcd, page.getCode()); + } + if (ObjectUtils.isNotNull(page.getName())) { + query.like(StStbprpB::getStnm, page.getName()); + } + if (ObjectUtils.isNotNull(page.getAgreement())) { + query.like(StStbprpB::getAgreement, page.getAgreement()); + } + return R.ok(service.page(page.getPageSo().toPage(), query)); } @Operation(summary = "雨量站详情带雨量列表") diff --git a/src/main/java/com/gunshi/project/xyt/entity/MyConstant.java b/src/main/java/com/gunshi/project/xyt/entity/MyConstant.java new file mode 100644 index 0000000..f3bb31e --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/entity/MyConstant.java @@ -0,0 +1,22 @@ +package com.gunshi.project.xyt.entity; + +/** + * @author xusan + * @date 2023/4/27 9:41 + */ +public class MyConstant { + + public static final String + + // 删除 + DEL = "0", + + // 未删除 + REC = "1"; + + /** + * 数据-数据服务运维员 角色编码 + */ + public static final String ROLE_PUSH = "data_zh_om"; + public static final String REDIS_KEY = "xyt:"; +} diff --git a/src/main/java/com/gunshi/project/xyt/entity/so/AttCctvBasePage.java b/src/main/java/com/gunshi/project/xyt/entity/so/AttCctvBasePage.java new file mode 100644 index 0000000..8057093 --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/entity/so/AttCctvBasePage.java @@ -0,0 +1,25 @@ +package com.gunshi.project.xyt.entity.so; + +import com.baomidou.mybatisplus.annotation.TableField; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * Description: + * Created by XuSan on 2024/7/17. + * + * @author XuSan + * @version 1.0 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class AttCctvBasePage extends GeneralDataPage{ + + /** + * menu_id + */ + @Schema(description="menu_id") + private Long menuId; + +} diff --git a/src/main/java/com/gunshi/project/xyt/entity/so/GeneralDataPage.java b/src/main/java/com/gunshi/project/xyt/entity/so/GeneralDataPage.java new file mode 100644 index 0000000..1da0a3c --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/entity/so/GeneralDataPage.java @@ -0,0 +1,37 @@ +package com.gunshi.project.xyt.entity.so; + +import com.gunshi.project.xyt.entity.page.GenericPageParams; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * Description: 数据通用查询 + * Created by XuSan on 2024/7/17. + * + * @author XuSan + * @version 1.0 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class GeneralDataPage extends GenericPageParams { + + /** + * 代码 + */ + @Schema(description="代码") + private String code; + + /** + * 名称 + */ + @Schema(description="名称") + private String name; + + /** + * 类型 + */ + @Schema(description="类型") + private String type; + +} diff --git a/src/main/java/com/gunshi/project/xyt/entity/so/StStbprpBPage.java b/src/main/java/com/gunshi/project/xyt/entity/so/StStbprpBPage.java new file mode 100644 index 0000000..96caf29 --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/entity/so/StStbprpBPage.java @@ -0,0 +1,22 @@ +package com.gunshi.project.xyt.entity.so; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * Description: + * Created by XuSan on 2024/7/17. + * + * @author XuSan + * @version 1.0 + */ +@EqualsAndHashCode(callSuper = true) +@Data +public class StStbprpBPage extends GeneralDataPage{ + /** + * 归属协议 + */ + @Schema(description="归属协议") + private String agreement; +} diff --git a/src/main/java/com/gunshi/project/xyt/mapper/FileAssociationsMapper.java b/src/main/java/com/gunshi/project/xyt/mapper/FileAssociationsMapper.java new file mode 100644 index 0000000..95fcc4e --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/mapper/FileAssociationsMapper.java @@ -0,0 +1,35 @@ +package com.gunshi.project.xyt.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.gunshi.project.xyt.model.FileAssociations; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +/** + * 描述: 文件关联业务表 + * author: xusan + * date: 2024-07-17 10:09:40 + */ +@Mapper +public interface FileAssociationsMapper extends BaseMapper { + + @Select(""" + + """) + List getFiles(@Param("tableName") String tableName,@Param("businessId") String businessId); +} \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/model/AttDamProfile.java b/src/main/java/com/gunshi/project/xyt/model/AttDamProfile.java index c43e2be..06d8b82 100644 --- a/src/main/java/com/gunshi/project/xyt/model/AttDamProfile.java +++ b/src/main/java/com/gunshi/project/xyt/model/AttDamProfile.java @@ -11,6 +11,7 @@ import jakarta.validation.constraints.Size; import lombok.Data; import java.io.Serializable; +import java.util.List; /** * 描述: 监测断面信息表 @@ -58,4 +59,8 @@ public class AttDamProfile implements Serializable { @Size(max = 250,message = "备注/描述最大长度要小于 250") private String remark; + + @TableField(exist = false) + @Schema(description = "文件集合") + private List files; } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/model/AttResBase.java b/src/main/java/com/gunshi/project/xyt/model/AttResBase.java index b6d0929..104a913 100644 --- a/src/main/java/com/gunshi/project/xyt/model/AttResBase.java +++ b/src/main/java/com/gunshi/project/xyt/model/AttResBase.java @@ -15,6 +15,7 @@ import lombok.Data; import java.io.Serializable; import java.math.BigDecimal; import java.util.Date; +import java.util.List; /** * 描述: 水库基本信息表 @@ -485,4 +486,8 @@ public class AttResBase implements Serializable { @Size(max = 255,message = "adcd最大长度要小于 255") private String adcd; + + @TableField(exist = false) + @Schema(description = "文件id集合") + private List fileIds; } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/model/CctvBMenu.java b/src/main/java/com/gunshi/project/xyt/model/CctvBMenu.java index cbf95e5..794d6a4 100644 --- a/src/main/java/com/gunshi/project/xyt/model/CctvBMenu.java +++ b/src/main/java/com/gunshi/project/xyt/model/CctvBMenu.java @@ -5,15 +5,13 @@ import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; -import com.fasterxml.jackson.annotation.JsonFormat; -import com.gunshi.core.dateformat.DateFormatString; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.Size; import lombok.Data; import java.io.Serializable; -import java.util.Date; +import java.util.List; /** * 描述: 视频点目录 @@ -59,4 +57,9 @@ public class CctvBMenu implements Serializable { @Schema(description="排序") private Integer orderIndex; + @TableField(exist = false) + @Schema(description="子集") + private List children; + + } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/model/FileAssociations.java b/src/main/java/com/gunshi/project/xyt/model/FileAssociations.java new file mode 100644 index 0000000..f494998 --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/model/FileAssociations.java @@ -0,0 +1,105 @@ +package com.gunshi.project.xyt.model; + + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import com.fasterxml.jackson.annotation.JsonFormat; +import com.gunshi.core.dateformat.DateFormatString; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.Size; +import lombok.Data; + +import java.io.Serializable; +import java.util.Date; + +/** +* 描述: 文件关联业务表 +* author: xusan +* date: 2024-07-17 10:09:40 +*/ +@Schema(description="文件关联业务表") +@Data +@TableName("public.file_associations") +public class FileAssociations implements Serializable { + + public final static String thisTableName = "file_associations"; + + private static final long serialVersionUID = 1L; + + /** + * 主键 + */ + @TableId(value="id", type= IdType.AUTO) + @Schema(description="主键") + @NotBlank(message = "主键不能为空") + private Long id; + + /** + * 业务id + */ + @TableField(value="business_id") + @Schema(description="业务id") + @NotBlank(message = "业务id不能为空") + private String businessId; + /** + * 业务id + */ + @TableField(value="business_str_id") + @Schema(description="业务id") + @NotBlank(message = "业务id不能为空") + private String businessStrId; + + /** + * 文件id + */ + @TableField(value="file_id") + @Schema(description="文件id") + @NotBlank(message = "文件id不能为空") + private Long fileId; + + /** + * 序号 + */ + @TableField(value="sort_on") + @Schema(description="序号") + private Integer sortOn; + + /** + * 时间戳 + */ + @TableField(value="tm") + @Schema(description="时间戳") + @NotBlank(message = "时间戳不能为空") + @JsonFormat(pattern = DateFormatString.YYYY_MM_DD_HH_MM_SS, timezone = "GMT+8") + private Date tm; + + /** + * 业务表名 + */ + @TableField(value="table_name") + @Schema(description="业务表名") + @Size(max = 255,message = "业务表名最大长度要小于 255") + @NotBlank(message = "业务表名不能为空") + private String tableName; + /** + * 业务表名 + */ + @TableField(value="del") + @Size(max = 1,message = "删除标识最大长度要小于 2") + @Schema(description="删除标识0: 未删除,1:已删除") + @NotBlank(message = "删除标识不能为空") + private String del; + + + @TableField(exist = false) + @Schema(description = "文件路径") + private String filePath; + + @TableField(exist = false) + @Schema(description = "文件名称") + private String fileName; + +} \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/model/IaCBsnssinfo.java b/src/main/java/com/gunshi/project/xyt/model/IaCBsnssinfo.java index ce4c143..f269b79 100644 --- a/src/main/java/com/gunshi/project/xyt/model/IaCBsnssinfo.java +++ b/src/main/java/com/gunshi/project/xyt/model/IaCBsnssinfo.java @@ -1,9 +1,7 @@ package com.gunshi.project.xyt.model; -import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import com.fasterxml.jackson.annotation.JsonFormat; import com.gunshi.core.dateformat.DateFormatString; @@ -14,6 +12,7 @@ import lombok.Data; import java.io.Serializable; import java.util.Date; +import java.util.List; /** * 描述: 防治区企事业单位汇总表 @@ -191,4 +190,7 @@ public class IaCBsnssinfo implements Serializable { @JsonFormat(pattern = DateFormatString.YYYY_MM_DD_HH_MM_SS, timezone = "GMT+8") private Date moditime; + @TableField(exist = false) + @Schema(description = "文件集合") + private List files; } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/model/ResPlanB.java b/src/main/java/com/gunshi/project/xyt/model/ResPlanB.java index 98b2a8a..4ae5326 100644 --- a/src/main/java/com/gunshi/project/xyt/model/ResPlanB.java +++ b/src/main/java/com/gunshi/project/xyt/model/ResPlanB.java @@ -14,6 +14,7 @@ import lombok.Data; import java.io.Serializable; import java.util.Date; +import java.util.List; /** * 描述: 水库预案表 @@ -112,4 +113,8 @@ public class ResPlanB implements Serializable { @JsonFormat(pattern = DateFormatString.YYYY_MM_DD_HH_MM_SS, timezone = "GMT+8") private Date moditime; + + @TableField(exist = false) + @Schema(description = "文件集合") + private List files; } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/model/ResProjectImg.java b/src/main/java/com/gunshi/project/xyt/model/ResProjectImg.java index 5a88dbe..8e85c74 100644 --- a/src/main/java/com/gunshi/project/xyt/model/ResProjectImg.java +++ b/src/main/java/com/gunshi/project/xyt/model/ResProjectImg.java @@ -14,6 +14,7 @@ import lombok.Data; import java.io.Serializable; import java.util.Date; +import java.util.List; /** * 描述: 水库工程图片 @@ -79,4 +80,7 @@ public class ResProjectImg implements Serializable { @JsonFormat(pattern = DateFormatString.YYYY_MM_DD_HH_MM_SS, timezone = "GMT+8") private Date moditime; + @TableField(exist = false) + @Schema(description = "文件集合") + private List files; } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/model/StStbprpB.java b/src/main/java/com/gunshi/project/xyt/model/StStbprpB.java index 06e4f4a..a2fd3f7 100644 --- a/src/main/java/com/gunshi/project/xyt/model/StStbprpB.java +++ b/src/main/java/com/gunshi/project/xyt/model/StStbprpB.java @@ -520,6 +520,13 @@ public class StStbprpB implements Serializable { // @Size(max = 0,message = "测站状态 0无效 1有效最大长度要小于 0") private Integer status; + /** + * 归属协议 + */ + @Schema(description="归属协议") + @TableField(value="agreement") + private String agreement; + public static final String COL_STCD = "stcd"; } \ No newline at end of file diff --git a/src/main/java/com/gunshi/project/xyt/service/CctvBMenuService.java b/src/main/java/com/gunshi/project/xyt/service/CctvBMenuService.java index a0bd403..00a69bf 100644 --- a/src/main/java/com/gunshi/project/xyt/service/CctvBMenuService.java +++ b/src/main/java/com/gunshi/project/xyt/service/CctvBMenuService.java @@ -4,10 +4,15 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.gunshi.project.xyt.mapper.CctvBMenuMapper; import com.gunshi.project.xyt.model.CctvBMenu; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Date; +import java.util.Comparator; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; /** * 描述: 视频点目录 @@ -20,6 +25,33 @@ import java.util.Date; public class CctvBMenuService extends ServiceImpl { + public List tree() { + List list = list(lambdaQuery().orderByDesc(CctvBMenu::getId)); + if (CollectionUtils.isEmpty(list)){ + return list; + } + Map> listMap = list.stream().collect(Collectors.groupingBy(CctvBMenu::getParentId)); + + list.forEach(o -> o.setChildren(listMap.get(o.getId()))); + List parentList = list.stream().filter(o -> Objects.isNull(o.getParentId())).collect(Collectors.toList()); + return sorted(parentList); + } + + + private List sorted( List tree) { + + List sorteds = null; + + if (CollectionUtils.isNotEmpty(tree)){ + sorteds = tree.stream().sorted(Comparator.comparing(CctvBMenu::getOrderIndex) + ).collect(Collectors.toList()); + sorteds.forEach(o->{ + o.setChildren(sorted(o.getChildren())); + }); + } + + return sorteds; + } } diff --git a/src/main/java/com/gunshi/project/xyt/service/FileAssociationsService.java b/src/main/java/com/gunshi/project/xyt/service/FileAssociationsService.java new file mode 100644 index 0000000..ac05b66 --- /dev/null +++ b/src/main/java/com/gunshi/project/xyt/service/FileAssociationsService.java @@ -0,0 +1,103 @@ +package com.gunshi.project.xyt.service; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.gunshi.project.xyt.mapper.FileAssociationsMapper; +import com.gunshi.project.xyt.model.FileAssociations; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.cache.annotation.CacheEvict; +import org.springframework.cache.annotation.Cacheable; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +import static com.gunshi.project.xyt.entity.MyConstant.*; + + +/** + * 描述: 文件关联业务表 + * author: xusan + * date: 2024-07-17 10:09:40 + */ +@Slf4j +@Service +@Transactional +public class FileAssociationsService extends ServiceImpl { + + private static final String THIS_REDIS_KEY = REDIS_KEY + FileAssociations.thisTableName + ":"; + + @CacheEvict(value = THIS_REDIS_KEY, key = "#tableName+':'+#businessId", allEntries = true) + public void saveFile(List files, String tableName, String businessId) { + if (CollectionUtils.isEmpty(files)) { + log.info("fileIds is null!"); + } + + // 查询是否添加 + List dbList = this.lambdaQuery() + .eq(FileAssociations::getTableName, tableName) + .eq(FileAssociations::getBusinessId, businessId) + .eq(FileAssociations::getDel, REC) + .list(); + + if (CollectionUtils.isNotEmpty(dbList)) { + Set fileIds = dbList.stream().map(FileAssociations::getFileId) + .collect(Collectors.toSet()); + // 删除已添加数据, 删除重复数据 删除不成功即新数据 + files = files.stream() + .filter(fileAssociations -> !fileIds.remove(fileAssociations.getFileId())) + .collect(Collectors.toList()); + + if (CollectionUtils.isNotEmpty(files)) { + + // 删除 + if (this.lambdaUpdate() + .set(FileAssociations::getDel, 1) + .eq(FileAssociations::getTableName, tableName) + .eq(FileAssociations::getBusinessId, businessId) + .in(FileAssociations::getFileId, fileIds) + .update()) { + log.info("delete file {} success!", fileIds); + } + + } + } + + + // 做新增 + if (CollectionUtils.isNotEmpty(files)) { + + files.forEach(fileId -> { + FileAssociations fileAssociations = new FileAssociations(); + fileAssociations.setTableName(tableName); + fileAssociations.setBusinessId(businessId); + }); + + if (!this.saveBatch(files)) { + log.error("save file error!"); + } + + } + + } + + @CacheEvict(value = THIS_REDIS_KEY, key = "#tableName+':'+#businessId", allEntries = true) + public void deleteFile(String tableName, String businessId) { + // 删除 + if (this.lambdaUpdate() + .set(FileAssociations::getDel, DEL) + .eq(FileAssociations::getTableName, tableName) + .eq(FileAssociations::getBusinessId, businessId) + .update()) { + log.info("delete file {} success!", businessId); + } + } + + @Cacheable(value = THIS_REDIS_KEY, key = "#tableName+':'+#businessId") + public List getFiles(String tableName, String businessId) { + return this.baseMapper.getFiles(tableName,businessId); + } + +} diff --git a/src/main/resources/mapper/FileAssociationsMapper.xml b/src/main/resources/mapper/FileAssociationsMapper.xml new file mode 100644 index 0000000..5f1500d --- /dev/null +++ b/src/main/resources/mapper/FileAssociationsMapper.xml @@ -0,0 +1,5 @@ + + + + +