|
|
@@ -1,25 +1,28 @@
|
|
|
package com.mirage.mirageservice.service;
|
|
|
|
|
|
+import com.github.pagehelper.PageHelper;
|
|
|
import com.google.common.collect.Lists;
|
|
|
-import com.mirage.mirageservice.domain.CsMinWechatUser;
|
|
|
-import com.mirage.mirageservice.domain.FamilyMemberInfo;
|
|
|
-import com.mirage.mirageservice.domain.FamilyRelationInfo;
|
|
|
-import com.mirage.mirageservice.domain.FamilyTreeInfo;
|
|
|
+import com.mirage.core.meta.PageResultVo;
|
|
|
+import com.mirage.core.meta.PageUtil;
|
|
|
+import com.mirage.core.utils.GsonUtil;
|
|
|
+import com.mirage.mirageservice.domain.*;
|
|
|
import com.mirage.mirageservice.enums.FamilyRelationEnum;
|
|
|
import com.mirage.mirageservice.mapper.mysql.FamilyMemberInfoMapper;
|
|
|
+import com.mirage.mirageservice.mapper.mysql.FamilyMemberPhotoAlbumMapper;
|
|
|
+import com.mirage.mirageservice.mapper.mysql.FamilyMomentsMapper;
|
|
|
import com.mirage.mirageservice.mapper.mysql.FamilyRelationInfoMapper;
|
|
|
-import com.mirage.mirageservice.meta.FamilyMemberInfoAndRelation;
|
|
|
-import com.mirage.mirageservice.meta.FamilyTreeResponse;
|
|
|
-import com.mirage.mirageservice.meta.MemberInfoRequest;
|
|
|
-import com.mirage.mirageservice.meta.SelfFamilyCardResponse;
|
|
|
+import com.mirage.mirageservice.meta.*;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.Date;
|
|
|
+import java.util.LinkedList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -29,10 +32,17 @@ import java.util.stream.Collectors;
|
|
|
@Slf4j
|
|
|
public class FamilyService {
|
|
|
|
|
|
+ private static final String REDIS_MOMENTS_LAST_ID = "redis_moments_last_id_";
|
|
|
+ @Resource
|
|
|
+ private StringRedisTemplate stringRedisTemplate;
|
|
|
@Resource
|
|
|
private FamilyMemberInfoMapper familyMemberInfoMapper;
|
|
|
@Resource
|
|
|
private FamilyRelationInfoMapper familyRelationInfoMapper;
|
|
|
+ @Resource
|
|
|
+ private FamilyMemberPhotoAlbumMapper familyMemberPhotoAlbumMapper;
|
|
|
+ @Resource
|
|
|
+ private FamilyMomentsMapper familyMomentsMapper;
|
|
|
|
|
|
public SelfFamilyCardResponse getSelfFamilyMember(Long uid){
|
|
|
SelfFamilyCardResponse familyCardResponse = new SelfFamilyCardResponse();
|
|
|
@@ -219,12 +229,14 @@ public class FamilyService {
|
|
|
if(null == selfMemberInfo){
|
|
|
throw new Exception("请先填写自己信息再录入亲属信息");
|
|
|
}
|
|
|
+ // 当帮其他人填写亲属信息时,替换此信息,关系表中关联用户非自己
|
|
|
+ Long operationMid = null == request.getSourceMid() ? selfMemberInfo.getId() : request.getSourceMid();
|
|
|
// 保存亲属关系
|
|
|
FamilyRelationInfo relationInfo = null;
|
|
|
switch (relationEnum) {
|
|
|
case FATHER:
|
|
|
relationInfo = new FamilyRelationInfo();
|
|
|
- relationInfo.setChildMid(selfMemberInfo.getId());
|
|
|
+ relationInfo.setChildMid(operationMid);
|
|
|
relationInfo.setParentMid(memberInfo.getId());
|
|
|
relationInfo.setRelationType(FamilyRelationEnum.FATHER.getType());
|
|
|
relationInfo.setSubRelationType(request.getRelationRequest().getSubRelationType());
|
|
|
@@ -233,7 +245,7 @@ public class FamilyService {
|
|
|
break;
|
|
|
case MATHER:
|
|
|
relationInfo = new FamilyRelationInfo();
|
|
|
- relationInfo.setChildMid(selfMemberInfo.getId());
|
|
|
+ relationInfo.setChildMid(operationMid);
|
|
|
relationInfo.setParentMid(memberInfo.getId());
|
|
|
relationInfo.setRelationType(FamilyRelationEnum.MATHER.getType());
|
|
|
relationInfo.setSubRelationType(request.getRelationRequest().getSubRelationType());
|
|
|
@@ -252,7 +264,7 @@ public class FamilyService {
|
|
|
case DAUGHTER:
|
|
|
relationInfo = new FamilyRelationInfo();
|
|
|
relationInfo.setChildMid(memberInfo.getId());
|
|
|
- relationInfo.setParentMid(selfMemberInfo.getId());
|
|
|
+ relationInfo.setParentMid(operationMid);
|
|
|
relationInfo.setRelationType(FamilyRelationEnum.FATHER.getType());
|
|
|
relationInfo.setSubRelationType(request.getRelationRequest().getSubRelationType());
|
|
|
relationInfo.setRelationValue(request.getRelationRequest().getRelationValue());
|
|
|
@@ -271,7 +283,7 @@ public class FamilyService {
|
|
|
break;
|
|
|
}
|
|
|
if(null != relationInfo) {
|
|
|
- relationInfo.setSourceMid(selfMemberInfo.getId());
|
|
|
+ relationInfo.setSourceMid(operationMid);
|
|
|
relationInfo.setRelationStatus(request.getRelationRequest().getRelationStatus());
|
|
|
relationInfo.setCreateTime(new Date());
|
|
|
relationInfo.setModifiedTime(new Date());
|
|
|
@@ -284,4 +296,201 @@ public class FamilyService {
|
|
|
}
|
|
|
return memberInfo;
|
|
|
}
|
|
|
+
|
|
|
+ public boolean uploadMemberAlbum(Long uid, FamilyMemberPhotoAlbum memberPhotoAlbum){
|
|
|
+ if(null == uid
|
|
|
+ || null == memberPhotoAlbum
|
|
|
+ || StringUtils.isBlank(memberPhotoAlbum.getUrl())){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // mid为空上传自己相册
|
|
|
+ if(null == memberPhotoAlbum.getMid()){
|
|
|
+ FamilyMemberInfo memberInfo = this.getMemberByUid(uid);
|
|
|
+ if(null == memberInfo){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ memberPhotoAlbum.setMid(memberInfo.getId());
|
|
|
+ }
|
|
|
+ memberPhotoAlbum.setUid(uid);
|
|
|
+ memberPhotoAlbum.setGmtCreate(new Date());
|
|
|
+ memberPhotoAlbum.setGmtModified(new Date());
|
|
|
+ memberPhotoAlbum.setUploadTime(new Date());
|
|
|
+ memberPhotoAlbum.setIsDeleted(0);
|
|
|
+ familyMemberPhotoAlbumMapper.insertSelective(memberPhotoAlbum);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public PageResultVo<FamilyMemberPhotoAlbum> getMemberPhotoAlbum(Long mid, Integer type, Integer pageSize, Integer pageIndex){
|
|
|
+ if(null == mid){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ PageHelper.startPage(pageIndex, pageSize);
|
|
|
+ return PageUtil.convertPageResult(familyMemberPhotoAlbumMapper.selectAllByMidAndTypeAndIsDeletedOrderByUploadTimeDesc(mid, type, 0));
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean deletePhotoAlbumById(Long id){
|
|
|
+ if(null == id){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ FamilyMemberPhotoAlbum familyMemberPhotoAlbum = familyMemberPhotoAlbumMapper.selectByPrimaryKey(id);
|
|
|
+ if(null == familyMemberPhotoAlbum || familyMemberPhotoAlbum.getIsDeleted() == 1){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ familyMemberPhotoAlbum.setIsDeleted(1);
|
|
|
+ familyMemberPhotoAlbum.setGmtModified(new Date());
|
|
|
+ familyMemberPhotoAlbumMapper.updateByPrimaryKeySelective(familyMemberPhotoAlbum);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean addFamilyMoments(Long uid, MomentsRequest momentsRequest){
|
|
|
+ if(null == uid
|
|
|
+ || null == momentsRequest.getType()
|
|
|
+ || null == momentsRequest.getVisibleType()
|
|
|
+ || null == momentsRequest.getContentInfo()){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ FamilyMemberInfo memberInfo = this.getMemberByUid(uid);
|
|
|
+ if(null == memberInfo){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ // 可见范围:0:全员 1:支系堂派 2:聚落 3:家族内男性 4:出生地
|
|
|
+ FamilyMoments familyMoments = new FamilyMoments();
|
|
|
+ familyMoments.setType(momentsRequest.getType());
|
|
|
+ familyMoments.setExpireTime(momentsRequest.getExpireTime());
|
|
|
+ familyMoments.setContent(GsonUtil.toJson(momentsRequest.getContentInfo()));
|
|
|
+ familyMoments.setPublishUid(uid);
|
|
|
+ familyMoments.setPublishTime(new Date());
|
|
|
+ familyMoments.setVisibleType(momentsRequest.getVisibleType());
|
|
|
+ if(momentsRequest.getVisibleType() == 1){
|
|
|
+ familyMoments.setVisibleValue(memberInfo.getBranchFamilyHall());
|
|
|
+ } else if(momentsRequest.getVisibleType() == 2){
|
|
|
+ familyMoments.setVisibleValue(memberInfo.getClusterPlace());
|
|
|
+ } else if (momentsRequest.getVisibleType() == 3) {
|
|
|
+ familyMoments.setVisibleValue("1");
|
|
|
+ } else if (momentsRequest.getVisibleType() == 4) {
|
|
|
+ familyMoments.setVisibleValue(memberInfo.getBirthPlace());
|
|
|
+ }
|
|
|
+ familyMoments.setIsDeleted(0);
|
|
|
+ familyMoments.setGmtCreate(new Date());
|
|
|
+ familyMoments.setGmtModified(new Date());
|
|
|
+ familyMomentsMapper.insertSelective(familyMoments);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean deleteMoments(Long id, Long uid){
|
|
|
+ if(null == id || null == uid){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ FamilyMoments moments = familyMomentsMapper.selectByPrimaryKey(id);
|
|
|
+ if(null == moments || moments.getIsDeleted() == 1){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if(!Objects.equals(moments.getPublishUid(), uid)){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ moments.setIsDeleted(1);
|
|
|
+ moments.setGmtModified(new Date());
|
|
|
+ familyMomentsMapper.updateByPrimaryKeySelective(moments);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<FamilyMomentsAndPublishInfo> getFamilyAnnouncementList(Long uid){
|
|
|
+ LinkedList<FamilyMomentsAndPublishInfo> result = Lists.newLinkedList();
|
|
|
+ List<FamilyMoments> familyMoments = familyMomentsMapper.selectAllByTypeAndExpireTimeGreaterThanOrExpireTimeAndIsDeletedAndVisibleTypeOrderByPublishTimeDesc(1, System.currentTimeMillis(), -1L, 0, null);
|
|
|
+ if(null == familyMoments || familyMoments.isEmpty()){
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ for(FamilyMoments moments : familyMoments){
|
|
|
+ FamilyMemberInfo memberInfo = familyMemberInfoMapper.selectByUid(moments.getPublishUid());
|
|
|
+ result.add(new FamilyMomentsAndPublishInfo(moments, memberInfo));
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<FamilyMomentsAndPublishInfo> getUserMomentsList(Long uid, Long lastId, Integer pageSize){
|
|
|
+ FamilyMemberInfo memberInfo = familyMemberInfoMapper.selectByUid(uid);
|
|
|
+ if(null == memberInfo){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ LinkedList<FamilyMomentsAndPublishInfo> result = Lists.newLinkedList();
|
|
|
+ List<FamilyMoments> familyMoments = familyMomentsMapper.selectAllMoments(0, 0, null, lastId, pageSize);
|
|
|
+ if(null == familyMoments || familyMoments.isEmpty()){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ for(FamilyMoments moments : familyMoments){
|
|
|
+ if(moments.getVisibleType() == 0){
|
|
|
+ result.add(new FamilyMomentsAndPublishInfo(moments, memberInfo));
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if(moments.getVisibleType() == 1
|
|
|
+ && StringUtils.isNotBlank(memberInfo.getBranchFamilyHall())
|
|
|
+ && memberInfo.getBranchFamilyHall().equals(moments.getVisibleValue())){
|
|
|
+ result.add(new FamilyMomentsAndPublishInfo(moments, memberInfo));
|
|
|
+ } else if(moments.getVisibleType() == 2
|
|
|
+ && StringUtils.isNotBlank(memberInfo.getClusterPlace())
|
|
|
+ && memberInfo.getClusterPlace().equals(moments.getVisibleValue())){
|
|
|
+ result.add(new FamilyMomentsAndPublishInfo(moments, memberInfo));
|
|
|
+ } else if (moments.getVisibleType() == 3
|
|
|
+ && Integer.parseInt(moments.getVisibleValue()) == memberInfo.getSex()) {
|
|
|
+ result.add(new FamilyMomentsAndPublishInfo(moments, memberInfo));
|
|
|
+ } else if (moments.getVisibleType() == 4
|
|
|
+ && StringUtils.isNotBlank(memberInfo.getBirthPlace())
|
|
|
+ && (memberInfo.getBirthPlace().contains(moments.getVisibleValue())
|
|
|
+ || memberInfo.getBirthPlace().equalsIgnoreCase(moments.getVisibleValue()))) {
|
|
|
+ result.add(new FamilyMomentsAndPublishInfo(moments, memberInfo));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 最后一个id记录,用于红点提示
|
|
|
+ Long alreadyReadId = result.get(result.size() - 1).getFamilyMoments().getId();
|
|
|
+ stringRedisTemplate.boundValueOps(REDIS_MOMENTS_LAST_ID).set(String.valueOf(alreadyReadId));
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新家族圈消息提示.
|
|
|
+ *
|
|
|
+ * @param uid
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean newsRedDot(Long uid){
|
|
|
+ if(null == uid){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ String cacheValue = stringRedisTemplate.boundValueOps(REDIS_MOMENTS_LAST_ID).get();
|
|
|
+ Long lastId = StringUtils.isBlank(cacheValue) ? null : Long.parseLong(cacheValue);
|
|
|
+ List<FamilyMoments> familyMoments = familyMomentsMapper.selectAllMoments(0, 0, null, lastId, 1000);
|
|
|
+ if(null == familyMoments || familyMoments.isEmpty()){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ FamilyMemberInfo memberInfo = this.getMemberByUid(uid);
|
|
|
+ if(null == memberInfo){
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ for(FamilyMoments moments : familyMoments){
|
|
|
+ if(moments.getVisibleType() == 0){
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ if(moments.getVisibleType() == 1
|
|
|
+ && StringUtils.isNotBlank(memberInfo.getBranchFamilyHall())
|
|
|
+ && memberInfo.getBranchFamilyHall().equals(moments.getVisibleValue())){
|
|
|
+ return true;
|
|
|
+ } else if(moments.getVisibleType() == 2
|
|
|
+ && StringUtils.isNotBlank(memberInfo.getClusterPlace())
|
|
|
+ && memberInfo.getClusterPlace().equals(moments.getVisibleValue())){
|
|
|
+ return true;
|
|
|
+ } else if (moments.getVisibleType() == 3
|
|
|
+ && Integer.parseInt(moments.getVisibleValue()) == memberInfo.getSex()) {
|
|
|
+ return true;
|
|
|
+ } else if (moments.getVisibleType() == 4
|
|
|
+ && StringUtils.isNotBlank(memberInfo.getBirthPlace())
|
|
|
+ && (memberInfo.getBirthPlace().contains(moments.getVisibleValue())
|
|
|
+ || memberInfo.getBirthPlace().equalsIgnoreCase(moments.getVisibleValue()))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
+
|
|
|
+
|