286ea655cb938b66ac065135e11ffee3c3ed6b5e.svn-base 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. package cn.com.goldenwater.dcproj.service.impl.rsvr;
  2. import cn.com.goldenwater.core.service.AbstractCrudService;
  3. import cn.com.goldenwater.dcproj.constValue.CommonLabel;
  4. import cn.com.goldenwater.dcproj.constValue.SplitValue;
  5. import cn.com.goldenwater.dcproj.dao.*;
  6. import cn.com.goldenwater.dcproj.model.*;
  7. import cn.com.goldenwater.dcproj.param.BisInspRsvrPblmMendParam;
  8. import cn.com.goldenwater.dcproj.param.GwComFileParam;
  9. import cn.com.goldenwater.dcproj.service.AttRsBaseService;
  10. import cn.com.goldenwater.dcproj.service.BisInspRsvrPblmMendService;
  11. import cn.com.goldenwater.dcproj.service.GwComFileService;
  12. import cn.com.goldenwater.dcproj.utils.*;
  13. import com.github.pagehelper.PageHelper;
  14. import com.github.pagehelper.PageInfo;
  15. import net.sf.json.JSONArray;
  16. import net.sf.json.JSONObject;
  17. import net.sf.json.JsonConfig;
  18. import org.apache.commons.collections.map.HashedMap;
  19. import org.apache.commons.lang3.StringUtils;
  20. import org.slf4j.Logger;
  21. import org.slf4j.LoggerFactory;
  22. import org.springframework.beans.factory.annotation.Autowired;
  23. import org.springframework.beans.factory.annotation.Value;
  24. import org.springframework.stereotype.Service;
  25. import java.io.File;
  26. import java.text.SimpleDateFormat;
  27. import java.util.*;
  28. import java.util.stream.Collectors;
  29. /**
  30. * @author lune
  31. * @date 2020-7-7
  32. */
  33. @Service
  34. public class BisInspRsvrPblmMendServiceImpl extends AbstractCrudService<BisInspRsvrPblmMend, BisInspRsvrPblmMendParam> implements BisInspRsvrPblmMendService {
  35. private Logger logger = LoggerFactory.getLogger(BisInspRsvrPblmMendServiceImpl.class);
  36. private static String accessToken = "";
  37. @Value("${mwr.ducha.url}")
  38. private String quanguoUrl;
  39. @Value("${hunan.phone}")
  40. private String phone;
  41. @Value("${quanguocode}")
  42. private String smscode;
  43. @Value("${getFile.prefix}")
  44. public String prefix;
  45. @Autowired
  46. private OlBisInspOrgDao olBisInspOrgDao;
  47. @Autowired
  48. private BisInspRsvrPblmMendDao bisInspRsvrPblmMendDao;
  49. @Autowired
  50. private GwComFileDao gwComFileDao;
  51. @Autowired
  52. private AttAdBaseDao attAdBaseDao;
  53. @Value("${web.upload-path}")
  54. public String fileDir;
  55. @Autowired
  56. private BisInspRsvrRgstrDao bisInspRsvrRgstrDao;
  57. @Autowired
  58. private GwComFileService gwComFileService;
  59. public BisInspRsvrPblmMendServiceImpl(BisInspRsvrPblmMendDao bisInspRsvrPblmMendDao) {
  60. super(bisInspRsvrPblmMendDao);
  61. this.bisInspRsvrPblmMendDao = bisInspRsvrPblmMendDao;
  62. }
  63. @Override
  64. public PageInfo<BisInspRsvrPblmMend> findRsvrPblmPage(BisInspRsvrPblmMendParam bisInspRsvrPblmMendParam) {
  65. if (StringUtils.isNotBlank(bisInspRsvrPblmMendParam.getAdCode())) {
  66. bisInspRsvrPblmMendParam.setAdCode(AdLevelUtil.SubAd(bisInspRsvrPblmMendParam.getAdCode()).get(SplitValue.SUBAD).toString());
  67. }
  68. PageHelper.startPage(bisInspRsvrPblmMendParam);
  69. List<BisInspRsvrPblmMend> result = bisInspRsvrPblmMendDao.findRsvrPblmList(bisInspRsvrPblmMendParam);
  70. if (result.size() > 0) {
  71. result.forEach(mend -> {
  72. List<GwComFile> gwComFiles = gwComFileDao.findFileByBiz(mend.getId());
  73. if (gwComFiles != null && gwComFiles.size() > 0) {
  74. gwComFiles = gwComFiles.stream().filter(file -> "MEND_EXTRA".equals(file.getBizType())).collect(Collectors.toList());
  75. }
  76. mend.setGwComFiles(gwComFiles);
  77. });
  78. }
  79. PageInfo<BisInspRsvrPblmMend> pageInfo = new PageInfo<>(result);
  80. return pageInfo;
  81. }
  82. /**
  83. * 每日凌晨一点定时导入小水库问题数据
  84. */
  85. @Override
  86. public void getQuanguo() {
  87. //登录
  88. BisInspAllRlationPers bisInspAllRlationPers = this.login();
  89. Map<String, String> params = new HashMap<>();
  90. if (bisInspAllRlationPers != null) {
  91. Map<String, String> headerMap = new HashMap<>();
  92. headerMap.put(CommonLabel.ACCESS_TOKEN, accessToken);
  93. headerMap.put(CommonLabel.PERSID, bisInspAllRlationPers.getGuid());
  94. List<AttAdBase> attAdBases = attAdBaseDao.getAdData("000000000000");
  95. Calendar calendar = Calendar.getInstance();
  96. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  97. String entm = DateUtils.Calendar2Str(calendar, "yyyy-MM-dd HH:mm:ss");
  98. calendar.add(Calendar.DAY_OF_MONTH, -3);//今天的时间减三天
  99. String sttm = DateUtils.Calendar2Str(calendar, "yyyy-MM-dd HH:mm:ss");
  100. logger.info("-------------开始导入部里数据----------------");
  101. for (AttAdBase attAdBase : attAdBases) {
  102. //设置省份导入
  103. String adCode = attAdBase.getAdCode();
  104. params.put("adCode", AdLevelUtil.getAddvcd(adCode));
  105. /*params.put("adCode", "53");*/
  106. params.put("startTime", sttm);
  107. params.put("endTime", entm);
  108. List<BisInspRsvrPblmMend> bisInspRsvrPblmMends = getBisInspRects(bisInspAllRlationPers, params, headerMap);
  109. //获取小水库数据并插入本地库
  110. // insertRsvr(bisInspRsvrPblmMends, bisInspAllRlationPers, params, headerMap);
  111. bisInspRsvrPblmMends.stream().forEach(bisInspRsvrPblmMend -> {
  112. bisInspRsvrPblmMendDao.insertRsvr(bisInspRsvrPblmMend);
  113. //插入附件信息,下载附件文件
  114. String fileBizId = bisInspRsvrPblmMend.getId();
  115. if (downloadFile(fileBizId, headerMap)) {
  116. //下载成功
  117. logger.info("下载成功");
  118. } else {
  119. //下载失败
  120. logger.info("下载失败");
  121. }
  122. //如果附件已经插入则放弃,如果没有则进行插入
  123. });
  124. }
  125. logger.info("-------------导入部里数据结束----------------");
  126. }
  127. }
  128. /**
  129. * 调用部里登录接口
  130. *
  131. * @return
  132. */
  133. public BisInspAllRlationPers login() {
  134. String apiUrl = quanguoUrl + "/bis/insp/loginByCode";
  135. Map<String, String> params = new HashMap<>();
  136. params.put("phone", phone);
  137. params.put("code", smscode);
  138. String content = HttpClientUtils.doHttpsPost(apiUrl, params, new HashedMap());
  139. JSONObject jsonObject = JSONObject.fromObject(content);
  140. //登录结果返回
  141. if (jsonObject != null && jsonObject.size() > 3) {
  142. //获取token
  143. accessToken = jsonObject.getString(CommonLabel.ACCESS_TOKEN);
  144. String data = jsonObject.getString("data");
  145. JSONObject object = JSONObject.fromObject(data);
  146. return (BisInspAllRlationPers) JSONObject.toBean(object, BisInspAllRlationPers.class);
  147. }
  148. return new BisInspAllRlationPers();
  149. }
  150. /**
  151. * 下发通知,问题反馈
  152. *
  153. * @param params
  154. * @param headerMap
  155. * @param
  156. */
  157. private void sendInform(Map<String, String> params, Map<String, String> headerMap, List<BisInspRsvrPblmMend> bisInspRsvrPblmMends) {
  158. /* String rectIds = rectList.stream().map(n -> n.getId()).collect(Collectors.joining(","));
  159. params.clear();
  160. params.put("rectIds", rectIds);
  161. String rectpblmUrl = quanguoUrl + "/api/bis/insp/rect/findRecPblmListByRectIds";
  162. HttpClientUtils.doHttpsPost(rectpblmUrl, params, headerMap);
  163. //通知下发成功,更改获取通知状态
  164. String rectMsgUrl = quanguoUrl + "/api/bis/insp/rect/restRectByIds";
  165. HttpClientUtils.doHttpsPost(rectMsgUrl, params, headerMap);
  166. //问题反馈成功,信息反馈(未部署)
  167. String rectPortUrl = quanguoUrl + "/api/bis/insp/rect/restRectPblmByIds";
  168. HttpClientUtils.doHttpsPost(rectPortUrl, params, headerMap);*/
  169. }
  170. /**
  171. * 获取小水库数据并插入本地库
  172. *
  173. * @param bisInspAllRlationPers
  174. * @param params
  175. * @param headerMap
  176. */
  177. private void insertRsvr(List<BisInspRsvrPblmMend> bisInspRsvrPblmMends, BisInspAllRlationPers bisInspAllRlationPers, Map<String, String> params, Map<String, String> headerMap) {
  178. /* List<BisInspRsvrPblmMend> list = new ArrayList<>();
  179. int delDataStep = 0;
  180. for (int i = 0; i < bisInspRsvrPblmMends.size(); i++) {
  181. list.add(bisInspRsvrPblmMends.get(i));
  182. delDataStep++;
  183. if (delDataStep == 50) {
  184. bisInspRsvrPblmMendDao.insertRsvr(list);
  185. list.clear();
  186. delDataStep = 0;
  187. }
  188. if (i == bisInspRsvrPblmMends.size() - 1) {
  189. bisInspRsvrPblmMendDao.insertRsvr(list);
  190. list.clear();
  191. }
  192. }*/
  193. }
  194. /**
  195. * 下载数据
  196. *
  197. * @param bisInspAllRlationPers
  198. * @param params
  199. * @param headerMap
  200. * @return
  201. */
  202. private List<BisInspRsvrPblmMend> getBisInspRects(BisInspAllRlationPers bisInspAllRlationPers, Map<String, String> params, Map<String, String> headerMap) {
  203. //OlBisInspOrg olBisInspOrg = olBisInspOrgDao.get(bisInspAllRlationPers.getOrgId());
  204. //获取用户相关信息
  205. String rectUrl = quanguoUrl + "/bis/insp/rsvr/pblm/mend/downLoadRsvrList";
  206. Calendar date = Calendar.getInstance();
  207. params.put("year", String.valueOf(date.get(Calendar.YEAR)));
  208. params.put("mnth", String.valueOf(date.get(Calendar.MONTH) + 1));
  209. //params.put("rsName", "弄贯(二)水库");
  210. String rectContent = "";
  211. try {
  212. rectContent = HttpClientUtils.doHttpsPost2(rectUrl, params, headerMap);
  213. JSONObject jsonObject = JSONObject.fromObject(rectContent);
  214. JSONArray jsonArray = jsonObject.getJSONArray("data");
  215. List<BisInspRsvrPblmMend> bisInspRsvrPblmMends;
  216. bisInspRsvrPblmMends = JSONArray.toList(jsonArray, new BisInspRsvrPblmMend(), new JsonConfig());
  217. return bisInspRsvrPblmMends;
  218. } catch (Exception e) {
  219. logger.info(rectContent);
  220. logger.info(e.getMessage());
  221. return null;
  222. }
  223. }
  224. /**
  225. * 手动导入小水库数据
  226. *
  227. * @param bisInspRsvrPblmMendParam
  228. */
  229. @Override
  230. public void importRsvrData(BisInspRsvrPblmMendParam bisInspRsvrPblmMendParam) {
  231. //调用部里登录接口
  232. BisInspAllRlationPers bisInspAllRlationPers = this.login();
  233. Map<String, String> params = new HashMap<>();
  234. if (bisInspAllRlationPers != null) {
  235. Map<String, String> headerMap = new HashMap<>();
  236. headerMap.put(CommonLabel.ACCESS_TOKEN, accessToken);
  237. headerMap.put(CommonLabel.PERSID, bisInspAllRlationPers.getGuid());
  238. //获取用户相关信息
  239. List<AttAdBase> attAdBases = attAdBaseDao.getAdData("000000000000");
  240. for (AttAdBase attAdBase : attAdBases) {
  241. String adCode = attAdBase.getAdCode();
  242. params.put("adCode", AdLevelUtil.getAddvcd(adCode));
  243. List<BisInspRsvrPblmMend> bisInspRsvrPblmMends = getBisInspRects(bisInspAllRlationPers, params, headerMap);
  244. //获取小水库数据并插入本地库
  245. /*insertRsvr(bisInspRsvrPblmMends, bisInspAllRlationPers, params, headerMap);*/
  246. bisInspRsvrPblmMends.stream().forEach(bisInspRsvrPblmMend -> {
  247. bisInspRsvrPblmMendDao.insertRsvr(bisInspRsvrPblmMend);
  248. });
  249. }
  250. }
  251. }
  252. public Boolean downloadFile(String bizId, Map<String, String> headerMap) {
  253. String rectUrl = quanguoUrl + "/file/findFileByBiz?bizId=" + bizId;
  254. Map<String, String> params = new HashMap<>();
  255. //params.put("bizId", bizId);
  256. String rectContent = "";
  257. try {
  258. rectContent = HttpClientUtils.doHttpsPost(rectUrl, params, headerMap);
  259. JSONObject jsonObject = JSONObject.fromObject(rectContent);
  260. JSONArray jsonArray = jsonObject.getJSONArray("data");
  261. List<GwComFile> gwComFiles;
  262. gwComFiles = JSONArray.toList(jsonArray, new GwComFile(), new JsonConfig());
  263. //拼接 访问地址做下载
  264. for (GwComFile gwComFile : gwComFiles
  265. ) {
  266. String path = quanguoUrl + "/" + gwComFile.getFilePath();
  267. fileDir = fileDir.replace("upload/", "");
  268. String dirPath = fileDir + gwComFile.getFilePath().substring(0, gwComFile.getFilePath().lastIndexOf("/"));
  269. File pathFile = new File(dirPath);
  270. if (!pathFile.exists()) {
  271. pathFile.mkdirs();
  272. }
  273. ;
  274. HttpsDownloadUtils.downloadFile(path, fileDir + gwComFile.getFilePath());
  275. //插入插入本地数据库记录
  276. if (null != gwComFileService.get(gwComFile.getId())) {
  277. gwComFileService.update(gwComFile);
  278. } else {
  279. gwComFileService.insert(gwComFile);
  280. }
  281. }
  282. return true;
  283. } catch (Exception ex) {
  284. logger.info(rectContent);
  285. logger.info(ex.getMessage());
  286. return false;
  287. }
  288. }
  289. @Override
  290. public void updRevwInfo() {
  291. //调用部里登录接口
  292. BisInspAllRlationPers bisInspAllRlationPers = this.login();
  293. Map<String, String> params = new HashMap<>();
  294. String mwrUrl = quanguoUrl + "/bis/insp/rsvr/pblm/mend/findRsvrList";
  295. Map<String, String> headerMap = new HashMap<>();
  296. headerMap.put(CommonLabel.ACCESS_TOKEN, accessToken);
  297. headerMap.put(CommonLabel.PERSID, bisInspAllRlationPers.getGuid());
  298. params.put("revwInfo", "revwInfo");
  299. params.put("persGuid", bisInspAllRlationPers.getGuid());
  300. String mwrContent = HttpClientUtils.doHttpsPost2(mwrUrl, params, headerMap);
  301. JSONObject jsonObject = JSONObject.fromObject(mwrContent);
  302. JSONArray mwrJsonArray = jsonObject.getJSONArray("data");
  303. List<BisInspRsvrPblmMend> bisInspRsvrPblmMends = JSONArray.toList(mwrJsonArray, new BisInspRsvrPblmMend(), new JsonConfig());
  304. for (BisInspRsvrPblmMend bisInspRsvrPblmMend : bisInspRsvrPblmMends) {
  305. bisInspRsvrPblmMendDao.updateRevwInfo(bisInspRsvrPblmMend.getId(), bisInspRsvrPblmMend.getRevwInfo());
  306. }
  307. }
  308. @Override
  309. public int update2021(BisInspRsvrPblmMend bisInspRsvrPblmMend) {
  310. int update = update(bisInspRsvrPblmMend);
  311. BisInspRsvrRgstr bisInspRsvrRgstr = new BisInspRsvrRgstr();
  312. String rgstrId = bisInspRsvrPblmMend.getRgstrId();
  313. bisInspRsvrRgstr.setRgstrId(rgstrId);
  314. BisInspRsvrPblmMendParam mendParam = new BisInspRsvrPblmMendParam();
  315. mendParam.setRsCode(bisInspRsvrPblmMend.getRsCode());
  316. // mendParam.setRsName(bisInspRsvrPblmMend.getRsName());
  317. // mendParam.setAdCode(bisInspRsvrPblmMend.getAdCode());
  318. List<BisInspRsvrPblmMend> mendList = findList(mendParam);
  319. if (mendList != null) { //统计所有问题的状态得出登记表状态
  320. String rectState = "2";//要求前端校验提交的数据(即当前修改的问题必须有值)
  321. for (BisInspRsvrPblmMend mend : mendList) {
  322. if (mend.getRevwState() == null || !"2".equals(mend.getRevwState())) {
  323. rectState = "1";
  324. break;
  325. }
  326. }
  327. bisInspRsvrRgstr.setRectStat(rectState);
  328. }
  329. BisInspRsvrRgstr rgstr = bisInspRsvrRgstrDao.get(rgstrId);
  330. if (rgstr != null) {
  331. if (!Constant.STRING_TWO.equals(rgstr.getState())) {
  332. bisInspRsvrRgstr.setState(Constant.STRING_ONE);
  333. }
  334. bisInspRsvrRgstrDao.update(bisInspRsvrRgstr);
  335. }
  336. List<GwComFile> gwComFiles = bisInspRsvrPblmMend.getGwComFiles();
  337. // 为 佐证材料 类的文件 不能删除,所以直接加上
  338. GwComFileParam param = new GwComFileParam();
  339. param.setBizId(bisInspRsvrPblmMend.getId());
  340. param.setBizType("MEND_PROV");
  341. List<GwComFile> prov = gwComFileService.findList(param);
  342. if (gwComFiles != null && gwComFiles.size() > 0) {
  343. if (prov != null) gwComFiles.addAll(prov);
  344. gwComFileService.updateBiz(gwComFiles, bisInspRsvrPblmMend.getId());
  345. }
  346. return 0;
  347. }
  348. @Autowired
  349. private AttRsBaseService attRsBaseService;
  350. @Override
  351. public int insert2021(BisInspRsvrPblmMend bisInspRsvrPblmMend) {
  352. Optional.ofNullable(bisInspRsvrPblmMend).map(BisInspRsvrPblmMend::getRsCode).ifPresent(rsCode -> {
  353. AttRsBase attRsBase = attRsBaseService.get(rsCode);
  354. Optional.ofNullable(attRsBase).ifPresent(base -> {
  355. bisInspRsvrPblmMend.setEngScal(base.getEngScal());
  356. bisInspRsvrPblmMend.setRsName(base.getRsName());
  357. });
  358. });
  359. int insert = insert(bisInspRsvrPblmMend);
  360. BisInspRsvrRgstr bisInspRsvrRgstr = new BisInspRsvrRgstr();
  361. String rgstrId = bisInspRsvrPblmMend.getRgstrId();
  362. bisInspRsvrRgstr.setRgstrId(rgstrId);
  363. BisInspRsvrPblmMendParam mendParam = new BisInspRsvrPblmMendParam();
  364. // mendParam.setRsCode(bisInspRsvrPblmMend.getRsCode());
  365. mendParam.setRsName(bisInspRsvrPblmMend.getRsName());
  366. mendParam.setAdCode(bisInspRsvrPblmMend.getAdCode());
  367. List<BisInspRsvrPblmMend> mendList = findList(mendParam);
  368. if (mendList != null) { //统计所有问题的状态得出登记表状态
  369. String rectState = "2";//要求前端校验提交的数据(即当前修改的问题必须有值)
  370. for (BisInspRsvrPblmMend mend : mendList) {
  371. if (mend.getRevwState() == null || !mend.getRevwState().equals("2")) {
  372. rectState = "1";
  373. break;
  374. }
  375. }
  376. bisInspRsvrRgstr.setRectStat(rectState);
  377. }
  378. BisInspRsvrRgstr rgstr = bisInspRsvrRgstrDao.get(rgstrId);
  379. if (rgstr != null) {
  380. if (!Constant.STRING_TWO.equals(rgstr.getState())) {
  381. bisInspRsvrRgstr.setState(Constant.STRING_ONE);
  382. }
  383. bisInspRsvrRgstrDao.update(bisInspRsvrRgstr);
  384. }
  385. List<GwComFile> gwComFiles = bisInspRsvrPblmMend.getGwComFiles();
  386. if (gwComFiles != null && gwComFiles.size() > 0) {
  387. gwComFileService.updateBiz(gwComFiles, bisInspRsvrPblmMend.getId());
  388. }
  389. return 0;
  390. }
  391. @Override
  392. public PageInfo<BisInspRsvrPblmMend> pagerPc(BisInspRsvrPblmMendParam bisInspRsvrPblmMendParam) {
  393. PageHelper.startPage(bisInspRsvrPblmMendParam);
  394. List<BisInspRsvrPblmMend> list = bisInspRsvrPblmMendDao.findList(bisInspRsvrPblmMendParam);
  395. return new PageInfo<>(list);
  396. }
  397. }