修改了动态多条件查询的参数

This commit is contained in:
DESKTOP-4U0TDEF\20371 2021-07-16 08:47:53 +08:00
parent c0b1108e14
commit cd1888041a
15 changed files with 845 additions and 11 deletions

View File

@ -0,0 +1,60 @@
package com.xkrs.controller;
import com.xkrs.service.FireAndRangerService;
import com.xkrs.utils.Result;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.util.Map;
/**
* @author xkrs
*/
@RestController
public class FireAndRangerController {
@Resource
private FireAndRangerService fireAndRangerService;
/**
* 将火点分配给某个人
* @param map
* @param token
* @return
*/
@PreAuthorize("hasAnyRole('ROLE_city','ROLE_county')")
@PostMapping("/addFireAndRanger")
public Result addFireAndRanger(@RequestBody Map map, @RequestHeader(value="Authorization") String token) throws UnsupportedEncodingException {
String rangerName = (String) map.get("rangerName");
String fireCode = (String) map.get("fireCode");
String handler = (String) map.get("handler");
String verifier = (String) map.get("verifier");
return fireAndRangerService.addFireAndRanger(rangerName,fireCode,handler,verifier,token);
}
/**
* 护林员查看自己的火点任务
* @param token
* @return
*/
@Secured("ROLE_ranger")
@GetMapping("/selectFireInformation")
public Result selectFireInformation(@RequestHeader(value="Authorization") String token){
return fireAndRangerService.selectFireInformation(token);
}
/**
* 根据火点编码查询核查信息
* @param map
* @return
*/
@PreAuthorize("hasAnyRole('ROLE_city','ROLE_county')")
@PostMapping("/findFireAndRanger")
public Result findFireAndRangerByFireCode(@RequestBody Map map, @RequestHeader(value="Authorization") String token) throws Exception {
String fireCode = (String) map.get("fireCode");
return fireAndRangerService.findFireAndRangerByFireCode(fireCode,token);
}
}

View File

@ -0,0 +1,56 @@
package com.xkrs.controller;
import com.xkrs.service.XkRsForestRangerService;
import com.xkrs.utils.Result;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Map;
/**
* @author xkrs
*/
@RestController
public class XkRsForestRangerController {
@Resource
private XkRsForestRangerService xkRsForestRangerService;
/**
* 根据区县编码查询相关护林员的信息
* @param rangerCountyCode
* @return
*/
@GetMapping("/findByRangerCountyCode")
public Result findByRangerCountyCode(@RequestParam("rangerCountyCode") String rangerCountyCode){
return xkRsForestRangerService.findByRangerCountyCode(rangerCountyCode);
}
/**
* 根据区县编码查询该区县所有护林员的信息
* @param countyCode
* @param token
* @return
*/
@PreAuthorize("hasAnyRole('ROLE_city','ROLE_county')")
@GetMapping("/findAllByRangerCountyCode")
public Result findAllByRangerCountyCode(@RequestParam("countyCode") String countyCode, @RequestHeader(value="Authorization") String token){
return xkRsForestRangerService.findAllByRangerCountyCode(countyCode,token);
}
/**
* 根据手机号修改护林员的位置
* @param map
* @return
*/
@PostMapping("/updateLatAndLonByPhone")
public Result updateLatAndLonByPhone(@RequestBody Map map){
String rangerLatitude = (String) map.get("rangerLatitude");
String rangerLongitude = (String) map.get("rangerLongitude");
String rangerPhone = (String) map.get("rangerPhone");
return xkRsForestRangerService.updateLatAndLonByPhone(rangerLatitude,rangerLongitude,rangerPhone);
}
}

View File

@ -0,0 +1,24 @@
package com.xkrs.dao;
import com.xkrs.entity.City;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Component;
import java.util.List;
/**
* @author xkrs
*/
@Component
public interface CityDao extends JpaRepository<City,Long>, JpaSpecificationExecutor<City> {
/**
* 根据省编码查询城市有关信息
* @param proCode
* @return
*/
@Query(value = "select city_name,city_code,city_latitude,city_longitude from city where pro_code = ?",nativeQuery = true)
List<Object[]> selectCityNameAndLatAndLog(String proCode);
}

View File

