Commit acc83c44 by zhengxj

finish 技工时效,单量,距离 on 20191019 by zhengxj

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@24357 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent 3e98fa2b
......@@ -67,7 +67,7 @@ public class AMapUtils {
return map;
}
public static double getDistanceMeter(GlobalCoordinates gpsFrom, GlobalCoordinates gpsTo) {
public static Double getDistanceMeter(GlobalCoordinates gpsFrom, GlobalCoordinates gpsTo) {
// 创建GeodeticCalculator,调用计算方法,传入坐标系、经纬度用于计算距离
GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(Ellipsoid.Sphere, gpsFrom, gpsTo);
......
......@@ -805,15 +805,26 @@ public class OrderController extends BaseController {
* @return ResultObject 返回类型
*
*/
@AuthCheck
@RequestMapping(value = "/getMechanicListBySpId", method = { RequestMethod.GET, RequestMethod.POST })
public ResultObject getMechanicList(HttpServletRequest request, @RequestParam(required = true) Integer id,
@RequestParam(required = true) Integer merchantId, Integer district,
@RequestParam(required = true, defaultValue = "d") String orderBy, String keyWord) {
if (null == id) {
return new ResultObject(ResultCodeEnum.FAIL.getCode(), "必传参数订单id为空,请检查!");
}
SysOrder order = orderService.selectByPrimaryKey(id);
if (null == order) {
return new ResultObject(ResultCodeEnum.FAIL.getCode(), "订单不存在,请检查!");
}
Integer merchantId = order.getMerchantId();
if (null == merchantId) {
return new ResultObject(ResultCodeEnum.FAIL.getCode(), "该订单未匹配服务商!!");
}
// orderBy:c按单量排序,d按距离排序,t按时效排序
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(),
orderService.getMechanicList(merchantId, district, keyWord, orderBy));
orderService.getMechanicList(id, keyWord, orderBy));
}
......
......@@ -51,7 +51,7 @@ public class MechanicBusiness implements Serializable {
/**
* 距离幅
*/
private String distance;
private Integer distance;
/**
* 时效
......@@ -103,11 +103,11 @@ public class MechanicBusiness implements Serializable {
this.rise = rise;
}
public String getDistance() {
public Integer getDistance() {
return distance;
}
public void setDistance(String distance) {
public void setDistance(Integer distance) {
this.distance = distance;
}
......
......@@ -2,7 +2,7 @@ package com.glsx.ordercenter.mapper;
import java.util.List;
import org.springframework.data.repository.query.Param;
import org.apache.ibatis.annotations.Param;
import com.glsx.ordercenter.dto.MechanicBusiness;
import com.glsx.ordercenter.pojo.user.SysMechanic;
......@@ -27,7 +27,7 @@ public interface SysMechanicMapper {
SysMechanic selectByUserId(Integer userId);
List<MechanicBusiness> getMechanicList(Integer serviceId, String keyWord);
List<MechanicBusiness> getMechanicList(@Param("serviceId") Integer serviceId, @Param("keyWord") String keyWord);
MechanicBusiness getMechanicOrderCountAndTimeliness(@Param("mechanicId") Integer mechanicId);
}
\ No newline at end of file
......@@ -302,6 +302,6 @@ public interface IOrderService {
Map<String, Integer> countByOrderStatusAndUserType(QueryOrderReq oueryOrderReq);
List<MechanicBusiness> getMechanicList(Integer serviceId, Integer district, String keyWord, String orderBy);
List<MechanicBusiness> getMechanicList(Integer orderId, String keyWord, String orderBy);
}
......@@ -3602,56 +3602,80 @@ public class OrderServiceImpl implements IOrderService {
* 指派、改派技工--查询技工列表
*/
@Override
public List<MechanicBusiness> getMechanicList(Integer serviceId, Integer district, String keyWord, String orderBy) {
public List<MechanicBusiness> getMechanicList(Integer orderId, String keyWord, String orderBy) {
SysOrder order = selectByPrimaryKey(orderId);
int serviceId = order.getMerchantId();
Integer district = order.getDistrict();
List<MechanicBusiness> list = sysMechanicDao.getMechanicList(serviceId, keyWord);
List<MechanicBusiness> newList = new ArrayList<>();
if (list.isEmpty()) {
List result = null;
if (!list.isEmpty()) {
for (MechanicBusiness mechanicBusiness : list) {
MechanicBusiness mb = sysMechanicDao
.getMechanicOrderCountAndTimeliness(mechanicBusiness.getMechanicId());
// 安装时效
mechanicBusiness.setTimeliness(mb.getTimeliness());
if (StringUtils.isEmpty(mb.getTimeliness())) {
mechanicBusiness.setTimeliness("暂无安装时效信息!");
} else {
mechanicBusiness.setTimeliness(mb.getTimeliness());
}
// 单量
mechanicBusiness.setCount(mb.getCount());
if (null == mb.getCount()) {
mechanicBusiness.setCount(0);
} else {
mechanicBusiness.setCount(mb.getCount());
}
if (!StringUtils.isEmpty(mechanicBusiness.getAddress()) && null != district) {
// 订单地址
Map<String, String> orderAddress = AMapUtils
.parseAddress(areaService.getFullAreaByDistrictId(district));
String orderAddress = areaService.getFullAreaByDistrictId(district);
// 技工地址
Map<String, String> mechanicAddress = AMapUtils.parseAddress(mechanicBusiness.getAddress());
if (orderAddress.containsKey("latitude") && mechanicAddress.containsKey("latitude")) {
// 技工坐标
GlobalCoordinates source = new GlobalCoordinates(
Double.parseDouble(mechanicAddress.get("latitude")),
Double.parseDouble(mechanicAddress.get("longitude")));
// 订单坐标
GlobalCoordinates target = new GlobalCoordinates(
Double.parseDouble(orderAddress.get("latitude")),
Double.parseDouble(orderAddress.get("longitude")));
// 距离
mechanicBusiness.setDistance(AMapUtils.getDistanceMeter(source, target) + "米");
String mechanicAddress = mechanicBusiness.getAddress();
if (!StringUtils.isEmpty(orderAddress) && !StringUtils.isEmpty(mechanicAddress)) {
Map<String, String> mechanicAddressMp = AMapUtils.parseAddress(mechanicAddress);
Map<String, String> orderAddressMap = AMapUtils.parseAddress(orderAddress);
if (orderAddressMap.containsKey("latitude") && mechanicAddressMp.containsKey("latitude")) {
// 技工坐标
GlobalCoordinates source = new GlobalCoordinates(
Double.parseDouble(orderAddressMap.get("latitude")),
Double.parseDouble(orderAddressMap.get("longitude")));
// 订单坐标
GlobalCoordinates target = new GlobalCoordinates(
Double.parseDouble(mechanicAddressMp.get("latitude")),
Double.parseDouble(mechanicAddressMp.get("longitude")));
// 距离
mechanicBusiness.setDistance(AMapUtils.getDistanceMeter(source, target).intValue());
}
}
}
// orderBy:c按单量排序降序,d按距离升序排序(默认),t按时效升序排序
switch (orderBy) {
case "c":
newList = list.stream().sorted(Comparator.comparing(MechanicBusiness::getCount).reversed())
result = list.stream()
.sorted(Comparator
.comparing(MechanicBusiness::getCount, Comparator.nullsFirst(Integer::compareTo))
.reversed())
.collect(Collectors.toList());
break;
case "t":
newList = list.stream().sorted(Comparator.comparing(MechanicBusiness::getTimeliness))
result = list.stream().sorted(Comparator.comparing(MechanicBusiness::getTimeliness,
Comparator.nullsFirst(String::compareTo)))
.collect(Collectors.toList());
break;
default:
newList = list.stream().sorted(Comparator.comparing(MechanicBusiness::getDistance))
result = list.stream().sorted(Comparator.comparing(MechanicBusiness::getDistance,
Comparator.nullsFirst(Integer::compareTo)))
.collect(Collectors.toList());
break;
}
}
}
return newList;
return result;
}
}
......@@ -232,7 +232,7 @@
) d
<where>
<if test="keyWord != null and keyWord != ''">
and (d.name like #{keyWord} or d.phoneNumber like #{keyWord} or address
and (d.name like #{keyWord} or d.phone like #{keyWord} or address
like #{keyWord})
</if>
</where>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!