ProjectGanttController.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. package jnpf.controller;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import io.swagger.v3.oas.annotations.Operation;
  4. import io.swagger.v3.oas.annotations.Parameter;
  5. import io.swagger.v3.oas.annotations.Parameters;
  6. import io.swagger.v3.oas.annotations.tags.Tag;
  7. import jnpf.annotation.EncryptApi;
  8. import jnpf.base.ActionResult;
  9. import jnpf.base.Page;
  10. import jnpf.base.controller.SuperController;
  11. import jnpf.base.vo.ListVO;
  12. import jnpf.constant.MsgCode;
  13. import jnpf.entity.ProjectGanttEntity;
  14. import jnpf.exception.DataException;
  15. import jnpf.model.projectgantt.*;
  16. import jnpf.permission.entity.UserEntity;
  17. import jnpf.permission.service.UserService;
  18. import jnpf.service.ProjectGanttService;
  19. import jnpf.util.JsonUtil;
  20. import jnpf.util.JsonUtilEx;
  21. import jnpf.util.UploaderUtil;
  22. import jnpf.util.treeutil.ListToTreeUtil;
  23. import jnpf.util.treeutil.SumTree;
  24. import jnpf.util.treeutil.TreeDotUtils;
  25. import org.apache.commons.lang3.StringUtils;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.web.bind.annotation.*;
  28. import jakarta.validation.Valid;
  29. import java.util.ArrayList;
  30. import java.util.Collections;
  31. import java.util.List;
  32. import java.util.stream.Collectors;
  33. /**
  34. * 项目计划
  35. *
  36. * @author JNPF开发平台组
  37. * @version V3.1.0
  38. * @copyright 引迈信息技术有限公司(https://www.jnpfsoft.com)
  39. * @date 2019年9月26日 上午9:18
  40. */
  41. @Tag(name = "项目计划", description = "ProjectGantt")
  42. @RestController
  43. @RequestMapping("/api/extend/ProjectGantt")
  44. public class ProjectGanttController extends SuperController<ProjectGanttService, ProjectGanttEntity> {
  45. @Autowired
  46. private ProjectGanttService projectGanttService;
  47. @Autowired
  48. private UserService userService;
  49. /**
  50. * 项目列表
  51. *
  52. * @param page 分页模型
  53. * @return
  54. */
  55. @Operation(summary = "获取项目管理列表")
  56. @GetMapping
  57. @SaCheckPermission("extend.projectGantt")
  58. public ActionResult<ListVO<ProjectGanttListVO>> list(Page page) {
  59. List<ProjectGanttEntity> data = projectGanttService.getList(page);
  60. List<ProjectGanttListVO> list = JsonUtil.getJsonToList(data, ProjectGanttListVO.class);
  61. //获取用户给项目参与人员列表赋值
  62. List<String> userId = new ArrayList<>();
  63. list.forEach(t -> {
  64. String[] ids = t.getManagerIds().split(",");
  65. Collections.addAll(userId, ids);
  66. });
  67. List<UserEntity> userList = userService.getUserName(userId);
  68. for (ProjectGanttListVO vo : list) {
  69. List<String> managerList = new ArrayList<>();
  70. Collections.addAll(managerList, vo.getManagerIds().split(","));
  71. List<UserEntity> user = userList.stream().filter(t -> managerList.contains(t.getId())).collect(Collectors.toList());
  72. List<ProjectGanttManagerIModel> list1 = new ArrayList<>();
  73. user.forEach(t -> {
  74. ProjectGanttManagerIModel model1 = new ProjectGanttManagerIModel();
  75. model1.setAccount(t.getRealName() + "/" + t.getAccount());
  76. model1.setHeadIcon(UploaderUtil.uploaderImg(t.getHeadIcon()));
  77. list1.add(model1);
  78. });
  79. vo.setManagersInfo(list1);
  80. }
  81. ListVO listVO = new ListVO<>();
  82. listVO.setList(list);
  83. return ActionResult.success(listVO);
  84. }
  85. /**
  86. * 任务列表
  87. *
  88. * @param page 分页模型
  89. * @param projectId 主键
  90. * @return
  91. */
  92. @Operation(summary = "获取项目任务列表")
  93. @GetMapping("/{projectId}/Task")
  94. @Parameters({
  95. @Parameter(name = "projectId", description = "主键",required = true),
  96. })
  97. @SaCheckPermission("extend.projectGantt")
  98. public ActionResult<ListVO<ProjectGanttTaskTreeVO>> taskList(Page page, @PathVariable("projectId") String projectId) {
  99. List<ProjectGanttEntity> data = projectGanttService.getTaskList(projectId);
  100. List<ProjectGanttEntity> dataAll = data;
  101. if (!StringUtils.isEmpty(page.getKeyword())) {
  102. data = data.stream().filter(t -> String.valueOf(t.getFullName()).contains(page.getKeyword()) || String.valueOf(t.getEnCode()).contains(page.getKeyword())).collect(Collectors.toList());
  103. }
  104. List<ProjectGanttEntity> list = JsonUtil.getJsonToList(ListToTreeUtil.treeWhere(data, dataAll), ProjectGanttEntity.class);
  105. List<ProjectGanttTreeModel> treeList = JsonUtil.getJsonToList(list, ProjectGanttTreeModel.class);
  106. List<SumTree<ProjectGanttTreeModel>> trees = TreeDotUtils.convertListToTreeDot(treeList);
  107. List<ProjectGanttTaskTreeVO> listVO = JsonUtil.getJsonToList(trees, ProjectGanttTaskTreeVO.class);
  108. ListVO vo = new ListVO();
  109. vo.setList(listVO);
  110. return ActionResult.success(vo);
  111. }
  112. /**
  113. * 任务树形
  114. *
  115. * @param projectId 主键
  116. * @param id 主键
  117. * @return
  118. */
  119. @Operation(summary = "获取项目计划任务树形(新建任务)")
  120. @GetMapping("/{projectId}/Task/Selector/{id}")
  121. @Parameters({
  122. @Parameter(name = "projectId", description = "主键",required = true),
  123. @Parameter(name = "id", description = "主键",required = true),
  124. })
  125. @SaCheckPermission("extend.projectGantt")
  126. public ActionResult<ListVO<ProjectGanttTaskTreeVO>> taskTreeView(@PathVariable("projectId") String projectId, @PathVariable("id") String id) {
  127. List<ProjectGanttTaskTreeModel> treeList = new ArrayList<>();
  128. List<ProjectGanttEntity> data = projectGanttService.getTaskList(projectId);
  129. if (!"0".equals(id)) {
  130. //上级不能选择自己
  131. data.remove(projectGanttService.getInfo(id));
  132. }
  133. for (ProjectGanttEntity entity : data) {
  134. ProjectGanttTaskTreeModel treeModel = new ProjectGanttTaskTreeModel();
  135. treeModel.setId(entity.getId());
  136. treeModel.setFullName(entity.getFullName());
  137. treeModel.setParentId(entity.getParentId());
  138. treeList.add(treeModel);
  139. }
  140. List<SumTree<ProjectGanttTaskTreeModel>> trees = TreeDotUtils.convertListToTreeDotFilter(treeList);
  141. List<ProjectGanttTaskTreeVO> listVO = JsonUtil.getJsonToList(trees, ProjectGanttTaskTreeVO.class);
  142. ListVO vo = new ListVO();
  143. vo.setList(listVO);
  144. return ActionResult.success(vo);
  145. }
  146. /**
  147. * 信息
  148. *
  149. * @param id 主键
  150. * @return
  151. */
  152. @Operation(summary = "获取项目计划信息")
  153. @GetMapping("/{id}")
  154. @Parameters({
  155. @Parameter(name = "id", description = "主键",required = true),
  156. })
  157. @SaCheckPermission("extend.projectGantt")
  158. public ActionResult<ProjectGanttInfoVO> info(@PathVariable("id") String id) throws DataException {
  159. ProjectGanttEntity entity = projectGanttService.getInfo(id);
  160. ProjectGanttInfoVO vo = JsonUtil.getJsonToBeanEx(entity, ProjectGanttInfoVO.class);
  161. return ActionResult.success(vo);
  162. }
  163. /**
  164. * 信息
  165. *
  166. * @param id 主键
  167. * @return
  168. */
  169. @Operation(summary = "获取项目计划信息")
  170. @GetMapping("Task/{id}")
  171. @Parameters({
  172. @Parameter(name = "id", description = "主键",required = true),
  173. })
  174. @SaCheckPermission("extend.projectGantt")
  175. public ActionResult<ProjectGanttTaskInfoVO> taskInfo(@PathVariable("id") String id) throws DataException {
  176. ProjectGanttEntity entity = projectGanttService.getInfo(id);
  177. ProjectGanttTaskInfoVO vo = JsonUtil.getJsonToBeanEx(entity, ProjectGanttTaskInfoVO.class);
  178. return ActionResult.success(vo);
  179. }
  180. /**
  181. * 删除
  182. *
  183. * @param id 主键
  184. * @return
  185. */
  186. @Operation(summary = "删除项目计划/任务")
  187. @DeleteMapping("/{id}")
  188. @Parameters({
  189. @Parameter(name = "id", description = "主键",required = true),
  190. })
  191. @SaCheckPermission("extend.projectGantt")
  192. public ActionResult delete(@PathVariable("id") String id) {
  193. if (projectGanttService.allowDelete(id)) {
  194. ProjectGanttEntity entity = projectGanttService.getInfo(id);
  195. if (entity != null) {
  196. projectGanttService.delete(entity);
  197. return ActionResult.success(MsgCode.SU003.get());
  198. }
  199. return ActionResult.fail(MsgCode.FA003.get());
  200. } else {
  201. return ActionResult.fail(MsgCode.ETD112.get());
  202. }
  203. }
  204. /**
  205. * 创建
  206. *
  207. * @param projectGanttCrForm 项目模型
  208. * @return
  209. */
  210. @EncryptApi
  211. @Operation(summary = "添加项目计划")
  212. @PostMapping
  213. @Parameters({
  214. @Parameter(name = "projectGanttCrForm", description = "项目模型",required = true),
  215. })
  216. @SaCheckPermission("extend.projectGantt")
  217. public ActionResult create(@RequestBody @Valid ProjectGanttCrForm projectGanttCrForm) {
  218. ProjectGanttEntity entity = JsonUtil.getJsonToBean(projectGanttCrForm, ProjectGanttEntity.class);
  219. entity.setType(1);
  220. entity.setParentId("0");
  221. if (projectGanttService.isExistByFullName(projectGanttCrForm.getFullName(), entity.getId())) {
  222. return ActionResult.fail(MsgCode.EXIST001.get());
  223. }
  224. if (projectGanttService.isExistByEnCode(projectGanttCrForm.getEnCode(), entity.getId())) {
  225. return ActionResult.fail(MsgCode.EXIST002.get());
  226. }
  227. projectGanttService.create(entity);
  228. return ActionResult.success(MsgCode.SU001.get());
  229. }
  230. /**
  231. * 编辑
  232. *
  233. * @param id 主键
  234. * @param projectGanttUpForm 项目模型
  235. * @return
  236. */
  237. @Operation(summary = "修改项目计划")
  238. @PutMapping("/{id}")
  239. @Parameters({
  240. @Parameter(name = "id", description = "主键",required = true),
  241. @Parameter(name = "projectGanttUpForm", description = "项目模型",required = true),
  242. })
  243. @SaCheckPermission("extend.projectGantt")
  244. public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid ProjectGanttUpForm projectGanttUpForm) {
  245. ProjectGanttEntity entity = JsonUtil.getJsonToBean(projectGanttUpForm, ProjectGanttEntity.class);
  246. if (projectGanttService.isExistByFullName(projectGanttUpForm.getFullName(), id)) {
  247. return ActionResult.fail(MsgCode.EXIST001.get());
  248. }
  249. if (projectGanttService.isExistByEnCode(projectGanttUpForm.getEnCode(), id)) {
  250. return ActionResult.fail(MsgCode.EXIST002.get());
  251. }
  252. boolean flag = projectGanttService.update(id, entity);
  253. if (flag == false) {
  254. return ActionResult.fail(MsgCode.FA002.get());
  255. }
  256. return ActionResult.success(MsgCode.SU004.get());
  257. }
  258. /**
  259. * 创建
  260. *
  261. * @param projectGanttTsakCrForm 项目模型
  262. * @return
  263. */
  264. @Operation(summary = "添加项目任务")
  265. @PostMapping("/Task")
  266. @Parameters({
  267. @Parameter(name = "projectGanttTsakCrForm", description = "项目模型",required = true),
  268. })
  269. @SaCheckPermission("extend.projectGantt")
  270. public ActionResult createTask(@RequestBody @Valid ProjectGanttTsakCrForm projectGanttTsakCrForm) {
  271. ProjectGanttEntity entity = JsonUtil.getJsonToBean(projectGanttTsakCrForm, ProjectGanttEntity.class);
  272. entity.setType(2);
  273. if (projectGanttService.isExistByFullName(projectGanttTsakCrForm.getFullName(), entity.getId())) {
  274. return ActionResult.fail(MsgCode.EXIST001.get());
  275. }
  276. projectGanttService.create(entity);
  277. return ActionResult.success(MsgCode.SU001.get());
  278. }
  279. /**
  280. * 编辑
  281. *
  282. * @param id 主键
  283. * @param projectGanttTsakCrForm 项目模型
  284. * @return
  285. */
  286. @Operation(summary = "修改项目任务")
  287. @PutMapping("/Task/{id}")
  288. @Parameters({
  289. @Parameter(name = "projectGanttTsakCrForm", description = "项目模型",required = true),
  290. @Parameter(name = "id", description = "主键",required = true),
  291. })
  292. @SaCheckPermission("extend.projectGantt")
  293. public ActionResult updateTask(@PathVariable("id") String id, @RequestBody @Valid ProjectGanttTsakUpForm projectGanttTsakCrForm) {
  294. ProjectGanttEntity entity = JsonUtil.getJsonToBean(projectGanttTsakCrForm, ProjectGanttEntity.class);
  295. if (projectGanttService.isExistByFullName(projectGanttTsakCrForm.getFullName(), id)) {
  296. return ActionResult.fail(MsgCode.EXIST001.get());
  297. }
  298. boolean flag = projectGanttService.update(id, entity);
  299. if (flag == false) {
  300. return ActionResult.fail(MsgCode.FA002.get());
  301. }
  302. return ActionResult.success(MsgCode.SU004.get());
  303. }
  304. }