提交
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
package com.mosty.yjzl.controller;
|
package com.mosty.yjzl.controller;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.mosty.base.model.dto.yjzl.TbZdxlFgdwSaveDTO;
|
||||||
import com.mosty.base.model.dto.yjzl.TbZdxlFgdwUpdateDTO;
|
import com.mosty.base.model.dto.yjzl.TbZdxlFgdwUpdateDTO;
|
||||||
import com.mosty.base.model.query.yjzl.TbZdxlFgdwQuery;
|
import com.mosty.base.model.query.yjzl.TbZdxlFgdwQuery;
|
||||||
import com.mosty.base.model.vo.yjzl.TbZdxlFgdwVO;
|
import com.mosty.base.model.vo.yjzl.TbZdxlFgdwVO;
|
||||||
@ -20,7 +21,9 @@ import org.springframework.validation.BindingResult;
|
|||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zhangzhao
|
* @author zhangzhao
|
||||||
@ -91,6 +94,36 @@ public class TbZdxlFgdwController {
|
|||||||
return ResponseResult.success(tbZdxlFgdwService.selectList(query));
|
return ResponseResult.success(tbZdxlFgdwService.selectList(query));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增单条
|
||||||
|
* @param dto 保存DTO对象
|
||||||
|
* @param bindResult 校验对象
|
||||||
|
* @return ResponseResult 实体主键ID
|
||||||
|
*/
|
||||||
|
@ApiOperation(value = "新增单条")
|
||||||
|
@PostMapping("/save")
|
||||||
|
@JwtSysUser
|
||||||
|
@Log(title = "指导巡逻-方格点位接口-新增单条", businessType = BusinessType.INSERT)
|
||||||
|
public ResponseResult<Long> save(@RequestBody @Valid TbZdxlFgdwSaveDTO dto, BindingResult bindResult){
|
||||||
|
try {
|
||||||
|
//基础信息校验
|
||||||
|
String message = SpringValidUtils.getErrorsMsg(bindResult);
|
||||||
|
if (StringUtils.isNotBlank(message)) {
|
||||||
|
return ResponseResult.fail(MessageUtils.getSaveFailMsg() + message);
|
||||||
|
}
|
||||||
|
|
||||||
|
//新增
|
||||||
|
Long resultId = tbZdxlFgdwService.saveEntity(dto);
|
||||||
|
if(ObjectUtils.isNotEmpty(resultId)){
|
||||||
|
return ResponseResult.success(resultId);
|
||||||
|
}
|
||||||
|
return ResponseResult.fail(MessageUtils.getSaveFailMsg());
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return ResponseResult.fail(MessageUtils.getSaveServerErrorMsg());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改单条
|
* 修改单条
|
||||||
* @param dto 修改DTO对象
|
* @param dto 修改DTO对象
|
||||||
@ -121,4 +154,22 @@ public class TbZdxlFgdwController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据经纬度获取正方形四个点位
|
||||||
|
* @param longitude 经度
|
||||||
|
* @param latitude 纬度
|
||||||
|
* @param distance 范围(米),半径
|
||||||
|
* @return ResponseResult 正方形四个角点坐标
|
||||||
|
*/
|
||||||
|
@ApiOperation(value = "根据经纬度获取正方形四个点位")
|
||||||
|
@GetMapping("/getSquarePoints")
|
||||||
|
@JwtSysUser
|
||||||
|
@Log(title = "指导巡逻-方格点位接口-获取正方形点位", businessType = BusinessType.OTHER)
|
||||||
|
public ResponseResult<Map<String, BigDecimal>> getSquarePoints(
|
||||||
|
@RequestParam("longitude") Double longitude,
|
||||||
|
@RequestParam("latitude") Double latitude,
|
||||||
|
@RequestParam(value = "distance", defaultValue = "500") Double distance) {
|
||||||
|
return ResponseResult.success(tbZdxlFgdwService.getSquarePoints(longitude, latitude, distance));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,13 +5,16 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.mosty.base.model.dto.yjzl.TbZdxlFgdwSaveDTO;
|
||||||
import com.mosty.base.model.dto.yjzl.TbZdxlFgdwUpdateDTO;
|
import com.mosty.base.model.dto.yjzl.TbZdxlFgdwUpdateDTO;
|
||||||
import com.mosty.base.model.entity.yjzl.zddw.TbZdxlFgdw;
|
import com.mosty.base.model.entity.yjzl.zddw.TbZdxlFgdw;
|
||||||
import com.mosty.base.model.query.yjzl.TbZdxlFgdwQuery;
|
import com.mosty.base.model.query.yjzl.TbZdxlFgdwQuery;
|
||||||
|
import com.mosty.base.model.vo.base.DeptInfoVo;
|
||||||
import com.mosty.base.model.vo.yjzl.TbZdxlFgdwVO;
|
import com.mosty.base.model.vo.yjzl.TbZdxlFgdwVO;
|
||||||
import com.mosty.base.utils.PageUtils;
|
import com.mosty.base.utils.PageUtils;
|
||||||
import com.mosty.base.utils.QueryWrapperUtils;
|
import com.mosty.base.utils.QueryWrapperUtils;
|
||||||
import com.mosty.yjzl.mapper.TbZdxlFgdwMapper;
|
import com.mosty.yjzl.mapper.TbZdxlFgdwMapper;
|
||||||
|
import com.mosty.yjzl.remote.TbBaseAdaptRemoteService;
|
||||||
import com.mosty.yjzl.service.TbZdxlFgdwService;
|
import com.mosty.yjzl.service.TbZdxlFgdwService;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
@ -20,8 +23,12 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zhangzhao
|
* @author zhangzhao
|
||||||
@ -34,6 +41,7 @@ import java.util.List;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class TbZdxlFgdwServiceImpl extends ServiceImpl<TbZdxlFgdwMapper, TbZdxlFgdw> implements TbZdxlFgdwService {
|
public class TbZdxlFgdwServiceImpl extends ServiceImpl<TbZdxlFgdwMapper, TbZdxlFgdw> implements TbZdxlFgdwService {
|
||||||
|
|
||||||
|
private final TbBaseAdaptRemoteService tbBaseAdaptRemoteService;
|
||||||
@Override
|
@Override
|
||||||
public TbZdxlFgdwVO selectById(Long id) {
|
public TbZdxlFgdwVO selectById(Long id) {
|
||||||
if(ObjectUtils.isEmpty(id)){
|
if(ObjectUtils.isEmpty(id)){
|
||||||
@ -125,6 +133,35 @@ public class TbZdxlFgdwServiceImpl extends ServiceImpl<TbZdxlFgdwMapper, TbZdxlF
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public Long saveEntity(TbZdxlFgdwSaveDTO dto) {
|
||||||
|
//复制参数至实体
|
||||||
|
TbZdxlFgdw entity = BeanUtil.copyProperties(dto, TbZdxlFgdw.class);
|
||||||
|
entity.setMc1(dto.getMc());
|
||||||
|
entity.setX11(dto.getX1());
|
||||||
|
entity.setY11(dto.getY1());
|
||||||
|
entity.setX21(dto.getX2());
|
||||||
|
entity.setY21(dto.getY2());
|
||||||
|
|
||||||
|
DeptInfoVo dept = this.tbBaseAdaptRemoteService.getOrgByOrgcode(dto.getSsbmdm());
|
||||||
|
if(Objects.nonNull(dept)){
|
||||||
|
entity.setSsbm(dept.getDeptname());
|
||||||
|
entity.setSsbmdm(dept.getDeptcode());
|
||||||
|
entity.setSsxgajdm(dept.getFxjcode());
|
||||||
|
entity.setSsxgaj(dept.getFxjname());
|
||||||
|
entity.setSssgaj(dept.getDszname());
|
||||||
|
entity.setSssgajdm(dept.getDszcode());
|
||||||
|
}
|
||||||
|
//新增实体
|
||||||
|
int resultInt = this.baseMapper.insert(entity);
|
||||||
|
if(resultInt > 0){
|
||||||
|
//返回主键
|
||||||
|
return entity.getId();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 组装查询参数
|
* 组装查询参数
|
||||||
* @param qw QueryWrapper
|
* @param qw QueryWrapper
|
||||||
@ -184,4 +221,32 @@ public class TbZdxlFgdwServiceImpl extends ServiceImpl<TbZdxlFgdwMapper, TbZdxlF
|
|||||||
return resultVO;
|
return resultVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, BigDecimal> getSquarePoints(double longitude, double latitude, double distance) {
|
||||||
|
Map<String, BigDecimal> squareMap = new HashMap<>();
|
||||||
|
// 计算经度弧度,从弧度转换为角度
|
||||||
|
double dLongitude = 2 * (Math.asin(Math.sin(distance / (2 * 6378137)) / Math.cos(Math.toRadians(latitude))));
|
||||||
|
dLongitude = Math.toDegrees(dLongitude);
|
||||||
|
// 计算纬度角度
|
||||||
|
double dLatitude = distance / 6378137;
|
||||||
|
dLatitude = Math.toDegrees(dLatitude);
|
||||||
|
// 正方形四个角点
|
||||||
|
// 左上角
|
||||||
|
double[] leftTopPoint = {latitude + dLatitude, longitude - dLongitude};
|
||||||
|
|
||||||
|
// 右下角
|
||||||
|
double[] rightBottomPoint = {latitude - dLatitude, longitude + dLongitude};
|
||||||
|
|
||||||
|
BigDecimal x1 = BigDecimal.valueOf(leftTopPoint[1]);
|
||||||
|
BigDecimal y1 = BigDecimal.valueOf(leftTopPoint[0]);
|
||||||
|
BigDecimal x2 = BigDecimal.valueOf(rightBottomPoint[1]);
|
||||||
|
BigDecimal y2 = BigDecimal.valueOf(rightBottomPoint[0]);
|
||||||
|
|
||||||
|
squareMap.put("x1", x1);
|
||||||
|
squareMap.put("y1", y1);
|
||||||
|
squareMap.put("x2", x2);
|
||||||
|
squareMap.put("y2", y2);
|
||||||
|
return squareMap;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,14 @@
|
|||||||
package com.mosty.yjzl.service;
|
package com.mosty.yjzl.service;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.mosty.base.model.dto.yjzl.TbZdxlFgdwSaveDTO;
|
||||||
import com.mosty.base.model.dto.yjzl.TbZdxlFgdwUpdateDTO;
|
import com.mosty.base.model.dto.yjzl.TbZdxlFgdwUpdateDTO;
|
||||||
import com.mosty.base.model.query.yjzl.TbZdxlFgdwQuery;
|
import com.mosty.base.model.query.yjzl.TbZdxlFgdwQuery;
|
||||||
import com.mosty.base.model.vo.yjzl.TbZdxlFgdwVO;
|
import com.mosty.base.model.vo.yjzl.TbZdxlFgdwVO;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author zhangzhao
|
* @author zhangzhao
|
||||||
@ -57,4 +60,20 @@ public interface TbZdxlFgdwService {
|
|||||||
*/
|
*/
|
||||||
Long updateEntity(TbZdxlFgdwUpdateDTO dto);
|
Long updateEntity(TbZdxlFgdwUpdateDTO dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增单条
|
||||||
|
* @param dto 保存DTO对象
|
||||||
|
* @return 实体主键ID
|
||||||
|
*/
|
||||||
|
Long saveEntity(TbZdxlFgdwSaveDTO dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据经纬度获取正方形四个点位
|
||||||
|
* @param longitude 经度
|
||||||
|
* @param latitude 纬度
|
||||||
|
* @param distance 范围(米),半径
|
||||||
|
* @return 正方形四个角点坐标
|
||||||
|
*/
|
||||||
|
Map<String, BigDecimal> getSquarePoints(double longitude, double latitude, double distance);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user