@ -0,0 +1,54 @@
package com.xkrs.dao;
import com.xkrs.entity.FireAndRanger;
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;
/**
* @author xkrs
*/
@Component
public interface FireAndRangerDao extends JpaRepository<FireAndRanger,Long>, JpaSpecificationExecutor<FireAndRanger> {
/**
* 根据火点编码查询信息
* @param fireCode
* @return
*/
FireAndRanger findByFireCode(String fireCode);
/**
* 根据护林员手机号查询
* @param rangerName
* @return
*/
FireAndRanger findByRangerNameAndProgressType(String rangerName, String progressType);
/**
* 根据火点编码删除火点信息
* @param fireCode
* @return
*/
FireAndRanger deleteByFireCode(String fireCode);
/**
* 根据火点编码修改结束时间
* @param fireCode
* @param endTime
*/
@Modifying(clearAutomatically=true)
@Query(value = "update fire_and_ranger set end_time = ?2 where fire_code = ?1",nativeQuery = true)
void updateEndTimeByFireCode(String fireCode, String endTime);
/**
* 根据火点编码修改进程状态
* @param fireCode
* @param endTime
*/
@Modifying(clearAutomatically=true)
@Query(value = "update fire_and_ranger set progress_type = ?2 where fire_code = ?1",nativeQuery = true)
void updateProgressTypeByFireCode(String fireCode, String endTime);
}

View File

@ -0,0 +1,18 @@
package com.xkrs.dao;
import com.xkrs.entity.FireTask;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @author xkrs
*/
public interface FireTaskDao extends JpaRepository<FireTask,Long>, JpaSpecificationExecutor<FireTask> {
/**
* 根据火点编码查询该条任务
* @param fireCode
* @return
*/
FireTask findByTaskFireCode(String fireCode);
}

View File

@ -0,0 +1,29 @@
package com.xkrs.dao;
import com.xkrs.entity.FireTaskPhoto;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
/**
* @author xkrs
*/
public interface FireTaskPhotoDao extends JpaRepository<FireTaskPhoto,Long>, JpaSpecificationExecutor<FireTaskPhoto> {
/**
* 根据火点编码查询图片
* @param fireCode
* @return
*/
@Query(value = "select task_photo from fire_task_photo where photo_fire_code = :fireCode",nativeQuery = true)
List<Object[]> findPhotoPath(String fireCode);
/**
* 通过火点编码查询图片的信息
* @param fireCode
* @return
*/
List<FireTaskPhoto> findAllByPhotoFireCode(String fireCode);
}

View File

@ -0,0 +1,63 @@
package com.xkrs.dao;
import com.xkrs.model.entity.ForestRanger;
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 java.util.List;
/**
* @author xkrs
*/
public interface XkRsForestRangerDao extends JpaRepository<ForestRanger,Long>, JpaSpecificationExecutor<ForestRanger> {
/**
* 根据市区县编码查询护林员的信息
* @param rangerCountyCode
* @return
*/
ForestRanger findByRangerCountyCode(String rangerCountyCode);
/**
* 根据手机号对护林员的位置进行修改
* @param rangerLatitude
* @param rangerLongitude
* @param rangerPhone
*/
@Modifying(clearAutomatically=true)
@Query(value = "update xk_forest_ranger set ranger_latitude = ?1,ranger_longitude = ?2 where ranger_phone = ?3",nativeQuery = true)
void updateLatAndLonByPhone(String rangerLatitude,String rangerLongitude,String rangerPhone);
/**
* 根据手机号修改护林员的状态值
* @param rangerPhone
* @param rangerType
*/
@Modifying(clearAutomatically=true)
@Query(value = "update xk_forest_ranger set ranger_type = ?2 where ranger_phone = ?1",nativeQuery = true)
void updateRangerTypeByPhone(String rangerPhone,String rangerType);
/**
* 根据手机号查询护林员的信息
* @param rangerPhone
* @return
*/
ForestRanger findByRangerPhone(String rangerPhone);
/**
* 根据区县编码查询该区县护林员的信息
* @param rangerCountyCode
* @return
*/
List<ForestRanger> findAllByRangerCountyCode(String rangerCountyCode);
/**
* 根据区县编码模糊查询护林员的信息
* @param rangerCountyCode
* @return
*/
@Query(value = "select * from xk_forest_ranger where ranger_county_code like CONCAT('%',:rangerCountyCode,'%')",nativeQuery = true)
List<ForestRanger> findAllsByRangerCountyCode(String rangerCountyCode);
}

