227 lines
9.4 KiB
Java
227 lines
9.4 KiB
Java
package com.xkrs.service.impl;
|
||
|
||
import com.xkrs.common.encapsulation.PromptMessageEnum;
|
||
import com.xkrs.common.tool.TokenUtil;
|
||
import com.xkrs.dao.*;
|
||
import com.xkrs.model.entity.*;
|
||
import com.xkrs.model.qo.FirePointQo;
|
||
import com.xkrs.model.vo.AppPhotoVo;
|
||
import com.xkrs.model.vo.AppTaskBodyVo;
|
||
import com.xkrs.service.FirePointService;
|
||
import com.xkrs.utils.*;
|
||
import org.slf4j.Logger;
|
||
import org.slf4j.LoggerFactory;
|
||
import org.springframework.cglib.beans.BeanCopier;
|
||
import org.springframework.context.i18n.LocaleContextHolder;
|
||
import org.springframework.stereotype.Service;
|
||
import org.springframework.web.multipart.MultipartFile;
|
||
|
||
import javax.annotation.Resource;
|
||
import javax.transaction.Transactional;
|
||
import java.io.IOException;
|
||
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
|
||
*/
|
||
@Service
|
||
public class FirePointServiceImpl implements FirePointService {
|
||
|
||
public static Logger log = LoggerFactory.getLogger(FirePointServiceImpl.class);
|
||
|
||
@Resource
|
||
private FirePointDao firePointDao;
|
||
|
||
@Resource
|
||
private Query query;
|
||
|
||
@Resource
|
||
private SysUserDao sysUserDao;
|
||
|
||
@Resource
|
||
private FireAndRangerDao fireAndRangerDao;
|
||
|
||
@Resource
|
||
private ForestRangerDao forestRangerDao;
|
||
|
||
@Resource
|
||
private FireTaskDao fireTaskDao;
|
||
|
||
@Resource
|
||
private JdbcUtils jdbcUtils;
|
||
|
||
@Resource
|
||
private FireTaskPhotoDao fireTaskPhotoDao;
|
||
|
||
/**
|
||
* 添加火点信息
|
||
* @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");
|
||
log.info("-------发现新火点");
|
||
return firePointDao.save(firePointEntity);
|
||
|
||
}
|
||
|
||
/**
|
||
* 查询今天的火点信息
|
||
* @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);
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 提交核查任务
|
||
* @param files
|
||
* @param appTaskBodyVo
|
||
* @return
|
||
*/
|
||
@Transactional(rollbackOn = Exception.class)
|
||
@Override
|
||
public String insertAppTask(MultipartFile[] files, AppTaskBodyVo appTaskBodyVo) throws IOException {
|
||
// 获取区域信息
|
||
Locale locale = LocaleContextHolder.getLocale();
|
||
FirePointEntity byFireCode = firePointDao.findByFireCode(appTaskBodyVo.getFireCode());
|
||
if(byFireCode == null){
|
||
return outputEncapsulationObject(PromptMessageEnum.DATA_WRONG,"火点编码错误,请重新输入",locale);
|
||
}
|
||
FireTask byTaskFireCode = fireTaskDao.findByTaskFireCode(appTaskBodyVo.getFireCode());
|
||
if(byTaskFireCode != null){
|
||
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,"该火点的任务已经提交,请勿重复提交",locale);
|
||
}
|
||
String s = DateTimeUtil.dateTimeToString(LocalDateTime.now());
|
||
FireTask fireTask = new FireTask();
|
||
fireTask.setTaskFireCode(appTaskBodyVo.getFireCode());
|
||
fireTask.setTaskInformation(appTaskBodyVo.getTaskInformation());
|
||
fireTask.setTaskTime(s);
|
||
FireTask save = fireTaskDao.save(fireTask);
|
||
if(save == null){
|
||
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,"任务提交失败",locale);
|
||
}
|
||
List<FireTaskPhoto> fireTaskPhotos = PhotoUtil.uploadImage(files, appTaskBodyVo.getFireCode());
|
||
List<FireTaskPhoto> fireTaskPhotos1 = jdbcUtils.batchWithJdbcTemplate(fireTaskPhotos);
|
||
if(fireTaskPhotos1.size() == 0 || fireTaskPhotos1 == null){
|
||
return outputEncapsulationObject(PromptMessageEnum.PROCESS_FAIL,"图片上传失败,任务提交失败",locale);
|
||
}
|
||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"任务提交成功",locale);
|
||
}
|
||
|
||
/**
|
||
* 根据火点编码查询任务信息
|
||
* @param fireCode
|
||
* @return
|
||
* @throws Exception
|
||
*/
|
||
@Override
|
||
public String selectAppTask(String fireCode) throws Exception {
|
||
// 获取区域信息
|
||
Locale locale = LocaleContextHolder.getLocale();
|
||
FireTask byTaskFireCode = fireTaskDao.findByTaskFireCode(fireCode);
|
||
if(byTaskFireCode == null){
|
||
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时还没有该火点的任务信息",locale);
|
||
}
|
||
AppTaskBodyVo appTaskBodyVo = new AppTaskBodyVo();
|
||
// 做映射,返回vo类对象
|
||
BeanCopier beanCopier = BeanCopier.create(FireTask.class, AppTaskBodyVo.class, false);
|
||
beanCopier.copy(byTaskFireCode,appTaskBodyVo,null);
|
||
|
||
List<Object[]> photoPath = fireTaskPhotoDao.findPhotoPath(fireCode);
|
||
List<AppPhotoVo> appPhotoVos = ObjectToBeanUtils.objectToBean(photoPath, AppPhotoVo.class);
|
||
appTaskBodyVo.setTaskFirePhoto(appPhotoVos);
|
||
|
||
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,appTaskBodyVo,locale);
|
||
}
|
||
}
|