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/SOSTargetInfoServiceImpl.java |  173 ++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 110 insertions(+), 63 deletions(-)

diff --git a/app/src/main/java/com/yeshi/location/app/service/impl/sos/SOSTargetInfoServiceImpl.java b/app/src/main/java/com/yeshi/location/app/service/impl/sos/SOSTargetInfoServiceImpl.java
index c3b873f..0013f08 100644
--- a/app/src/main/java/com/yeshi/location/app/service/impl/sos/SOSTargetInfoServiceImpl.java
+++ b/app/src/main/java/com/yeshi/location/app/service/impl/sos/SOSTargetInfoServiceImpl.java
@@ -1,86 +1,133 @@
 package com.yeshi.location.app.service.impl.sos;
 
-import java.lang.Exception;
-import javax.annotation.Resource;
-import org.springframework.stereotype.Service;
-import java.util.Date;
-import org.yeshi.utils.bean.BeanUtil;
-import java.util.List;
 import com.yeshi.location.app.dao.sos.SOSTargetInfoDao;
+import com.yeshi.location.app.dao.sos.SOSTargetInfoDao.DaoQuery;
+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 com.yeshi.location.app.service.inter.sos.SOSTargetInfoService;
 import com.yeshi.location.app.service.query.sos.SOSTargetInfoQuery;
-import com.yeshi.location.app.dao.sos.SOSTargetInfoDao.DaoQuery;
-
 import org.springframework.data.mongodb.core.query.Criteria;
 import org.springframework.data.mongodb.core.query.Query;
+import org.springframework.stereotype.Service;
+import org.yeshi.utils.bean.BeanUtil;
+
+import javax.annotation.Resource;
+import java.util.*;
 
 @Service