View File

@ -0,0 +1,33 @@
package com.xkrs.vo;
import java.io.Serializable;
/**
* @author xkrs
*/
public class AppPhotoVo implements Serializable {
private String taskPhoto;
public AppPhotoVo() {
}
public AppPhotoVo(String taskPhoto) {
this.taskPhoto = taskPhoto;
}
public String getTaskPhoto() {
return taskPhoto;
}
public void setTaskPhoto(String taskPhoto) {
this.taskPhoto = taskPhoto;
}
@Override
public String toString() {
return "AppPhotoVo{" +
"taskPhoto='" + taskPhoto + '\'' +
'}';
}
}

View File

@ -0,0 +1,70 @@
package com.xkrs.vo;
import java.io.Serializable;
import java.util.List;
/**
* @author xkrs
*/
public class AppTaskBodyVo implements Serializable {
private String fireCode;
private String taskInformation;
private String taskTime;
private List taskFirePhoto;
public AppTaskBodyVo() {
}
public AppTaskBodyVo(String fireCode, String taskInformation, String taskTime, List taskFirePhoto) {
this.fireCode = fireCode;
this.taskInformation = taskInformation;
this.taskTime = taskTime;
this.taskFirePhoto = taskFirePhoto;
}
public String getFireCode() {
return fireCode;
}
public void setFireCode(String fireCode) {
this.fireCode = fireCode;
}
public String getTaskInformation() {
return taskInformation;
}
public void setTaskInformation(String taskInformation) {
this.taskInformation = taskInformation;
}
public String getTaskTime() {
return taskTime;
}
public void setTaskTime(String taskTime) {
this.taskTime = taskTime;
}
public List getTaskFirePhoto() {
return taskFirePhoto;
}
public void setTaskFirePhoto(List taskFirePhoto) {
this.taskFirePhoto = taskFirePhoto;
}
@Override
public String toString() {
return "AppTaskBodyVo{" +
"fireCode='" + fireCode + '\'' +
", taskInformation='" + taskInformation + '\'' +
", taskTime='" + taskTime + '\'' +
", taskFirePhoto=" + taskFirePhoto +
'}';
}
}

View File

@ -0,0 +1,36 @@
package com.xkrs.service;
import com.xkrs.utils.Result;
import java.io.UnsupportedEncodingException;
/**
* @author xkrs
*/
public interface FireAndRangerService {
/**
* 将火点分配给护林员
* @param token
* @param rangerName
* @param fireCode
* @param handler
* @param verifier
* @return
*/
Result addFireAndRanger(String rangerName, String fireCode, String handler, String verifier, String token) throws UnsupportedEncodingException;
/**
* 护林员查看自己的火点任务
* @param token
* @return
*/
Result selectFireInformation(String token);
/**
* 根据火点编码查询处理的信息
* @param fireCode
* @return
*/
Result findFireAndRangerByFireCode(String fireCode, String token) throws Exception;
}

View File

@ -0,0 +1,31 @@
package com.xkrs.service;
/**
* @author xkrs
*/
public interface XkRsForestRangerService {
/**
* 根据区县编码查询护林员的信息
* @param rangerCountyCode
* @return
*/
String findByRangerCountyCode(String rangerCountyCode);
/**
* 根据区县编码查询该区县所有护林员的信息
* @param countyCode
* @param token
* @return
*/
String findAllByRangerCountyCode(String countyCode, String token);
/**
* 根据手机号修改用户位置
* @param rangerLatitude
* @param rangerLongitude
* @param rangerPhone
* @return
*/
String updateLatAndLonByPhone(String rangerLatitude,String rangerLongitude,String rangerPhone);
}

View File

