From 5b29b80de208a43ec99efdb271355fc66f00a0a6 Mon Sep 17 00:00:00 2001 From: "DESKTOP-4U0TDEF\\20371" <2037158277@qq.com> Date: Fri, 16 Jul 2021 09:52:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E6=A0=B9=E6=8D=AE?= =?UTF-8?q?=E7=81=AB=E7=82=B9=E7=BC=96=E7=A0=81=E4=BF=AE=E6=94=B9=E7=81=AB?= =?UTF-8?q?=E7=82=B9=E7=8A=B6=E6=80=81=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xkrs/controller/FirePointController.java | 14 ++++ src/main/java/com/xkrs/dao/FirePointDao.java | 10 +++ .../com/xkrs/service/FirePointService.java | 9 +++ .../service/impl/FirePointServiceImpl.java | 75 +++++++++++++++++++ 4 files changed, 108 insertions(+) diff --git a/src/main/java/com/xkrs/controller/FirePointController.java b/src/main/java/com/xkrs/controller/FirePointController.java index 2246142..7c8677d 100644 --- a/src/main/java/com/xkrs/controller/FirePointController.java +++ b/src/main/java/com/xkrs/controller/FirePointController.java @@ -110,4 +110,18 @@ public class FirePointController { } return outputEncapsulationObject(PromptMessageEnum.SUCCESS,firePointEntities,locale); } + + /** + * 根据火点编码修改火点状态 + * @param map + * @param token + * @return + */ + @PostMapping("/updateTypeByFireCode") + @PreAuthorize("hasAnyAuthority('auth_general_user')") + public String updateTypeByFireCode(@RequestBody Map map, @RequestHeader(value="Authorization") String token){ + String fireCode = (String) map.get("fireCode"); + String fireType = (String) map.get("fireType"); + return firePointService.updateTypeByFireCode(fireCode,fireType,token); + } } diff --git a/src/main/java/com/xkrs/dao/FirePointDao.java b/src/main/java/com/xkrs/dao/FirePointDao.java index 8108b58..e57e5f2 100644 --- a/src/main/java/com/xkrs/dao/FirePointDao.java +++ b/src/main/java/com/xkrs/dao/FirePointDao.java @@ -3,6 +3,7 @@ package com.xkrs.dao; import com.xkrs.model.entity.FirePointEntity; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; +import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Component; @@ -28,4 +29,13 @@ public interface FirePointDao extends JpaRepository, JpaSp * @return */ FirePointEntity findByFireCode(String fireCode); + + /** + * 根据火点编码修改火点状态 + * @param fireCode + * @param fireType + */ + @Modifying(clearAutomatically=true) + @Query(value = "update fire_point set fire_type = ?2 where fire_code = ?1",nativeQuery = true) + void updateFireTypeByFireCode(String fireCode,String fireType); } diff --git a/src/main/java/com/xkrs/service/FirePointService.java b/src/main/java/com/xkrs/service/FirePointService.java index 99196e1..ce00e2c 100644 --- a/src/main/java/com/xkrs/service/FirePointService.java +++ b/src/main/java/com/xkrs/service/FirePointService.java @@ -35,4 +35,13 @@ public interface FirePointService { * @return */ List selectFirePoint(String cityCode,String satelliteType,String landType,String startTime,String endTime); + + /** + * 根据火点编码修改火点的状态(预警) + * @param fireCode + * @param fireType + * @param token + * @return + */ + String updateTypeByFireCode(String fireCode,String fireType,String token); } diff --git a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java index 56c67a3..46d8f5f 100644 --- a/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java +++ b/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java @@ -1,7 +1,14 @@ package com.xkrs.service.impl; +import com.xkrs.common.encapsulation.PromptMessageEnum; +import com.xkrs.common.tool.TokenUtil; +import com.xkrs.dao.FireAndRangerDao; import com.xkrs.dao.FirePointDao; +import com.xkrs.dao.ForestRangerDao; +import com.xkrs.dao.SysUserDao; +import com.xkrs.model.entity.FireAndRanger; import com.xkrs.model.entity.FirePointEntity; +import com.xkrs.model.entity.SysUserEntity; import com.xkrs.model.qo.FirePointQo; import com.xkrs.service.FirePointService; import com.xkrs.utils.AddressUtils; @@ -9,12 +16,17 @@ import com.xkrs.utils.DateTimeUtil; import com.xkrs.utils.Query; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import javax.transaction.Transactional; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.List; +import java.util.Locale; + +import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject; /** * @author XinYi Song @@ -30,6 +42,15 @@ public class FirePointServiceImpl implements FirePointService { @Resource private Query query; + @Resource + private SysUserDao sysUserDao; + + @Resource + private FireAndRangerDao fireAndRangerDao; + + @Resource + private ForestRangerDao forestRangerDao; + /** * 添加火点信息 * @param firePointQo @@ -79,4 +100,58 @@ public class FirePointServiceImpl implements FirePointService { public List selectFirePoint(String cityCode, String satelliteType, String landType, String startTime, String endTime) { return query.selectFirePoint(cityCode, satelliteType, landType, startTime, endTime); } + + /** + * 根据火点编码修改火点的状态(预警) + * @param fireCode + * @param fireType + * @param token + * @return + */ + @Transactional(rollbackOn = Exception.class) + @Override + public String updateTypeByFireCode(String fireCode, String fireType, String token) { + // 获取区域信息 + Locale locale = LocaleContextHolder.getLocale(); + String tokenUserName = TokenUtil.getTokenUserName(token); + SysUserEntity sysUserEntity = sysUserDao.selectByUserName(tokenUserName); + FirePointEntity byFireCode = firePointDao.findByFireCode(fireCode); + if (byFireCode.getFireType().equals("3") || byFireCode.getFireType().equals("-1")) { + return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,"该火点已经结案,请勿进行有关状态操作",locale); + } + if (fireType.equals(byFireCode.getFireType())) { + return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,"您正处于当前的状态,请勿进行该操作",locale); + } + firePointDao.updateFireTypeByFireCode(fireCode, fireType); + if (fireType.equals("1")) { + FirePointEntity byFireCode1 = firePointDao.findByFireCode(fireCode); + // 预警 + return outputEncapsulationObject(PromptMessageEnum.SUCCESS,byFireCode1,locale); + } else if (fireType.equals("2")){ + FirePointEntity byFireCode3 = firePointDao.findByFireCode(fireCode); + // 核查 + return outputEncapsulationObject(PromptMessageEnum.SUCCESS,byFireCode3,locale); + } else { + String rangerType = "0"; + FireAndRanger byFireCode1 = fireAndRangerDao.findByFireCode(fireCode); + if (byFireCode1 == null) { + FirePointEntity byFireCode4 = firePointDao.findByFireCode(fireCode); + String time = DateTimeUtil.dateTimeToString(LocalDateTime.now()); + FireAndRanger fireAndRanger = new FireAndRanger(); + fireAndRanger.setFireCode(fireCode); + // 由于测试阶段先用用户账号代替,后期换成getReallyName(用户真实姓名) + fireAndRanger.setHandler(sysUserEntity.getReallyName()); + fireAndRanger.setEndTime(time); + fireAndRangerDao.save(fireAndRanger); + // 结案 + return outputEncapsulationObject(PromptMessageEnum.SUCCESS,byFireCode4,locale); + } + // 火点结案,将护林员的状态修改为0 表示该护林员没有在执行任务,处于空闲状态 + forestRangerDao.updateRangerTypeByPhone(byFireCode1.getRangerName(), rangerType); + String time = DateTimeUtil.dateTimeToString(LocalDateTime.now()); + fireAndRangerDao.updateEndTimeByFireCode(fireCode, time); + fireAndRangerDao.updateProgressTypeByFireCode(fireCode, "0"); + return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"结案",locale); + } + } }