e59f0557261b2e139962b75d6927d68ba9e1c3c9.svn-base 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. package cn.com.goldenwater.dcproj.service.impl.tac;
  2. import cn.com.goldenwater.core.service.AbstractCrudService;
  3. import cn.com.goldenwater.dcproj.constValue.SmsCodeEnum;
  4. import cn.com.goldenwater.dcproj.dao.AttAdXBaseDao;
  5. import cn.com.goldenwater.dcproj.dao.BisInspAllRlationPersDao;
  6. import cn.com.goldenwater.dcproj.dao.TacInspYearBatchAreaDao;
  7. import cn.com.goldenwater.dcproj.dao.TacInspYearBatchDao;
  8. import cn.com.goldenwater.dcproj.dao.TacInspYearBatchGroupDao;
  9. import cn.com.goldenwater.dcproj.dao.TacInspYearBatchGroupPersDao;
  10. import cn.com.goldenwater.dcproj.dao.TacInspYearBatchObjDao;
  11. import cn.com.goldenwater.dcproj.dao.TacPawpRgstrDao;
  12. import cn.com.goldenwater.dcproj.dao.TacWorkerBDao;
  13. import cn.com.goldenwater.dcproj.dto.TacInspYearBatchGroupDto;
  14. import cn.com.goldenwater.dcproj.dto.TacInspYearBatchObjDto;
  15. import cn.com.goldenwater.dcproj.model.AttAdXBase;
  16. import cn.com.goldenwater.dcproj.model.TacInspYearBatch;
  17. import cn.com.goldenwater.dcproj.model.TacInspYearBatchArea;
  18. import cn.com.goldenwater.dcproj.model.TacInspYearBatchGroup;
  19. import cn.com.goldenwater.dcproj.model.TacInspYearBatchGroupPers;
  20. import cn.com.goldenwater.dcproj.model.TacInspYearBatchObj;
  21. import cn.com.goldenwater.dcproj.model.TacWorkerB;
  22. import cn.com.goldenwater.dcproj.param.AttAdXBaseParam;
  23. import cn.com.goldenwater.dcproj.param.TacInspYearBatchAreaParam;
  24. import cn.com.goldenwater.dcproj.param.TacInspYearBatchGroupParam;
  25. import cn.com.goldenwater.dcproj.param.TacInspYearBatchGroupPersParam;
  26. import cn.com.goldenwater.dcproj.param.TacInspYearBatchObjParam;
  27. import cn.com.goldenwater.dcproj.param.TacPawpRgstrParam;
  28. import cn.com.goldenwater.dcproj.param.TacWorkerBParam;
  29. import cn.com.goldenwater.dcproj.service.TacInspYearBatchGroupService;
  30. import cn.com.goldenwater.dcproj.utils.DateUtils;
  31. import cn.com.goldenwater.dcproj.utils.HttpClientUtils;
  32. import cn.com.goldenwater.id.util.UuidUtil;
  33. import cn.com.goldenwater.target.CheckException;
  34. import net.sf.json.JSONObject;
  35. import org.apache.commons.lang3.StringUtils;
  36. import org.slf4j.Logger;
  37. import org.slf4j.LoggerFactory;
  38. import org.springframework.beans.factory.annotation.Autowired;
  39. import org.springframework.beans.factory.annotation.Value;
  40. import org.springframework.stereotype.Service;
  41. import org.springframework.transaction.annotation.Transactional;
  42. import java.text.ParseException;
  43. import java.text.SimpleDateFormat;
  44. import java.util.ArrayList;
  45. import java.util.Date;
  46. import java.util.HashMap;
  47. import java.util.List;
  48. import java.util.Map;
  49. import java.util.stream.Collectors;
  50. /**
  51. * @author lune
  52. * @date 2019-9-6
  53. */
  54. @Service
  55. @Transactional
  56. public class TacInspYearBatchGroupServiceImpl<main> extends AbstractCrudService<TacInspYearBatchGroup, TacInspYearBatchGroupParam> implements TacInspYearBatchGroupService {
  57. private Logger logger = LoggerFactory.getLogger(getClass());
  58. @Autowired
  59. private TacInspYearBatchGroupDao tacInspYearBatchGroupDao;
  60. @Autowired
  61. private TacInspYearBatchDao yearBatchDao;
  62. @Autowired
  63. private TacWorkerBDao workerBDao;
  64. @Autowired
  65. private TacPawpRgstrDao tacPawpRgstrDao;
  66. @Autowired
  67. private AttAdXBaseDao attAdXBaseDao;
  68. @Autowired
  69. private TacInspYearBatchAreaDao areaDao;
  70. @Autowired
  71. private TacInspYearBatchGroupPersDao groupPersDao;
  72. @Autowired
  73. private TacInspYearBatchObjDao tacInspYearBatchObjDao;
  74. @Autowired
  75. private BisInspAllRlationPersDao rlationPersDao;
  76. @Value("${api.url}")
  77. private String apiUrl;
  78. //稽察专家回复超时时间
  79. // @Value("${replyTimeout}")
  80. // private long replyTimeout;
  81. private static String apiKey = "1036432406699048960";
  82. private static String apiSecrect = "bbSsX1wvmaKdca5x2+yBDgeFtl9hj4zJmnegunWuLuHLwLo+QjxOr3//P4BJNrVADa7tN4w0DX1KS/VSec5G0x+ucDeAcSt9tWgFGyoBVtblybh+vzLbwH4sJa92hQfu\n";
  83. public TacInspYearBatchGroupServiceImpl(TacInspYearBatchGroupDao tacInspYearBatchGroupDao) {
  84. super(tacInspYearBatchGroupDao);
  85. this.tacInspYearBatchGroupDao = tacInspYearBatchGroupDao;
  86. }
  87. @Override
  88. public List<TacInspYearBatchGroup> getGroupListByLoginId(TacInspYearBatchGroupParam tacInspYearBatchGroupParam) {
  89. List<TacInspYearBatchGroup> groupList = tacInspYearBatchGroupDao.getGroupListApp(tacInspYearBatchGroupParam);
  90. if (groupList.size() > 0) {
  91. groupList.forEach(group -> {
  92. TacInspYearBatchAreaParam areaParam = new TacInspYearBatchAreaParam();
  93. areaParam.setGroupId(group.getId());
  94. List<TacInspYearBatchArea> areaList = this.areaDao.findList(areaParam);
  95. if (areaList.size() > 0) {
  96. String str = "";
  97. for (TacInspYearBatchArea area : areaList) {
  98. str = str + area.getAdName() + ",";
  99. }
  100. if (str.length() > 0) {
  101. str = str.substring(0, str.length() - 1);
  102. }
  103. group.setAreas(str);
  104. }
  105. });
  106. }
  107. return groupList;
  108. }
  109. @Override
  110. public int insertGroupList(TacInspYearBatchGroupDto groupDto) {
  111. if (groupDto == null) {
  112. return 0;
  113. }
  114. List<String> adCodes = groupDto.getAdCodes();
  115. if (adCodes.size() > 0) {
  116. for (String adCode : adCodes) {
  117. TacInspYearBatchGroup group = new TacInspYearBatchGroup();
  118. group.setId(UuidUtil.uuid());
  119. group.setYearBatchId(groupDto.getBatchId());
  120. group.setTenet(groupDto.getTenet());
  121. group.setInTm(new Date());
  122. TacInspYearBatchGroupParam groupParam = new TacInspYearBatchGroupParam();
  123. groupParam.setYearBatchId(groupDto.getBatchId());
  124. String groupNum = this.tacInspYearBatchGroupDao.getMaxGourpNum(groupParam);
  125. if (StringUtils.isBlank(groupNum)) {
  126. groupNum = "1";
  127. }
  128. group.setProvince(groupDto.getProvince());
  129. group.setGroupNm(Long.valueOf(groupNum));
  130. group.setConfirmer("0");
  131. tacInspYearBatchGroupDao.insert(group);
  132. if (adCode.contains(",")) {
  133. String[] ads = adCode.split(",");
  134. for (String ad : ads) {
  135. TacInspYearBatchArea area = new TacInspYearBatchArea();
  136. area.setId(UuidUtil.uuid());
  137. area.setGroupId(group.getId());
  138. area.setYearBatchId(group.getYearBatchId());
  139. area.setAdCode(ad);
  140. area.setInTm(new Date());
  141. area.setUpTm(new Date());
  142. area.setProvince(groupDto.getProvince());
  143. areaDao.insert(area);
  144. }
  145. } else {
  146. TacInspYearBatchArea area = new TacInspYearBatchArea();
  147. area.setId(UuidUtil.uuid());
  148. area.setGroupId(group.getId());
  149. area.setYearBatchId(group.getYearBatchId());
  150. area.setAdCode(adCode);
  151. area.setInTm(new Date());
  152. area.setUpTm(new Date());
  153. area.setProvince(groupDto.getProvince());
  154. areaDao.insert(area);
  155. }
  156. }
  157. TacInspYearBatch yearBatch = new TacInspYearBatch();
  158. yearBatch.setId(groupDto.getBatchId());
  159. yearBatch.setIsAreaGroup("1");
  160. yearBatchDao.update(yearBatch);
  161. }
  162. return 0;
  163. }
  164. @Override
  165. public List<TacInspYearBatchGroup> getGroupList(TacInspYearBatchGroupParam groupParam) {
  166. List<TacInspYearBatchGroup> groupList = this.tacInspYearBatchGroupDao.findList(groupParam);
  167. List<TacInspYearBatchGroup> result = new ArrayList<>();
  168. if (groupList.size() > 0) {
  169. for (TacInspYearBatchGroup tacInspYearBatchGroup : groupList) {
  170. TacWorkerBParam workerBParam = new TacWorkerBParam();
  171. workerBParam.setGroupId(tacInspYearBatchGroup.getId());
  172. workerBParam.setProvince(groupParam.getProvince());
  173. if(StringUtils.isNotBlank(groupParam.getName()) && StringUtils.isBlank(groupParam.getPersName())){
  174. groupParam.setPersName(groupParam.getName());
  175. }
  176. if (StringUtils.isNotBlank(groupParam.getPersName())) {
  177. workerBParam.setName(groupParam.getPersName());
  178. List<TacWorkerB> bs = workerBDao.getWorkListByGroupId(workerBParam);
  179. if (bs.size() == 0) {
  180. continue;
  181. }
  182. workerBParam.setName("");
  183. tacInspYearBatchGroup.setWorkersList(workerBDao.getWorkListByGroupId(workerBParam));
  184. } else {
  185. List<TacWorkerB> bs = workerBDao.getWorkListByGroupId(workerBParam);
  186. tacInspYearBatchGroup.setWorkersList(bs);
  187. }
  188. //获取督查区域
  189. TacInspYearBatchAreaParam areaParam = new TacInspYearBatchAreaParam();
  190. areaParam.setGroupId(tacInspYearBatchGroup.getId());
  191. areaParam.setProvince(groupParam.getProvince());
  192. if (StringUtils.isNotBlank(groupParam.getAdCode())) {
  193. areaParam.setAdCode(groupParam.getAdCode());
  194. List<TacInspYearBatchArea> areaList = this.areaDao.findList(areaParam);
  195. if (areaList.size() == 0) {
  196. continue;
  197. }
  198. areaParam.setAdCode("");
  199. }
  200. List<TacInspYearBatchArea> areaList = this.areaDao.findList(areaParam);
  201. if (areaList.size() > 0) {
  202. String str = "";
  203. for (TacInspYearBatchArea area : areaList) {
  204. str = str + area.getAdName() + ",";
  205. }
  206. if (str.length() > 0) {
  207. str = str.substring(0, str.length() - 1);
  208. }
  209. tacInspYearBatchGroup.setAreas(str);
  210. }
  211. tacInspYearBatchGroup.setAreaList(areaList);
  212. TacInspYearBatchObjParam objParam = new TacInspYearBatchObjParam();
  213. objParam.setGroupId(tacInspYearBatchGroup.getId());
  214. objParam.setProvince(groupParam.getProvince());
  215. if (StringUtils.isNotBlank(groupParam.getType())) {
  216. objParam.setType(groupParam.getType());
  217. List<TacInspYearBatchObjDto> list = tacInspYearBatchObjDao.getObjList(objParam);
  218. if (list.size() == 0) {
  219. continue;
  220. }
  221. objParam.setType("");
  222. }
  223. List<TacInspYearBatchObj> objs = tacInspYearBatchObjDao.getObjAndType(objParam);
  224. tacInspYearBatchGroup.setObjList(objs);
  225. result.add(tacInspYearBatchGroup);
  226. }
  227. }
  228. return result;
  229. }
  230. @Override
  231. public int deleteGroupById(String id, String province) {
  232. this.tacInspYearBatchGroupDao.delete(id);
  233. TacInspYearBatchAreaParam areaParam = new TacInspYearBatchAreaParam();
  234. areaParam.setGroupId(id);
  235. areaParam.setProvince(province);
  236. areaDao.deleteBy(areaParam);
  237. TacInspYearBatchObjParam tacInspYearBatchObjParam = new TacInspYearBatchObjParam();
  238. tacInspYearBatchObjParam.setGroupId(id);
  239. tacInspYearBatchObjDao.deleteBy(tacInspYearBatchObjParam);
  240. TacPawpRgstrParam tacPawpRgstrParam = new TacPawpRgstrParam();
  241. tacPawpRgstrParam.setGroupId(id);
  242. tacPawpRgstrDao.deleteBy(tacPawpRgstrParam);
  243. TacInspYearBatchGroupPersParam groupPersParam = new TacInspYearBatchGroupPersParam();
  244. groupPersParam.setGroupId(id);
  245. int a = groupPersDao.deleteGroupPersByGroupId(groupPersParam);
  246. return 1;
  247. }
  248. @Override
  249. public int deleteGroupList(TacInspYearBatchGroupDto dto) {
  250. if (dto == null || dto.getGroupList() == null) {
  251. return 0;
  252. }
  253. List<String> groupIdList = dto.getGroupList().stream().map(m -> m.getId()).collect(Collectors.toList());
  254. List<String> batchObjList = this.tacInspYearBatchObjDao.getObjListByGroupIdList(groupIdList);
  255. if(null != batchObjList && batchObjList.size()>0){
  256. // 这个组下面有项目,不能删除组
  257. throw new CheckException("删除的组里有项目,请先去掉组里的项目!!!");
  258. }
  259. dto.getGroupList().forEach(group -> {
  260. this.tacInspYearBatchGroupDao.delete(group.getId());
  261. TacInspYearBatchObjParam tacInspYearBatchObjParam = new TacInspYearBatchObjParam();
  262. tacInspYearBatchObjParam.setGroupId(group.getId());
  263. tacInspYearBatchObjParam.setProvince(dto.getProvince());
  264. tacInspYearBatchObjDao.deleteBy(tacInspYearBatchObjParam);
  265. TacPawpRgstrParam tacPawpRgstrParam = new TacPawpRgstrParam();
  266. tacPawpRgstrParam.setGroupId(group.getId());
  267. tacPawpRgstrParam.setProvince(dto.getProvince());
  268. tacPawpRgstrDao.deleteBy(tacPawpRgstrParam);
  269. TacInspYearBatchAreaParam areaParam = new TacInspYearBatchAreaParam();
  270. areaParam.setGroupId(group.getId());
  271. areaParam.setProvince(dto.getProvince());
  272. areaDao.deleteBy(areaParam);
  273. TacInspYearBatchGroupPersParam groupPersParam = new TacInspYearBatchGroupPersParam();
  274. groupPersParam.setGroupId(group.getId());
  275. int a = groupPersDao.deleteGroupPersByGroupId(groupPersParam);
  276. });
  277. return 0;
  278. }
  279. @Override
  280. public TacInspYearBatchGroup getGroupById(String id, String province) {
  281. TacInspYearBatchGroup group = tacInspYearBatchGroupDao.get(id);
  282. TacInspYearBatchAreaParam areaParam = new TacInspYearBatchAreaParam();
  283. areaParam.setGroupId(group.getId());
  284. areaParam.setProvince(province);
  285. List<TacInspYearBatchArea> list = areaDao.findList(areaParam);
  286. group.setAreaList(list);
  287. return group;
  288. }
  289. @Override
  290. public int updateGroupArea(TacInspYearBatchGroup group) {
  291. Map<String, List<TacInspYearBatchArea>> map = new HashMap<>();
  292. if (group.getAreaList() != null) {
  293. group.getAreaList().forEach(tacInspYearBatchArea -> {
  294. if (map.keySet().contains(tacInspYearBatchArea.getAdName())) {
  295. map.get(tacInspYearBatchArea.getAdName()).add(tacInspYearBatchArea);
  296. } else {
  297. List<TacInspYearBatchArea> list = new ArrayList<>();
  298. list.add(tacInspYearBatchArea);
  299. map.put(tacInspYearBatchArea.getAdName(), list);
  300. }
  301. });
  302. }
  303. if (group.getAdNames() != null) {
  304. for (Map<String, String> stringMap : group.getAdNames()) {
  305. String adName = stringMap.get("adName");
  306. if (map.containsKey(adName)) {
  307. map.remove(adName);
  308. continue;
  309. }
  310. AttAdXBaseParam adXBaseParam = new AttAdXBaseParam();
  311. adXBaseParam.setAdName(adName);
  312. AttAdXBase attAdXBase = attAdXBaseDao.getByName(adXBaseParam);
  313. if (attAdXBase == null) {
  314. continue;
  315. }
  316. TacInspYearBatchArea batchArea = new TacInspYearBatchArea();
  317. batchArea.setId(UuidUtil.uuid());
  318. batchArea.setGroupId(group.getId());
  319. batchArea.setYearBatchId(group.getYearBatchId());
  320. batchArea.setGroupNm(group.getGroupNm());
  321. batchArea.setAdCode(attAdXBase.getAdCode());
  322. batchArea.setAdName(adName);
  323. batchArea.setBatch(group.getBatch());
  324. batchArea.setYear(group.getYear());
  325. batchArea.setInTm(new Date());
  326. batchArea.setUpTm(new Date());
  327. batchArea.setProvince(group.getProvince());
  328. areaDao.insert(batchArea);
  329. }
  330. List<TacInspYearBatchArea> areaList = new ArrayList();
  331. for (List<TacInspYearBatchArea> list : map.values()) {
  332. areaList.addAll(list);
  333. }
  334. if (areaList.size() > 0) {
  335. TacInspYearBatchGroupPersParam groupPersParam = new TacInspYearBatchGroupPersParam();
  336. for (TacInspYearBatchArea area : areaList) {
  337. groupPersParam.setGroupId(area.getGroupId());
  338. groupPersDao.deleteBy(groupPersParam);
  339. if (area.getId().contains(",")) {
  340. for (String id : area.getId().split(",")) {
  341. areaDao.delete(id);
  342. }
  343. } else {
  344. areaDao.delete(area.getId());
  345. }
  346. }
  347. }
  348. }
  349. return 0;
  350. }
  351. @Override
  352. public List<TacInspYearBatchGroup> getGroupListAndObj(TacInspYearBatchGroupParam groupParam) {
  353. List<TacInspYearBatchGroup> groupList = this.tacInspYearBatchGroupDao.findList(groupParam);
  354. if (groupList.size() > 0) {
  355. for (TacInspYearBatchGroup tacInspYearBatchGroup : groupList) {
  356. TacWorkerBParam workerBParam = new TacWorkerBParam();
  357. workerBParam.setGroupId(tacInspYearBatchGroup.getId());
  358. workerBParam.setProvince(groupParam.getProvince());
  359. tacInspYearBatchGroup.setWorkersList(workerBDao.getWorkListByGroupId(workerBParam));
  360. //获取督查区域
  361. TacInspYearBatchAreaParam areaParam = new TacInspYearBatchAreaParam();
  362. areaParam.setGroupId(tacInspYearBatchGroup.getId());
  363. areaParam.setProvince(groupParam.getProvince());
  364. List<TacInspYearBatchArea> areaList = this.areaDao.findList(areaParam);
  365. if (areaList.size() > 0) {
  366. String str = "";
  367. for (TacInspYearBatchArea area : areaList) {
  368. str = str + area.getAdName() + ",";
  369. }
  370. if (str.length() > 0) {
  371. str = str.substring(0, str.length() - 1);
  372. }
  373. tacInspYearBatchGroup.setAreas(str);
  374. }
  375. TacInspYearBatchObjParam objParam = new TacInspYearBatchObjParam();
  376. objParam.setGroupId(tacInspYearBatchGroup.getId());
  377. objParam.setProvince(groupParam.getProvince());
  378. List<TacInspYearBatchObj> objs = tacInspYearBatchObjDao.findList(objParam);
  379. tacInspYearBatchGroup.setObjList(objs);
  380. }
  381. }
  382. return groupList;
  383. }
  384. @Override
  385. public List<TacInspYearBatchGroup> getGroupListByPersId(TacInspYearBatchGroupParam groupParam) {
  386. List<TacInspYearBatchGroup> list = tacInspYearBatchGroupDao.getGroupListByPersId(groupParam);
  387. if (list.size() > 0) {
  388. for (TacInspYearBatchGroup tacInspYearBatchGroup : list) {
  389. TacInspYearBatchAreaParam areaParam = new TacInspYearBatchAreaParam();
  390. areaParam.setGroupId(tacInspYearBatchGroup.getId());
  391. areaParam.setProvince(groupParam.getProvince());
  392. List<TacInspYearBatchArea> areaList = this.areaDao.findList(areaParam);
  393. tacInspYearBatchGroup.setAreaList(areaList);
  394. }
  395. }
  396. return list;
  397. }
  398. @Override
  399. public List<TacInspYearBatchGroup> getGroupListApp(TacInspYearBatchGroupParam tacInspYearBatchGroupParam) {
  400. if (StringUtils.isNotBlank(tacInspYearBatchGroupParam.getPersId())) {
  401. if ("1".equals(rlationPersDao.get(tacInspYearBatchGroupParam.getPersId()).getPersType())) {
  402. tacInspYearBatchGroupParam.setPersId("");
  403. }
  404. }
  405. List<TacInspYearBatchGroup> list = tacInspYearBatchGroupDao.getGroupListApp(tacInspYearBatchGroupParam);
  406. if (list.size() > 0) {
  407. for (TacInspYearBatchGroup tacInspYearBatchGroup : list) {
  408. TacInspYearBatchAreaParam areaParam = new TacInspYearBatchAreaParam();
  409. areaParam.setGroupId(tacInspYearBatchGroup.getId());
  410. areaParam.setProvince(tacInspYearBatchGroupParam.getProvince());
  411. List<TacInspYearBatchArea> areaList = this.areaDao.findList(areaParam);
  412. tacInspYearBatchGroup.setAreaList(areaList);
  413. }
  414. }
  415. return list;
  416. }
  417. @Override
  418. public int updateGroupList(TacInspYearBatchGroupDto dto) {
  419. if (dto == null) {
  420. return 0;
  421. }
  422. if (dto.getGroupList() == null && StringUtils.isBlank(dto.getBatchId())) {
  423. return 0;
  424. }
  425. if (dto.getGroupList() != null) {
  426. dto.getGroupList().forEach(group -> {
  427. group.setUpTm(new Date());
  428. tacInspYearBatchGroupDao.update(group);
  429. });
  430. }
  431. if (StringUtils.isNotBlank(dto.getBatchId())) {
  432. TacInspYearBatchGroup group = new TacInspYearBatchGroup();
  433. SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
  434. group.setYearBatchId(dto.getBatchId());
  435. try {
  436. if (StringUtils.isNotBlank(dto.getSttm()) && StringUtils.isNotBlank(dto.getEntm())) {
  437. group.setStTm(fmt.parse(dto.getSttm()));
  438. group.setEnTm(fmt.parse(dto.getEntm()));
  439. int a = tacInspYearBatchGroupDao.updateByBatchId(group);
  440. }
  441. } catch (ParseException e) {
  442. }
  443. }
  444. return 0;
  445. }
  446. @Override
  447. public String sendGroupMessage(TacInspYearBatchGroupParam tacInspYearBatchGroupParam) throws Exception {
  448. List<TacInspYearBatchGroupPers> smsWorkListByGroupId = groupPersDao.getSmsWorkListByGroupId(tacInspYearBatchGroupParam);
  449. //分组数据
  450. TacInspYearBatchGroup by = tacInspYearBatchGroupDao.get(tacInspYearBatchGroupParam.getId());
  451. String sttm= DateUtils.Date2Str(by.getStTm(),"yyyy-MM-dd");
  452. String entm= DateUtils.Date2Str(by.getEnTm(),"yyyy-MM-dd");
  453. //获取督查区域
  454. TacInspYearBatchAreaParam areaParam = new TacInspYearBatchAreaParam();
  455. areaParam.setGroupId(tacInspYearBatchGroupParam.getId());
  456. areaParam.setProvince(tacInspYearBatchGroupParam.getProvince());
  457. List<TacInspYearBatchArea> areaList = this.areaDao.findList(areaParam);
  458. String areas = "";
  459. if (areaList.size() > 0) {
  460. for (TacInspYearBatchArea area : areaList) {
  461. areas = areas + area.getAdName() + ",";
  462. }
  463. if (areas.length() > 0) {
  464. areas = areas.substring(0, areas.length() - 1);
  465. }
  466. }
  467. TacInspYearBatchObjParam objParam = new TacInspYearBatchObjParam();
  468. objParam.setGroupId(tacInspYearBatchGroupParam.getId());
  469. objParam.setProvince(tacInspYearBatchGroupParam.getProvince());
  470. List<TacInspYearBatchObj> objList = tacInspYearBatchObjDao.getObjAndType(objParam);
  471. String objs = "";
  472. if (objList.size() > 0) {
  473. for (TacInspYearBatchObj obj : objList) {
  474. objs = objs + obj.getOjbNm() + ",";
  475. }
  476. if (areas.length() > 0) {
  477. objs = objs.substring(0, objs.length() - 1);
  478. }
  479. }
  480. //发送短信
  481. String resultCode = sendMessageByGroup(smsWorkListByGroupId,sttm,entm, areas, objs);
  482. //定时任务24小时以后查看短信是否回复状态
  483. // ReplyTimeout(tacInspYearBatchGroupParam);
  484. return resultCode;
  485. }
  486. /**
  487. * 排除特定专业后剩余专家是否选中
  488. *
  489. * @param smsWorkListByGroupId
  490. * @return
  491. *//*
  492. boolean professionalCoverage(List<TacInspYearBatchGroupPers> smsWorkListByGroupId) {
  493. List<String> getRoleTypes = new ArrayList<>();
  494. for (TacInspYearBatchGroupPers tacInspYearBatchGroupPers : smsWorkListByGroupId) {
  495. if (StringUtils.isNotBlank(tacInspYearBatchGroupPers.getRoleType())) {
  496. getRoleTypes.add(tacInspYearBatchGroupPers.getRoleType());
  497. }
  498. }
  499. if (getRoleTypes.size() > 0) {
  500. //排除非必选专业专家,与所分配专家对比。
  501. //全部专业专家类型特派员:20; 助理:19; 前期专家:11 建管专家:12;计划专家:13;财务专家:14;质量专家:15;安全专家:16
  502. List<String> professions = Stream.of("11", "12", "13", "14", "15", "16", "19", "20").collect(Collectors.toList());
  503. List<String> filtrationMajors = Stream.of(filtrationMajor.split(",")).collect(Collectors.toList());
  504. //去除非必选专业专家
  505. List<String> collect = professions.stream().filter(s -> filtrationMajors.stream().noneMatch(x -> x.contains(s))).collect(Collectors.toList());
  506. for (String s : collect) {
  507. for (String major : getRoleTypes) {
  508. if (!major.contains(s)) {
  509. return false;
  510. }
  511. }
  512. }
  513. return true;
  514. } else {
  515. return false;
  516. }
  517. }
  518. */
  519. String sendMessageByGroup(List<TacInspYearBatchGroupPers> smsWorkListByGroupId,String sttm,String entm, String areas, String objs) throws Exception {
  520. Map<String, String> params = new HashMap<String, String>();
  521. params.put("apiKey", apiKey);
  522. params.put("apiSecrect", apiSecrect);
  523. params.put("signName", "金水云平台");
  524. params.put("templeteCode", "SMS_210060995");
  525. for (TacInspYearBatchGroupPers groupPers : smsWorkListByGroupId) {
  526. if ("1".equals(groupPers.getIsSms())) {
  527. continue;
  528. }
  529. if (StringUtils.isBlank(groupPers.getPhone())) {
  530. continue;
  531. }
  532. params.put("templateParam", "{\"year\":\"" + groupPers.getYear() + "\",\"batch\":\"" + groupPers.getBatch() + "\",\"groupNm\":\"" + groupPers.getGroupNm() + "\",\"sttm\":\"" + sttm + "\",\"entm\":\"" + entm + "\",\"area\":\"" + areas+ "\",\"objList\":\"" + objs + "\"}");
  533. params.put("mobile", groupPers.getPhone());
  534. logger.info("稽察通知短信发送前:" + groupPers.getPhone());
  535. Map<String, String> headerMap=new HashMap<String, String>();
  536. // String content = HttpClientUtils.doHttpsPost2(apiUrl + "/api/sms/send", params,headerMap);
  537. // String content ="{\"success\":true,\"code\":null,\"message\":null,\"path\":null,\"throwable\":null,\"data\":[{\"id\":\"a2397b8cc0464d03b5ac26c3ff1a2289\",\"phoneNumber\":\"17521189449\",\"content\":\"1\",\"sendTime\":1615200000000,\"destCode\":\"2478260\",\"sequenceId\":\"8.39577428E8\"}]}";
  538. String content = HttpClientUtils.simplePostInvoke(apiUrl + "/gateway/api/sms/send", params);
  539. // String content="{\"success\":true,\"code\":null,\"message\":null,\"path\":null,\"throwable\":null,\"data\":{\"requestId\":\"42FC6AA4-D083-4393-BE55-30995E545BDF\",\"bizId\":\"831619709317356433^0\",\"code\":\"OK\",\"message\":\"OK\"},\"accessToken\":null}";
  540. logger.info("稽察通知短信发送后:" + content);
  541. if(StringUtils.isNotBlank(content)){
  542. JSONObject jsonContent = JSONObject.fromObject(content);
  543. if (jsonContent.get("success") != null && (Boolean) jsonContent.get("success")) {
  544. //修改专家是否已发短信,已通知。
  545. groupPers.setIsSms("1");
  546. groupPers.setIsNotice("1");
  547. groupPers.setNoticeInfo("发送至:" + params.get("mobile") + "," + params.get("templateParam"));
  548. groupPers.setSendsmsTm(new Date());
  549. groupPersDao.update(groupPers);
  550. } else {
  551. continue;
  552. }
  553. }else{
  554. continue;
  555. }
  556. }
  557. return SmsCodeEnum.SUCCESS.getKey();//短信发送成功
  558. }
  559. /*void ReplyTimeout(TacInspYearBatchGroupParam tacInspYearBatchGroupParam) {
  560. if (replyTimeout > 0) {
  561. //创建定时任务
  562. Timer timer = new Timer("发送短信通知定时任务");
  563. TimerTask task = new TimerTask() {
  564. @Override
  565. public void run() {
  566. System.out.println("短信定时任务开启");
  567. if (StringUtils.isNotBlank(tacInspYearBatchGroupParam.getYearBatchId()) && StringUtils.isNotBlank(tacInspYearBatchGroupParam.getId())) {
  568. TacInspYearBatchGroupPersParam tacInspYearBatchGroupPersParam = new TacInspYearBatchGroupPersParam();
  569. tacInspYearBatchGroupPersParam.setGroupId(tacInspYearBatchGroupParam.getId());
  570. tacInspYearBatchGroupPersParam.setYearBatchId(tacInspYearBatchGroupParam.getYearBatchId());
  571. List<TacInspYearBatchGroupPers> list = groupPersDao.findList(tacInspYearBatchGroupPersParam);
  572. if (list.size() > 0) {
  573. list.forEach(groupPers -> {
  574. if ("1".equals(groupPers.getIsNotice()) && "1".equals(groupPers.getIsSms())) {
  575. if ("0".equals(groupPers.getIsJoin()) || StringUtils.isBlank(groupPers.getIsJoin())) {
  576. TacInspYearBatchReason tacInspYearBatchReason = new TacInspYearBatchReason();
  577. tacInspYearBatchReason.setId(UuidUtil.uuid());
  578. tacInspYearBatchReason.setInTm(new Date());
  579. tacInspYearBatchReason.setUpTm(new Date());
  580. //回复超时
  581. tacInspYearBatchReason.setNinReason("回复超时");
  582. tacInspYearBatchReasonDao.insert(tacInspYearBatchReason);
  583. TacInspYearBatchGroupPersParam persParam = new TacInspYearBatchGroupPersParam();
  584. persParam.setYearBatchId(groupPers.getYearBatchId());
  585. persParam.setGroupId(groupPers.getId());
  586. persParam.setPersId(groupPers.getPersId());
  587. groupPersDao.deleteGroupPersInfo(groupPers);
  588. }
  589. }
  590. });
  591. }
  592. }
  593. }
  594. };
  595. timer.schedule(task, replyTimeout);
  596. }
  597. }*/
  598. @Override
  599. public int confirmerGroup(TacInspYearBatchGroupParam tacInspYearBatchGroupParam) {
  600. int update = 0;
  601. TacInspYearBatchGroup tacInspYearBatchGroup = tacInspYearBatchGroupDao.get(tacInspYearBatchGroupParam.getId());
  602. if (tacInspYearBatchGroup != null) {
  603. tacInspYearBatchGroup.setConfirmer("1");
  604. update = tacInspYearBatchGroupDao.update(tacInspYearBatchGroup);
  605. return update;
  606. }
  607. return update;
  608. }
  609. }