ProjectGanttServiceImpl.java 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. package jnpf.service.impl;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import jnpf.base.Page;
  4. import jnpf.base.service.SuperServiceImpl;
  5. import jnpf.entity.ProjectGanttEntity;
  6. import jnpf.mapper.ProjectGanttMapper;
  7. import jnpf.service.ProjectGanttService;
  8. import jnpf.util.RandomUtil;
  9. import jnpf.util.UserProvider;
  10. import org.apache.commons.lang3.StringUtils;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.stereotype.Service;
  13. import org.springframework.transaction.annotation.Transactional;
  14. import java.util.Date;
  15. import java.util.List;
  16. /**
  17. * 订单明细
  18. *
  19. * @author JNPF开发平台组
  20. * @copyright 引迈信息技术有限公司
  21. * @date 2019年9月26日 上午9:18
  22. */
  23. @Service
  24. public class ProjectGanttServiceImpl extends SuperServiceImpl<ProjectGanttMapper, ProjectGanttEntity> implements ProjectGanttService {
  25. @Override
  26. public List<ProjectGanttEntity> getList(Page page) {
  27. QueryWrapper<ProjectGanttEntity> queryWrapper = new QueryWrapper<>();
  28. queryWrapper.lambda().eq(ProjectGanttEntity::getType, 1).orderByAsc(ProjectGanttEntity::getSortCode)
  29. .orderByDesc(ProjectGanttEntity::getCreatorTime);
  30. if (!StringUtils.isEmpty(page.getKeyword())) {
  31. queryWrapper.lambda().and(
  32. t -> t.like(ProjectGanttEntity::getEnCode, page.getKeyword())
  33. .or().like(ProjectGanttEntity::getFullName, page.getKeyword())
  34. );
  35. }
  36. return this.list(queryWrapper);
  37. }
  38. @Override
  39. public List<ProjectGanttEntity> getTaskList(String projectId) {
  40. ProjectGanttEntity entity = this.getInfo(projectId);
  41. QueryWrapper<ProjectGanttEntity> queryWrapper = new QueryWrapper<>();
  42. queryWrapper.lambda().eq(ProjectGanttEntity::getType, 2).eq(ProjectGanttEntity::getProjectId, projectId).orderByAsc(ProjectGanttEntity::getSortCode);
  43. List<ProjectGanttEntity> list = this.list(queryWrapper);
  44. list.add(entity);
  45. return list;
  46. }
  47. @Override
  48. public ProjectGanttEntity getInfo(String id) {
  49. QueryWrapper<ProjectGanttEntity> queryWrapper = new QueryWrapper<>();
  50. queryWrapper.lambda().eq(ProjectGanttEntity::getId, id);
  51. return this.getOne(queryWrapper);
  52. }
  53. @Override
  54. public boolean allowDelete(String id) {
  55. QueryWrapper<ProjectGanttEntity> queryWrapper = new QueryWrapper<>();
  56. queryWrapper.lambda().and(t ->
  57. t.eq(ProjectGanttEntity::getParentId, id).or().eq(ProjectGanttEntity::getProjectId, id)
  58. );
  59. return this.list(queryWrapper).size() < 1;
  60. }
  61. @Override
  62. public void delete(ProjectGanttEntity entity) {
  63. this.removeById(entity.getId());
  64. }
  65. @Override
  66. public void create(ProjectGanttEntity entity) {
  67. entity.setId(RandomUtil.uuId());
  68. if (entity.getEnabledMark() == null) {
  69. entity.setEnabledMark(1);
  70. }
  71. entity.setSortCode(RandomUtil.parses());
  72. entity.setCreatorUserId(UserProvider.getUser().getUserId());
  73. this.save(entity);
  74. }
  75. @Override
  76. public boolean update(String id, ProjectGanttEntity entity) {
  77. entity.setId(id);
  78. entity.setLastModifyTime(new Date());
  79. entity.setLastModifyUserId(UserProvider.getUser().getUserId());
  80. return this.updateById(entity);
  81. }
  82. @Override
  83. public boolean isExistByFullName(String fullName, String id) {
  84. QueryWrapper<ProjectGanttEntity> queryWrapper = new QueryWrapper<>();
  85. queryWrapper.lambda().eq(ProjectGanttEntity::getFullName, fullName);
  86. if (!StringUtils.isEmpty(id)) {
  87. queryWrapper.lambda().ne(ProjectGanttEntity::getId, id);
  88. }
  89. return this.count(queryWrapper) > 0 ? true : false;
  90. }
  91. @Override
  92. public boolean isExistByEnCode(String enCode, String id) {
  93. QueryWrapper<ProjectGanttEntity> queryWrapper = new QueryWrapper<>();
  94. queryWrapper.lambda().eq(ProjectGanttEntity::getEnCode, enCode);
  95. if (!StringUtils.isEmpty(id)) {
  96. queryWrapper.lambda().ne(ProjectGanttEntity::getId, id);
  97. }
  98. return this.count(queryWrapper) > 0 ? true : false;
  99. }
  100. @Override
  101. @Transactional
  102. public boolean first(String id) {
  103. boolean isOk = false;
  104. //获取要上移的那条数据的信息
  105. ProjectGanttEntity upEntity = this.getById(id);
  106. Long upSortCode = upEntity.getSortCode() == null ? 0 : upEntity.getSortCode();
  107. //查询上几条记录
  108. QueryWrapper<ProjectGanttEntity> queryWrapper = new QueryWrapper<>();
  109. queryWrapper.lambda()
  110. .lt(ProjectGanttEntity::getSortCode, upSortCode)
  111. .eq(ProjectGanttEntity::getParentId, upEntity.getParentId())
  112. .orderByDesc(ProjectGanttEntity::getSortCode);
  113. List<ProjectGanttEntity> downEntity = this.list(queryWrapper);
  114. if (downEntity.size() > 0) {
  115. //交换两条记录的sort值
  116. Long temp = upEntity.getSortCode();
  117. upEntity.setSortCode(downEntity.get(0).getSortCode());
  118. downEntity.get(0).setSortCode(temp);
  119. this.updateById(downEntity.get(0));
  120. this.updateById(upEntity);
  121. isOk = true;
  122. }
  123. return isOk;
  124. }
  125. @Override
  126. @Transactional
  127. public boolean next(String id) {
  128. boolean isOk = false;
  129. //获取要下移的那条数据的信息
  130. ProjectGanttEntity downEntity = this.getById(id);
  131. Long upSortCode = downEntity.getSortCode() == null ? 0 : downEntity.getSortCode();
  132. //查询下几条记录
  133. QueryWrapper<ProjectGanttEntity> queryWrapper = new QueryWrapper<>();
  134. queryWrapper.lambda()
  135. .gt(ProjectGanttEntity::getSortCode, upSortCode)
  136. .eq(ProjectGanttEntity::getParentId,downEntity.getParentId())
  137. .orderByAsc(ProjectGanttEntity::getSortCode);
  138. List<ProjectGanttEntity> upEntity = this.list(queryWrapper);
  139. if (upEntity.size() > 0) {
  140. //交换两条记录的sort值
  141. Long temp = downEntity.getSortCode();
  142. downEntity.setSortCode(upEntity.get(0).getSortCode());
  143. upEntity.get(0).setSortCode(temp);
  144. this.updateById(upEntity.get(0));
  145. this.updateById(downEntity);
  146. isOk = true;
  147. }
  148. return isOk;
  149. }
  150. }