DataShareController.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /**
  2. * Copyright 2019 DH
  3. * All right reserved.
  4. * 项目名称: 运维系统
  5. * 创建日期:2023/11/10
  6. */
  7. package org.springblade.share;
  8. import com.alibaba.fastjson.JSONArray;
  9. import com.alibaba.fastjson.JSONObject;
  10. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  11. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  12. import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
  13. import io.swagger.annotations.Api;
  14. import io.swagger.annotations.ApiImplicitParam;
  15. import io.swagger.annotations.ApiImplicitParams;
  16. import io.swagger.annotations.ApiOperation;
  17. import lombok.AllArgsConstructor;
  18. import org.springblade.constant.BusinessConstant;
  19. import org.springblade.core.boot.ctrl.BladeController;
  20. import org.springblade.core.tool.api.R;
  21. import org.springblade.core.tool.utils.Func;
  22. import org.springblade.modules.system.entity.User;
  23. import org.springblade.modules.system.service.IUserService;
  24. import org.springblade.modules.yjxt.base.map.entity.DangerAreaEntity;
  25. import org.springblade.modules.yjxt.base.map.service.IDangerAreaService;
  26. import org.springblade.modules.yjxt.business.check.dto.DangerAreaCheckInfoDTO;
  27. import org.springblade.modules.yjxt.business.check.entity.DangerAreaCheckInfoEntity;
  28. import org.springblade.modules.yjxt.business.check.service.IDangerAreaCheckService;
  29. import org.springblade.modules.yjxt.business.resident.dto.DangerAreaResidentInfoDTO;
  30. import org.springblade.modules.yjxt.business.resident.service.IDangerAreaResidentService;
  31. import org.springblade.modules.yjxt.business.transfer.dto.DamageTransferPersonInfoDTO;
  32. import org.springblade.modules.yjxt.business.transfer.entity.DamageTransferPersonInfoEntity;
  33. import org.springblade.modules.yjxt.business.transfer.service.IDamageTransferPersonService;
  34. import org.springblade.modules.yjxt.business.warn.dto.OriginalWarningInfoDTO;
  35. import org.springblade.modules.yjxt.business.warn.entity.OriginalWarningInfoEntity;
  36. import org.springblade.modules.yjxt.business.warn.service.IOriginalWarningService;
  37. import org.springframework.web.bind.annotation.GetMapping;
  38. import org.springframework.web.bind.annotation.RequestMapping;
  39. import org.springframework.web.bind.annotation.RestController;
  40. import java.time.LocalDateTime;
  41. import java.time.ZoneId;
  42. import java.time.format.DateTimeFormatter;
  43. import java.util.*;
  44. /***
  45. * Date:2023/11/10
  46. * Title:文件所属模块(必须填写)
  47. * Description:对本文件的详细描述,原则上不能少于30字
  48. * @author dylan
  49. * @version 1.0
  50. * Remark:认为有必要的其他信息
  51. */
  52. @RestController
  53. @RequestMapping("ywxt-business/public/data/share")
  54. @AllArgsConstructor
  55. @Api(value = "共享管理接口", tags = "提供第三方查询接口")
  56. public class DataShareController extends BladeController {
  57. private final IUserService userService;
  58. private final IDangerAreaCheckService danagerAreaCheckService;
  59. private final IDamageTransferPersonService damageTransferPersonService;
  60. private final IDangerAreaResidentService dangerAreaResidentService;
  61. private final IOriginalWarningService warningService;
  62. private final IDangerAreaService dangerAreaService;
  63. private final IOriginalWarningService originalWarningService;
  64. /**
  65. * 巡查巡检列表查询,不分页
  66. */
  67. @GetMapping("/yj/check/list")
  68. @ApiImplicitParams({
  69. @ApiImplicitParam(name = "warnId", value = "预警ID", paramType = "query", dataType = "string")
  70. })
  71. @ApiOperationSupport(order = 1)
  72. @ApiOperation(value = "不分页", notes = "")
  73. public R<List<JSONObject>> yjCheckList(DangerAreaCheckInfoDTO dto) {
  74. if (Func.isNull(dto.getWarnId())) {
  75. return R.fail("参数错误");
  76. }
  77. if (dto.getWarnId().length() == 0) {
  78. return R.fail("参数错误");
  79. }
  80. LambdaQueryWrapper<DangerAreaCheckInfoEntity> wrapper = Wrappers.<DangerAreaCheckInfoEntity>query().lambda();
  81. wrapper.eq(DangerAreaCheckInfoEntity::getWarnId, dto.getWarnId());
  82. wrapper.orderByAsc(DangerAreaCheckInfoEntity::getCreateTime);
  83. List<DangerAreaCheckInfoEntity> list = danagerAreaCheckService.list(wrapper);
  84. List<JSONObject> datas = new ArrayList<>(list.size());
  85. for (DangerAreaCheckInfoEntity entity : list) {
  86. JSONObject d = new JSONObject();
  87. d.put("warnId", entity.getWarnId());
  88. User user = userService.getById(entity.getCreateUser());
  89. if (!Func.isNull(user)) {
  90. d.put("checkPerson", user.getRealName());
  91. } else {
  92. d.put("checkPerson", "");
  93. }
  94. d.put("checkTime", entity.getCreateTime().getTime());
  95. if (!Func.isNull(entity.getLongitude())) {
  96. d.put("lng", entity.getLongitude());
  97. }
  98. if (!Func.isNull(entity.getLatitude())) {
  99. d.put("lat", entity.getLatitude());
  100. }
  101. if (!Func.isNull(entity.getAddress())) {
  102. d.put("location", entity.getAddress());
  103. }
  104. d.put("isFlood", entity.getIsFlood());
  105. d.put("isDamage", entity.getIsDamage());
  106. if (!Func.isNull(entity.getRemark())) {
  107. d.put("remark", entity.getRemark());
  108. }
  109. JSONArray photos = new JSONArray();
  110. if (!Func.isNull(entity.getCheckPhotos())) {
  111. String photo = entity.getCheckPhotos();
  112. String[] photoArr = photo.trim().split(",");
  113. for (String url : photoArr) {
  114. JSONObject p = new JSONObject();
  115. p.put("url", BusinessConstant.OSS_BASE_PATH + url);
  116. photos.add(p);
  117. }
  118. }
  119. d.put("photos", photos);
  120. datas.add(d);
  121. }
  122. return R.data(datas);
  123. }
  124. /**
  125. * 灾害转移统计查询
  126. * 根据危险区统计
  127. */
  128. @GetMapping("/yj/transfer/dangerarea/count")
  129. @ApiImplicitParams({
  130. @ApiImplicitParam(name = "dangerAreaPid", value = "危险区ID", paramType = "query", dataType = "string"),
  131. @ApiImplicitParam(name = "startTime", value = "预警开始时间", paramType = "query", dataType = "string"),
  132. @ApiImplicitParam(name = "endTime", value = "预警结束时间", paramType = "query", dataType = "string"),
  133. @ApiImplicitParam(name = "warnLevelCode", value = "预警等级", paramType = "query", dataType = "string"),
  134. })
  135. @ApiOperationSupport(order = 1)
  136. @ApiOperation(value = "不分页", notes = "")
  137. public R<List<JSONObject>> yjTransferCountByDangerarea(DamageTransferPersonInfoDTO dto) {
  138. if (Func.isNull(dto.getDangerAreaPid())) {
  139. return R.fail("危险区ID参数错误");
  140. }
  141. // if (Func.isNull(dto.getStartTime()) || Func.isNull(dto.getEndTime())) {
  142. // return R.fail("查询时间参数错误");
  143. // }
  144. // if (Func.isNull(dto.getWarnLevelCode())) {
  145. // return R.fail("预警等级参数错误");
  146. // }
  147. List<JSONObject> datas = new ArrayList<>();
  148. OriginalWarningInfoDTO originalWarningInfoDTO = new OriginalWarningInfoDTO();
  149. originalWarningInfoDTO.setDangerAreaPid(dto.getDangerAreaPid());
  150. if (Func.notNull(dto.getWarnLevelCode())) {
  151. originalWarningInfoDTO.setWarnLevelCode(dto.getWarnLevelCode());
  152. }
  153. if (Func.notNull(dto.getStartTime()) && Func.notNull(dto.getEndTime())) {
  154. LocalDateTime startDateTime = LocalDateTime.parse(dto.getStartTime(), DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
  155. originalWarningInfoDTO.setStartTime(Date.from(startDateTime.atZone(ZoneId.systemDefault()).toInstant()));
  156. LocalDateTime endDateTime = LocalDateTime.parse(dto.getEndTime(), DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
  157. originalWarningInfoDTO.setEndTime(Date.from(endDateTime.atZone(ZoneId.systemDefault()).toInstant()));
  158. } else if (Func.notNull(dto.getStartTime())) {
  159. LocalDateTime startDateTime = LocalDateTime.parse(dto.getStartTime(), DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
  160. originalWarningInfoDTO.setStartTime(Date.from(startDateTime.atZone(ZoneId.systemDefault()).toInstant()));
  161. }
  162. List<OriginalWarningInfoEntity> originalWarningInfoEntityList = originalWarningService.selectDangerAreaList(originalWarningInfoDTO);
  163. if (Func.notNull(originalWarningInfoEntityList)) {
  164. for (OriginalWarningInfoEntity entity : originalWarningInfoEntityList) {
  165. JSONObject vo = new JSONObject();
  166. vo.put("warnId", entity.getWarnId());
  167. vo.put("warnTime", entity.getWarnTime().getTime());
  168. vo.put("warnLevelCode",entity.getWarnLevelCode());
  169. DangerAreaResidentInfoDTO residentInfoDTO = new DangerAreaResidentInfoDTO();
  170. residentInfoDTO.setDangerAreaCode(entity.getWarnAdcd());
  171. long totalTransferPerson = dangerAreaResidentService.residentCount(residentInfoDTO);
  172. DamageTransferPersonInfoDTO transferPersonInfoDTO = new DamageTransferPersonInfoDTO();
  173. transferPersonInfoDTO.setWarnId(entity.getWarnId());
  174. long safetyTransferPerson = damageTransferPersonService.transferPersonCount(transferPersonInfoDTO);
  175. vo.put("totalTransferPerson", totalTransferPerson);
  176. vo.put("safetyTransferPerson", safetyTransferPerson);
  177. JSONArray personList = new JSONArray();
  178. LambdaQueryWrapper<DamageTransferPersonInfoEntity> wrapper2 = Wrappers.<DamageTransferPersonInfoEntity>query().lambda();
  179. wrapper2.eq(DamageTransferPersonInfoEntity::getWarnId, entity.getWarnId());
  180. List<DamageTransferPersonInfoEntity> transferPersonInfoEntityList = damageTransferPersonService.list(wrapper2);
  181. if (Func.notNull(transferPersonInfoEntityList)) {
  182. for (DamageTransferPersonInfoEntity transferPersonInfoEntity : transferPersonInfoEntityList) {
  183. JSONObject person = new JSONObject();
  184. person.put("personName", transferPersonInfoEntity.getPersonName());
  185. person.put("recordTime", transferPersonInfoEntity.getCreateTime().getTime());
  186. personList.add(person);
  187. }
  188. }
  189. vo.put("transferPersonList", personList);
  190. datas.add(vo);
  191. }
  192. }
  193. return R.data(datas);
  194. }
  195. /**
  196. * 灾害转移统计查询
  197. * 根据预警ID查询
  198. *
  199. * @param dto
  200. * @return
  201. */
  202. @GetMapping("/yj/transfer/count")
  203. @ApiImplicitParams({
  204. @ApiImplicitParam(name = "warnId", value = "预警ID", paramType = "query", dataType = "string")
  205. })
  206. @ApiOperationSupport(order = 1)
  207. @ApiOperation(value = "不分页", notes = "")
  208. public R<List<JSONObject>> yjTransferCount(DamageTransferPersonInfoDTO dto) {
  209. if (Func.isNull(dto.getWarnId())) {
  210. return R.fail("参数错误");
  211. }
  212. LambdaQueryWrapper<OriginalWarningInfoEntity> wrapper = Wrappers.<OriginalWarningInfoEntity>query().lambda();
  213. wrapper.eq(OriginalWarningInfoEntity::getWarnId, dto.getWarnId());
  214. OriginalWarningInfoEntity warningInfoEntity = warningService.getOne(wrapper);
  215. if (Func.isNull(warningInfoEntity)) {
  216. return R.fail("预警数据空");
  217. }
  218. List<JSONObject> datas = new ArrayList<>(1);
  219. JSONObject vo = new JSONObject();
  220. DangerAreaResidentInfoDTO residentInfoDTO = new DangerAreaResidentInfoDTO();
  221. residentInfoDTO.setDangerAreaCode(warningInfoEntity.getWarnAdcd());
  222. long totalTransferPerson = dangerAreaResidentService.residentCount(residentInfoDTO);
  223. DamageTransferPersonInfoDTO transferPersonInfoDTO = new DamageTransferPersonInfoDTO();
  224. transferPersonInfoDTO.setWarnId(dto.getWarnId());
  225. long safetyTransferPerson = damageTransferPersonService.transferPersonCount(transferPersonInfoDTO);
  226. vo.put("totalTransferPerson", totalTransferPerson);
  227. vo.put("safetyTransferPerson", safetyTransferPerson);
  228. JSONArray personList = new JSONArray();
  229. LambdaQueryWrapper<DamageTransferPersonInfoEntity> wrapper2 = Wrappers.<DamageTransferPersonInfoEntity>query().lambda();
  230. wrapper2.eq(DamageTransferPersonInfoEntity::getIsDeleted, 0);
  231. wrapper2.eq(DamageTransferPersonInfoEntity::getWarnId, dto.getWarnId());
  232. List<DamageTransferPersonInfoEntity> transferPersonInfoEntityList = damageTransferPersonService.list(wrapper2);
  233. if (!Func.isNull(transferPersonInfoEntityList)) {
  234. for (DamageTransferPersonInfoEntity transferPersonInfoEntity : transferPersonInfoEntityList) {
  235. JSONObject person = new JSONObject();
  236. person.put("personName", transferPersonInfoEntity.getPersonName());
  237. person.put("recordTime", transferPersonInfoEntity.getCreateTime().getTime());
  238. personList.add(person);
  239. }
  240. }
  241. vo.put("transferPersonList", personList);
  242. datas.add(vo);
  243. return R.data(datas);
  244. }
  245. }