司机与组织修改
parent
c0cd34679f
commit
cafbb22ceb
|
|
@ -0,0 +1,91 @@
|
|||
package com.njzscloud.dispose.cst.customer.pojo.result;
|
||||
|
||||
import com.njzscloud.dispose.cst.customer.constant.IdentityCategory;
|
||||
import com.njzscloud.dispose.cst.customer.constant.SettlementWay;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 客户信息
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public class CustomerResult {
|
||||
|
||||
/**
|
||||
* Id
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户 Id;一个用户可以有多个身份
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 身份类型;多个身份多条数据,PingTai-->平台、ChanFei-->产废方、QingYun-->清运方、XiaoNa-->消纳方、CaiGou-->采购方
|
||||
*/
|
||||
private IdentityCategory identityCategory;
|
||||
|
||||
/**
|
||||
* 组织信息 Id;cst_org.id
|
||||
*/
|
||||
private Long orgId;
|
||||
|
||||
/**
|
||||
* 客户姓名
|
||||
*/
|
||||
private String customerName;
|
||||
|
||||
/**
|
||||
* 客户联系电话
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 结算方式,YueJie-->月结、YuE-->余额、XianFu-->现付
|
||||
*/
|
||||
private SettlementWay settlementWay;
|
||||
|
||||
/**
|
||||
* 是否管理员;是否为当前的组织管理员,0-->否、1-->是
|
||||
*/
|
||||
private Boolean manager;
|
||||
|
||||
/**
|
||||
* 创建人 Id;sys_user.id
|
||||
*/
|
||||
private Long creatorId;
|
||||
|
||||
/**
|
||||
* 修改人 Id;sys_user.id
|
||||
*/
|
||||
private Long modifierId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
private LocalDateTime modifyTime;
|
||||
|
||||
/**
|
||||
* 是否删除;0-->未删除、1-->已删除
|
||||
*/
|
||||
private Boolean deleted;
|
||||
|
||||
}
|
||||
|
|
@ -62,6 +62,14 @@ public class DriverController {
|
|||
return R.success(driverService.detail(id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过userId获取司机详情
|
||||
*/
|
||||
@GetMapping("/detailByUserId")
|
||||
public R<DriverResult> detailByUserId(@RequestParam("userId") Long userId) {
|
||||
return R.success(driverService.detailByUserId(userId));
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -20,4 +20,6 @@ public interface DriverMapper extends BaseMapper<DriverEntity> {
|
|||
|
||||
DriverResult getById(Long id);
|
||||
|
||||
DriverResult getByUserId(Long userId);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ public interface DriverService extends IService<DriverEntity> {
|
|||
|
||||
DriverResult detail(Long id);
|
||||
|
||||
DriverResult detailByUserId(Long userId);
|
||||
|
||||
PageResult<DriverResult> paging(PageParam pageParam, DriverQueryParam queryParam);
|
||||
|
||||
String getCode(QRCodeParam codeParam);
|
||||
|
|
|
|||
|
|
@ -81,6 +81,11 @@ public class DriverServiceImpl extends ServiceImpl<DriverMapper, DriverEntity> i
|
|||
return baseMapper.getById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DriverResult detailByUserId(Long userId) {
|
||||
return baseMapper.getByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<DriverResult> paging(PageParam pageParam, DriverQueryParam queryParam) {
|
||||
if (queryParam == null) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
package com.njzscloud.dispose.cst.org.constant;
|
||||
|
||||
import com.njzscloud.common.core.ienum.DictStr;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
/**
|
||||
* 运输方排序类型
|
||||
*/
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public enum TransSortType implements DictStr {
|
||||
/**
|
||||
* 按创建时间倒序
|
||||
*/
|
||||
TIME("TIME", "按创建时间倒序"),
|
||||
|
||||
/**
|
||||
* 按清运数排序
|
||||
*/
|
||||
CLEARANCE("CLEARANCE", "按清运数排序"),
|
||||
|
||||
/**
|
||||
* 按综合评价倒序
|
||||
*/
|
||||
EVALUATE("EVALUATE", "按综合评价倒序"),
|
||||
|
||||
/**
|
||||
* 按距离正序
|
||||
*/
|
||||
DISTANCE("DISTANCE", "按距离正序"),
|
||||
;
|
||||
|
||||
private final String val;
|
||||
private final String txt;
|
||||
}
|
||||
|
|
@ -96,4 +96,21 @@ public class OrgController {
|
|||
public R<PageResult<OrgResult>> paging(PageParam pageParam, OrgPagingParam orgPagingParam) {
|
||||
return R.success(orgService.paging(pageParam, orgPagingParam));
|
||||
}
|
||||
|
||||
/**
|
||||
* 运输方分页查询
|
||||
*
|
||||
* @param pageParam 分页参数
|
||||
* @param sortType 排序类型:TIME-按创建时间倒序、CLEARANCE-按清运数排序、EVALUATE-按综合评价倒序、DISTANCE-按距离正序
|
||||
* @param lng 经度(DISTANCE 排序时必传)
|
||||
* @param lat 纬度(DISTANCE 排序时必传)
|
||||
*/
|
||||
@GetMapping("/transOrgPaging")
|
||||
public R<PageResult<OrgResult>> transOrgPaging(PageParam pageParam,
|
||||
@RequestParam(value = "sortType", required = false) String sortType,
|
||||
@RequestParam(value = "lng", required = false) Double lng,
|
||||
@RequestParam(value = "lat", required = false) Double lat) {
|
||||
return R.success(orgService.transOrgPaging(pageParam, sortType, lng, lat));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.njzscloud.dispose.cst.customer.pojo.entity.CustomerEntity;
|
||||
import com.njzscloud.dispose.cst.customer.pojo.result.CustomerResult;
|
||||
import com.njzscloud.dispose.cst.customer.pojo.result.SearchCustomerResult;
|
||||
import com.njzscloud.dispose.cst.org.pojo.entity.OrgEntity;
|
||||
import com.njzscloud.dispose.cst.org.pojo.result.OrgResult;
|
||||
import com.njzscloud.dispose.cst.org.pojo.result.TransOrgStatistics;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
|
|
@ -24,7 +26,14 @@ public interface OrgMapper extends BaseMapper<OrgEntity> {
|
|||
|
||||
Page<OrgResult> paging(Page<OrgResult> page, @Param("ew") QueryWrapper<OrgResult> ew);
|
||||
|
||||
List<CustomerEntity> queryList(@Param("ew") QueryWrapper<CustomerEntity> ew);
|
||||
List<CustomerResult> queryList(@Param("ew") QueryWrapper<CustomerEntity> ew);
|
||||
|
||||
SearchCustomerResult getCustomer(@Param("customerId") Long customerId);
|
||||
|
||||
/**
|
||||
* 查询运输方统计信息
|
||||
* @param orgIds 组织ID列表
|
||||
* @return 统计信息列表
|
||||
*/
|
||||
List<TransOrgStatistics> queryTransOrgStatistics(@Param("orgIds") List<Long> orgIds);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.njzscloud.dispose.cst.org.pojo.param;
|
||||
|
||||
import com.njzscloud.dispose.cst.customer.constant.IdentityCategory;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
|
@ -14,4 +15,9 @@ public class OrgPagingParam {
|
|||
* 统一社会信用代码/组织名称/法人名称
|
||||
*/
|
||||
private String keywords;
|
||||
|
||||
/**
|
||||
* 身份类型
|
||||
*/
|
||||
private IdentityCategory identityCategory;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
package com.njzscloud.dispose.cst.org.pojo.result;
|
||||
|
||||
import com.njzscloud.dispose.cst.customer.pojo.entity.CustomerEntity;
|
||||
import com.njzscloud.dispose.cst.customer.pojo.result.CustomerResult;
|
||||
import com.njzscloud.dispose.cst.org.constant.OrgCategory;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
|
@ -170,6 +171,21 @@ public class OrgResult {
|
|||
/**
|
||||
* 客户信息
|
||||
*/
|
||||
private List<CustomerEntity> customerList;
|
||||
private List<CustomerResult> customerList;
|
||||
|
||||
/**
|
||||
* 平台订单排名
|
||||
*/
|
||||
private Integer orderRank;
|
||||
|
||||
/**
|
||||
* 清运数排名
|
||||
*/
|
||||
private Integer clearanceRank;
|
||||
|
||||
/**
|
||||
* 综合评价(0-5分,0.5精度)
|
||||
*/
|
||||
private BigDecimal overallScore;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
package com.njzscloud.dispose.cst.org.pojo.result;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 运输方统计信息
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Accessors(chain = true)
|
||||
public class TransOrgStatistics {
|
||||
|
||||
/**
|
||||
* 组织Id
|
||||
*/
|
||||
private Long orgId;
|
||||
|
||||
/**
|
||||
* 订单数量
|
||||
*/
|
||||
private Integer orderCount;
|
||||
|
||||
/**
|
||||
* 清运数量
|
||||
*/
|
||||
private Integer clearanceCount;
|
||||
|
||||
/**
|
||||
* 综合评分
|
||||
*/
|
||||
private BigDecimal overallScore;
|
||||
}
|
||||
|
|
@ -10,21 +10,27 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|||
import com.njzscloud.common.core.ex.Exceptions;
|
||||
import com.njzscloud.common.mp.support.PageParam;
|
||||
import com.njzscloud.common.mp.support.PageResult;
|
||||
import com.njzscloud.dispose.cst.customer.constant.IdentityCategory;
|
||||
import com.njzscloud.dispose.cst.customer.pojo.entity.CustomerEntity;
|
||||
import com.njzscloud.dispose.cst.customer.pojo.result.CustomerResult;
|
||||
import com.njzscloud.dispose.cst.customer.pojo.result.SearchCustomerResult;
|
||||
import com.njzscloud.dispose.cst.org.constant.ApplyStatus;
|
||||
import com.njzscloud.dispose.cst.org.constant.TransSortType;
|
||||
import com.njzscloud.dispose.cst.org.mapper.OrgMapper;
|
||||
import com.njzscloud.dispose.cst.org.pojo.entity.OrgApplyEntity;
|
||||
import com.njzscloud.dispose.cst.org.pojo.entity.OrgEntity;
|
||||
import com.njzscloud.dispose.cst.org.pojo.param.AddOrgParam;
|
||||
import com.njzscloud.dispose.cst.org.pojo.param.OrgPagingParam;
|
||||
import com.njzscloud.dispose.cst.org.pojo.result.OrgResult;
|
||||
import com.njzscloud.dispose.cst.org.pojo.result.TransOrgStatistics;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
|
@ -85,12 +91,14 @@ public class OrgService extends ServiceImpl<OrgMapper, OrgEntity> implements ISe
|
|||
*/
|
||||
public PageResult<OrgResult> paging(PageParam pageParam, OrgPagingParam orgPagingParam) {
|
||||
String keywords = orgPagingParam.getKeywords();
|
||||
IdentityCategory identityCategory = orgPagingParam.getIdentityCategory();
|
||||
QueryWrapper<OrgResult> ew = Wrappers.<OrgResult>query()
|
||||
.eq("deleted", Boolean.FALSE)
|
||||
.eq("o.deleted", Boolean.FALSE)
|
||||
.eq(identityCategory != null, "c.identity_category", identityCategory)
|
||||
.and(StrUtil.isNotBlank(keywords), it ->
|
||||
it.like("uscc", keywords)
|
||||
.or().like("org_name", keywords)
|
||||
.or().like("legal_representative", keywords)
|
||||
it.like("o.uscc", keywords)
|
||||
.or().like("o.org_name", keywords)
|
||||
.or().like("o.legal_representative", keywords)
|
||||
);
|
||||
PageResult<OrgResult> page = PageResult.of(baseMapper.paging(pageParam.toPage(), ew));
|
||||
List<OrgResult> records = page.getRecords();
|
||||
|
|
@ -101,16 +109,166 @@ public class OrgService extends ServiceImpl<OrgMapper, OrgEntity> implements ISe
|
|||
.map(OrgResult::getId)
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
Map<Long, List<CustomerEntity>> orgMap = baseMapper.queryList(Wrappers.<CustomerEntity>query()
|
||||
.eq("deleted", Boolean.FALSE)
|
||||
.eq("manager", Boolean.TRUE)
|
||||
.in("org_id", orgIds))
|
||||
QueryWrapper<CustomerEntity> customerEw = Wrappers.<CustomerEntity>query()
|
||||
.eq("cc.deleted", Boolean.FALSE)
|
||||
.eq("cc.manager", Boolean.TRUE)
|
||||
.in("cc.org_id", orgIds);
|
||||
// 如果指定了身份类型,客户列表也需要过滤
|
||||
if (identityCategory != null) {
|
||||
customerEw.eq("cc.identity_category", identityCategory);
|
||||
}
|
||||
Map<Long, List<CustomerResult>> orgMap = baseMapper.queryList(customerEw)
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(CustomerEntity::getOrgId));
|
||||
.collect(Collectors.groupingBy(CustomerResult::getOrgId));
|
||||
records.forEach(org -> org.setCustomerList(orgMap.get(org.getId())));
|
||||
return page;
|
||||
}
|
||||
|
||||
/**
|
||||
* 运输方分页查询
|
||||
*
|
||||
* @param pageParam 分页参数
|
||||
* @param sortType 排序类型:time-按创建时间倒序、clearance-按清运数排序、evaluate-按综合评价倒序、distance-按距离正序
|
||||
* @param lng 经度(sortType=distance时必传)
|
||||
* @param lat 纬度(sortType=distance时必传)
|
||||
*/
|
||||
public PageResult<OrgResult> transOrgPaging(PageParam pageParam, String sortType, Double lng, Double lat) {
|
||||
// 默认按创建时间倒序
|
||||
if (StrUtil.isBlank(sortType)) {
|
||||
sortType = TransSortType.TIME.getVal();
|
||||
}
|
||||
QueryWrapper<OrgResult> ew = Wrappers.<OrgResult>query()
|
||||
.eq("o.deleted", Boolean.FALSE)
|
||||
.eq("c.identity_category", IdentityCategory.YunShu);
|
||||
// 根据排序类型添加排序条件
|
||||
if (TransSortType.TIME.getVal().equals(sortType)) {
|
||||
ew.orderByDesc("o.create_time");
|
||||
}
|
||||
PageResult<OrgResult> page = PageResult.of(baseMapper.paging(pageParam.toPage(), ew));
|
||||
List<OrgResult> records = page.getRecords();
|
||||
if (records.isEmpty()) {
|
||||
return page;
|
||||
}
|
||||
List<Long> orgIds = records.stream()
|
||||
.map(OrgResult::getId)
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
QueryWrapper<CustomerEntity> customerEw = Wrappers.<CustomerEntity>query()
|
||||
.eq("cc.deleted", Boolean.FALSE)
|
||||
.eq("cc.manager", Boolean.TRUE)
|
||||
.in("cc.org_id", orgIds);
|
||||
customerEw.eq("cc.identity_category", IdentityCategory.YunShu);
|
||||
Map<Long, List<CustomerResult>> orgMap = baseMapper.queryList(customerEw)
|
||||
.stream()
|
||||
.collect(Collectors.groupingBy(CustomerResult::getOrgId));
|
||||
records.forEach(org -> org.setCustomerList(orgMap.get(org.getId())));
|
||||
// 查询统计数据并计算排名
|
||||
setTransOrgStatistics(records, orgIds);
|
||||
// 根据排序类型进行排序
|
||||
sortRecords(records, sortType, lng, lat);
|
||||
return page;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据排序类型对记录进行排序
|
||||
*/
|
||||
private void sortRecords(List<OrgResult> records, String sortType, Double userLng, Double userLat) {
|
||||
if (TransSortType.CLEARANCE.getVal().equals(sortType)) {
|
||||
// 按清运数排序(降序)
|
||||
records.sort((a, b) -> {
|
||||
Integer clearanceA = b.getClearanceRank() != null ? b.getClearanceRank() : 0;
|
||||
Integer clearanceB = a.getClearanceRank() != null ? a.getClearanceRank() : 0;
|
||||
return clearanceA.compareTo(clearanceB);
|
||||
});
|
||||
} else if (TransSortType.EVALUATE.getVal().equals(sortType)) {
|
||||
// 按综合评价倒序
|
||||
records.sort((a, b) -> {
|
||||
BigDecimal scoreA = b.getOverallScore() != null ? b.getOverallScore() : BigDecimal.ZERO;
|
||||
BigDecimal scoreB = a.getOverallScore() != null ? a.getOverallScore() : BigDecimal.ZERO;
|
||||
return scoreA.compareTo(scoreB);
|
||||
});
|
||||
} else if (TransSortType.DISTANCE.getVal().equals(sortType) && userLng != null && userLat != null) {
|
||||
// 按距离正序(计算直线距离)
|
||||
records.sort((a, b) -> {
|
||||
Double distanceA = calculateDistance(userLng, userLat,
|
||||
a.getLng() != null ? a.getLng() : 0.0,
|
||||
a.getLat() != null ? a.getLat() : 0.0);
|
||||
Double distanceB = calculateDistance(userLng, userLat,
|
||||
b.getLng() != null ? b.getLng() : 0.0,
|
||||
b.getLat() != null ? b.getLat() : 0.0);
|
||||
return distanceA.compareTo(distanceB);
|
||||
});
|
||||
}
|
||||
// time 排序已在 SQL 中处理,无需额外排序
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算两个经纬度之间的直线距离(单位:公里)
|
||||
* 使用 Haversine 公式
|
||||
*/
|
||||
private double calculateDistance(double lng1, double lat1, double lng2, double lat2) {
|
||||
final double R = 6371; // 地球半径(公里)
|
||||
double latDistance = Math.toRadians(lat2 - lat1);
|
||||
double lngDistance = Math.toRadians(lng2 - lng1);
|
||||
double a = Math.sin(latDistance / 2) * Math.sin(latDistance / 2)
|
||||
+ Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2))
|
||||
* Math.sin(lngDistance / 2) * Math.sin(lngDistance / 2);
|
||||
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
||||
return Math.round(R * c * 1000) / 1000.0; // 返回公里,保留3位小数
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置运输方统计数据和排名
|
||||
*/
|
||||
private void setTransOrgStatistics(List<OrgResult> records, List<Long> orgIds) {
|
||||
// 查询所有运输方的统计数据
|
||||
List<TransOrgStatistics> statisticsList = baseMapper.queryTransOrgStatistics(orgIds);
|
||||
if (statisticsList.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
Map<Long, TransOrgStatistics> statisticsMap = statisticsList.stream()
|
||||
.collect(Collectors.toMap(TransOrgStatistics::getOrgId, s -> s, (a, b) -> a));
|
||||
// 计算订单数量排名(降序,数量多的排名靠前)
|
||||
List<TransOrgStatistics> orderRankedList = statisticsList.stream()
|
||||
.sorted(Comparator.comparingInt((TransOrgStatistics s) -> s.getOrderCount() == null ? 0 : s.getOrderCount()).reversed())
|
||||
.toList();
|
||||
Map<Long, Integer> orderRankMap = new java.util.HashMap<>();
|
||||
int orderRank = 1;
|
||||
Integer prevOrderCount = null;
|
||||
for (TransOrgStatistics stat : orderRankedList) {
|
||||
Integer count = stat.getOrderCount() == null ? 0 : stat.getOrderCount();
|
||||
if (prevOrderCount != null && !count.equals(prevOrderCount)) {
|
||||
orderRank = orderRankMap.size() + 1;
|
||||
}
|
||||
orderRankMap.put(stat.getOrgId(), orderRank);
|
||||
prevOrderCount = count;
|
||||
}
|
||||
// 计算清运数量排名(降序,数量多的排名靠前)
|
||||
List<TransOrgStatistics> clearanceRankedList = statisticsList.stream()
|
||||
.sorted(Comparator.comparingInt((TransOrgStatistics s) -> s.getClearanceCount() == null ? 0 : s.getClearanceCount()).reversed())
|
||||
.toList();
|
||||
Map<Long, Integer> clearanceRankMap = new java.util.HashMap<>();
|
||||
int clearanceRank = 1;
|
||||
Integer prevClearanceCount = null;
|
||||
for (TransOrgStatistics stat : clearanceRankedList) {
|
||||
Integer count = stat.getClearanceCount() == null ? 0 : stat.getClearanceCount();
|
||||
if (prevClearanceCount != null && !count.equals(prevClearanceCount)) {
|
||||
clearanceRank = clearanceRankMap.size() + 1;
|
||||
}
|
||||
clearanceRankMap.put(stat.getOrgId(), clearanceRank);
|
||||
prevClearanceCount = count;
|
||||
}
|
||||
// 设置到OrgResult中
|
||||
records.forEach(org -> {
|
||||
TransOrgStatistics stat = statisticsMap.get(org.getId());
|
||||
if (stat != null) {
|
||||
org.setOrderRank(orderRankMap.get(org.getId()));
|
||||
org.setClearanceRank(clearanceRankMap.get(org.getId()));
|
||||
org.setOverallScore(stat.getOverallScore());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void apply(Long customerId, Long orgId) {
|
||||
SearchCustomerResult customerResult = baseMapper.getCustomer(customerId);
|
||||
|
|
|
|||
|
|
@ -51,11 +51,6 @@ public class ProjectResult {
|
|||
*/
|
||||
private Long transOrgId;
|
||||
|
||||
/**
|
||||
* 运输方组织名称
|
||||
*/
|
||||
private String transOrgName;
|
||||
|
||||
/**
|
||||
* 运输方组织信息
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -8,8 +8,11 @@ import com.baomidou.mybatisplus.core.metadata.OrderItem;
|
|||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.njzscloud.common.core.ex.Exceptions;
|
||||
import com.njzscloud.common.mp.support.PageParam;
|
||||
import com.njzscloud.common.mp.support.PageResult;
|
||||
import com.njzscloud.common.security.util.SecurityUtil;
|
||||
import com.njzscloud.dispose.cst.customer.constant.IdentityCategory;
|
||||
import com.njzscloud.dispose.cst.customer.pojo.entity.CustomerEntity;
|
||||
import com.njzscloud.dispose.cst.customer.service.CustomerService;
|
||||
import com.njzscloud.dispose.cst.org.pojo.entity.OrgEntity;
|
||||
|
|
@ -19,6 +22,7 @@ import com.njzscloud.dispose.cst.project.pojo.entity.ProjectEntity;
|
|||
import com.njzscloud.dispose.cst.project.pojo.param.ProjectQueryParam;
|
||||
import com.njzscloud.dispose.cst.project.pojo.result.ProjectResult;
|
||||
import com.njzscloud.dispose.cst.project.service.ProjectService;
|
||||
import com.njzscloud.dispose.sys.auth.pojo.result.MyResult;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -82,6 +86,25 @@ public class ProjectServiceImpl extends ServiceImpl<ProjectMapper, ProjectEntity
|
|||
// 直接调用自定义分页 SQL
|
||||
Page<ProjectEntity> page = pageParam.toPage();
|
||||
page.addOrder(OrderItem.desc("p.create_time"));
|
||||
// 管理员查看全部,非管理员按身份过滤
|
||||
if (!SecurityUtil.isAdmin()) {
|
||||
MyResult userDetail = SecurityUtil.loginUser();
|
||||
Long currentCustomerId = userDetail.getCurrentCustomerId();
|
||||
if (currentCustomerId != null) {
|
||||
CustomerEntity customer = customerService.getById(currentCustomerId);
|
||||
if (customer != null && customer.getIdentityCategory() != null) {
|
||||
ew.eq(IdentityCategory.ChanFei.equals(customer.getIdentityCategory())
|
||||
|| IdentityCategory.CaiGou.equals(customer.getIdentityCategory()),
|
||||
"p.fringe_customer_id", currentCustomerId);
|
||||
ew.eq(IdentityCategory.YunShu.equals(customer.getIdentityCategory()),
|
||||
"p.trans_customer_id", currentCustomerId);
|
||||
} else {
|
||||
throw Exceptions.clierr("客户信息或客户身份类型不存在");
|
||||
}
|
||||
} else {
|
||||
throw Exceptions.clierr("当前登录人无客户信息");
|
||||
}
|
||||
}
|
||||
Page<ProjectResult> paging = baseMapper.paging(page, ew);
|
||||
|
||||
if (CollUtil.isNotEmpty(paging.getRecords())) {
|
||||
|
|
|
|||
|
|
@ -36,6 +36,14 @@
|
|||
WHERE cd.id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="getByUserId" resultMap="DriverResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM cst_driver cd
|
||||
left join cst_org co on cd.org_id = co.id
|
||||
WHERE cd.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<select id="paging" resultMap="DriverResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
|
|
|
|||
|
|
@ -3,7 +3,9 @@
|
|||
<mapper namespace="com.njzscloud.dispose.cst.org.mapper.OrgMapper">
|
||||
<resultMap id="BaseResultMap" autoMapping="true" type="com.njzscloud.dispose.cst.org.pojo.result.OrgResult">
|
||||
</resultMap>
|
||||
<resultMap id="CustomerResultMap" autoMapping="true" type="com.njzscloud.dispose.cst.customer.pojo.entity.CustomerEntity">
|
||||
<resultMap id="CustomerResultMap" autoMapping="true" type="com.njzscloud.dispose.cst.customer.pojo.result.CustomerResult">
|
||||
</resultMap>
|
||||
<resultMap id="TransOrgStatisticsResultMap" autoMapping="true" type="com.njzscloud.dispose.cst.org.pojo.result.TransOrgStatistics">
|
||||
</resultMap>
|
||||
<update id="admitCustomer">
|
||||
UPDATE cst_customer
|
||||
|
|
@ -21,36 +23,37 @@
|
|||
|
||||
<select id="paging" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
id,
|
||||
org_category,
|
||||
uscc,
|
||||
org_name,
|
||||
business_license,
|
||||
license_start_time,
|
||||
license_end_time,
|
||||
legal_representative,
|
||||
idcard,
|
||||
idcard_start_time,
|
||||
idcard_end_time,
|
||||
idcard_front,
|
||||
idcard_back,
|
||||
province,
|
||||
city,
|
||||
area,
|
||||
town,
|
||||
province_name,
|
||||
city_name,
|
||||
area_name,
|
||||
town_name,
|
||||
address,
|
||||
lng,
|
||||
lat,
|
||||
creator_id,
|
||||
modifier_id,
|
||||
create_time,
|
||||
modify_time,
|
||||
deleted
|
||||
FROM cst_org
|
||||
o.id,
|
||||
o.org_category,
|
||||
o.uscc,
|
||||
o.org_name,
|
||||
o.business_license,
|
||||
o.license_start_time,
|
||||
o.license_end_time,
|
||||
o.legal_representative,
|
||||
o.idcard,
|
||||
o.idcard_start_time,
|
||||
o.idcard_end_time,
|
||||
o.idcard_front,
|
||||
o.idcard_back,
|
||||
o.province,
|
||||
o.city,
|
||||
o.area,
|
||||
o.town,
|
||||
o.province_name,
|
||||
o.city_name,
|
||||
o.area_name,
|
||||
o.town_name,
|
||||
o.address,
|
||||
o.lng,
|
||||
o.lat,
|
||||
o.creator_id,
|
||||
o.modifier_id,
|
||||
o.create_time,
|
||||
o.modify_time,
|
||||
o.deleted
|
||||
FROM cst_org o
|
||||
LEFT JOIN cst_customer c ON o.id = c.org_id AND c.deleted = 0 AND c.manager = 1
|
||||
<if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
|
||||
${ew.customSqlSegment}
|
||||
</if>
|
||||
|
|
@ -58,27 +61,71 @@
|
|||
|
||||
<select id="queryList" resultMap="CustomerResultMap">
|
||||
SELECT
|
||||
id,
|
||||
user_id,
|
||||
identity_category,
|
||||
org_id,
|
||||
customer_name,
|
||||
phone,
|
||||
settlement_way,
|
||||
manager,
|
||||
creator_id,
|
||||
modifier_id,
|
||||
create_time,
|
||||
modify_time,
|
||||
deleted
|
||||
from cst_customer
|
||||
cc.id,
|
||||
cc.user_id,
|
||||
su.avatar,
|
||||
cc.identity_category,
|
||||
cc.org_id,
|
||||
cc.customer_name,
|
||||
cc.phone,
|
||||
cc.settlement_way,
|
||||
cc.manager,
|
||||
cc.creator_id,
|
||||
cc.modifier_id,
|
||||
cc.create_time,
|
||||
cc.modify_time,
|
||||
cc.deleted
|
||||
from cst_customer cc
|
||||
LEFT JOIN sys_user su ON su.id = cc.user_id
|
||||
<if test="ew.customSqlSegment != null and ew.customSqlSegment != ''">
|
||||
${ew.customSqlSegment}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="getCustomer" resultType="com.njzscloud.dispose.cst.customer.pojo.result.SearchCustomerResult">
|
||||
SELECT *
|
||||
FROM cst_customer
|
||||
WHERE id = #{customerId}
|
||||
</select>
|
||||
|
||||
<!-- 查询运输方统计信息:订单数量、清运数量、综合评分 -->
|
||||
<select id="queryTransOrgStatistics" resultMap="TransOrgStatisticsResultMap">
|
||||
SELECT
|
||||
t1.org_id AS orgId,
|
||||
t1.orderCount,
|
||||
t2.clearanceCount,
|
||||
t3.overallScore
|
||||
FROM (
|
||||
-- 订单数量统计
|
||||
SELECT
|
||||
trans_org_id AS org_id,
|
||||
COUNT(*) AS orderCount
|
||||
FROM cst_order
|
||||
WHERE deleted = 0 AND order_status = 'YiWanCheng' AND trans_org_id IS NOT NULL
|
||||
GROUP BY trans_org_id
|
||||
) t1
|
||||
LEFT JOIN (
|
||||
-- 清运数量统计(通过orderId关联)
|
||||
SELECT
|
||||
o.trans_org_id AS org_id,
|
||||
COUNT(*) AS clearanceCount
|
||||
FROM cst_order_trans t
|
||||
INNER JOIN cst_order o ON t.order_id = o.id
|
||||
WHERE t.trans_status = 'YiWanCheng'
|
||||
GROUP BY o.trans_org_id
|
||||
) t2 ON t1.org_id = t2.org_id
|
||||
LEFT JOIN (
|
||||
-- 综合评分(向上取整到0.5)
|
||||
SELECT
|
||||
trans_org_id AS org_id,
|
||||
CEIL(AVG(overall_score) * 2) / 2 AS overallScore
|
||||
FROM cst_order_evaluate
|
||||
WHERE deleted = 0
|
||||
GROUP BY trans_org_id
|
||||
) t3 ON t1.org_id = t3.org_id
|
||||
WHERE t1.org_id IN
|
||||
<foreach collection="orgIds" item="orgId" open="(" separator="," close=")">
|
||||
#{orgId}
|
||||
</foreach>
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue