|
@@ -1,18 +1,24 @@
|
|
|
package com.yh.saas.plugin.yiliangyiyun.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
|
|
import com.baomidou.mybatisplus.plugins.Page;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yh.saas.common.support.util.IdGenerator;
|
|
|
+import com.yh.saas.common.support.util.StringUtils;
|
|
|
import com.yh.saas.plugin.yiliangyiyun.entity.HyReleaseGoodsInfo;
|
|
|
import com.yh.saas.plugin.yiliangyiyun.entity.PublishTaskInfo;
|
|
|
import com.yh.saas.plugin.yiliangyiyun.mapper.HyReleaseGoodsInfoMapper;
|
|
|
import com.yh.saas.plugin.yiliangyiyun.service.IHyReleaseGoodsInfoService;
|
|
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
|
|
+import com.yh.saas.plugin.yiliangyiyun.util.EntCoordUtil;
|
|
|
+import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
+import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* <p>
|
|
@@ -22,12 +28,19 @@ import java.util.Map;
|
|
|
* @author Gdc
|
|
|
* @since 2023-06-02
|
|
|
*/
|
|
|
+@EnableScheduling
|
|
|
@Service
|
|
|
public class HyReleaseGoodsInfoServiceImpl extends ServiceImpl<HyReleaseGoodsInfoMapper, HyReleaseGoodsInfo> implements IHyReleaseGoodsInfoService {
|
|
|
|
|
|
+ /**
|
|
|
+ * 地球半径,单位 km
|
|
|
+ */
|
|
|
+ private static final double EARTH_RADIUS = 6378.137;
|
|
|
+
|
|
|
@Override
|
|
|
public Page<HyReleaseGoodsInfo> selectTask(HyReleaseGoodsInfo hyReleaseGoodsInfo) {
|
|
|
Map<String, Object> pageView = new HashMap<>();
|
|
|
+ Page<HyReleaseGoodsInfo> page = new Page<>();
|
|
|
pageView.put("startRecord", (hyReleaseGoodsInfo.getCurrentPage() - 1)
|
|
|
* hyReleaseGoodsInfo.getPageSize());
|
|
|
//用户id
|
|
@@ -36,12 +49,136 @@ public class HyReleaseGoodsInfoServiceImpl extends ServiceImpl<HyReleaseGoodsInf
|
|
|
pageView.put("searchKeyWord", hyReleaseGoodsInfo.getSearchKeyWord());
|
|
|
pageView.put("pageSize", hyReleaseGoodsInfo.getPageSize());
|
|
|
pageView.put("currentPage", hyReleaseGoodsInfo.getCurrentPage());
|
|
|
- // 查询总数
|
|
|
- Integer dataCount = baseMapper.getCountByCondition(pageView);
|
|
|
+ pageView.put("loadingPlaceCity", hyReleaseGoodsInfo.getLoadingPlaceCity());
|
|
|
+ pageView.put("unLoadingPlaceCity", hyReleaseGoodsInfo.getUnLoadingPlaceCity());
|
|
|
+ if(hyReleaseGoodsInfo.getLoadingPlace() != null && !hyReleaseGoodsInfo.getLoadingPlace().isEmpty()){
|
|
|
+ String result = "";
|
|
|
+ String[] array = hyReleaseGoodsInfo.getLoadingPlace().split(",");
|
|
|
+ for (String tmp:array) {
|
|
|
+ result += "'"+tmp+"',";
|
|
|
+ }
|
|
|
+ if(result.length() > 0){
|
|
|
+ result = result.substring(0,result.length()-1);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ result = "'"+hyReleaseGoodsInfo.getLoadingPlace()+"'";
|
|
|
+ }
|
|
|
+ pageView.put("loadingPlace", result);
|
|
|
+ }
|
|
|
+ if(hyReleaseGoodsInfo.getUnLoadingPlace() != null && !hyReleaseGoodsInfo.getUnLoadingPlace().isEmpty()){
|
|
|
+ String result = "";
|
|
|
+ String[] array = hyReleaseGoodsInfo.getUnLoadingPlace().split(",");
|
|
|
+ for (String tmp:array) {
|
|
|
+ result += "'"+tmp+"',";
|
|
|
+ }
|
|
|
+ if(result.length() > 0){
|
|
|
+ result = result.substring(0,result.length()-1);
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ result = "'"+hyReleaseGoodsInfo.getUnLoadingPlace()+"'";
|
|
|
+ }
|
|
|
+ pageView.put("unLoadingPlace", result);
|
|
|
+ }
|
|
|
+ //货源列表
|
|
|
+ List<HyReleaseGoodsInfo> hyReleaseGoodsInfoList = new ArrayList<>();
|
|
|
+ //按时间排序货源列表
|
|
|
List<HyReleaseGoodsInfo> dataList = baseMapper.getListByCondition(pageView);
|
|
|
- Page<HyReleaseGoodsInfo> page = new Page<>();
|
|
|
- page.setRecords(dataList == null ? Lists.newArrayList() : dataList);
|
|
|
- page.setTotal(dataCount == null ? 0 : dataCount);
|
|
|
+ if (!CollectionUtils.isEmpty(dataList)) {
|
|
|
+ //查询发货地经纬度
|
|
|
+ for (int i = 0; i < dataList.size(); i++) {
|
|
|
+ HyReleaseGoodsInfo hyReleaseGoodsInfo1 = dataList.get(i);
|
|
|
+ //发货地经纬度
|
|
|
+ double lat2 = Math.toRadians(Double.valueOf(hyReleaseGoodsInfo1.getSendLatitude()));
|
|
|
+ double lng2 = Math.toRadians(Double.valueOf(hyReleaseGoodsInfo1.getSendLongitude()));
|
|
|
+ //根据司机经纬度求货距
|
|
|
+ if (!StringUtils.isEmpty(hyReleaseGoodsInfo.getDriverLatitude()) && !StringUtils.isEmpty(hyReleaseGoodsInfo.getDriverLongitude())) {
|
|
|
+ double lat1 = Math.toRadians(Double.valueOf(hyReleaseGoodsInfo.getDriverLatitude()));
|
|
|
+ double lng1 = Math.toRadians(Double.valueOf(hyReleaseGoodsInfo.getDriverLongitude()));
|
|
|
+ // 纬度之差
|
|
|
+ double a = lat1 - lat2;
|
|
|
+ // 经度之差
|
|
|
+ double b = lng1 - lng2;
|
|
|
+ // 计算两点距离的公式
|
|
|
+ double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
|
|
|
+ Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(b / 2), 2)));
|
|
|
+
|
|
|
+ // 弧长乘地球半径, 返回单位: 千米
|
|
|
+ s = s * EARTH_RADIUS;
|
|
|
+ hyReleaseGoodsInfo1.setCargoDistance(Math.floor(s));
|
|
|
+ }
|
|
|
+ //根据装货城市求货距
|
|
|
+ else if (!StringUtils.isEmpty(hyReleaseGoodsInfo.getLoadingPlaceCity())) {
|
|
|
+ //根据装货城市获取经纬度
|
|
|
+ String str = EntCoordUtil.getCoordinate(hyReleaseGoodsInfo.getLoadingPlaceCity());
|
|
|
+ String str1 = str.substring(0, str.indexOf(","));//经度
|
|
|
+ String str2 = str.substring(str1.length() + 1, str.length());//纬度
|
|
|
+
|
|
|
+ //装货地经纬度
|
|
|
+ double lng1 = Math.toRadians(Double.valueOf(str1));
|
|
|
+ double lat1 = Math.toRadians(Double.valueOf(str2));
|
|
|
+ // 纬度之差
|
|
|
+ double a = lat1 - lat2;
|
|
|
+ // 经度之差
|
|
|
+ double b = lng1 - lng2;
|
|
|
+ // 计算两点距离的公式
|
|
|
+ double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
|
|
|
+ Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(b / 2), 2)));
|
|
|
+ // 弧长乘地球半径, 返回单位: 千米
|
|
|
+ s = s * EARTH_RADIUS;
|
|
|
+ hyReleaseGoodsInfo1.setCargoDistance(Math.floor(s));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ hyReleaseGoodsInfoList.addAll(dataList);
|
|
|
+ //司机标识
|
|
|
+ if (hyReleaseGoodsInfo.getDriverFlag()!=null) {
|
|
|
+ if (hyReleaseGoodsInfo.getLoadingPlace() == null && hyReleaseGoodsInfo.getLoadingPlaceCity() == null) {
|
|
|
+ page.setRecords(Lists.newArrayList());
|
|
|
+ page.setTotal(0);
|
|
|
+ page.setCurrent(hyReleaseGoodsInfo.getCurrentPage());
|
|
|
+ page.setSize(hyReleaseGoodsInfo.getPageSize());
|
|
|
+ return page;
|
|
|
+ }
|
|
|
+ //周边信息列表
|
|
|
+ List<HyReleaseGoodsInfo> dataList1 = baseMapper.getAllListsByCondition(pageView);
|
|
|
+ dataList1.removeAll(dataList);
|
|
|
+ if (!CollectionUtils.isEmpty(dataList1)) {
|
|
|
+ if (!StringUtils.isEmpty(hyReleaseGoodsInfo.getLoadingPlaceCity())) {
|
|
|
+ //查询发货地经纬度
|
|
|
+ for (int i = 0; i < dataList1.size(); i++) {
|
|
|
+ HyReleaseGoodsInfo hyReleaseGoodsInfo1 = dataList1.get(i);
|
|
|
+ //发货地经纬度
|
|
|
+ double lng2 = Math.toRadians(Double.valueOf(hyReleaseGoodsInfo1.getSendLongitude()));
|
|
|
+ double lat2 = Math.toRadians(Double.valueOf(hyReleaseGoodsInfo1.getSendLatitude()));
|
|
|
+ //根据装货城市获取经纬度
|
|
|
+ String str = EntCoordUtil.getCoordinate(hyReleaseGoodsInfo.getLoadingPlaceCity());
|
|
|
+ String str1 = str.substring(0, str.indexOf(","));//经度
|
|
|
+ String str2 = str.substring(str1.length() + 1, str.length());//纬度
|
|
|
+
|
|
|
+ //装货地经纬度
|
|
|
+ double lng1 = Math.toRadians(Double.valueOf(str1));
|
|
|
+ double lat1 = Math.toRadians(Double.valueOf(str2));
|
|
|
+ // 纬度之差
|
|
|
+ double a = lat1 - lat2;
|
|
|
+ // 经度之差
|
|
|
+ double b = lng1 - lng2;
|
|
|
+ // 计算两点距离的公式
|
|
|
+ double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
|
|
|
+ Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(b / 2), 2)));
|
|
|
+ // 弧长乘地球半径, 返回单位: 千米
|
|
|
+ s = s * EARTH_RADIUS;
|
|
|
+ if (s <= 300) {
|
|
|
+ //货距小于300公里,放入周边信息列表
|
|
|
+ hyReleaseGoodsInfo1.setCargoDistance(Math.floor(s));
|
|
|
+ hyReleaseGoodsInfo1.setPeripheralInfo("1");
|
|
|
+ hyReleaseGoodsInfoList.add(hyReleaseGoodsInfo1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ page.setRecords(hyReleaseGoodsInfoList == null ? Lists.newArrayList() : hyReleaseGoodsInfoList);
|
|
|
+ page.setTotal(hyReleaseGoodsInfoList.size() == 0 ? 0 : hyReleaseGoodsInfoList.size());
|
|
|
page.setCurrent(hyReleaseGoodsInfo.getCurrentPage());
|
|
|
page.setSize(hyReleaseGoodsInfo.getPageSize());
|
|
|
return page;
|
|
@@ -86,4 +223,31 @@ public class HyReleaseGoodsInfoServiceImpl extends ServiceImpl<HyReleaseGoodsInf
|
|
|
this.updateById(hyReleaseGoodsInfo);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 48小时自动下架
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Scheduled(cron = "0 0 */1 * * ?")
|
|
|
+ public String autoDown(){
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ //设置小时
|
|
|
+ calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY) - 48);
|
|
|
+ //格式化时间
|
|
|
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ //48小时之前
|
|
|
+ String time=df.format(calendar.getTime());
|
|
|
+ List<HyReleaseGoodsInfo> hyReleaseGoodsInfoList=this.selectList(new EntityWrapper<HyReleaseGoodsInfo>()
|
|
|
+ .eq("status","已上架")
|
|
|
+ .le("update_date",time));
|
|
|
+ if (!CollectionUtils.isEmpty(hyReleaseGoodsInfoList)){
|
|
|
+ for (HyReleaseGoodsInfo hyReleaseGoodsInfo:hyReleaseGoodsInfoList){
|
|
|
+ hyReleaseGoodsInfo.setStatus("已下架");
|
|
|
+ this.updateById(hyReleaseGoodsInfo);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "OK";
|
|
|
+
|
|
|
+ }
|
|
|
}
|