@ -0,0 +1,171 @@
package com.xkrs.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xkrs.dao.*;
import com.xkrs.entity.*;
import com.xkrs.service.FireAndRangerService;
import com.xkrs.utils.*;
import com.xkrs.vo.AppPhotoVo;
import com.xkrs.vo.AppTaskBodyVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.http.HttpHeaders;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author xkrs
*/
@Service
public class FireAndRangerServiceImpl implements FireAndRangerService {
public static Logger log = LoggerFactory.getLogger(FireAndRangerServiceImpl.class);
@Resource
private FireAndRangerDao fireAndRangerDao;
@Resource
private ForestUserDao forestUserDao;
@Resource
private FirePointDao firePointDao;
@Resource
private XkRsForestRangerDao forestRangerDao;
@Resource
private RestTemplateUtil restTemplateUtil;
@Resource
private FireTaskDao fireTaskDao;
@Resource
private FireTaskPhotoDao fireTaskPhotoDao;
/**
* 将火点分配给护林员
* @param rangerName
* @param fireCode
* @return
*/
@Transactional(rollbackOn = Exception.class)
@Override
public Result addFireAndRanger(String rangerName, String fireCode, String handler, String verifier, String token) throws UnsupportedEncodingException {
String tokenUserName = TokenUtil.getTokenUserName(token);
if(tokenUserName == null || "".equals(tokenUserName)){
return Result.error("您还未注册和登录,请先注册和登录!");
}
FireAndRanger byFireCode = fireAndRangerDao.findByFireCode(fireCode);
if(byFireCode != null){
return Result.error("该火点已经分配,请勿重复操作");
}
XkRsFirePoint byFireCode1 = firePointDao.findByFireCode(fireCode);
// 给app端推送的消息内容
Map<String,Object> map = new HashMap(3);
map.put("latitude",byFireCode1.getLatitude());
map.put("longitude",byFireCode1.getLongitude());
map.put("detailedAddress",byFireCode1.getDetailedAddress());
String content = JSON.toJSONString(map);
String ss = URLEncoder.encode(content,"utf-8");
//String url = "https://api.xmpush.xiaomi.com/v3/message/alias?title=收到消息&description=请"+rangerName+ "去核查该火点信息&payload="+content+"&restricted_package_name=com.xkrs.fieldverification&notify_id=1&extra.notify_effect=2&extra.intent_uri=fieldverify://xkrs.com&alias="+rangerName;
String url = "https://api.xmpush.xiaomi.com/v3/message/alias?title=收到消息&description=请"+verifier+"去核查该火点信息&payload="+ss+"&restricted_package_name=com.xkrs.fieldverification&notify_id=2&extra.notify_effect=2&extra.intent_uri=fieldverify://xkrs.com&alias="+rangerName+"&extra.notify_foreground=0&extra.channel_id=mipush";
String time = LocalDateTimeUtil.localDateTime2String(LocalDateTime.now());
FireAndRanger fireAndRanger = new FireAndRanger();
fireAndRanger.setRangerName(rangerName);
fireAndRanger.setFireCode(fireCode);
fireAndRanger.setHandlerTime(time);
fireAndRanger.setHandler(handler);
fireAndRanger.setVerifier(verifier);
fireAndRanger.setProgressType("1");
// 将火点分配给该护林员后将护林员状态修改为1 表示正在执行火点任务
forestRangerDao.updateRangerTypeByPhone(rangerName,"1");
JSONObject jsonObject = new JSONObject();
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.add("Authorization","key=QW+6vVbWptJHscqD7zuM5w==");
log.info("-----------已向app发送消息");
restTemplateUtil.doPostMessageToApp(url, httpHeaders, jsonObject);
FireAndRanger save = fireAndRangerDao.save(fireAndRanger);
if(save == null){
return Result.error("操作失败");
}
return Result.ok("操作成功");
}
/**
* 护林员查看自己的火点任务
* @param token
* @return
*/
@Override
public Result selectFireInformation(String token) {
String tokenUserName = TokenUtil.getTokenUserName(token);
if(tokenUserName == null || "".equals(tokenUserName)){
return Result.error("您还未注册和登录,请先注册和登录!");
}
XkRsUser xkRsUser = forestUserDao.selectUserName(tokenUserName);
XkRsForestRanger byRangerPhone = forestRangerDao.findByRangerPhone(xkRsUser.getNickName());
if(byRangerPhone.getRangerType().equals("1")){
FireAndRanger byRangerName = fireAndRangerDao.findByRangerNameAndProgressType(xkRsUser.getNickName(),"1");
if(byRangerName == null){
return Result.error("暂时还没有任何任务");
}
XkRsFirePoint byFireCode = firePointDao.findByFireCode(byRangerName.getFireCode());
return Result.ok(byFireCode);
}else {
return Result.error("暂时还没有任务");
}
}
/**
* 根据火点编码查询核查的信息
* @param fireCode
* @return
*/
@Override
public Result findFireAndRangerByFireCode(String fireCode, String token) throws Exception {
String tokenUserName = TokenUtil.getTokenUserName(token);
if(tokenUserName == null || "".equals(tokenUserName)){
return Result.error("您还未注册和登录,请先注册和登录!");
}
FireAndRanger byFireCode = fireAndRangerDao.findByFireCode(fireCode);
if(byFireCode == null){
return Result.error("暂时还没有该火点核查的信息");
}
Map map = new HashMap(3);
map.put("fire",byFireCode);
FireTask byTaskFireCode = fireTaskDao.findByTaskFireCode(fireCode);
if(byTaskFireCode == null){
map.put("task",null);
return Result.ok().data(map);
}else {
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);
map.put("task",appTaskBodyVo);
return Result.ok().data(map);
}
}
}

