|
@@ -1,20 +1,23 @@
|
|
|
package com.bofeng.service;
|
|
|
|
|
|
import com.baomidou.mybatisplus.toolkit.IdWorker;
|
|
|
-import com.bofeng.dao.OutScanEstateMapper;
|
|
|
-import com.bofeng.dao.OutScanMapper;
|
|
|
-import com.bofeng.entity.OutScan;
|
|
|
-import com.bofeng.entity.OutScanEstate;
|
|
|
+import com.bofeng.dao.*;
|
|
|
+import com.bofeng.entity.*;
|
|
|
+import lombok.SneakyThrows;
|
|
|
import org.gavaghan.geodesy.Ellipsoid;
|
|
|
import org.gavaghan.geodesy.GeodeticCalculator;
|
|
|
import org.gavaghan.geodesy.GlobalCoordinates;
|
|
|
import org.joda.time.DateTime;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
|
|
|
@Service
|
|
|
@Transactional(readOnly = true)
|
|
@@ -24,6 +27,14 @@ public class ScanService {
|
|
|
private OutScanMapper outScanMapper;
|
|
|
@Autowired
|
|
|
private OutScanEstateMapper outScanEstateMapper;
|
|
|
+ @Autowired
|
|
|
+ private UserOpenMapper userOpenMapper;
|
|
|
+ @Autowired
|
|
|
+ private OutUserMapper outUserMapper;
|
|
|
+ @Autowired
|
|
|
+ private MsReportMapper msReportMapper;
|
|
|
+ @Autowired
|
|
|
+ private ReturnWorkLyMapper returnWorkLyMapper;
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
|
|
|
public void saveOutScan(Long userId, Integer inType, String coord, String address, Long uptownId, Long doorId, Integer status, String errorInfo) {
|
|
@@ -68,6 +79,7 @@ public class ScanService {
|
|
|
|
|
|
/**
|
|
|
* 根据经纬度查询距离
|
|
|
+ *
|
|
|
* @param longitudeFrom
|
|
|
* @param latitudeFrom
|
|
|
* @param longitudeTo
|
|
@@ -79,4 +91,103 @@ public class ScanService {
|
|
|
GlobalCoordinates target = new GlobalCoordinates(latitudeTo, longitudeTo);
|
|
|
return new GeodeticCalculator().calculateGeodeticCurve(Ellipsoid.Sphere, source, target).getEllipsoidalDistance();
|
|
|
}
|
|
|
+
|
|
|
+ // @Async
|
|
|
+ @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED)
|
|
|
+ public void returnWorkLY() {
|
|
|
+ new Runnable() {
|
|
|
+ @SneakyThrows
|
|
|
+ @Override
|
|
|
+ public void run() {
|
|
|
+ returnWorkLyMapper.deleteReturnWork();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ List<UserOpen> opens = userOpenMapper.getUsersByUptownId(1238790987234L);
|
|
|
+ ReturnWorkLy r = new ReturnWorkLy();
|
|
|
+ for (int i = 0; i < opens.size(); i++) {
|
|
|
+ OutUser outUser1 = outUserMapper.getOutUserByPhone(4, opens.get(i).getLinkman(), Long.parseLong(opens.get(i).getPhone()));
|
|
|
+ if (outUser1 != null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ OutUser outUser = outUserMapper.getOutUserByPhone(1, opens.get(i).getLinkman(), Long.parseLong(opens.get(i).getPhone()));
|
|
|
+ if (outUser != null) {
|
|
|
+ r.setRwId(IdWorker.getId());
|
|
|
+ r.setUserId(opens.get(i).getUserId());
|
|
|
+ r.setTimeCreate(new DateTime());
|
|
|
+ returnWorkLyMapper.insert(r);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ Boolean ly2 = false;
|
|
|
+ String startDate = "";
|
|
|
+ int intSize = 4;
|
|
|
+ OutUser outUser2 = outUserMapper.getOutUserByPhoneNotTime(5, opens.get(i).getLinkman(), Long.parseLong(opens.get(i).getPhone()));
|
|
|
+ if (outUser2 != null) {
|
|
|
+ ly2 = true;
|
|
|
+ startDate = s.format(outUser2.getStartDate());
|
|
|
+ Long day = (new Date().getTime() - outUser2.getStartDate().getTime()) / (1000 * 60 * 60 * 24);
|
|
|
+ intSize = Integer.parseInt(Long.toString(day)) < 4 ? Integer.parseInt(Long.toString(day)) : 4;
|
|
|
+ }
|
|
|
+ MsReport msReport = msReportMapper.queryMsReportIsXG(opens.get(i).getUserId());
|
|
|
+ if (msReport != null) {
|
|
|
+ if (ly2 && outUser2.getStartDate().getTime() < msReport.getReportDate().getTime()) {
|
|
|
+ continue;
|
|
|
+ } else if (!ly2) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<MsReport> msReportList = msReportMapper.queryMsReportIsXGHome(opens.get(i).getUserId());
|
|
|
+ if (msReportList.size() > 0) {
|
|
|
+ if (ly2 && outUser2.getStartDate().getTime() < msReportList.get(0).getReportDate().getTime()) {
|
|
|
+ continue;
|
|
|
+ } else if (!ly2) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<MsReport> msReports = msReportMapper.selectMsReportLate(opens.get(i).getUserId(), startDate);
|
|
|
+ if (msReports.size() < intSize) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<MsReport> msReports2 = msReportMapper.selectMsReportThereError(opens.get(i).getUserId(), startDate);
|
|
|
+ if (msReports2.size() > 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ List<MsReport> msReports3 = msReportMapper.selectMsReportThereErrorFamily(opens.get(i).getUserId(), startDate);
|
|
|
+ if (msReports3.size() > 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ MsTripDet work = msReportMapper.returnWork(opens.get(i).getUserId());
|
|
|
+ if (work != null) {
|
|
|
+ if (ly2 && outUser2.getStartDate().getTime() < s.parse(work.getReturnWork()).getTime()) {
|
|
|
+ if (sdf.parse(work.getReturnWork() + " 00:00:00").getTime() + 1000L * 3600 * 24 * 15 > sdf.parse(s.format(new Date()) + " 00:00:00").getTime()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ } else if (!ly2) {
|
|
|
+ if (sdf.parse(work.getReturnWork() + " 00:00:00").getTime() + 1000L * 3600 * 24 * 15 > sdf.parse(s.format(new Date()) + " 00:00:00").getTime()) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ MsReport msReport1 = msReportMapper.msAddr(opens.get(i).getUserId());
|
|
|
+ if (msReport1 != null && !msReport1.getWorkMsg().equals(msReport1.getTodayMsg()) && !compareWhere(msReport1.getWorkMsg(), msReport1.getTodayMsg())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ r.setRwId(IdWorker.getId());
|
|
|
+ r.setUserId(opens.get(i).getUserId());
|
|
|
+ r.setTimeCreate(new DateTime());
|
|
|
+ returnWorkLyMapper.insert(r);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }.run();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 比较出发地和目地地是否一样, 一样返回true,不一样返回false
|
|
|
+ */
|
|
|
+ public Boolean compareWhere(String str1, String str2) {
|
|
|
+ Boolean type = false;
|
|
|
+ if ((str1.equals("2") || str1.equals("3")) && (str2.equals("2") || str2.equals("3"))) {
|
|
|
+ type = true;
|
|
|
+ }
|
|
|
+ return type;
|
|
|
+ }
|
|
|
}
|