From 4f015b8c624484e0c3b2d88b944163ce43a48d1f Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 27 十一月 2021 17:15:28 +0800
Subject: [PATCH] 功能完善

---
 app/src/main/java/com/yeshi/location/app/service/impl/sos/SOSRecordServiceImpl.java |   80 ++++++++++++++++++++++++++++++++++++++--
 1 files changed, 76 insertions(+), 4 deletions(-)

diff --git a/app/src/main/java/com/yeshi/location/app/service/impl/sos/SOSRecordServiceImpl.java b/app/src/main/java/com/yeshi/location/app/service/impl/sos/SOSRecordServiceImpl.java
index 1ae0fa1..a905a47 100644
--- a/app/src/main/java/com/yeshi/location/app/service/impl/sos/SOSRecordServiceImpl.java
+++ b/app/src/main/java/com/yeshi/location/app/service/impl/sos/SOSRecordServiceImpl.java
@@ -3,15 +3,18 @@
 import java.lang.Exception;
 import javax.annotation.Resource;
 
+import com.sun.org.apache.regexp.internal.RECompiler;
+import com.yeshi.location.app.dao.sos.SOSTargetInfoDao;
+import com.yeshi.location.app.entity.sos.SOSRecordList;
+import com.yeshi.location.app.entity.sos.SOSTargetInfo;
+import com.yeshi.location.app.service.inter.sos.SOSRecordListService;
 import org.springframework.data.domain.Sort;
 import org.springframework.stereotype.Service;
 
-import java.util.Arrays;
-import java.util.Date;
+import java.util.*;
 
+import org.yeshi.utils.TimeUtil;
 import org.yeshi.utils.bean.BeanUtil;
-
-import java.util.List;
 
 import com.yeshi.location.app.dao.sos.SOSRecordDao;
 import com.yeshi.location.app.entity.sos.SOSRecord;
@@ -27,6 +30,12 @@
 
     @Resource
     private SOSRecordDao sOSRecordDao;
+
+    @Resource
+    private SOSTargetInfoDao sosTargetInfoDao;
+
+    @Resource
+    private SOSRecordListService sosRecordListService;
 
     @Override
     public List<SOSRecord> list(SOSRecordQuery sOSRecordQuery, int page, int pageSize) {
@@ -62,6 +71,11 @@
 
     @Override
     public void add(SOSRecord sOSRecord) throws Exception {
+
+        if (sOSRecord.getId() == null) {
+            sOSRecord.setId(sOSRecord.getUid() + "-" + TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMddHHmmssSSS"));
+        }
+
         //鏌ヨ涓婚敭ID鏄惁瀛樺湪
         if (sOSRecordDao.get(sOSRecord.getId()) != null) {
             throw new Exception("宸插瓨鍦�");
@@ -70,8 +84,17 @@
         if (sOSRecord.getCreateTime() == null) {
             sOSRecord.setCreateTime(new Date());
         }
+
+
         //淇濆瓨
         sOSRecordDao.save(sOSRecord);
+
+        //娣诲姞鍒板垪琛ㄨ褰�
+        SOSRecordList recordList = new SOSRecordList();
+        recordList.setSourceId(sOSRecord.getId());
+        recordList.setType(SOSRecordList.SOSRecordType.initiative);
+        recordList.setUid(sOSRecord.getUid());
+        sosRecordListService.add(recordList);
     }
 
     @Override
@@ -90,5 +113,54 @@
         }
     }
 
+    @Override
+    public void deleteAll(Long uid) {
+        Query query = new Query();
+        query.addCriteria(Criteria.where("uid").is(uid));
+        sOSRecordDao.delete(query);
+    }
+
+    @Override
+    public List<SOSRecord> listByIds(List<String> ids) {
+
+        if (ids == null || ids.size() == 0) {
+            return new ArrayList<>();
+        }
+        List<Criteria> orList = new ArrayList<>();
+        for (String id : ids) {
+            orList.add(Criteria.where("_id").is(id));
+        }
+        Criteria[] ors = new Criteria[orList.size()];
+        orList.toArray(ors);
+
+        Query query = new Query();
+        query.addCriteria(new Criteria().orOperator(ors));
+        List<SOSRecord> list = sOSRecordDao.findList(query);
+        Comparator<SOSRecord> cm = (SOSRecord o1, SOSRecord o2) -> {
+            return ids.indexOf(o1.getId()) - ids.indexOf(o2.getId());
+        };
+        Collections.sort(list, cm);
+        return list;
+    }
+
+    @Override
+    public List<SOSRecord> listDetail(List<String> ids) {
+        List<SOSRecord> list = listByIds(ids);
+        List<SOSTargetInfo> targetList = sosTargetInfoDao.listBySOSIds(ids);
+        Map<String, List<SOSTargetInfo>> map = new HashMap<>();
+        for (SOSTargetInfo targetInfo : targetList) {
+            if (map.get(targetInfo.getSosId()) == null) {
+                map.put(targetInfo.getSosId(), new ArrayList<>());
+            }
+            map.get(targetInfo.getSosId()).add(targetInfo);
+        }
+
+        for (SOSRecord record : list) {
+            record.setTargetList(map.get(record.getId()));
+        }
+
+        return list;
+    }
+
 
 }
\ No newline at end of file

--
Gitblit v1.8.0