This commit is contained in:
xyc 2025-05-27 17:51:23 +08:00
parent ca9bdc21cc
commit 8802208c01
9 changed files with 145 additions and 76 deletions

View File

@ -907,8 +907,8 @@ public class PartnerOwnController extends BaseController {
* @return
*/
@GetMapping("/fileStatistics")
public CommonResult<?> fileStatistics(@RequestParam(value = "startTime", required = false) String startTime,
public CommonResult<?> fileStatistics(String servicePackageId,@RequestParam(value = "startTime", required = false) String startTime,
@RequestParam(value = "endTime", required = false) String endTime){
return success(partnerList.fileStatistics(startTime, endTime));
return success(partnerList.fileStatistics(servicePackageId,startTime, endTime));
}
}

View File

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.inspection.mapper;
import cn.iocoder.yudao.module.inspection.entity.InspectionFileRecord;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -20,4 +21,6 @@ public interface InspectionFileRecordMapper extends BaseMapper<InspectionFileRec
* @return
*/
List<InspectionFileRecord> getRecordList(Long id);
long queryCount(@Param("servicePackageId") String servicePackageId,@Param("startTime") String startTime, @Param("endTime") String endTime);
}

View File

@ -40,4 +40,7 @@ public class OrderTableQuery {
/** 等于1时是查询预约转订单 */
private String type;
/** 检测时长 */
private String[] inspectionTime;
}

View File

@ -251,5 +251,5 @@ public interface AppInspectionPartnerService extends IService<ShopMallPartners>
* @param endTime 结束时间
* @return 结果
*/
Map<String, Object> fileStatistics(String startTime, String endTime);
Map<String, Object> fileStatistics(String servicePackageId,String startTime, String endTime);
}

View File

@ -19,4 +19,6 @@ public interface InspectionFileRecordService extends IService<InspectionFileReco
* @return 检测文档记录列表
*/
List<InspectionFileRecord> getRecordList(Long id);
long queryCount(String servicePackageId, String startTime, String endTime);
}

View File

@ -74,6 +74,7 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@Service("appInspectionPartnerService")
@ -1534,112 +1535,141 @@ public class AppInspectionPartnerServiceImpl extends ServiceImpl<AppInspectionPa
@Override
public InspectionInfoVo inspectionDetail(Long inspectionInfoId) {
InspectionInfo info = inspectionInfoService.getById(inspectionInfoId);
if (info == null) return null;
OrderInfo order = orderService.getById(info.getInspectionOrderId());
if (order == null) return null;
InspectionGoodsSku sku = skuService.getById(order.getSkuId());
AdminUserDO buyUser = userService.getUser(info.getUserId());
AdminUserDO worker = userService.getUser(info.getWorkId());
ShopInspectionGoods goods = goodsService.getById(order.getGoodsId());
ShopInspectionCategory category = categoryService.getById(info.getCategoryId());
// 批量查询用户信息
Set<Long> userIds = new HashSet<>();
userIds.add(info.getUserId());
userIds.add(info.getWorkId());
if (info.getLeadManId() != null) userIds.add(info.getLeadManId());
if (info.getMeetManId() != null) userIds.add(info.getMeetManId());
List<AdminUserDO> userList = userService.list(Wrappers.<AdminUserDO>lambdaQuery()
.in(AdminUserDO::getId,userIds)); // 你需新增 getUsers(Collection<Long> ids)
//转为map
Map<Long, AdminUserDO> userMap = userList.stream().collect(Collectors.toMap(AdminUserDO::getId, Function.identity()));
AdminUserDO buyUser = userMap.get(info.getUserId());
AdminUserDO worker = userMap.get(info.getWorkId());
AdminUserDO leadMan = userMap.get(info.getLeadManId());
AdminUserDO meetMan = userMap.get(info.getMeetManId());
InspectionInfoVo res = new InspectionInfoVo();
BeanUtils.copyProperties(order, res);
BeanUtils.copyProperties(order, res); // 建议手动复制必要字段
res.setInspectionId(info.getId());
if (ObjectUtil.isNotNull(worker)) {
res.setWorkerAvatar(Optional.ofNullable(worker.getAvatar()).orElse(null));
res.setWorkerName(Optional.ofNullable(worker.getNickname()).orElse(null));
res.setBuyUserName(buyUser != null ? buyUser.getNickname() : "");
res.setBuyUserPhone(buyUser != null ? buyUser.getMobile() : "");
if (worker != null) {
res.setWorkerAvatar(worker.getAvatar());
res.setWorkerName(worker.getNickname());
res.setWorkerPhone(worker.getMobile());
}
res.setOtherName(Optional.ofNullable(info.getOtherName()).orElse(null));
res.setOtherPhone(Optional.ofNullable(info.getOtherPhone()).orElse(null));
res.setCustomerSource(Optional.ofNullable(info.getCustomerSource()).orElse(null));
res.setBusinessChannel(Optional.ofNullable(info.getBusinessChannel()).orElse(null));
if (ObjectUtil.isNotEmpty(info.getCarModel())) {
// 截取字符串到牌字
String carModel = info.getCarModel();
if (carModel != null && carModel.contains("")) {
res.setCarModel(carModel.substring(0, carModel.indexOf("")));
} else {
res.setCarModel(carModel); // 或设置为 "" / null / "未知" 等默认值
}
res.setOtherName(info.getOtherName());
res.setOtherPhone(info.getOtherPhone());
res.setCustomerSource(info.getCustomerSource());
res.setBusinessChannel(info.getBusinessChannel());
// 车系处理
res.setCarModel(extractCarModel(info.getCarModel()));
// 处理检测时长
if ("1".equals(info.getStatus())) {
long durationMs = calculateInspectionDuration(info);
res.setInspectionDuration(formatDuration(durationMs));
}
//判断检测是否完成
if (info.getStatus().equals("1")){
//计算检测时长以x小时x分展示
// 计算时间差单位为毫秒
//判断结束时间是否为空
long betweenMs = 0;
if (ObjectUtil.isNotNull(info.getEndTime())) {
betweenMs = DateUtil.betweenMs(info.getStartTime(), info.getEndTime());
}else {
//查询步骤表根据时间倒叙
InspectionStepInfo one = stepInfoService.getOne(Wrappers.<InspectionStepInfo>lambdaQuery().eq(InspectionStepInfo::getInspectionInfoId, info.getId()).orderByDesc(InspectionStepInfo::getCreateTime).last("LIMIT 1"));
betweenMs = DateUtil.betweenMs(info.getStartTime(), one.getUpdateTime());
}
// 转换为小时和分钟
long minutes = betweenMs / (1000 * 60);
long hours = minutes / 60;
long remainMinutes = minutes % 60;
res.setInspectionDuration(hours + "小时" + remainMinutes + "");
}
//根据车辆注册日期计算车龄
if (ObjectUtil.isNotNull(info.getCarRegisterDate())) {
// 车龄
if (info.getCarRegisterDate() != null) {
res.setCarAge(DateUtil.betweenYear(info.getCarRegisterDate(), new Date(), true));
}
/*根据工单表中的leadManId查询对应的引车员*/
if (ObjectUtil.isNotNull(info.getLeadManId())) {
AdminUserDO leadMan = adminUserService.getById(info.getLeadManId());
if (ObjectUtil.isNotNull(leadMan)) {
res.setLeadManName(leadMan.getNickname());
res.setLeadManId(info.getLeadManId());
}
if (leadMan != null) {
res.setLeadManName(leadMan.getNickname());
res.setLeadManId(leadMan.getId());
} else {
res.setLeadManName("");
}
/*根据工单表中的meetManId查询对应的 MeetMan*/
if (ObjectUtil.isNotNull(info.getMeetManId())) {
AdminUserDO meetMan = adminUserService.getById(info.getMeetManId());
if (ObjectUtil.isNotNull(meetMan)) {
res.setMeetManName(meetMan.getNickname());
res.setMeetManId(info.getMeetManId());
}
if (meetMan != null) {
res.setMeetManName(meetMan.getNickname());
res.setMeetManId(meetMan.getId());
} else {
res.setMeetManName("");
}
res.setBuyUserName(Optional.ofNullable(buyUser.getNickname()).orElse(""));
res.setBuyUserPhone(buyUser.getMobile());
// 设置订单相关字段
res.setGoodsId(order.getGoodsId());
res.setGoodsPrice(order.getGoodsPrice());
res.setIsOnline(order.getIsOnline());
res.setOrderStatus(order.getOrderStatus());
// SKU 信息
res.setGoodsName(sku != null ? sku.getSkuName() : null);
// 图片
res.setGoodsImage(goods != null ? goods.getImage() : null);
// 检测信息字段
res.setCarNum(info.getCarNum());
res.setCategoryId(info.getCategoryId());
res.setCarType(category != null ? category.getCategoryName() : null);
res.setStartTime(info.getStartTime());
res.setEndTime(info.getEndTime());
res.setStatus(info.getStatus());
res.setGoodsId(order.getGoodsId());
res.setGoodsPrice(order.getGoodsPrice());
res.setGoodsName(sku.getSkuName());
res.setIsOnline(order.getIsOnline());
res.setRecheckCount(info.getRecheckCount());
res.setReinspectCount(info.getReinspectCount());
res.setIsRetrial(info.getIsRetrial());
res.setIsPass(info.getIsPass());
res.setRemark(info.getRemark());
res.setMakeCert(info.getMakeCert());
res.setOrderStatus(order.getOrderStatus());
ShopInspectionGoods goods = goodsService.getById(order.getGoodsId());
res.setGoodsImage(goods.getImage());
LambdaQueryWrapper<InspectionStepInfo> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(InspectionStepInfo::getInspectionInfoId, inspectionInfoId).orderByAsc(InspectionStepInfo::getStepNum);
queryWrapper.orderBy(true, false, InspectionStepInfo::getId);
// 步骤信息
List<InspectionStepInfo> list = stepInfoService.listByInspectionInfoId(inspectionInfoId);
if (CollectionUtil.isNotEmpty(list)) {
res.setStepInfos(list);
}
ShopInspectionCategory category = categoryService.getById(info.getCategoryId());
res.setCarType(category.getCategoryName());
// 查询节点表
List<InspectionWorkNode> workNodes = inspectionWorkNodeService.getWeorkNodesById(Integer.parseInt(String.valueOf(inspectionInfoId)));
// 工作节点
List<InspectionWorkNode> workNodes = inspectionWorkNodeService.getWeorkNodesById(inspectionInfoId.intValue());
res.setWorkNodes(workNodes);
return res;
}
private String extractCarModel(String carModel) {
if (StrUtil.isBlank(carModel)) return null;
int idx = carModel.indexOf("");
return idx > 0 ? carModel.substring(0, idx) : carModel;
}
private long calculateInspectionDuration(InspectionInfo info) {
if (info.getEndTime() != null) {
return DateUtil.betweenMs(info.getStartTime(), info.getEndTime());
}
InspectionStepInfo latest = stepInfoService.getOne(Wrappers.<InspectionStepInfo>lambdaQuery()
.eq(InspectionStepInfo::getInspectionInfoId, info.getId())
.orderByDesc(InspectionStepInfo::getCreateTime).last("LIMIT 1"));
return latest != null ? DateUtil.betweenMs(info.getStartTime(), latest.getUpdateTime()) : 0;
}
private String formatDuration(long ms) {
long minutes = ms / (1000 * 60);
return (minutes / 60) + "小时" + (minutes % 60) + "";
}
@Override
public List<InspectionInfo> workerInspectionList(Long workerId, String status, String searchValue) {
return baseMapper.workerInspectionList(workerId, status, searchValue);
@ -2293,7 +2323,7 @@ public class AppInspectionPartnerServiceImpl extends ServiceImpl<AppInspectionPa
* @return 结果
*/
@Override
public Map<String, Object> fileStatistics(String startTime, String endTime) {
public Map<String, Object> fileStatistics(String servicePackageId,String startTime, String endTime) {
// 判断开始时间与结束时间如果为空 默认查询本月
if (StringUtils.isEmpty(startTime)) {
startTime = DateUtil.format(DateUtil.beginOfMonth(new Date()), "yyyy-MM-dd");
@ -2302,11 +2332,11 @@ public class AppInspectionPartnerServiceImpl extends ServiceImpl<AppInspectionPa
endTime = DateUtil.format(DateUtil.endOfMonth(new Date()), "yyyy-MM-dd");
}
long addCount = inspectionFileService.count(Wrappers.<InspectionFile>lambdaQuery()
.eq(InspectionFile::getServicePackageId, servicePackageId)
.between(InspectionFile::getCreateTime, startTime, endTime));
// 查询文件记录表
long updateCount = inspectionFileRecordService.count(Wrappers.<InspectionFileRecord>lambdaQuery()
.between(InspectionFileRecord::getCreateTime, startTime, endTime));
long updateCount = inspectionFileRecordService.queryCount(servicePackageId, startTime, endTime);
Map<String, Object> map = new HashMap<>();
map.put("addCount", addCount);

View File

@ -28,4 +28,15 @@ public class InspectionFileRecordServiceImpl extends ServiceImpl<InspectionFileR
public List<InspectionFileRecord> getRecordList(Long id) {
return baseMapper.getRecordList(id);
}
/**
* @param servicePackageId
* @param startTime
* @param endTime
* @return
*/
@Override
public long queryCount(String servicePackageId, String startTime, String endTime) {
return baseMapper.queryCount(servicePackageId, startTime, endTime);
}
}

View File

@ -705,6 +705,16 @@ FROM
AND (TIMESTAMPDIFF(YEAR, ii.car_register_date, CURDATE()) >= #{query.carYear}
AND TIMESTAMPDIFF(YEAR, ii.car_register_date, CURDATE()) &lt; #{query.carYear} + 1)
</if>
<if test="query.inspectionTime != null and query.inspectionTime.length == 2">
AND ii.start_time IS NOT NULL AND ii.end_time IS NOT NULL
AND TIMESTAMPDIFF(MINUTE, ii.start_time, ii.end_time)
BETWEEN #{query.inspectionTime[0]} AND #{query.inspectionTime[1]}
</if>
<if test="query.inspectionTime[0] !=null and query.inspectionTime.length == 1">
AND ii.start_time IS NOT NULL AND ii.end_time IS NOT NULL
AND TIMESTAMPDIFF(MINUTE, ii.start_time, ii.end_time) >= #{query.inspectionTime[0]}
</if>
</where>
AND oi.deleted = '0'
) t

View File

@ -10,4 +10,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
where record.file_id = #{id}
and record.deleted = 0
</select>
<select id="queryCount" resultType="java.lang.Long">
select count(1)
from inspection_file_record record
INNER JOIN inspection_file file on record.file_id = file.id
where record.deleted = 0
AND file.service_package_id = #{servicePackageId}
<if test="startTime != null">
AND record.create_time between #{startTime} and #{endTime}
</if>
</select>
</mapper>