VisualServiceImpl.java 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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.extension.plugins.pagination.Page;
  6. import jnpf.base.entity.SystemEntity;
  7. import jnpf.base.service.SuperService;
  8. import jnpf.base.service.SystemService;
  9. import jnpf.constant.MsgCode;
  10. import jnpf.base.service.SuperServiceImpl;
  11. import jnpf.exception.DataException;
  12. import jnpf.util.RandomUtil;
  13. import jnpf.util.StringUtil;
  14. import jnpf.util.UserProvider;
  15. import jnpf.util.context.RequestContext;
  16. import jnpf.visualdata.entity.VisualConfigEntity;
  17. import jnpf.visualdata.entity.VisualEntity;
  18. import jnpf.visualdata.mapper.VisualMapper;
  19. import jnpf.visualdata.model.visual.VisualPaginationModel;
  20. import jnpf.visualdata.service.VisualConfigService;
  21. import jnpf.visualdata.service.VisualService;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.stereotype.Service;
  24. import java.util.Date;
  25. import java.util.List;
  26. /**
  27. * 大屏基本信息
  28. *
  29. * @author JNPF开发平台组
  30. * @version V3.1.0
  31. * @copyright 引迈信息技术有限公司
  32. * @date 2021年6月15日
  33. */
  34. @Service
  35. public class VisualServiceImpl extends SuperServiceImpl<VisualMapper, VisualEntity> implements VisualService {
  36. @Autowired
  37. private VisualConfigService configService;
  38. @Autowired
  39. private SystemService systemService;
  40. @Override
  41. public List getList(VisualPaginationModel pagination) {
  42. QueryWrapper<VisualEntity> queryWrapper = new QueryWrapper<>();
  43. SystemEntity infoByEnCode = systemService.getInfoByEnCode(RequestContext.getAppCode());
  44. if(ObjectUtil.isNotEmpty(pagination.getTitle())){
  45. queryWrapper.lambda().like(VisualEntity::getTitle, pagination.getTitle());
  46. }
  47. queryWrapper.lambda().eq(VisualEntity::getCategory, pagination.getCategory());
  48. queryWrapper.lambda().eq(VisualEntity::getSystemId, infoByEnCode.getId());
  49. queryWrapper.lambda().orderByDesc(VisualEntity::getCreateTime);
  50. Page page = new Page(pagination.getCurrent(), pagination.getSize());
  51. Page iPages = this.page(page, queryWrapper);
  52. return pagination.setData(iPages);
  53. }
  54. @Override
  55. public List<VisualEntity> getList() {
  56. SystemEntity infoByEnCode = systemService.getInfoByEnCode(RequestContext.getAppCode());
  57. QueryWrapper<VisualEntity> queryWrapper = new QueryWrapper<>();
  58. queryWrapper.lambda().eq(VisualEntity::getSystemId, infoByEnCode.getId());
  59. queryWrapper.lambda().orderByDesc(VisualEntity::getCreateTime);
  60. return this.list(queryWrapper);
  61. }
  62. @Override
  63. public VisualEntity getInfo(String id) {
  64. QueryWrapper<VisualEntity> queryWrapper = new QueryWrapper<>();
  65. queryWrapper.lambda().eq(VisualEntity::getId, id);
  66. return this.getOne(queryWrapper);
  67. }
  68. @Override
  69. public void create(VisualEntity entity, VisualConfigEntity configEntity) {
  70. getSystemId(entity);
  71. entity.setId(RandomUtil.uuId());
  72. entity.setCreateTime(new Date());
  73. entity.setUpdateUser(UserProvider.getLoginUserId());
  74. entity.setStatus(1);
  75. entity.setIsDeleted(0);
  76. this.creUpdateCheck(entity,true);
  77. this.save(entity);
  78. configEntity.setVisualId(entity.getId());
  79. configService.create(configEntity);
  80. }
  81. private void getSystemId(VisualEntity entity) {
  82. SystemEntity infoByEnCode = systemService.getInfoByEnCode(RequestContext.getAppCode());
  83. entity.setSystemId(infoByEnCode.getId());
  84. }
  85. @Override
  86. public String getSystemIdByReq() {
  87. SystemEntity infoByEnCode = systemService.getInfoByEnCode(RequestContext.getAppCode());
  88. return null==infoByEnCode.getId()?"":infoByEnCode.getId();
  89. }
  90. @Override
  91. public boolean update(String id, VisualEntity entity, VisualConfigEntity configEntity) {
  92. getSystemId(entity);
  93. entity.setId(id);
  94. entity.setUpdateTime(new Date());
  95. entity.setUpdateUser(UserProvider.getLoginUserId());
  96. this.creUpdateCheck(entity,true);
  97. boolean flag = this.updateById(entity);
  98. if (configEntity != null) {
  99. configService.update(configEntity.getId(), configEntity);
  100. }
  101. return flag;
  102. }
  103. @Override
  104. public void delete(VisualEntity entity) {
  105. if (entity != null) {
  106. this.removeById(entity.getId());
  107. VisualConfigEntity config = configService.getInfo(entity.getId());
  108. configService.delete(config);
  109. }
  110. }
  111. @Override
  112. public void createImport(VisualEntity entity, VisualConfigEntity configEntity) throws DataException {
  113. try {
  114. getSystemId(entity);
  115. this.creUpdateCheck(entity,true);
  116. entity.setId(RandomUtil.uuId());
  117. this.save(entity);
  118. configService.create(configEntity);
  119. }catch (Exception e){
  120. throw new DataException(MsgCode.IMP003.get());
  121. }
  122. }
  123. public void creUpdateCheck(VisualEntity entity, Boolean fullNameCheck) {
  124. String title = entity.getTitle();
  125. String systemId = entity.getSystemId();
  126. // 名称长度验证(假设长度限制为80)
  127. if (StringUtil.isNotEmpty(title)&&title.length() > 80) {
  128. throw new DataException(MsgCode.EXIST005.get());
  129. }
  130. // 动态构建查询条件
  131. LambdaQueryWrapper<VisualEntity> queryWrapper = new LambdaQueryWrapper<>();
  132. if (fullNameCheck) {
  133. queryWrapper.eq(VisualEntity::getTitle, title)
  134. .eq(VisualEntity::getSystemId, systemId);
  135. List<VisualEntity> list = this.list(queryWrapper);
  136. if (!list.isEmpty()) {
  137. if (StringUtil.isNotEmpty(entity.getId())&&list.get(0).getId().equals(entity.getId())) {
  138. return;
  139. }
  140. throw new DataException(MsgCode.EXIST003.get());
  141. }
  142. }
  143. }
  144. }