VisualGlobServiceImpl.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. package jnpf.visualdata.service.impl;
  2. import cn.hutool.core.util.ObjectUtil;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  5. import com.baomidou.mybatisplus.core.metadata.IPage;
  6. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  7. import jnpf.base.service.SuperServiceImpl;
  8. import jnpf.constant.MsgCode;
  9. import jnpf.exception.DataException;
  10. import jnpf.util.RandomUtil;
  11. import jnpf.util.StringUtil;
  12. import jnpf.visualdata.entity.VisualDbEntity;
  13. import jnpf.visualdata.entity.VisualGlobEntity;
  14. import jnpf.visualdata.mapper.VisualGlobMapper;
  15. import jnpf.visualdata.model.visual.VisualPaginationModel;
  16. import jnpf.visualdata.service.VisualGlobService;
  17. import jnpf.visualdata.service.VisualService;
  18. import org.springframework.beans.factory.annotation.Autowired;
  19. import org.springframework.stereotype.Service;
  20. import java.util.List;
  21. /**
  22. * 全局变量
  23. *
  24. * @author JNPF开发平台组
  25. * @version V3.5.0
  26. * @copyright 引迈信息技术有限公司
  27. * @date 2023年7月7日
  28. */
  29. @Service
  30. public class VisualGlobServiceImpl extends SuperServiceImpl<VisualGlobMapper, VisualGlobEntity> implements VisualGlobService {
  31. @Autowired
  32. private VisualService visualService;
  33. @Override
  34. public List<VisualGlobEntity> getList(VisualPaginationModel pagination) {
  35. QueryWrapper<VisualGlobEntity> queryWrapper = new QueryWrapper<>();
  36. if(ObjectUtil.isNotEmpty(pagination.getGlobalName())){
  37. queryWrapper.lambda().like(VisualGlobEntity::getGlobalName, pagination.getGlobalName());
  38. }
  39. queryWrapper.lambda().eq(VisualGlobEntity::getSystemId,visualService.getSystemIdByReq());
  40. Page page = new Page(pagination.getCurrent(), pagination.getSize());
  41. IPage<VisualGlobEntity> iPages = this.page(page, queryWrapper);
  42. return pagination.setData(iPages);
  43. }
  44. @Override
  45. public List<VisualGlobEntity> getList() {
  46. QueryWrapper<VisualGlobEntity> queryWrapper = new QueryWrapper<>();
  47. queryWrapper.lambda().eq(VisualGlobEntity::getSystemId,visualService.getSystemIdByReq());
  48. return this.list(queryWrapper);
  49. }
  50. @Override
  51. public VisualGlobEntity getInfo(String id) {
  52. QueryWrapper<VisualGlobEntity> queryWrapper = new QueryWrapper<>();
  53. queryWrapper.lambda().eq(VisualGlobEntity::getId, id);
  54. return this.getOne(queryWrapper);
  55. }
  56. @Override
  57. public void create(VisualGlobEntity entity) {
  58. entity.setSystemId(visualService.getSystemIdByReq());
  59. entity.setId(RandomUtil.uuId());
  60. this.creUpdateCheck(entity,true);
  61. this.save(entity);
  62. }
  63. @Override
  64. public boolean update(String id, VisualGlobEntity entity) {
  65. entity.setSystemId(visualService.getSystemIdByReq());
  66. entity.setId(id);
  67. this.creUpdateCheck(entity,true);
  68. return this.updateById(entity);
  69. }
  70. @Override
  71. public void delete(VisualGlobEntity entity) {
  72. if (entity != null) {
  73. this.removeById(entity.getId());
  74. }
  75. }
  76. public void creUpdateCheck(VisualGlobEntity entity, Boolean fullNameCheck) {
  77. String title = entity.getGlobalName();
  78. String systemId = entity.getSystemId();
  79. // 名称长度验证(假设长度限制为80)
  80. if (StringUtil.isNotEmpty(title)&&title.length() > 80) {
  81. throw new DataException(MsgCode.EXIST005.get());
  82. }
  83. // 动态构建查询条件
  84. LambdaQueryWrapper<VisualGlobEntity> queryWrapper = new LambdaQueryWrapper<>();
  85. if (fullNameCheck) {
  86. queryWrapper.eq(VisualGlobEntity::getGlobalName, title)
  87. .eq(VisualGlobEntity::getSystemId, systemId);
  88. List<VisualGlobEntity> list = this.list(queryWrapper);
  89. if (!list.isEmpty()) {
  90. if (StringUtil.isNotEmpty(entity.getId())&&list.get(0).getId().equals(entity.getId())) {
  91. return;
  92. }
  93. throw new DataException(MsgCode.EXIST003.get());
  94. }
  95. }
  96. }
  97. }