fire_point/src/main/java/com/xkrs/service/impl/FirePointServiceImpl.java

158 lines
6.4 KiB
Java
Raw Normal View History

2021-07-13 10:18:08 +08:00
package com.xkrs.service.impl;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.common.tool.TokenUtil;
import com.xkrs.dao.FireAndRangerDao;
2021-07-13 10:18:08 +08:00
import com.xkrs.dao.FirePointDao;
import com.xkrs.dao.ForestRangerDao;
import com.xkrs.dao.SysUserDao;
import com.xkrs.model.entity.FireAndRanger;
2021-07-13 10:18:08 +08:00
import com.xkrs.model.entity.FirePointEntity;
import com.xkrs.model.entity.SysUserEntity;
2021-07-13 10:18:08 +08:00
import com.xkrs.model.qo.FirePointQo;
import com.xkrs.service.FirePointService;
import com.xkrs.utils.AddressUtils;
import com.xkrs.utils.DateTimeUtil;
import com.xkrs.utils.Query;
2021-07-14 17:35:10 +08:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.i18n.LocaleContextHolder;
2021-07-13 10:18:08 +08:00
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.transaction.Transactional;
2021-07-15 15:22:23 +08:00
import java.time.LocalDate;
2021-07-13 10:18:08 +08:00
import java.time.LocalDateTime;
2021-07-15 15:22:23 +08:00
import java.util.List;
import java.util.Locale;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
2021-07-13 10:18:08 +08:00
/**
* @author XinYi Song
*/
@Service
public class FirePointServiceImpl implements FirePointService {
2021-07-14 17:35:10 +08:00
public static Logger log = LoggerFactory.getLogger(FirePointServiceImpl.class);
2021-07-13 10:18:08 +08:00
@Resource
private FirePointDao firePointDao;
@Resource
private Query query;
@Resource
private SysUserDao sysUserDao;
@Resource
private FireAndRangerDao fireAndRangerDao;
@Resource
private ForestRangerDao forestRangerDao;
2021-07-13 10:18:08 +08:00
/**
* 添加火点信息
* @param firePointQo
* @return
*/
@Override
public FirePointEntity insertFirePoint(FirePointQo firePointQo) {
FirePointEntity firePointEntity = new FirePointEntity();
firePointEntity.setFireCode(firePointQo.getFireCode());
firePointEntity.setCountyCode(firePointQo.getCountyCode().toString());
firePointEntity.setCountyName(firePointQo.getCountyName());
firePointEntity.setSatelliteTime(DateTimeUtil.timeMillisToString(firePointQo.getSatelliteTimeTs().longValue()));
firePointEntity.setLongitude(firePointQo.getLongitude());
firePointEntity.setLatitude(firePointQo.getLatitude());
firePointEntity.setFirePointAddress(AddressUtils.getLatAndLng(firePointQo.getLatitude().toString(),firePointQo.getLongitude().toString()));
firePointEntity.setSatelliteType(firePointQo.getSatelliteType());
firePointEntity.setLandType(firePointQo.getLandType());
firePointEntity.setConfidence(firePointQo.getConfidence());
firePointEntity.setAddTime(DateTimeUtil.dateTimeToString(LocalDateTime.now()));
firePointEntity.setFireType("0");
2021-07-14 17:35:10 +08:00
log.info("-------发现新火点");
2021-07-13 10:18:08 +08:00
return firePointDao.save(firePointEntity);
}
2021-07-15 15:22:23 +08:00
/**
* 查询今天的火点信息
* @param
* @return
*/
@Override
public List<FirePointEntity> selectTodayFirePoint() {
String addTime = DateTimeUtil.dateToString(LocalDate.now());
return firePointDao.selectTodayFirePoint(addTime);
}
/**
* 动态多条件查询火点信息
* @param cityCode
* @param satelliteType
* @param landType
* @param startTime
* @param endTime
* @return
*/
@Override
public List<FirePointEntity> 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);
}
}
2021-07-13 10:18:08 +08:00
}