View File

@ -0,0 +1,83 @@
package com.xkrs.service.impl;
import com.xkrs.common.encapsulation.PromptMessageEnum;
import com.xkrs.common.tool.TokenUtil;
import com.xkrs.dao.XkRsForestRangerDao;
import com.xkrs.model.entity.ForestRanger;
import com.xkrs.service.XkRsForestRangerService;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import java.util.List;
import java.util.Locale;
import static com.xkrs.common.encapsulation.OutputEncapsulation.outputEncapsulationObject;
/**
* @author xkrs
*/
@Service
public class XkRsForestRangerServiceImpl implements XkRsForestRangerService {
@Resource
private XkRsForestRangerDao xkRsForestRangerDao;
/**
* 根据曲线编码查询护林员的信息
* @param rangerCountyCode
* @return
*/
@Override
public String findByRangerCountyCode(String rangerCountyCode) {
// 获取区域信息
Locale locale = LocaleContextHolder.getLocale();
ForestRanger byRangerCountyCode = xkRsForestRangerDao.findByRangerCountyCode(rangerCountyCode);
if(byRangerCountyCode == null){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"该区县暂时还没有相关护林员的信息",locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,byRangerCountyCode,locale);
}
/**
* 根据区县编码查询该区县所有护林员的信息
* @param countyCode
* @return
*/
@Override
public String findAllByRangerCountyCode(String countyCode, String token) {
// 获取区域信息
Locale locale = LocaleContextHolder.getLocale();
String tokenUserName = TokenUtil.getTokenUserName(token);
if("370000".equals(countyCode)){
List<ForestRanger> all = xkRsForestRangerDao.findAll();
if(all == null || all.size() == 0){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时还没该省护林员的信息",locale);
}
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,all,locale);
}else {
List<ForestRanger> allByRangerCountyCode = xkRsForestRangerDao.findAllsByRangerCountyCode(countyCode);
if(allByRangerCountyCode == null || allByRangerCountyCode.size() == 0){
return outputEncapsulationObject(PromptMessageEnum.DATA_NONE,"暂时还没该市护林员的信息",locale);
}
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,allByRangerCountyCode,locale);
}
}
/**
* 根据手机号修改护林员的位置信息
* @param rangerLatitude
* @param rangerLongitude
* @param rangerPhone
* @return
*/
@Transactional(rollbackOn = Exception.class)
@Override
public String updateLatAndLonByPhone(String rangerLatitude, String rangerLongitude, String rangerPhone) {
// 获取区域信息
Locale locale = LocaleContextHolder.getLocale();
xkRsForestRangerDao.updateLatAndLonByPhone(rangerLatitude,rangerLongitude,rangerPhone);
return outputEncapsulationObject(PromptMessageEnum.SUCCESS,"操作成功",locale);
}
}

View File

