VisualComponentServiceImpl.java 4.2 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.VisualCategoryEntity;
  13. import jnpf.visualdata.entity.VisualComponentEntity;
  14. import jnpf.visualdata.mapper.VisualComponentMapper;
  15. import jnpf.visualdata.model.visual.VisualPaginationModel;
  16. import jnpf.visualdata.service.VisualComponentService;
  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 VisualComponentServiceImpl extends SuperServiceImpl<VisualComponentMapper, VisualComponentEntity> implements VisualComponentService {
  31. @Autowired
  32. private VisualService visualService;
  33. @Override
  34. public List<VisualComponentEntity> getList(VisualPaginationModel pagination) {
  35. QueryWrapper<VisualComponentEntity> queryWrapper = new QueryWrapper<>();
  36. if(ObjectUtil.isNotEmpty(pagination.getName())){
  37. queryWrapper.lambda().like(VisualComponentEntity::getName, pagination.getName());
  38. }
  39. queryWrapper.lambda().eq(VisualComponentEntity::getSystemId,visualService.getSystemIdByReq());
  40. queryWrapper.lambda().eq(VisualComponentEntity::getType, pagination.getType());
  41. Page page = new Page(pagination.getCurrent(), pagination.getSize());
  42. IPage<VisualComponentEntity> iPages = this.page(page, queryWrapper);
  43. return pagination.setData(iPages);
  44. }
  45. @Override
  46. public List<VisualComponentEntity> getList() {
  47. QueryWrapper<VisualComponentEntity> queryWrapper = new QueryWrapper<>();
  48. queryWrapper.lambda().eq(VisualComponentEntity::getSystemId,visualService.getSystemIdByReq());
  49. return this.list(queryWrapper);
  50. }
  51. @Override
  52. public VisualComponentEntity getInfo(String id) {
  53. QueryWrapper<VisualComponentEntity> queryWrapper = new QueryWrapper<>();
  54. queryWrapper.lambda().eq(VisualComponentEntity::getId, id);
  55. return this.getOne(queryWrapper);
  56. }
  57. @Override
  58. public void create(VisualComponentEntity entity) {
  59. entity.setSystemId(visualService.getSystemIdByReq());
  60. this.creUpdateCheck(entity,true);
  61. entity.setId(RandomUtil.uuId());
  62. this.save(entity);
  63. }
  64. @Override
  65. public boolean update(String id, VisualComponentEntity entity) {
  66. entity.setSystemId(visualService.getSystemIdByReq());
  67. this.creUpdateCheck(entity,true);
  68. entity.setId(id);
  69. return this.updateById(entity);
  70. }
  71. @Override
  72. public void delete(VisualComponentEntity entity) {
  73. if (entity != null) {
  74. this.removeById(entity.getId());
  75. }
  76. }
  77. public void creUpdateCheck(VisualComponentEntity entity, Boolean fullNameCheck) {
  78. String title = entity.getName();
  79. String systemId = entity.getSystemId();
  80. // 名称长度验证(假设长度限制为80)
  81. if (StringUtil.isNotEmpty(title)&&title.length() > 80) {
  82. throw new DataException(MsgCode.EXIST005.get());
  83. }
  84. // 动态构建查询条件
  85. LambdaQueryWrapper<VisualComponentEntity> queryWrapper = new LambdaQueryWrapper<>();
  86. if (fullNameCheck) {
  87. queryWrapper.eq(VisualComponentEntity::getName, title)
  88. .eq(VisualComponentEntity::getSystemId, systemId);
  89. List<VisualComponentEntity> list = this.list(queryWrapper);
  90. if (!list.isEmpty()) {
  91. if (StringUtil.isNotEmpty(entity.getId())&&list.get(0).getId().equals(entity.getId())) {
  92. return;
  93. }
  94. throw new DataException(MsgCode.EXIST003.get());
  95. }
  96. }
  97. }
  98. }