CheckDataServiceImpl.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. package com.ghsc.partybuild.service.impl;
  2. import com.ghsc.partybuild.mapper.*;
  3. import com.ghsc.partybuild.model.*;
  4. import com.ghsc.partybuild.service.CheckDataService;
  5. import com.ghsc.partybuild.service.UserService;
  6. import com.ghsc.partybuild.util.StringUtils;
  7. import com.github.pagehelper.PageHelper;
  8. import com.github.pagehelper.PageInfo;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.stereotype.Service;
  11. import org.springframework.transaction.annotation.Propagation;
  12. import org.springframework.transaction.annotation.Transactional;
  13. import java.util.*;
  14. import java.util.stream.Collectors;
  15. @Service("checkDataService")
  16. public class CheckDataServiceImpl implements CheckDataService {
  17. @Autowired
  18. PtCheckpartyMapper checkpartyMapper;
  19. @Autowired
  20. PtChecknamelistMapper checknamelistMapper;
  21. @Autowired
  22. PtCheckdataCQuery checkdataCQuery;
  23. @Autowired
  24. PtCheckdataMapper CheckdataMapper;
  25. @Autowired
  26. PtCheckscoreMapper checkscoreMapper;
  27. @Autowired
  28. PtCheckquestionMapper checkquestionMapper;
  29. @Autowired
  30. CfUsersCQuery cfUsersCQuery;
  31. @Autowired
  32. UserService userService;
  33. @Autowired
  34. StringUtils stringUtils;
  35. @Override
  36. public PageInfo<HashMap<String, Object>> getCheckNameList(int pageIndex, int pageSize, Integer year, Integer quarter, String dzzdm, String checkUserName, String partyCode, Integer recordStatus) {
  37. PageHelper.startPage(pageIndex, pageSize);
  38. List<HashMap<String, Object>> list = checkdataCQuery.selectCheckNameList(year, quarter, dzzdm, checkUserName, partyCode, recordStatus, null);
  39. PageInfo<HashMap<String, Object>> result = new PageInfo(list);
  40. return result;
  41. }
  42. @Override
  43. public List<HashMap<String, Object>> getCheckPartyList(Integer year, Integer quarter) {
  44. List<HashMap<String, Object>> list = checkdataCQuery.selectCheckPartyList(year, quarter);
  45. return list;
  46. }
  47. @Override
  48. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  49. public int saveCheckNameList(PtChecknamelist item, List<PtCheckparty> checkPartyList) {
  50. PtChecknamelist dbItem = checknamelistMapper.selectByPrimaryKey(item.getNameid());
  51. if (dbItem == null) {
  52. item.setCreatetime(new Date());
  53. item.setRecordstatus(1);
  54. item.setNameid(UUID.randomUUID().toString());
  55. checknamelistMapper.insertSelective(item);
  56. } else {
  57. checknamelistMapper.updateByPrimaryKey(item);
  58. }
  59. PtCheckpartyExample example = new PtCheckpartyExample();
  60. example.or().andNameidEqualTo(item.getNameid());
  61. checkpartyMapper.deleteByExample(example);
  62. checkPartyList.forEach(it -> {
  63. it.setNameid(item.getNameid());
  64. it.setPartyid(UUID.randomUUID().toString());
  65. checkpartyMapper.insertSelective(it);
  66. });
  67. assetrCheckScore(item.getYear(),item.getQuarter(),item.getCheckuserid(),item.getCheckusername(),checkPartyList);
  68. // 查询选择的用户是否有检查人员权限
  69. List<HashMap<String, Object>> userInfo = cfUsersCQuery.selectUserAllByUserID(item.getCheckuserid());
  70. if (!userInfo.isEmpty()) {
  71. // 查询该用户是否绑定了检查人员角色
  72. List<HashMap<String, Object>> roleList = cfUsersCQuery.GetRoleByUserId(item.getCheckuserid());
  73. HashMap<String, Object> jcRole = roleList.stream().filter(it -> it.get("ROLEID").equals("27f0fd61-3107-486f-9240-4f9ef909103e")).findFirst().orElse(null);
  74. if (jcRole == null) {
  75. // 没有检查人员角色的,绑定一个
  76. userService.saveUserRoleList("27f0fd61-3107-486f-9240-4f9ef909103e", item.getCheckuserid(), false);
  77. }
  78. }
  79. return 1;
  80. }
  81. /**
  82. * 生成考核评分
  83. * @param year
  84. * @param quarter
  85. * @param checkUserId
  86. * @param checkUserName
  87. * @param checkPartyList
  88. */
  89. private void assetrCheckScore(Integer year, Integer quarter,String checkUserId,String checkUserName, List<PtCheckparty> checkPartyList) {
  90. List<String> partyCodes = checkPartyList.stream().map(x -> x.getPartycode()).collect(Collectors.toList());
  91. checkPartyList.forEach(party -> {
  92. PtCheckscoreExample example = new PtCheckscoreExample();
  93. example.or().andYearEqualTo(year).andQuarterEqualTo(quarter).andDzzdmEqualTo(party.getPartycode());
  94. PtCheckscore partyScore = checkscoreMapper.selectByExample(example).stream().findFirst().orElse(null);
  95. if (partyScore==null) {
  96. partyScore =new PtCheckscore();
  97. partyScore.setScoreid(UUID.randomUUID().toString());
  98. partyScore.setYear(year);
  99. partyScore.setQuarter(quarter);
  100. partyScore.setCheckuserid(checkUserId);
  101. partyScore.setDzzdm(party.getPartycode());
  102. partyScore.setCheckusername(checkUserName);
  103. partyScore.setRecordstatus(0);
  104. checkscoreMapper.insert(partyScore);
  105. }else{
  106. partyScore.setCheckuserid(UUID.randomUUID().toString());
  107. partyScore.setCheckuserid(checkUserId);
  108. checkscoreMapper.updateByPrimaryKeySelective(partyScore);
  109. }
  110. });
  111. }
  112. @Override
  113. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  114. public Integer deleteCheckNameList(List<String> nameIdList) {
  115. PtCheckpartyExample example = new PtCheckpartyExample();
  116. example.or().andNameidIn(nameIdList);
  117. checkpartyMapper.deleteByExample(example);
  118. PtChecknamelistExample ckExp = new PtChecknamelistExample();
  119. ckExp.or().andNameidIn(nameIdList);
  120. checknamelistMapper.deleteByExample(ckExp);
  121. PtCheckdataExample cdExp = new PtCheckdataExample();
  122. cdExp.or().andDataidIn(nameIdList);
  123. CheckdataMapper.deleteByExample(cdExp);
  124. return 1;
  125. }
  126. @Override
  127. public Integer changeCheckNameListStatus(List<String> nameIdList, Integer recordStatus) {
  128. PtChecknamelist record = new PtChecknamelist();
  129. record.setRecordstatus(recordStatus);
  130. PtChecknamelistExample ckExp = new PtChecknamelistExample();
  131. ckExp.or().andNameidIn(nameIdList);
  132. checknamelistMapper.updateByExampleSelective(record, ckExp);
  133. return 1;
  134. }
  135. @Override
  136. public HashMap<String, Object> getCheckName(String id) {
  137. List<HashMap<String, Object>> list = checkdataCQuery.selectCheckNameList(null, null, null, null, null, null, null);
  138. HashMap<String, Object> item = list.stream().filter(x -> x.get("nameid").toString().equals(id)).findFirst().orElse(null);
  139. return item;
  140. }
  141. @Override
  142. public PageInfo<HashMap<String, Object>> getCheckDataList(int pageIndex, int pageSize, Integer year, String dzzdm, String remark, String roleID, String userid) {
  143. // 如果是核查人员,只允许查询用户核查名单中存在的组织的材料数据
  144. String dzzdmInStr = null;
  145. if (!stringUtils.IsNullOrEmpty(roleID) && roleID.equals("27f0fd61-3107-486f-9240-4f9ef909103e")) {
  146. List<HashMap<String, Object>> checkNameList = checkdataCQuery.selectCheckNameList(null, null, null, null, null, null, userid);
  147. // 获取党组织代码
  148. List<String> distinctDzzdmList = checkNameList.stream()
  149. .map(item -> item.get("partcodes"))
  150. .filter(Objects::nonNull)
  151. .map(Object::toString).distinct().collect(Collectors.toList());
  152. if (!distinctDzzdmList.isEmpty()) {
  153. // 拼接in查询条件
  154. dzzdmInStr = distinctDzzdmList.stream()
  155. .map(s -> "'" + s.replace("'", "''") + "'")
  156. .collect(Collectors.joining(",", "", ""));
  157. }
  158. }
  159. PageHelper.startPage(pageIndex, pageSize);
  160. List<HashMap<String, Object>> list = checkdataCQuery.selectCheckDataList(year, dzzdm, remark, dzzdmInStr);
  161. PageInfo<HashMap<String, Object>> result = new PageInfo(list);
  162. return result;
  163. }
  164. @Override
  165. public List<HashMap<String, Object>> getCheckDataFleList(String year) {
  166. List<HashMap<String, Object>> list = checkdataCQuery.selectCheckDataFleList(year);
  167. return list;
  168. }
  169. @Override
  170. public int saveCheckdata(PtCheckdata item, String userid, String username) {
  171. PtCheckdata dbItem = CheckdataMapper.selectByPrimaryKey(item.getDataid());
  172. if (dbItem == null) {
  173. item.setCheckdatauserid(userid);
  174. item.setCheckdatausername(username);
  175. item.setRecordstatus(1);
  176. item.setCreatetime(new Date());
  177. item.setCreateuserid(userid);
  178. item.setCreateusername(username);
  179. return CheckdataMapper.insert(item);
  180. } else {
  181. item.setUpdatetime(new Date());
  182. item.setUpdateuserid(userid);
  183. item.setUpdateusername(username);
  184. return CheckdataMapper.updateByPrimaryKeySelective(item);
  185. }
  186. }
  187. @Override
  188. public PtCheckdata getCheckdata(String id) {
  189. return CheckdataMapper.selectByPrimaryKey(id);
  190. }
  191. @Override
  192. public PageInfo<HashMap<String, Object>> getCheckScoreList(int pageIndex, int pageSize, Integer year, Integer quarter, String dzzdm, String checkUserName, Float minScore,Float maxScore,Integer recordStatus,String checkuserid, String roleID, String userid) {
  193. // 如果是核查人员,只允许查询用户核查名单中存在的组织的材料数据
  194. String dzzdmInStr = null;
  195. if (!stringUtils.IsNullOrEmpty(roleID) && roleID.equals("27f0fd61-3107-486f-9240-4f9ef909103e")) {
  196. List<HashMap<String, Object>> checkNameList = checkdataCQuery.selectCheckNameList(null, null, null, null, null, null, userid);
  197. // 获取党组织代码
  198. List<String> distinctDzzdmList = checkNameList.stream()
  199. .map(item -> item.get("partcodes"))
  200. .filter(Objects::nonNull)
  201. .map(Object::toString).distinct().collect(Collectors.toList());
  202. if (!distinctDzzdmList.isEmpty()) {
  203. // 拼接in查询条件
  204. dzzdmInStr = distinctDzzdmList.stream()
  205. .map(s -> "'" + s.replace("'", "''") + "'")
  206. .collect(Collectors.joining(",", "", ""));
  207. }
  208. }
  209. PageHelper.startPage(pageIndex, pageSize);
  210. List<HashMap<String, Object>> list = checkdataCQuery.selectCheckScoreList( year, quarter, dzzdm, checkUserName, minScore, maxScore, recordStatus,checkuserid,dzzdmInStr);
  211. PageInfo<HashMap<String, Object>> result = new PageInfo(list);
  212. return result;
  213. }
  214. @Override
  215. @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
  216. public int saveCheckScore(PtCheckscore item ,List<PtCheckquestion> questionList) {
  217. PtCheckscore dbItem = checkscoreMapper.selectByPrimaryKey(item.getScoreid());
  218. dbItem.setScore(item.getScore());
  219. dbItem.setUpdatetime(new Date());
  220. dbItem.setUpdateuserid(item.getUpdateuserid());
  221. dbItem.setUpdateusername(item.getUpdateusername());
  222. if (dbItem.getScore() != null) {
  223. dbItem.setRecordstatus(1);
  224. } else {
  225. dbItem.setRecordstatus(2);
  226. }
  227. checkscoreMapper.updateByPrimaryKeySelective(dbItem);
  228. PtCheckquestionExample example=new PtCheckquestionExample();
  229. example.or().andScoreidEqualTo(item.getScoreid());
  230. checkquestionMapper.deleteByExample(example);
  231. questionList.forEach(x->{
  232. x.setQuestionid(UUID.randomUUID().toString());
  233. x.setScoreid(item.getScoreid());
  234. checkquestionMapper.insert(x);
  235. });
  236. return 1;
  237. }
  238. @Override
  239. public List<PtCheckquestion> getCheckquestionList(String scoreId) {
  240. PtCheckquestionExample example=new PtCheckquestionExample();
  241. example.or().andScoreidEqualTo(scoreId);
  242. return checkquestionMapper.selectByExample(example);
  243. }
  244. }