lidongdong
2022-12-06 2a212f983f35e1c569dfec3a172fb5f0c9f85fac
springcloud_k8s_panzhihuazhihuishequ/service_community/src/main/java/com/panzhihua/service_community/service/impl/ConvenientElevatingPointServiceImpl.java
@@ -22,9 +22,7 @@
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.*;
import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;
@@ -67,6 +65,10 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R addPoint(ConvenientElevatingPointDTO convenientElevatingPointDTO) {
        ConvenientElevatingPointDO convenientElevatingPointDODB = this.baseMapper.selectOne(new LambdaQueryWrapper<ConvenientElevatingPointDO>().eq(ConvenientElevatingPointDO::getWechatAccount, convenientElevatingPointDTO.getWechatAccount()));
        if (!Objects.isNull(convenientElevatingPointDODB)){
            return  R.fail("该微信手机号已使用,请更换");
        }
        ConvenientElevatingPointDO convenientElevatingPointDO = new ConvenientElevatingPointDO();
        BeanUtils.copyProperties(convenientElevatingPointDTO, convenientElevatingPointDO);
        String communityId = convenientElevatingPointDTO.getCommunityId();
@@ -89,10 +91,15 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R putPoint(ConvenientElevatingPointDTO convenientElevatingPointDTO) {
        ConvenientElevatingPointDO convenientElevatingPointDODB = this.baseMapper.selectOne(new LambdaQueryWrapper<ConvenientElevatingPointDO>().eq(ConvenientElevatingPointDO::getWechatAccount, convenientElevatingPointDTO.getWechatAccount()));
        Long id = convenientElevatingPointDTO.getId();
        ConvenientElevatingPointDO convenientElevatingPointDO = this.baseMapper.selectById(id);
        if (isNull(convenientElevatingPointDO)) {
            return R.fail("自提点不存在");
        }
        if (nonNull(convenientElevatingPointDODB) && !convenientElevatingPointDODB.getId().equals(convenientElevatingPointDO.getId())) {
            R.fail("该微信手机号:" + convenientElevatingPointDTO.getWechatAccount() + "已被使用!请更换");
        }
        String communityId = convenientElevatingPointDTO.getCommunityId();
        if (nonNull(communityId)) {
@@ -123,7 +130,9 @@
    @Override
    public R detailPoint(Long pointId) {
        ConvenientElevatingPointDO convenientElevatingPointDO = this.baseMapper.selectById(pointId);
        return R.ok(convenientElevatingPointDO);
        ConvenientElevatingPointVO convenientElevatingPointVO = new ConvenientElevatingPointVO();
        BeanUtils.copyProperties(convenientElevatingPointDO,convenientElevatingPointVO);
        return R.ok(convenientElevatingPointVO);
    }
    public R findPointByMerchantId(Long merchantId, String lat, String lng) {
@@ -138,19 +147,47 @@
        String maxLng = around.get("maxLng").toString();
        List<ConvenientElevatingPointDO> convenientElevatingPointDOS = this.baseMapper.selectList(
                new LambdaQueryWrapper<ConvenientElevatingPointDO>()
                        .ge(ConvenientElevatingPointDO::getLat, minLng)
                        .le(ConvenientElevatingPointDO::getLat, maxLng)
                        .ge(ConvenientElevatingPointDO::getLon, minLat)
                        .le(ConvenientElevatingPointDO::getLon, maxLat));
                        .ge(ConvenientElevatingPointDO::getLat, Double.parseDouble(minLng))
                        .le(ConvenientElevatingPointDO::getLat, Double.parseDouble(maxLng))
                        .ge(ConvenientElevatingPointDO::getLon, Double.parseDouble(minLat))
                        .le(ConvenientElevatingPointDO::getLon, Double.parseDouble(maxLat))
                        .eq(ConvenientElevatingPointDO::getBusinessStatus,1));
        List<ConvenientElevatingPointVO> convenientElevatingPointVOS = new ArrayList<>();
        convenientElevatingPointDOS.forEach(f -> {
            ConvenientElevatingPointVO convenientElevatingPointVO = new ConvenientElevatingPointVO();
            BeanUtils.copyProperties(f, convenientElevatingPointVO);
            Double distance = MapDistance.distanceOfTwoPoints(lng, lat, f.getLon(), f.getLat());
            Double distance = MapDistance.distanceOfTwoPoints(lat, lng, f.getLon(), f.getLat());
            convenientElevatingPointVO.setDistance(distance);
            convenientElevatingPointVOS.add(convenientElevatingPointVO);
        });
        Collections.sort(convenientElevatingPointVOS);
        return R.ok(convenientElevatingPointVOS);
    }
    @Override
    public R findPointNumByDistance(Integer distance, String lat, String lng) {
        Map<Object, Object> around = MapDistance.getAround(lat, lng, distance * 1000d);
        String maxLat = around.get("maxLat").toString();
        String minLat = around.get("minLat").toString();
        String minLng = around.get("minLng").toString();
        String maxLng = around.get("maxLng").toString();
        List<ConvenientElevatingPointDO> convenientElevatingPointDOS = this.baseMapper.selectList(
                new LambdaQueryWrapper<ConvenientElevatingPointDO>()
                        .ge(ConvenientElevatingPointDO::getLat, Double.parseDouble(minLng))
                        .le(ConvenientElevatingPointDO::getLat, Double.parseDouble(maxLng))
                        .ge(ConvenientElevatingPointDO::getLon, Double.parseDouble(minLat))
                        .le(ConvenientElevatingPointDO::getLon, Double.parseDouble(maxLat))
                        .eq(ConvenientElevatingPointDO::getBusinessStatus,1));
        List<ConvenientElevatingPointVO> convenientElevatingPointVOS = new ArrayList<>();
        convenientElevatingPointDOS.forEach(f -> {
            ConvenientElevatingPointVO convenientElevatingPointVO = new ConvenientElevatingPointVO();
            BeanUtils.copyProperties(f, convenientElevatingPointVO);
            Double distancem = MapDistance.distanceOfTwoPoints(lat, lng, f.getLon(), f.getLat());
            convenientElevatingPointVO.setDistance(distancem);
            convenientElevatingPointVOS.add(convenientElevatingPointVO);
        });
        Collections.sort(convenientElevatingPointVOS);
        return R.ok(convenientElevatingPointVOS.size());
    }
}