DashboardsService.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package com.server;
  2. import com.dao.DashboardsMapper;
  3. import com.dao.UserMapper;
  4. import com.fasterxml.jackson.databind.ObjectMapper;
  5. import com.github.pagehelper.PageInfo;
  6. import com.model.po.Dashboards;
  7. import com.model.pojo.RepCode;
  8. import com.model.pojo.RepEntity;
  9. import com.model.pojo.TestPage;
  10. import com.model.vo.configVo.ChangeOrderInfo;
  11. import com.model.vo.configVo.DashboardsInfo;
  12. import com.util.GetTokenData;
  13. import com.util.TimeUtil;
  14. import org.springframework.beans.BeanUtils;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.stereotype.Service;
  17. import java.util.Iterator;
  18. import java.util.List;
  19. import java.util.Map;
  20. @Service
  21. public class DashboardsService {
  22. @Autowired
  23. TimeUtil timeUtil;
  24. @Autowired
  25. DashboardsMapper dashboardsMapper;
  26. @Autowired
  27. ObjectMapper objectMapper;
  28. @Autowired
  29. GetTokenData getTokenData;
  30. @Autowired
  31. UserMapper userMapper;
  32. @Autowired
  33. ChartsUtilService chartsUtilService;
  34. /*
  35. 保存看板
  36. */
  37. public RepEntity setDashboards(String token, DashboardsInfo dashboardsInfo){
  38. Map<String, String> stringMap = getTokenData.getTokenData(token);
  39. int userId = Integer.parseInt(stringMap.get("id"));
  40. String name = stringMap.get("name");
  41. Dashboards dashboards = new Dashboards();
  42. BeanUtils.copyProperties(dashboardsInfo,dashboards);
  43. dashboards.setCreateBy(name);
  44. dashboards.setCreateId(userId);
  45. dashboardsMapper.setDashboards(dashboards);
  46. int id = dashboards.getId();
  47. return new RepEntity(RepCode.success, id);
  48. }
  49. /*
  50. 更新看板
  51. */
  52. public RepEntity updateDashboards(String token, DashboardsInfo dashboardsInfo) {
  53. Map<String, String> stringMap = getTokenData.getTokenData(token);
  54. int userId = Integer.parseInt(stringMap.get("id"));
  55. String name = stringMap.get("name");
  56. int createId = dashboardsMapper.getCreateIdById(dashboardsInfo.getId());
  57. if (userId != createId){
  58. return new RepEntity(RepCode.NoAuthority);
  59. }
  60. Dashboards dashboards = new Dashboards();
  61. BeanUtils.copyProperties(dashboardsInfo, dashboards);
  62. dashboards.setCreateBy(name);
  63. dashboards.setCreateId(userId);
  64. dashboardsMapper.updateDashboards(dashboards);
  65. return new RepEntity(RepCode.success);
  66. }
  67. /*
  68. 删除看板
  69. */
  70. public RepEntity delDashboards(String token, List<Integer> idList){
  71. Map<String, String> stringMap = getTokenData.getTokenData(token);
  72. int userId = Integer.parseInt(stringMap.get("id"));
  73. Iterator isList = idList.iterator();
  74. while (isList.hasNext()){
  75. int id = (int) isList.next();
  76. int createId = dashboardsMapper.getCreateIdById(id);
  77. if (userId != createId){
  78. return new RepEntity(RepCode.NoAuthority);
  79. }
  80. }
  81. dashboardsMapper.delDashboards(idList);
  82. return new RepEntity(RepCode.success);
  83. }
  84. /*
  85. 查看看板
  86. */
  87. public RepEntity getListDashboards(String token, TestPage testPage){
  88. Map<String, String> stringMap = getTokenData.getTokenData(token);
  89. int id = Integer.parseInt(stringMap.get("id"));
  90. List<Dashboards> getListDashboards = dashboardsMapper.getListDashboards(id, testPage.enablePaging());
  91. PageInfo<Dashboards> pageInfo = new PageInfo<>(getListDashboards);
  92. return new RepEntity(RepCode.success, pageInfo);
  93. }
  94. /*
  95. 查看单个看板
  96. */
  97. public RepEntity getDashboards(String token, int id){
  98. Map<String, String> stringMap = getTokenData.getTokenData(token);
  99. int userId = Integer.parseInt(stringMap.get("id"));
  100. return new RepEntity(RepCode.success, dashboardsMapper.getDashboards(userId, id));
  101. }
  102. /*
  103. 转交看板
  104. */
  105. public RepEntity changeDashOrder(String token, ChangeOrderInfo changeOrderInfo){
  106. Map<String, String> stringMap = getTokenData.getTokenData(token);
  107. int userId = Integer.parseInt(stringMap.get("id"));
  108. int createId = dashboardsMapper.getCreateIdById(changeOrderInfo.getId());
  109. if (userId != createId){
  110. return new RepEntity(RepCode.NoAuthority);
  111. }
  112. String name = userMapper.getName(changeOrderInfo.getUserId());
  113. dashboardsMapper.changeDashOrder(name, changeOrderInfo.getUserId(), changeOrderInfo.getId());
  114. return new RepEntity(RepCode.success);
  115. }
  116. }