-public class SOSTargetInfoServiceImpl implements SOSTargetInfoService{
+public class SOSTargetInfoServiceImpl implements SOSTargetInfoService {
 
-  @Resource
-  private SOSTargetInfoDao sOSTargetInfoDao;
+    @Resource
+    private SOSTargetInfoDao sOSTargetInfoDao;
 
-  @Override
-  public List<SOSTargetInfo> list(SOSTargetInfoQuery sOSTargetInfoQuery, int page, int pageSize)  {
-    DaoQuery daoQuery = new DaoQuery();
-    try {
-        BeanUtil.copyProperties(sOSTargetInfoQuery, daoQuery);
-    } catch (IllegalAccessException e) {
-          e.printStackTrace();
+    @Resource
+    private SOSRecordListService sosRecordListService;
+
+    @Override
+    public List<SOSTargetInfo> list(SOSTargetInfoQuery sOSTargetInfoQuery, int page, int pageSize) {
+        DaoQuery daoQuery = new DaoQuery();
+        try {
+            BeanUtil.copyProperties(sOSTargetInfoQuery, daoQuery);
+        } catch (IllegalAccessException e) {
+            e.printStackTrace();
+        }
+        daoQuery.start = (page - 1) * pageSize;
+        daoQuery.count = pageSize;
+        return sOSTargetInfoDao.list(daoQuery);
     }
-    daoQuery.start=(page-1)*pageSize;
-    daoQuery.count=pageSize;
-    return sOSTargetInfoDao.list(daoQuery);
-  }
 
-  @Override
-  public long count(SOSTargetInfoQuery sOSTargetInfoQuery)  {
-    DaoQuery daoQuery = new DaoQuery();
-    try {
-        BeanUtil.copyProperties(sOSTargetInfoQuery, daoQuery);
-    } catch (IllegalAccessException e) {
-          e.printStackTrace();
+    @Override
+    public long count(SOSTargetInfoQuery sOSTargetInfoQuery) {
+        DaoQuery daoQuery = new DaoQuery();
+        try {
+            BeanUtil.copyProperties(sOSTargetInfoQuery, daoQuery);
+        } catch (IllegalAccessException e) {
+            e.printStackTrace();
+        }
+        return sOSTargetInfoDao.count(daoQuery);
     }
-    return sOSTargetInfoDao.count(daoQuery);
-  }
 
-  @Override
-  public SOSTargetInfo get(String id)  {
-    Query query=new Query();
-    query.addCriteria(Criteria.where("_id").is(id));
-    return sOSTargetInfoDao.findOne(query);
-  }
+    @Override
+    public SOSTargetInfo get(String id) {
+        Query query = new Query();
+        query.addCriteria(Criteria.where("_id").is(id));
+        return sOSTargetInfoDao.findOne(query);
+    }
 
-  @Override
-  public void add(SOSTargetInfo sOSTargetInfo)  throws Exception {
-     //鏌ヨ涓婚敭ID鏄惁瀛樺湪
-     if(sOSTargetInfoDao.get(sOSTargetInfo.getId())!=null){
-        throw new Exception("宸插瓨鍦�");
-     }
+    @Override
+    public void add(SOSTargetInfo sOSTargetInfo) throws Exception {
 
-     if(sOSTargetInfo.getCreateTime()==null){
-        sOSTargetInfo.setCreateTime(new Date());
-     }
-     //淇濆瓨
-     sOSTargetInfoDao.save(sOSTargetInfo);
-  }
+        if (sOSTargetInfo == null || sOSTargetInfo.getTargetUid() == null || sOSTargetInfo.getSosId() == null) {
+            throw new Exception("鍙傛暟涓嶅畬鏁�");
+        }
 
-  @Override
-  public void update(SOSTargetInfo sOSTargetInfo)  {
-     if(sOSTargetInfo.getUpdateTime()==null){
-        sOSTargetInfo.setUpdateTime(new Date());
-     }
-     //鏇存柊
-     sOSTargetInfoDao.updateSelective(sOSTargetInfo);
-  }
+        if (sOSTargetInfo.getId() == null) {
+            sOSTargetInfo.setId(SOSTargetInfo.createId(sOSTargetInfo.getSosId(), sOSTargetInfo.getTargetUid()));
+        }
+        //鏌ヨ涓婚敭ID鏄惁瀛樺湪
+        if (sOSTargetInfoDao.get(sOSTargetInfo.getId()) != null) {
+            throw new Exception("宸插瓨鍦�");
+        }
 
-  @Override
-  public void delete(List<String> idList)  {
-     for (String id : idList){
-        sOSTargetInfoDao.delete(id);
-     }
-  }
+        if (sOSTargetInfo.getStatus() == null) {
+            sOSTargetInfo.setStatus(SOSTargetInfo.STATUS_UNREAD);
+            sOSTargetInfo.setStatusDesc("鏈");
+        }
+
+        if (sOSTargetInfo.getCreateTime() == null) {
+            sOSTargetInfo.setCreateTime(new Date());
+        }
+
+
+        //淇濆瓨
+        sOSTargetInfoDao.save(sOSTargetInfo);
+
+        SOSRecordList recordList = new SOSRecordList();
+        recordList.setSourceId(sOSTargetInfo.getId());
+        recordList.setType(SOSRecordList.SOSRecordType.passive);
+        recordList.setUid(sOSTargetInfo.getTargetUid());
+        sosRecordListService.add(recordList);
+    }
+
+    @Override
+    public void update(SOSTargetInfo sOSTargetInfo) {
+        if (sOSTargetInfo.getUpdateTime() == null) {
+            sOSTargetInfo.setUpdateTime(new Date());
+        }
+        //鏇存柊
+        sOSTargetInfoDao.updateSelective(sOSTargetInfo);
+    }
+
+    @Override
+    public void delete(List<String> idList) {
+        for (String id : idList) {
+            sOSTargetInfoDao.delete(id);
+        }
+    }
+
+    @Override
+    public List<SOSTargetInfo> 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<SOSTargetInfo> list = sOSTargetInfoDao.findList(query);
+        Comparator<SOSTargetInfo> cm = (SOSTargetInfo o1, SOSTargetInfo o2) -> {
+            return ids.indexOf(o1.getId()) - ids.indexOf(o2.getId());
+        };
+        Collections.sort(list, cm);
+        return list;
+    }
 
 
 }
\ No newline at end of file

--
Gitblit v1.8.0