@ -1,5 +1,7 @@
package com.xkrs.utils;
import com.xkrs.dao.FirePointDao;
import com.xkrs.model.entity.FirePointEntity;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;
@ -18,31 +20,41 @@ import java.util.List;
@Component
public class Query {
/*@Resource
private ProjectOverviewDao projectOverviewDao;*/
@Resource
private FirePointDao firePointDao;
/**
* 动态多条件查询项目信息
* @param
* @return
*/
/*public List<ProjectOverview> selectProjectByDynamic(String projectNumber, String projectName) {
Specification<ProjectOverview> specification = new Specification<ProjectOverview>() {
public List<FirePointEntity> selectFirePoint(String cityCode,String satelliteType,String landType,String startTime,String endTime) {
Specification<FirePointEntity> specification = new Specification<FirePointEntity>() {
@Override
public Predicate toPredicate(Root<ProjectOverview> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
public Predicate toPredicate(Root<FirePointEntity> root, CriteriaQuery<?> criteriaQuery, CriteriaBuilder criteriaBuilder) {
List<Predicate> list = new ArrayList<>();
if (projectNumber != null && !"".equals(projectNumber)) {
list.add(criteriaBuilder.equal(root.get("projectNumber").as(String.class), projectNumber));
if (cityCode != null && !"".equals(cityCode)) {
String substring = cityCode.substring(0, 4);
list.add(criteriaBuilder.like(root.get("countyCode").as(String.class), "%" + substring + "%"));
}
if (projectName != null && !"".equals(projectName)) {
list.add(criteriaBuilder.like(root.get("projectName").as(String.class), "%" + projectName + "%"));
if (satelliteType != null && !"".equals(satelliteType)) {
list.add(criteriaBuilder.equal(root.get("satelliteType").as(String.class), satelliteType));
}
if (landType != null && !"".equals(landType)) {
list.add(criteriaBuilder.equal(root.get("landType").as(String.class), landType));
}
if(startTime != null && !"".equals(startTime)){
list.add(criteriaBuilder.greaterThanOrEqualTo(root.get("addTime").as(String.class), startTime));
}
if(endTime != null && !"".equals(endTime)){
list.add(criteriaBuilder.lessThanOrEqualTo(root.get("addTime").as(String.class), endTime));
}
Predicate[] predicates = new Predicate[list.size()];
return criteriaBuilder.and(list.toArray(predicates));
}
};
return projectOverviewDao.findAll(specification);
}*/
return firePointDao.findAll(specification);
}
}

View File

@ -0,0 +1,94 @@
package com.xkrs.utils;
import com.alibaba.fastjson.JSONObject;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
/**
* @author xkrs
*/
@Service
public class RestTemplateUtil {
@Resource
private RestTemplate restTemplate;
/**
* 以get方式请求第三方http接口 getForEntity
* @param url
* @return
*/
public JSONObject doGetForEntity(String url) {
ResponseEntity<JSONObject> responseEntity = restTemplate.getForEntity(url, JSONObject.class);
return responseEntity.getBody();
}
/**
* 以get方式请求第三方http接口 getForObject
* 返回值返回的是响应体
* @param url
* @return
*/
public JSONObject doGetForObject(String url) {
JSONObject result = restTemplate.getForObject(url, JSONObject.class);
return result;
}
/**
* 以post方式请求第三方http接口 postForEntity
* @param url
* @return
*/
public JSONObject doPostForEntity(String url) {
//可设置请求参数
JSONObject param = new JSONObject();
param.put("userName","admin");
param.put("ipAddress","");
param.put("clientType","WINPC");
ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(url, param, JSONObject.class);
return responseEntity.getBody();
}
/**
* 以post方式请求第三方http接口 postForObject
* @param url
* @return
*/
public JSONObject doPostForObject(String url,JSONObject param) {
JSONObject result = restTemplate.postForObject(url, param, JSONObject.class);
return result;
}
/**
* exchange方法请求第三方http接口
*
*/
public JSONObject doExchange(String url, HttpHeaders httpHeaders, JSONObject param) {
//创建请求对象
HttpEntity<JSONObject> request = new HttpEntity<>(param,httpHeaders);
//执行请求(请求路径请求方式请求体响应体)
ResponseEntity<JSONObject> responseEntity = restTemplate.exchange(url, HttpMethod.POST, request, JSONObject.class);
return responseEntity.getBody();
}
/**
* 发送第三方小米推送请求向app端推送消息
* @param url
* @param httpHeaders
* @param param
*/
public void doPostMessageToApp(String url,HttpHeaders httpHeaders,JSONObject param) {
//创建请求对象
HttpEntity<JSONObject> request = new HttpEntity<>(param,httpHeaders);
//执行请求(请求路径请求方式请求体响应体)
restTemplate.exchange(url, HttpMethod.POST, request, JSONObject.class);
}
}