ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/ReportController.java
@@ -381,6 +381,9 @@ List<TLocation> locations = locationService.list(); LambdaQueryWrapper<TTask> tTaskLambdaQueryWrapper = new LambdaQueryWrapper<>(); if (StringUtils.hasLength(query.getStartTime()) && StringUtils.hasLength(query.getEndTime())) { String endTime = query.getEndTime(); String replace = endTime.replace(" 00:00:00", " 23:59:59"); query.setEndTime(replace); tTaskLambdaQueryWrapper.ge(TTask::getImplementTime, query.getStartTime()); tTaskLambdaQueryWrapper.le(TTask::getImplementTime, query.getEndTime()); } @@ -511,11 +514,15 @@ List<TLocation> locations = locationService.list(); LambdaQueryWrapper<TTask> tTaskLambdaQueryWrapper = new LambdaQueryWrapper<>(); if (StringUtils.hasLength(query.getStartTime()) && StringUtils.hasLength(query.getEndTime())) { String endTime = query.getEndTime(); String replace = endTime.replace(" 00:00:00", " 23:59:59"); query.setEndTime(replace); tTaskLambdaQueryWrapper.ge(TTask::getImplementTime, query.getStartTime()); tTaskLambdaQueryWrapper.le(TTask::getImplementTime, query.getEndTime()); } List<ProjectDeptDetailsVO> res = new ArrayList<>(); List<TTask> tasks = taskCleanerService.list(tTaskLambdaQueryWrapper); List<TTaskDetail> taskDetails = taskDetailService.lambdaQuery().orderByDesc(BaseModel::getCreateTime).list(); List<String> collect = tasks.stream().map(TTask::getProjectId).distinct().collect(Collectors.toList()); List<TProjectDept> projectDepts = projectDeptService.list(); @@ -884,7 +891,7 @@ .divide(new BigDecimal(status4.size()).add(new BigDecimal(status5.size())), 2, RoundingMode.HALF_DOWN) .multiply(new BigDecimal(100)) : BigDecimal.ZERO); patrolInspectorVO.setNum10(status6.size()); patrolInspectorVO.setNum11(!taskList.isEmpty() ? new BigDecimal(status6.size()).divide(new BigDecimal(taskList.size()), 2, RoundingMode.HALF_DOWN) : BigDecimal.ZERO); patrolInspectorVO.setNum11(!taskList.isEmpty() ? new BigDecimal(status6.size()).divide(new BigDecimal(taskList.size()), 2, RoundingMode.HALF_DOWN).multiply(new BigDecimal(100)) : BigDecimal.ZERO); List<TLeave> collect1 = leaves.stream().filter(e -> e.getLeavePerson().equals(sysUser.getUserId() + "")).collect(Collectors.toList()); patrolInspectorVO.setNum12(collect1.size()); res.add(patrolInspectorVO); ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TAppealController.java
@@ -28,6 +28,7 @@ import javax.validation.Valid; import java.time.LocalDateTime; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -90,11 +91,15 @@ if (listIds.isEmpty()){ listIds.add("0"); } query.setPatrolInspectorIds(sysUsers.stream().filter(e->listIds.contains(e.getDeptId())).map(SysUser::getUserId) .collect(Collectors.toList())); if (listIds.contains("0")){ query.setPatrolInspectorIds(Collections.singletonList(0L)); }else{ query.setPatrolInspectorIds(sysUsers.stream().filter(e->listIds.contains(e.getDeptId())).map(SysUser::getUserId) .collect(Collectors.toList())); } if (StringUtils.hasLength(query.getPhonenumber())){ List<Long> patrolInspectorIds = sysUsers.stream().filter(sysUser -> sysUser.getPhonenumber().equals(query.getPhonenumber()) sysUser.getPhonenumber().contains(query.getPhonenumber()) && listIds.contains(sysUser.getDeptId()) ).map(SysUser::getUserId).collect(Collectors.toList()); if (patrolInspectorIds.isEmpty()){ @@ -105,7 +110,7 @@ } if (StringUtils.hasLength(query.getPhonenumber())){ List<Long> patrolInspectorIds = sysUsers.stream().filter(sysUser -> sysUser.getPhonenumber().equals(query.getPhonenumber()) sysUser.getPhonenumber().contains(query.getPhonenumber()) ).map(SysUser::getUserId).collect(Collectors.toList()); if (!CollectionUtils.isEmpty(query.getPatrolInspectorIds())){ // 取交集 @@ -180,7 +185,8 @@ TLocationType byId2 = locationTypeService.getById(byId1.getLocationType()); appealDetailVO.setLocationAddress(byId1.getLocationAddress()); appealDetailVO.setLocationIcon(byId2.getLocationIcon()); appealDetailVO.setLocationName(byId2.getLocationName()); appealDetailVO.setLocationName(byId1.getLocationName()); appealDetailVO.setLocationTypeName(byId2.getLocationName()); appealDetailVO.setTaskId(byId.getId()); if (appeal.getAuditPerson()!=null){ SysUser sysUser = sysUserService.selectUserById(Long.valueOf(appeal.getAuditPerson())); @@ -206,7 +212,7 @@ public R<Boolean> audit(@RequestBody @Valid TAppealAuditDTO dto) throws Exception { List<SysUser> sysUsers = sysUserService.selectAllList(); TAppeal appeal = appealService.getById(dto.getId()); SysUser sysUser = sysUsers.stream().filter(e -> e.getUserId().equals(Long.valueOf(dto.getAppealPerson()))) SysUser sysUser = sysUsers.stream().filter(e -> e.getUserId().equals(Long.valueOf(appeal.getAppealPerson()))) .findFirst().orElse(null); dto.setStatus(dto.getStatus()); dto.setAuditPerson(tokenService.getLoginUser().getUserId()+""); ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TLocationController.java
@@ -272,11 +272,18 @@ List<String> strings = new ArrayList<>(); strings.add(id); TProjectDept projectDept = projectDeptService.getById(id); if (projectDept.getParentId().equals("0")){ List<String> collect = projectDeptService.lambdaQuery().eq(TProjectDept::getParentId, projectDept.getId()) .list().stream().map(TProjectDept::getId).collect(Collectors.toList()); if (projectDept!=null){ if (projectDept.getParentId().equals("0")){ List<String> collect = projectDeptService.lambdaQuery().eq(TProjectDept::getParentId, projectDept.getId()) .list().stream().map(TProjectDept::getId).collect(Collectors.toList()); strings.addAll(collect); } }else{ List<String> collect = deptService.lambdaQuery().eq(TDept::getId, id) .list().stream().map(TDept::getId).collect(Collectors.toList()); strings.addAll(collect); } List<SysUser> res = sysUserService.selectUserByDeptId(strings); return R.ok(res); } ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TTaskController.java
@@ -9,6 +9,7 @@ import cn.afterturn.easypoi.excel.entity.ExportParams; import cn.afterturn.easypoi.excel.entity.TemplateExportParams; import cn.hutool.core.io.resource.ClassPathResource; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.ruoyi.common.core.domain.BaseModel; import com.ruoyi.common.utils.CodeGenerateUtils; import com.ruoyi.common.utils.DateUtils; @@ -224,6 +225,7 @@ tNotice.setDataId(task.getId()); tNotice.setNoticeSetType(noticeSet.getNoticeType()); if (dto.getAuditStatus() == 2) { dto.setHandleType(3); if (StringUtils.hasLength(location.getUnqualifiedTaskId())) { if (location.getUnqualifiedTaskId().split(",").length == 2) { // 已经两条不合格了 生成点位不合格预警记录 @@ -234,6 +236,13 @@ earlyWarningService.save(tEarlyWarning); location.setUnqualifiedTaskId(""); locationService.updateById(location); }else{ if (StringUtils.hasLength(location.getUnqualifiedTaskId())){ location.setUnqualifiedTaskId(location.getUnqualifiedTaskId() + "," + dto.getTaskId()); }else{ location.setUnqualifiedTaskId(dto.getTaskId()); } locationService.updateById(location); } } else { if (StringUtils.hasLength(location.getUnqualifiedTaskId())){ @@ -243,7 +252,6 @@ } locationService.updateById(location); } dto.setHandleType(3); // 将任务修改为待整改 task.setStatus(4); taskCleanerService.updateById(task); @@ -268,6 +276,8 @@ } else { dto.setHandleType(2); if (dto.getClearStatus() == 2) { if (StringUtils.hasLength(location.getUnqualifiedTaskId())) { if (location.getUnqualifiedTaskId().split(",").length == 2) { @@ -278,6 +288,13 @@ tEarlyWarning.setTaskId(location.getUnqualifiedTaskId()); earlyWarningService.save(tEarlyWarning); location.setUnqualifiedTaskId(""); locationService.updateById(location); }else{ if (StringUtils.hasLength(location.getUnqualifiedTaskId())){ location.setUnqualifiedTaskId(location.getUnqualifiedTaskId() + "," + dto.getTaskId()); }else{ location.setUnqualifiedTaskId(dto.getTaskId()); } locationService.updateById(location); } } else { @@ -322,6 +339,8 @@ } noticeService.save(tNotice); dto.setAuditPerson(tokenService.getLoginUser().getUserId() + ""); dto.setAuditRemark(dto.getAuditRemark()); dto.setAuditTime(LocalDateTime.now()); taskDetailService.save(dto); one.setAuditPerson(tokenService.getLoginUser().getUserId() + ""); one.setAuditTime(LocalDateTime.now()); @@ -334,30 +353,182 @@ @Log(title = "批量审核任务", businessType = BusinessType.UPDATE) @ApiOperation(value = "批量审核任务") @PostMapping(value = "/auditBatch") public R<Boolean> auditBatch(@RequestBody TTaskAuditBatchDTO dto) { public R<Boolean> auditBatch(@RequestBody TTaskAuditBatchDTO dto) throws Exception { List<TTaskDetail> tTaskDetails = new ArrayList<>(); List<TLocation> locations = locationService.list(); List<SysUser> sysUsers = sysUserService.selectAllList(); List<TTaskDetail> taskDetails = taskDetailService.list(Wrappers.lambdaQuery(TTaskDetail.class) .in(TTaskDetail::getTaskId, Arrays.asList(dto.getTaskIds().split(","))) .eq(TTaskDetail::getHandleType,1) .orderByDesc(TTaskDetail::getCreateTime)); taskDetails = new ArrayList<>(taskDetails.stream() .collect(Collectors.groupingBy( TTaskDetail::getTaskId, Collectors.collectingAndThen( Collectors.toList(), listAll -> listAll.get(0) ) )) .values()); for (String s : dto.getTaskIds().split(",")) { TTask byId = taskCleanerService.getById(s); TTask task = taskCleanerService.getById(s); SysUser sysUser = sysUsers.stream().filter(e -> e.getUserId().equals(Long.valueOf(task.getPatrolInspector()))) .findFirst().orElse(null); TLocation location = locations.stream().filter(e -> e.getId().equals(task.getLocationId())) .findFirst().orElse(null); TTaskDetail tTaskDetail = new TTaskDetail(); tTaskDetail.setTaskId(s); tTaskDetail.setAuditTime(LocalDateTime.now()); tTaskDetail.setAuditPerson(tokenService.getLoginUser().getUserId() + ""); // if (dto.getAuditStatus() == 2) { // tTaskDetail.setHandleType(3); // // 将任务修改为待整改 // task.setStatus(4); // taskCleanerService.updateById(task); // } else { // tTaskDetail.setHandleType(2); // // 如果是初次审核就通过 将状态设置为已完成 // List<TTaskDetail> list = taskDetailService.lambdaQuery() // .eq(TTaskDetail::getHandleType, 1).eq(TTaskDetail::getTaskId, s).list(); // if (list.size() == 1) { // task.setStatus(6); // taskCleanerService.updateById(task); // } else { // task.setStatus(5); // taskCleanerService.updateById(task); // } // } TNotice tNotice = new TNotice(); TNoticeSet noticeSet = noticeSetService.lambdaQuery().eq(TNoticeSet::getType, 2).last("limit 1") .one(); // 邮箱 TDictData email = dictDataService.lambdaQuery().eq(TDictData::getDataType,4).one(); // 授权码 TDictData code = dictDataService.lambdaQuery().eq(TDictData::getDataType,5).one(); tNotice.setUserId(task.getPatrolInspector()); tNotice.setStatus(1); tNotice.setDataId(task.getId()); tNotice.setNoticeSetType(noticeSet.getNoticeType()); TTaskDetail taskDetail = taskDetails.stream().filter(e -> e.getTaskId().equals(s)) .findFirst().orElse(null); taskDetail.setAuditPerson(tokenService.getLoginUser().getUserId() + ""); taskDetail.setAuditTime(LocalDateTime.now()); taskDetail.setAuditRemark(dto.getAuditRemark()); taskDetail.setAuditStatus(dto.getAuditStatus()); taskDetailService.updateById(taskDetail); if (dto.getAuditStatus() == 2) { tTaskDetail.setHandleType(3); // 将任务修改为待整改 byId.setStatus(4); taskCleanerService.updateById(byId); } else { tTaskDetail.setHandleType(2); // 如果是初次审核就通过 将状态设置为已完成 List<TTaskDetail> list = taskDetailService.lambdaQuery() .eq(TTaskDetail::getHandleType, 1).eq(TTaskDetail::getTaskId, s).list(); if (list.size() == 1) { byId.setStatus(6); taskCleanerService.updateById(byId); if (StringUtils.hasLength(location.getUnqualifiedTaskId())) { if (location.getUnqualifiedTaskId().split(",").length == 2) { // 已经两条不合格了 生成点位不合格预警记录 location.setUnqualifiedTaskId(location.getUnqualifiedTaskId() + "," + task.getId()); TEarlyWarning tEarlyWarning = new TEarlyWarning(); tEarlyWarning.setWarningType(2); tEarlyWarning.setTaskId(location.getUnqualifiedTaskId()); earlyWarningService.save(tEarlyWarning); location.setUnqualifiedTaskId(""); locationService.updateById(location); }else{ if (StringUtils.hasLength(location.getUnqualifiedTaskId())){ location.setUnqualifiedTaskId(location.getUnqualifiedTaskId() + "," + task.getId()); }else{ location.setUnqualifiedTaskId(task.getId()); } locationService.updateById(location); } } else { byId.setStatus(5); taskCleanerService.updateById(byId); if (StringUtils.hasLength(location.getUnqualifiedTaskId())){ location.setUnqualifiedTaskId(location.getUnqualifiedTaskId() + "," + task.getId()); }else{ location.setUnqualifiedTaskId(task.getId()); } locationService.updateById(location); } tTaskDetail.setHandleType(3); tTaskDetail.setAuditRemark(dto.getAuditRemark()); // 将任务修改为待整改 task.setStatus(4); taskCleanerService.updateById(task); // 增加消息 tNotice.setNoticeType(1); tNotice.setNoticeContent("【" + location.getLocationName() + "】任务不合格,请重新上传!"); if (sysUser!=null){ switch (noticeSet.getNoticeType()) { case 1: msgUtils.sendMsg1(sysUser.getPhonenumber(),location.getLocationName(),"驳回"); break; case 2: if (StringUtils.hasLength(email.getDataContent())&&StringUtils.hasLength(code.getDataContent())){ EmailUtils.sendEmail(sysUser.getEmail(),email.getDataContent(),code.getDataContent(),"【" + location.getLocationName() + "】任务不合格,请重新上传!"); } break; case 3: break; } } } else { if (taskDetail.getClearStatus() == 2) { if (StringUtils.hasLength(location.getUnqualifiedTaskId())) { if (location.getUnqualifiedTaskId().split(",").length == 2) { // 已经两条不合格了 生成点位不合格预警记录 location.setUnqualifiedTaskId(location.getUnqualifiedTaskId() + "," + task.getId()); TEarlyWarning tEarlyWarning = new TEarlyWarning(); tEarlyWarning.setWarningType(2); tEarlyWarning.setTaskId(location.getUnqualifiedTaskId()); earlyWarningService.save(tEarlyWarning); location.setUnqualifiedTaskId(""); locationService.updateById(location); }else{ if (StringUtils.hasLength(location.getUnqualifiedTaskId())){ location.setUnqualifiedTaskId(location.getUnqualifiedTaskId() + "," + task.getId()); }else{ location.setUnqualifiedTaskId(task.getId()); } locationService.updateById(location); } } else { if (StringUtils.hasLength(location.getUnqualifiedTaskId())){ location.setUnqualifiedTaskId(location.getUnqualifiedTaskId() + "," + task.getId()); }else{ location.setUnqualifiedTaskId(task.getId()); } locationService.updateById(location); } } taskDetail.setHandleType(2); // 如果是初次审核就通过 将状态设置为已完成 List<TTaskDetail> list = tTaskDetailService.lambdaQuery() .eq(TTaskDetail::getHandleType, 1) .eq(TTaskDetail::getTaskId, task.getId()).list(); if (list.size() < 2) { task.setStatus(6); taskCleanerService.updateById(task); tNotice.setNoticeType(2); tNotice.setNoticeContent("【" + location.getLocationName() + "】任务已通过"); } else { task.setStatus(5); taskCleanerService.updateById(task); tNotice.setNoticeType(2); tNotice.setNoticeContent("【" + location.getLocationName() + "】任务已通过"); } if (sysUser!=null){ switch (noticeSet.getNoticeType()) { case 1: msgUtils.sendMsg1(sysUser.getPhonenumber(),location.getLocationName(),"通过"); break; case 2: if (StringUtils.hasLength(email.getDataContent())&&StringUtils.hasLength(code.getDataContent())){ EmailUtils.sendEmail(sysUser.getEmail(),email.getDataContent(),code.getDataContent(),"【" + location.getLocationName() + "】任务已通过"); } break; case 3: break; } } } tTaskDetails.add(tTaskDetail); @@ -398,34 +569,31 @@ @ApiOperation(value = "详情任务-根据任务编号") @GetMapping(value = "/detailByTaskCode") public R<TaskDetailVO> detailByTaskCode(@RequestParam String taskCode) { TTask task = taskCleanerService.lambdaQuery().eq(TTask::getTaskCode, taskCode) .last("limit 1").one(); TTask byId = taskCleanerService.lambdaQuery().eq(TTask::getTaskCode, taskCode).last("limit 1").one(); List<TTaskDetail> list = taskDetailService.lambdaQuery().eq(TTaskDetail::getTaskId, byId.getId()) .orderByDesc(BaseModel::getCreateTime).list(); TaskDetailVO taskDetailVO = new TaskDetailVO(); if (task != null) { String id = task.getId(); List<TTaskDetail> list = taskDetailService.lambdaQuery().eq(TTaskDetail::getTaskId, id) .orderByDesc(BaseModel::getCreateTime).list(); TTask byId = taskCleanerService.getById(id); BeanUtils.copyProperties(byId, taskDetailVO); TLocation byId1 = locationService.getById(byId.getLocationId()); TLocationType byId2 = locationTypeService.getById(byId1.getLocationType()); taskDetailVO.setLocationAddress(byId1.getLocationAddress()); taskDetailVO.setLocationIcon(byId2.getLocationIcon()); taskDetailVO.setLocationName(byId2.getLocationName()); TTaskDetail tTaskDetail = list.stream().filter(e -> e.getHandleType() == 1).findFirst().orElse(null); if (tTaskDetail != null && tTaskDetail.getUnqualified() != null) { TDictData byId3 = dictDataService.getById(tTaskDetail.getUnqualified()); if (byId3 != null) { tTaskDetail.setUnqualifiedName(byId3.getDataContent()); } BeanUtils.copyProperties(byId, taskDetailVO); TLocation byId1 = locationService.getById(byId.getLocationId()); TLocationType byId2 = locationTypeService.getById(byId1.getLocationType()); taskDetailVO.setLocationAddress(byId1.getLocationAddress()); taskDetailVO.setLocationIcon(byId2.getLocationIcon()); taskDetailVO.setLocationName(byId1.getLocationName()); taskDetailVO.setLocationTypeName(byId2.getLocationName()); TTaskDetail tTaskDetail = list.stream().filter(e -> e.getHandleType() == 1).findFirst().orElse(null); if (tTaskDetail != null && tTaskDetail.getUnqualified() != null) { TDictData byId3 = dictDataService.getById(tTaskDetail.getUnqualified()); if (byId3 != null) { tTaskDetail.setUnqualifiedName(byId3.getDataContent()); } taskDetailVO.setTaskDetail(tTaskDetail); taskDetailVO.setRecords(list); } else { return R.fail("任务不存在"); } if (tTaskDetail != null) { tTaskDetail.setFinishTime(tTaskDetail.getCreateTime()); } taskDetailVO.setTaskDetail(tTaskDetail); taskDetailVO.setRecords(list); return R.ok(taskDetailVO); } @ApiOperation(value = "详情任务-操作记录-详情") ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TIndexController.java
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.annotation.Log; import com.ruoyi.common.basic.PageInfo; @@ -13,7 +14,9 @@ import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.entity.SysRole; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.utils.CodeGenerateUtils; import com.ruoyi.common.utils.bean.BeanUtils; import com.ruoyi.framework.web.service.TokenService; import com.ruoyi.system.applet.dto.*; @@ -27,6 +30,7 @@ import com.sun.org.apache.bcel.internal.generic.NEW; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.apache.poi.ss.formula.functions.T; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.util.CollectionUtils; @@ -459,16 +463,12 @@ leaveList.add(leaveUserListVO); } List<TTask> taskList = taskAll.stream().filter(e -> e.getPatrolInspector().equals(userId + "") && e.getStatus() == 4).collect(Collectors.toList()); List<String> taskIds = taskList.stream().map(TTask::getId).collect(Collectors.toList()); // 驳回原因 List<TTaskDetail> tTaskDetails = taskDetailService.list(new LambdaQueryWrapper<TTaskDetail>() .eq(TTaskDetail::getHandleType,3).groupBy(TTaskDetail::getTaskId).orderByDesc(TTaskDetail::getCreateTime)); for (TTask tTask : taskList) { List<TTaskDetail> taskDetailsStatus1 = taskDetailService.lambdaQuery() .eq(TTaskDetail::getAuditStatus, 1).in(TTaskDetail::getTaskId, taskIds) .eq(TTaskDetail::getClearStatus, 2) .groupBy(TTaskDetail::getTaskId) .orderByDesc(TTaskDetail::getCreateTime).list(); TTaskDetail taskDetailsStatus1 = taskDetailService.lambdaQuery() .eq(TTaskDetail::getTaskId, tTask.getId()) .in(TTaskDetail::getHandleType, Arrays.asList(3,6)) .orderByDesc(TTaskDetail::getCreateTime).last("limit 1").one(); TaskPendingVO taskTodayVO = new TaskPendingVO(); BeanUtils.copyProperties(tTask, taskTodayVO); TLocation tLocation = locationList.stream().filter(e -> e.getId().equals(tTask.getLocationId())).findFirst().orElse(null); @@ -479,12 +479,6 @@ taskTodayVO.setLocationName(tLocation.getLocationName()); if(StringUtils.hasLength(dto.getLon())){ taskTodayVO.setDistance(tTask.getDistance().divide(new BigDecimal(1000),2, RoundingMode.HALF_DOWN)); // Map<String, String> distance = amapApiClient.getDistance(dto.getLon() + "," + dto.getLat(), tLocation.getLocationLon() + "," + tLocation.getLocationLat(), 1); // if (distance != null) { // taskTodayVO.setDistance(new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_EVEN)); // } else { // taskTodayVO.setDistance(new BigDecimal("0")); // } }else { taskTodayVO.setDistance(new BigDecimal("0")); } @@ -494,9 +488,8 @@ taskTodayVO.setLocationTypeIcon(tLocationType.getLocationIcon()); } } TTaskDetail tTaskDetail = tTaskDetails.stream().filter(e -> e.getTaskId().equals(tTask.getId())).findFirst().orElse(null); if (tTaskDetail!=null){ taskTodayVO.setRemark(tTaskDetail.getAuditRemark()); if (taskDetailsStatus1!=null){ taskTodayVO.setRemark(taskDetailsStatus1.getAuditRemark()); } // 任务记录ids List<String> collect = taskAll.stream().map(TTask::getId).collect(Collectors.toList()); @@ -515,14 +508,9 @@ taskTodayVOOne.setLocationLat(tLocationOne.getLocationLat()); taskTodayVOOne.setLocationName(tLocationOne.getLocationName()); if(StringUtils.hasLength(dto.getLon())){ Map<String, String> distance = amapApiClient.getDistance(dto.getLon() + "," + dto.getLat(), tLocationOne.getLocationLon() + "," + tLocationOne.getLocationLat(), 1); if (distance != null) { taskTodayVOOne.setDistance(new BigDecimal(distance.get("distance")).divide(new BigDecimal(1000)).setScale(2, BigDecimal.ROUND_HALF_EVEN)); } else { taskTodayVOOne.setDistance(new BigDecimal("0")); } taskTodayVO.setDistance(tTask.getDistance().divide(new BigDecimal(1000),2, RoundingMode.HALF_DOWN)); }else { taskTodayVOOne.setDistance(new BigDecimal("0")); taskTodayVO.setDistance(new BigDecimal("0")); } TLocationType tLocationType = locationTypeList.stream().filter(e -> e.getId().equals(tLocationOne.getLocationType())).findFirst().orElse(null); if (tLocationType != null) { @@ -548,11 +536,10 @@ if(CollectionUtils.isEmpty(collect)){ break; } List<TTaskDetail> taskDetailsStatus1 = taskDetailService.lambdaQuery() .eq(TTaskDetail::getAuditStatus, 1).in(TTaskDetail::getTaskId, collect) .eq(TTaskDetail::getClearStatus, 2) .groupBy(TTaskDetail::getTaskId) .orderByDesc(TTaskDetail::getCreateTime).list(); TTaskDetail taskDetailsStatus1 = taskDetailService.lambdaQuery() .eq(TTaskDetail::getTaskId, tTask.getId()) .in(TTaskDetail::getHandleType, Arrays.asList(3,6)) .orderByDesc(TTaskDetail::getCreateTime).last("limit 1").one(); BeanUtils.copyProperties(tTask, taskTodayVO); TLocation tLocation = locationList.stream().filter(e -> e.getId().equals(tTask.getLocationId())).findFirst().orElse(null); if (tLocation != null) { @@ -576,9 +563,8 @@ taskTodayVO.setLocationTypeIcon(tLocationType.getLocationIcon()); } } TTaskDetail tTaskDetail = tTaskDetails.stream().filter(e -> e.getTaskId().equals(tTask.getId())).findFirst().orElse(null); if (tTaskDetail!=null){ taskTodayVO.setRemark(tTaskDetail.getAuditRemark()); if (taskDetailsStatus1!=null){ taskTodayVO.setRemark(taskDetailsStatus1.getAuditRemark()); } todayTask.add(taskTodayVO); @@ -594,7 +580,52 @@ tomorrowTask.add(taskTomorrowVO); } Collections.shuffle(tomorrowTask); res.setTomorrowTask(tomorrowTask); List<TTemplate> templates = templateService.list(); TTemplate tTemplate = templates.stream().filter(e -> e.getId().equals(sysUser.getTemplateId())).findFirst() .orElse(null); if (tTemplate!=null){ List<TTask> inspection = createInspection(tTemplate, userId); List<String> collect1 = inspection.stream().map(TTask::getId).collect(Collectors.toList()); if (collect1.isEmpty()){ collect1.add("0"); } List<TTask> temp =new ArrayList<>(); if (!StringUtils.hasLength(dto.getLon())){ temp = inspection; }else{ temp = taskCleanerService.getTaskByIds(collect1,dto.getLon(),dto.getLat()); } List<TaskTomorrowVO> taskTomorrowVOS = new ArrayList<>(); for (TTask tTask : temp) { TaskTomorrowVO taskTomorrowVO = new TaskTomorrowVO(); BeanUtils.copyProperties(tTask, taskTomorrowVO); TLocation tLocation = locationList.stream().filter(e -> e.getId().equals(tTask.getLocationId())).findFirst().orElse(null); if (tLocation!=null){ TLocationType tLocationType = locationTypeList.stream().filter(e -> e.getId().equals(tLocation.getLocationType())).findFirst().orElse(null); if (tLocationType!=null){ taskTomorrowVO.setLocationId(tLocation.getId()); taskTomorrowVO.setLocationName(tLocation.getLocationName()); taskTomorrowVO.setLocationTypeName(tLocationType.getLocationName()); taskTomorrowVO.setLocationTypeIcon(tLocationType.getLocationIcon()); taskTomorrowVO.setLocationAddress(tLocation.getLocationAddress()); taskTomorrowVO.setLocationLon(tLocation.getLocationLon()); taskTomorrowVO.setLocationLat(tLocation.getLocationLat()); if (StringUtils.hasLength(dto.getLon())){ taskTomorrowVO.setDistance(tTask.getDistance().divide(new BigDecimal("1000"),2, RoundingMode.HALF_DOWN)); }else { taskTomorrowVO.setDistance(new BigDecimal("0")); } } } taskTomorrowVOS.add(taskTomorrowVO); } res.setTomorrowTask(taskTomorrowVOS); }else{ res.setTomorrowTask(new ArrayList<>()); } res.setIsLeave(0); // 查询请假状态 List<TLeave> list2 = leaveService.lambdaQuery().eq(TLeave::getLeavePerson, userId) @@ -612,6 +643,290 @@ } return R.ok(res); } @Resource private TTemplateService templateService; // 项目部权重标识 private static final String PROJECT_DEPT_WEIGHT = ":PROJECT_DEPT_WEIGHT"; // 保洁员权重标识 private static final String CLEANER_WEIGHT = ":CLEANER_WEIGHT"; // 重复点位标识 private static final String REPEAT_LOCATION = ":REPEAT_LOCATION"; @Autowired private RedisCache redisCache; @Autowired private TTemplateDetailService templateDetailService; public List<TTask> createInspection(TTemplate template,Long userId) { // 查询所有的模板详情 List<TTemplateDetail> list = templateDetailService.list(Wrappers.lambdaQuery(TTemplateDetail.class) .eq(TTemplateDetail::getTemplateId, template.getId())); if (CollectionUtils.isEmpty(list)) { return new ArrayList<>(); } List<TTask> taskAll = new ArrayList<>(); // 通过模板id查询员工巡检员 List<SysUser> sysUsers = sysUserService.selectUserByTempLateId(template.getId()); sysUsers = sysUsers.stream().filter(e->e.getUserId().equals(userId)).collect(Collectors.toList()); // 创建任务 for (TTemplateDetail detail : list) { // 计算周期 int cycle = detail.getCycle(); switch (detail.getCycleType()){ case 2: cycle = cycle * 7; break; case 3: cycle = cycle * 30; break; case 4: cycle = cycle * 90; break; case 5: cycle = cycle * 365; break; } // 拿到保洁抽查次数 int num1 = detail.getNum1(); // 拿到项目部数 int num2 = detail.getNum2(); // 拿到每日重复点位 int num3 = detail.getNum3(); // 获取点位类型的占比 String num4 = detail.getNum4(); // 未绑定员工 if(CollectionUtils.isEmpty(sysUsers)){ continue; } int taskCount = 0; for (SysUser sysUser : sysUsers) { if("1".equals(sysUser.getStatus())){ continue; } List<TProjectDept> projectDeptLists = new ArrayList<>(); if(sysUser.getDeptType() == 1){ TProjectDept projectDept = projectDeptService.getById(sysUser.getDeptId()); if(projectDept.getStatus() == 1){ if("0".equals(projectDept.getParentId())){ projectDeptLists = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .eq(TProjectDept::getParentId, projectDept.getId()) .eq(TProjectDept::getStatus, 1)); }else { projectDeptLists.add(projectDept); } } }else { projectDeptLists = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .ne(TProjectDept::getParentId,0) .eq(TProjectDept::getStatus, 1)); } if(CollectionUtils.isEmpty(projectDeptLists)){ continue; } List<String> proDeptIds = projectDeptLists.stream().map(TProjectDept::getId).collect(Collectors.toList()); // 获取项目部在该模板详情中的权重 List<String> projectDeptIds = redisCache.getCacheList(detail.getId() + PROJECT_DEPT_WEIGHT); // 获取项目部列表 List<TProjectDept> projectDeptList; if(CollectionUtils.isEmpty(projectDeptIds)){ projectDeptList = projectDeptLists; }else { projectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .ne(TProjectDept::getParentId,0) .in(TProjectDept::getId, proDeptIds) .notIn(TProjectDept::getId, projectDeptIds)); // 所过所有的项目部都被抽取了,则重新抽取,并且清空项目部权重 if(CollectionUtils.isEmpty(projectDeptList)){ projectDeptList = projectDeptLists; } } // 如果可抽取的项目部数不足,先抽取余下项目部后,再清空权重,重新抽取 List<TProjectDept> projectDepts = randomSelection(projectDeptList, num2); if(projectDepts.size() < num2){ List<String> proIds = projectDepts.stream().map(TProjectDept::getId).collect(Collectors.toList()); List<TProjectDept> projectDeptList1 = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) .notIn(TProjectDept::getId, proIds) .ne(TProjectDept::getParentId,0)); List<TProjectDept> projectDepts1 = randomSelection(projectDeptList1, num2 - projectDepts.size()); List<String> proIds1 = projectDepts1.stream().map(TProjectDept::getId).collect(Collectors.toList()); // 将已抽取的项目部id保存到redis中 projectDepts.addAll(projectDepts1); }else { List<String> proIds = projectDepts.stream().map(TProjectDept::getId).collect(Collectors.toList()); // 将已抽取的项目部id保存到redis中 } List<String> proIds = projectDepts.stream().map(TProjectDept::getId).collect(Collectors.toList()); // 拿到抽取的项目部下的所有保洁员 // List<TProjectDept> tProjectDeptList = projectDeptService.list(Wrappers.lambdaQuery(TProjectDept.class) // .in(TProjectDept::getId, proIds)); // 获取片区id List<String> areaIds = projectDepts.stream().map(TProjectDept::getId).collect(Collectors.toList()); if(CollectionUtils.isEmpty(areaIds)){ return new ArrayList<>(); } // 计算每天需要抽取多少个保洁员 long count = cleanerService.count(Wrappers.lambdaQuery(TCleaner.class) .in(TCleaner::getProjectId, areaIds)); int cleanerSums = num1 * Integer.parseInt(count + ""); // 获取每天需要抽取的保洁员数,向上取整 if (cleanerSums < cycle){ cleanerSums = cycle; } int dayCleanerCount = cleanerSums / cycle; if((cycle == detail.getCurrentValue()) && cleanerSums % cycle != 0){ dayCleanerCount++; } // 获取保洁员权重 List<String> cleanerIds = redisCache.getCacheList(detail.getId() + CLEANER_WEIGHT); // 获取保洁员列表 List<TCleaner> cleaners; if(CollectionUtils.isEmpty(cleanerIds)){ cleaners = cleanerService.list(Wrappers.lambdaQuery(TCleaner.class) .in(TCleaner::getProjectId, areaIds)); }else { cleaners = cleanerService.list(Wrappers.lambdaQuery(TCleaner.class) .in(TCleaner::getProjectId, areaIds) .notIn(TCleaner::getId, cleanerIds)); if(CollectionUtils.isEmpty(cleaners)){ cleaners = cleanerService.list(Wrappers.lambdaQuery(TCleaner.class) .in(TCleaner::getProjectId, areaIds)); } } // 抽取保洁员 List<TCleaner> tCleaners = randomSelection(cleaners, dayCleanerCount); if(CollectionUtils.isEmpty(tCleaners)){ continue; } if(tCleaners.size() < dayCleanerCount){ List<String> cleanIds = tCleaners.stream().map(TCleaner::getId).collect(Collectors.toList()); List<TCleaner> cleaners1 = cleanerService.list(Wrappers.lambdaQuery(TCleaner.class) .in(TCleaner::getProjectId, areaIds) .notIn(TCleaner::getId, cleanIds)); List<TCleaner> tCleaners1 = randomSelection(cleaners1, dayCleanerCount - tCleaners.size()); List<String> cleanIds1 = tCleaners1.stream().map(TCleaner::getId).collect(Collectors.toList()); // 将已抽取的保洁员id保存到redis中 cleanIds1.addAll(cleanIds); tCleaners.addAll(tCleaners1); }else { List<String> cleanIds = tCleaners.stream().map(TCleaner::getId).collect(Collectors.toList()); } // 通过保洁员id查询点位 List<String> cleanersIds = tCleaners.stream().map(TCleaner::getId).collect(Collectors.toList()); List<TLocation> locationList = locationService.list(Wrappers.lambdaQuery(TLocation.class) .in(TLocation::getLocationCleaner, cleanersIds)); // 查询点位类型 JSONArray jsonArray = JSONObject.parseArray(num4); List<TLocation> tLocationList = new ArrayList<>(); for (Object o : jsonArray) { JSONObject jsonObject = JSONObject.parseObject(o.toString()); String id = jsonObject.getString("id"); BigDecimal value = jsonObject.getBigDecimal("value"); List<TLocation> locations = locationList.stream().filter(tLocation -> tLocation.getLocationType().equals(id)).collect(Collectors.toList()); if(!CollectionUtils.isEmpty(locations)){ BigDecimal bigDecimal = new BigDecimal(locations.size()).multiply(value.divide(new BigDecimal(100), 2, BigDecimal.ROUND_DOWN)).setScale(0, BigDecimal.ROUND_UP); int locationCount = bigDecimal.intValue(); if(locationCount > 0){ List<TLocation> tLocations = randomSelection(locations, locationCount); tLocationList.addAll(tLocations); } } } tLocationList = tLocationList.stream().distinct().collect(Collectors.toList()); // 抽取重复点位 Integer currentValue = detail.getCurrentValue(); if(currentValue != cycle){ // 周期天数加一 detail.setCurrentValue(currentValue + 1); // 获取重复点位 Set<TLocation> repeatLocation = redisCache.getCacheSet(detail.getId() + ":" + sysUser.getUserId() + REPEAT_LOCATION); if(!CollectionUtils.isEmpty(repeatLocation)){ List<TLocation> locations = randomSelection(new ArrayList<>(tLocationList), num3); tLocationList.addAll(locations); } Set<TLocation> locationSet = new HashSet<>(tLocationList); }else { // 设置当前周期为0 detail.setCurrentValue(0); } // 查询请假记录 TLeave leave = leaveService.getOne(Wrappers.lambdaQuery(TLeave.class) .eq(TLeave::getLeavePerson, sysUser.getUserId()) .eq(TLeave::getAuditStatus, 2) .orderByDesc(TLeave::getCreateTime) .last("LIMIT 1")); // 创建任务 List<TTask> tasks = new ArrayList<>(); for (TLocation tLocation : tLocationList) { TTask task = new TTask(); // 获取保洁员 tCleaners.stream().filter(tCleaner -> tCleaner.getId().equals(tLocation.getLocationCleaner())).findFirst().ifPresent(tCleaner -> { task.setProjectId(tCleaner.getProjectId()); task.setCleanerId(tCleaner.getId()); }); // 获取巡检员 task.setPatrolInspector(sysUser.getUserId().toString()); task.setPatrolInspectorDept(sysUser.getDeptId()); task.setUserId(sysUser.getUserId()); task.setStatus(1); task.setLocationId(tLocation.getId()); // 判断今天是否在请假时间内 if(Objects.nonNull(leave) && ((leave.getStartTime().toLocalDate().isBefore(LocalDate.now().plusDays(1)) && leave.getEndTime().toLocalDate().isAfter(LocalDate.now().plusDays(1))) || (leave.getStartTime().toLocalDate().isEqual(LocalDate.now().plusDays(1)) || leave.getEndTime().toLocalDate().isEqual(LocalDate.now().plusDays(1))))){ task.setImplementTime(leave.getEndTime().plusDays(1)); }else { task.setImplementTime(LocalDateTime.now().plusDays(1)); } task.setTaskType(1); task.setTemplateId(detail.getTemplateId()); String nameAndCode = CodeGenerateUtils.generateVolumeSn(); task.setTaskName(nameAndCode); task.setTaskCode(nameAndCode); task.setDisabled(true); tasks.add(task); } // 添加应生成任务数量 TTemplateCount templateCount = new TTemplateCount(); templateCount.setTemplateId(detail.getTemplateId()); // 查询所有的保洁员下面的点位 List<String> cleanIds = cleaners.stream().map(TCleaner::getId).collect(Collectors.toList()); List<TLocation> tLocations = locationService.list(Wrappers.lambdaQuery(TLocation.class) .in(TLocation::getLocationCleaner, cleanIds)); templateCount.setTaskCount(tLocations.size()); templateCount.setUserId(sysUser.getUserId()); // templateCountService.save(templateCount); taskAll.addAll(tasks); taskCleanerService.saveBatch(tasks); taskCount = taskCount + tasks.size(); } template.setTaskCount(taskCount); // templateService.updateById(template); // templateDetailService.updateById(detail); } return taskAll; } @Autowired private TTemplateCountService templateCountService; @Autowired private TCleanerService cleanerService; public static void sortTodayTasks(List<TaskTodayVO> taskList) { Map<Integer, Integer> statusOrder = new HashMap<>(); statusOrder.put(1, 0); @@ -623,6 +938,16 @@ taskList.sort(Comparator.comparingInt((TaskTodayVO o) -> statusOrder.getOrDefault(o.getStatus(), Integer.MAX_VALUE)).thenComparing(TaskTodayVO::getDistance)); } private static <T> List<T> randomSelection(List<T> list, int size) { List<T> selected = new ArrayList<>(); int length = list.size(); for (int i = 0; i < size; i++) { Collections.shuffle(list); // 如果需求的大小超过了集合的长度,则只能取到集合的全部元素 int subListSize = Math.min(size - selected.size(), length); selected.addAll(list.subList(0, subListSize)); } return selected; } } ruoyi-applet/src/main/java/com/ruoyi/web/controller/api/TUserController.java
@@ -122,7 +122,7 @@ @ApiOperation(value = "通过code获得openid,获取用户信息",tags = {"微信小程序登录"}) @GetMapping("/openIdByJsCode") public R<String> openIdByJsCode(@RequestParam String code) { Long userId = tokenService.getLoginUser().getUserId(); Long userId = tokenService.getLoginUserApplet().getUserId(); SysUser sysUser = sysUserService.selectUserById(userId); if(Objects.isNull(sysUser)){ return R.fail("未查询到当前登录用户信息"); ruoyi-system/src/main/java/com/ruoyi/system/mapper/TTaskMapper.java
@@ -30,7 +30,7 @@ List<TaskListVO> pageList(@Param("query")TaskListQuery query, @Param("pageInfo")PageInfo<TaskListVO> pageInfo); List<TaskUserListVO> pageListUser(@Param("query")TaskUserListQuery query, @Param("pageInfo")PageInfo<TaskUserListVO> pageInfo); List<TaskUserListVO> pageListUser(@Param("query")TaskUserListQuery query); /** * 导出任务记录 @@ -46,4 +46,6 @@ List<TLocationTaskListVO> pointInspectionHeatDetailTaskList(@Param("query")PointDetailQuery query, @Param("pageInfo")PageInfo<TLocationTaskListVO> pageInfo); List<TTask> indexTask(@Param("query") IndexDTO dto); List<TTask> getTaskByIds(@Param("ids") List<String> collect1,@Param("lon")String lon,@Param("lat")String lat); } ruoyi-system/src/main/java/com/ruoyi/system/service/TTaskCleanService.java
@@ -51,4 +51,6 @@ List<TTask> indexTask(IndexDTO dto); List<TTask> getTaskByIds(List<String> collect1,String lon,String lat); } ruoyi-system/src/main/java/com/ruoyi/system/service/impl/TTaskCleanServiceImpl.java
@@ -106,16 +106,50 @@ @Override public PageInfo<TaskUserListVO> pageListUser(TaskUserListQuery query) { PageInfo<TaskUserListVO> pageInfo = new PageInfo<>(query.getPageNum(), query.getPageSize()); List<TaskUserListVO> list = this.baseMapper.pageListUser(query,pageInfo); List<TaskUserListVO> list = this.baseMapper.pageListUser(query); List<TTaskDetail> taskDetails = taskDetailMapper.selectList(Wrappers.lambdaQuery(TTaskDetail.class) .eq(TTaskDetail::getHandleType,1) .orderByDesc(TTaskDetail::getCreateTime)); taskDetails = new ArrayList<>(taskDetails.stream() .collect(Collectors.groupingBy( TTaskDetail::getTaskId, Collectors.collectingAndThen( Collectors.toList(), listAll -> listAll.get(0) ) )) .values()); for (TaskUserListVO taskUserListVO : list) { TTaskDetail tTaskDetail = taskDetails.stream().filter(e -> e.getTaskId().equals(taskUserListVO.getId())) .findFirst().orElse(null); if (tTaskDetail!=null){ if (tTaskDetail.getClearStatus()==1){ taskUserListVO.setStatus(5); }else{ taskUserListVO.setStatus(4); } } if (taskUserListVO.getDistance()!=null){ taskUserListVO.setDistance(taskUserListVO.getDistance().divide(new BigDecimal("1000"),2, RoundingMode.HALF_DOWN)); }else{ taskUserListVO.setDistance(new BigDecimal("0")); } } pageInfo.setRecords(list); List<TaskUserListVO> res = new ArrayList<>(); if (query.getClearStatus()!=null){ for (TaskUserListVO taskUserListVO : list) { if (taskUserListVO.getClearStatus().equals(query.getClearStatus())){ res.add(taskUserListVO); } } pageInfo.setRecords(res); pageInfo.setTotal(res.size()); }else{ pageInfo.setRecords(list); pageInfo.setTotal(list.size()); } return pageInfo; } @@ -204,5 +238,10 @@ return this.baseMapper.indexTask(dto); } @Override public List<TTask> getTaskByIds(List<String> collect1,String lon,String lat) { return this.baseMapper.getTaskByIds(collect1,lon,lat); } } ruoyi-system/src/main/resources/mapper/system/TTaskMapper.xml
@@ -66,7 +66,6 @@ t2.location_address as locationAddress, t2.location_address_end as locationAddressEnd, t3.location_icon as locationTypeIcon, t5.clear_status as clearStatus, t4.nick_name as patrolInspectorName, t4.phonenumber as phonenumber, @@ -95,34 +94,19 @@ left join t_location t2 on t1.location_id = t2.id left join t_location_type t3 on t2.location_type = t3.id left join sys_user t4 on t1.patrol_inspector = t4.user_id inner JOIN ( SELECT t1.* FROM t_task_detail t1 left join (SELECT task_id, MAX(create_time) AS max_time FROM t_task_detail GROUP BY task_id order by create_time desc ) AS t2 ON t1.task_id = t2.task_id AND t1.create_time = t2.max_time ) t5 on t1.id = t5.task_id where 1=1 and t1.`disabled` = ${@com.ruoyi.common.enums.DisabledEnum@NO.getCode()} <if test="query.userId != null and query.userId != ''"> and t1.patrol_inspector = #{query.userId} </if> <if test="query.clearStatus != null and query.clearStatus == 1"> and (t1.status = 5 or t1.status = 6) </if> <if test="query.clearStatus != null and query.clearStatus == 2"> and (t1.status = 4 ) </if> <if test="query.clearStatus == null"> and (t1.status = 4 or t1.status = 5 or t1.status = 6 ) </if> <if test="query.startTime != null and query.startTime != ''"> and (t1.implement_time between #{query.startTime} and #{query.endTime}) </if> and (t1.status = 5 or t1.status = 6) order by t1.update_time desc </select> <select id="exportList" resultType="com.ruoyi.system.vo.system.TaskListVO"> @@ -271,5 +255,38 @@ and t1.patrol_inspector = #{query.userId} </select> <select id="getTaskByIds" resultType="com.ruoyi.system.model.TTask"> select t1.*, ROUND( 6378.138 * 2 * ASIN( SQRT( POW( SIN( ( #{lat} * PI() / 180 - t2.location_lat * PI() / 180 ) / 2 ), 2 ) + COS(#{lat} * PI() / 180) * COS(t2.location_lat * PI() / 180) * POW( SIN( ( #{lon} * PI() / 180 - t2.location_lon * PI() / 180 ) / 2 ), 2 ) ) ) * 1000 ) AS distance from t_task t1 left join t_location t2 on t1.location_id = t2.id where 1=1 <if test="ids != null and ids.size()>0"> and t1.id IN <foreach collection="ids" separator="," item="id" open="(" close=")"> #{id} </foreach> </if> </select> </mapper>