0fa24e113a3160e1b9b2b5d3fc7b7f6b90123273.svn-base 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. package cn.com.goldenwater.dcproj.service.impl.tac;
  2. import cn.com.goldenwater.dcproj.constValue.CommonLabel;
  3. import cn.com.goldenwater.dcproj.dao.*;
  4. import cn.com.goldenwater.dcproj.dto.TacCountDto;
  5. import cn.com.goldenwater.dcproj.model.TacEvalationInform;
  6. import cn.com.goldenwater.dcproj.model.TacInspYearBatchGroup;
  7. import cn.com.goldenwater.dcproj.model.TacInspYearBatchGroupMeg;
  8. import cn.com.goldenwater.dcproj.param.*;
  9. import cn.com.goldenwater.dcproj.service.TacIndexService;
  10. import org.apache.commons.collections.map.HashedMap;
  11. import org.apache.commons.lang3.StringUtils;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.data.redis.core.RedisTemplate;
  14. import org.springframework.stereotype.Service;
  15. import org.springframework.transaction.annotation.Transactional;
  16. import java.time.LocalDateTime;
  17. import java.time.ZoneOffset;
  18. import java.util.*;
  19. import java.util.concurrent.TimeUnit;
  20. /**
  21. * Created by jinshui on 2019/12/2.
  22. */
  23. @Service
  24. @Transactional
  25. public class TacIndexServiceImpl implements TacIndexService {
  26. @Autowired
  27. private RedisTemplate redisTemplate;
  28. @Autowired
  29. private TacPblmInfoDao tacPblmInfoDao;
  30. @Autowired
  31. private TacInspYearBatchGroupDao tacInspYearBatchGroupDao;
  32. @Autowired
  33. private TacInspYearBatchDao tacInspYearBatchDao;
  34. @Autowired
  35. private TacInspYearBatchAreaDao tacInspYearBatchAreaDao;
  36. @Autowired
  37. private BisInspAllRlationPersDao rlationPersDao;
  38. @Autowired
  39. private TacEvalationInformDao tacEvalationInformDao;
  40. @Autowired
  41. private TacInspYearBatchGroupMegDao tacInspYearBatchGroupMegDao;
  42. @Override
  43. public TacCountDto countPblmByYear(TacIndexParam tacIndexParam) {
  44. String year = null;
  45. String lastYear = null;
  46. if (tacIndexParam.getYear() != null && tacIndexParam.getYear() > 0) {
  47. year = String.valueOf(tacIndexParam.getYear());
  48. lastYear = String.valueOf(tacIndexParam.getYear() - 1);
  49. } else {
  50. year = String.valueOf(LocalDateTime.now().getYear());
  51. lastYear = String.valueOf(LocalDateTime.now().getYear() - 1);
  52. }
  53. TacCountDto tacCountDto = new TacCountDto();
  54. if (StringUtils.isNotBlank(year)) {
  55. int currCount = getCountByObj(year,tacIndexParam);
  56. int lastNum = getCountByObj(lastYear,tacIndexParam);
  57. tacCountDto.setCount(String.valueOf(currCount));
  58. if (lastNum == 0) {
  59. if (currCount == 0) {
  60. tacCountDto.setPercent(0);
  61. } else {
  62. tacCountDto.setPercent(100);
  63. }
  64. } else {
  65. if (lastNum == 0) {
  66. tacCountDto.setPercent(-100);
  67. } else {
  68. tacCountDto.setPercent((currCount - lastNum) * 100 / lastNum);
  69. }
  70. }
  71. }
  72. return tacCountDto;
  73. }
  74. @Override
  75. public TacCountDto countAuditByYear(TacIndexParam tacIndexParam) {
  76. String year = null;
  77. if (tacIndexParam.getYear() != null && tacIndexParam.getYear() > 0) {
  78. year = String.valueOf(tacIndexParam.getYear());
  79. } else {
  80. year = String.valueOf(LocalDateTime.now().getYear());
  81. }
  82. String province = tacIndexParam.getProvince();
  83. TacCountDto tacCountDto = null;
  84. Object obj = redisTemplate.opsForValue().get(province + year + "audit");
  85. if (obj == null) {
  86. tacCountDto = new TacCountDto();
  87. //get current group obj
  88. TacInspYearBatchGroupParam groupPersParam = new TacInspYearBatchGroupParam();
  89. // groupPersParam.setPersId(tacIndexParam.getPersId());
  90. groupPersParam.setYear(Long.valueOf(year));
  91. groupPersParam.setUseCurrTm("1");
  92. groupPersParam.setProvince(tacIndexParam.getProvince());
  93. List<TacInspYearBatchGroup> groupList = tacInspYearBatchGroupDao.getCurrentGroupList(groupPersParam);
  94. LocalDateTime ldt = LocalDateTime.now();
  95. if (groupList.size() > 0) {
  96. TacInspYearBatchGroup group = groupList.get(0);
  97. Date entm = group.getEnTm();
  98. Date sttm = group.getStTm();
  99. long diff = entm.getTime() - sttm.getTime();
  100. //获取天数
  101. long allDays = diff / (1000 * 60 * 60 * 24);
  102. Long milliSecond = ldt.toInstant(ZoneOffset.of("+8")).toEpochMilli();
  103. long days = (entm.getTime() - milliSecond )/(1000 * 60 * 60 * 24);
  104. tacCountDto.setCount(String.valueOf(days));
  105. if (days == 0) {
  106. tacCountDto.setPercent(100);
  107. } else {
  108. tacCountDto.setPercent((int)((allDays-days)*100/allDays));
  109. }
  110. } else {
  111. tacCountDto.setPercent(100);
  112. tacCountDto.setCount(CommonLabel.INIT_DATA);
  113. }
  114. redisTemplate.opsForValue().set(province + year + "audit", tacCountDto, 24 - ldt.getHour(), TimeUnit.HOURS);
  115. } else {
  116. tacCountDto = (TacCountDto)obj;
  117. }
  118. return tacCountDto;
  119. }
  120. @Override
  121. public List<TacCountDto> countObjByYear(TacIndexParam tacIndexParam) {
  122. String year = null;
  123. if (tacIndexParam.getYear() != null && tacIndexParam.getYear() > 0) {
  124. year = String.valueOf(tacIndexParam.getYear());
  125. } else {
  126. year = String.valueOf(LocalDateTime.now().getYear());
  127. }
  128. String province = tacIndexParam.getProvince();
  129. Object object = redisTemplate.opsForValue().get(province + year + "type");
  130. if (object == null) {
  131. TacInspYearBatchParam tacInspYearBatchParam = new TacInspYearBatchParam();
  132. // tacInspYearBatchParam.setPersId(tacIndexParam.getPersId());
  133. tacInspYearBatchParam.setYear(Long.valueOf(year));
  134. tacInspYearBatchParam.setProvince(tacIndexParam.getProvince());
  135. List<TacCountDto> result = tacInspYearBatchDao.countObjByYear(tacInspYearBatchParam);
  136. redisTemplate.opsForValue().set(province + year + "type", result, 1, TimeUnit.HOURS);
  137. return result;
  138. }
  139. return (List<TacCountDto>) object;
  140. }
  141. @Override
  142. public List<TacCountDto> countAdcodeAuditByYear(TacIndexParam tacIndexParam) {
  143. String year = null;
  144. if (tacIndexParam.getYear() != null && tacIndexParam.getYear() > 0) {
  145. year = String.valueOf(tacIndexParam.getYear());
  146. } else {
  147. year = String.valueOf(LocalDateTime.now().getYear());
  148. }
  149. String province = tacIndexParam.getProvince();
  150. Object object = (List<TacCountDto>)redisTemplate.opsForValue().get(province + year + "adCode");
  151. if (object == null) {
  152. TacInspYearBatchAreaParam areaParam = new TacInspYearBatchAreaParam();
  153. // areaParam.setPersId(tacIndexParam.getPersId());
  154. areaParam.setYear(Long.valueOf(year));
  155. areaParam.setProvince(tacIndexParam.getProvince());
  156. List<TacCountDto> result = tacInspYearBatchAreaDao.countAdcodeAuditByYear(areaParam);
  157. redisTemplate.opsForValue().set(province + year + "adCode", result, 1, TimeUnit.HOURS);
  158. return result;
  159. }
  160. return (List<TacCountDto>) object;
  161. }
  162. @Override
  163. public List<TacCountDto> countPblmInfoByYear(TacIndexParam tacIndexParam) {
  164. String year = null;
  165. if (tacIndexParam.getYear() != null && tacIndexParam.getYear() > 0) {
  166. year = String.valueOf(tacIndexParam.getYear());
  167. } else {
  168. year = String.valueOf(LocalDateTime.now().getYear());
  169. }
  170. String province = tacIndexParam.getProvince();
  171. Object list = redisTemplate.opsForValue().get(province + year + "pblmInfo");
  172. if (list == null) {
  173. TacPblmInfoParam pblmInfoParam = new TacPblmInfoParam();
  174. pblmInfoParam.setYear(Long.valueOf(year));
  175. pblmInfoParam.setProvince(tacIndexParam.getProvince());
  176. // pblmInfoParam.setPersId(tacIndexParam.getPersId());
  177. List<TacCountDto> dtos = tacPblmInfoDao.countPblmInfoByStb(pblmInfoParam);
  178. if (dtos.size() > 0) {
  179. Map<String, TacCountDto> result = new HashedMap();
  180. dtos.forEach(tacCountDto -> {
  181. StringBuilder sb = new StringBuilder("");
  182. if (StringUtils.isBlank(tacCountDto.getName())) {
  183. return;
  184. }
  185. if (tacCountDto.getName().contains("—")) {
  186. sb.append(tacCountDto.getName().split("—")[0]);
  187. } else {
  188. sb.append(tacCountDto.getName());
  189. }
  190. String key = sb.toString();
  191. tacCountDto.setName(key);
  192. if (result.keySet().contains(key)) {
  193. if ("0".equals(tacCountDto.getCode())) {
  194. result.get(key).setNormal(result.get(key).getNormal() + tacCountDto.getCount());
  195. }
  196. if ("1".equals(tacCountDto.getCode())) {
  197. result.get(key).setHeavier(result.get(key).getHeavier() + tacCountDto.getCount());
  198. }
  199. if ("2".equals(tacCountDto.getCode())) {
  200. result.get(key).setSerious(result.get(key).getSerious() + tacCountDto.getCount());
  201. }
  202. } else {
  203. if ("0".equals(tacCountDto.getCode())) {
  204. tacCountDto.setNormal(tacCountDto.getCount());
  205. }
  206. if ("1".equals(tacCountDto.getCode())) {
  207. tacCountDto.setHeavier(tacCountDto.getCount());
  208. }
  209. if ("2".equals(tacCountDto.getCode())) {
  210. tacCountDto.setSerious(tacCountDto.getCount());
  211. }
  212. result.put(key, tacCountDto);
  213. }
  214. });
  215. List<TacCountDto> rs = new ArrayList<>(result.values());
  216. redisTemplate.opsForValue().set(province + year + "pblmInfo", rs, 1, TimeUnit.HOURS);
  217. return rs;
  218. }
  219. }
  220. return (List<TacCountDto>)list;
  221. }
  222. @Override
  223. public List<TacEvalationInform> getPersMessagePage(TacIndexParam tacIndexParam) {
  224. TacEvalationInformParam tacEvalationInformParam = new TacEvalationInformParam();
  225. tacEvalationInformParam.setPersId(tacIndexParam.getPersId());
  226. tacEvalationInformParam.setSize((long) tacIndexParam.getPageSize());
  227. tacEvalationInformParam.setYear(tacIndexParam.getYear());
  228. tacEvalationInformParam.setProvince(tacIndexParam.getProvince());
  229. List<TacEvalationInform> informList = tacEvalationInformDao.getInformListBySize(tacEvalationInformParam);
  230. if (informList.size() > 0) {
  231. informList.forEach(inform -> {
  232. if ("1".equals(inform.getType())){
  233. //单元测评
  234. inform.setTitle(inform.getYear() + "第" + inform.getBatch() + "批稽察专家批次测评已经开放,请及时填报。");
  235. } else if ("2".equals(inform.getType())) {
  236. //年度测评
  237. inform.setTitle(inform.getYear() + "年特派员测评已经开放,请及时填报。");
  238. }
  239. });
  240. }
  241. TacInspYearBatchGroupMegParam groupMegParam = new TacInspYearBatchGroupMegParam();
  242. groupMegParam.setPersId(tacIndexParam.getPersId());
  243. groupMegParam.setSize(Long.valueOf(tacIndexParam.getPageSize()));
  244. groupMegParam.setYear(tacIndexParam.getYear());
  245. List<TacInspYearBatchGroupMeg> groupMegs = tacInspYearBatchGroupMegDao.getGroupMegListBySize(groupMegParam);
  246. if (groupMegs.size() > 0) {
  247. groupMegs.forEach(groupMeg -> {
  248. TacEvalationInform tacEvalationInform = new TacEvalationInform();
  249. tacEvalationInform.setUpTm(groupMeg.getUpTm());
  250. tacEvalationInform.setTitle(groupMeg.getYear() + "年第" + groupMeg.getBatch() + "批次稽察任务提示");
  251. tacEvalationInform.setId(groupMeg.getId());
  252. tacEvalationInform.setType("3");
  253. tacEvalationInform.setDataStat(groupMeg.getDataStat());
  254. informList.add(tacEvalationInform);
  255. });
  256. }
  257. Collections.sort(informList, new Comparator<TacEvalationInform>() {
  258. @Override
  259. public int compare(TacEvalationInform o1, TacEvalationInform o2) {
  260. if (o1.getUpTm() == null) {
  261. return -1;
  262. }
  263. return o1.getUpTm().compareTo(o2.getUpTm());
  264. }
  265. });
  266. if (informList.size() <= tacIndexParam.getPageSize()) {
  267. return informList;
  268. }
  269. List<TacEvalationInform> result = informList.subList(0, tacIndexParam.getPageSize());
  270. return result;
  271. }
  272. private int getCountByObj(String year, TacIndexParam tacIndexParam){
  273. int result = 0;
  274. String province = tacIndexParam.getProvince();
  275. Object obj = redisTemplate.opsForValue().get(province + year + "pblm");
  276. if (obj == null) {
  277. //根据年度查找数量
  278. TacPblmInfoParam pblmInfoParam = new TacPblmInfoParam();
  279. pblmInfoParam.setYear(Long.valueOf(year));
  280. pblmInfoParam.setProvince(tacIndexParam.getProvince());
  281. // pblmInfoParam.setPersId(tacIndexParam.getPersId());
  282. result = tacPblmInfoDao.getPblmCountByYear(pblmInfoParam);
  283. redisTemplate.opsForValue().set(province + year + "pblm",result,1, TimeUnit.HOURS);
  284. } else {
  285. result = Integer.valueOf(obj.toString());
  286. }
  287. return result;
  288. }
  289. @Override
  290. public List<TacCountDto> getAreaList(TacIndexParam tacIndexParam) {
  291. String year = null;
  292. if (tacIndexParam.getYear() != null && tacIndexParam.getYear() > 0) {
  293. year = String.valueOf(tacIndexParam.getYear());
  294. } else {
  295. year = String.valueOf(LocalDateTime.now().getYear());
  296. }
  297. //获取权限
  298. String persId = tacIndexParam.getPersId();
  299. if (StringUtils.isNotBlank(persId)) {
  300. if ("1".equals(rlationPersDao.get(persId).getPersType())) {
  301. persId = "";
  302. }
  303. }
  304. TacInspYearBatchGroupParam groupPersParam = new TacInspYearBatchGroupParam();
  305. groupPersParam.setPersId(persId);
  306. groupPersParam.setYear(Long.valueOf(year));
  307. groupPersParam.setUseCurrTm("1");
  308. groupPersParam.setProvince(tacIndexParam.getProvince());
  309. List<TacInspYearBatchGroup> groupList = tacInspYearBatchGroupDao.getCurrentGroupList(groupPersParam);
  310. if (groupList.size() > 0) {
  311. //得到当前批次的所有地区
  312. return listArea(groupList);
  313. }
  314. groupPersParam.setUseCurrTm("");
  315. List<TacInspYearBatchGroup> lastGroupList = tacInspYearBatchGroupDao.getCurrentGroupList(groupPersParam);
  316. if (lastGroupList.size() > 0) {
  317. return listArea(lastGroupList);
  318. }
  319. return null;
  320. }
  321. private List<TacCountDto> listArea(List<TacInspYearBatchGroup> groupList) {
  322. List<TacCountDto> result = null;
  323. if (groupList != null && groupList.size() > 0) {
  324. StringBuilder sb = new StringBuilder("");
  325. StringBuilder batch = new StringBuilder("");
  326. groupList.forEach(group -> {
  327. if (batch.length() == 0) {
  328. batch.append(group.getBatch());
  329. }
  330. if (group.getBatch().equals(Long.valueOf(batch.toString()))) {
  331. sb.append("'").append(group.getId()).append("'").append(",");
  332. }
  333. });
  334. if (sb.length() > 0) {
  335. TacInspYearBatchAreaParam areaParam = new TacInspYearBatchAreaParam();
  336. areaParam.setGroupId(sb.substring(0 , sb.length() - 1));
  337. result = tacInspYearBatchAreaDao.getAdNameList(areaParam);
  338. if (result != null && result.size() > 0) {
  339. result.forEach(countDto -> {
  340. String name = countDto.getName();
  341. if (name.endsWith("市")) {
  342. countDto.setName(name.substring(0, name.lastIndexOf("市")));
  343. }
  344. if (name.endsWith("省")) {
  345. countDto.setName(name.substring(0, name.lastIndexOf("省")));
  346. }
  347. if (name.length() > 6) {
  348. countDto.setName(name.substring(0, 5));
  349. }
  350. });
  351. }
  352. }
  353. }
  354. return result;
  355. }
  356. }