用户信息接口完善

master
panqihua 5 years ago
parent f4b06b0fdd
commit 096dea346c
  1. 10
      src/main/java/com/community/pocket/entity/vo/android/Info.java
  2. 20
      src/main/java/com/community/pocket/repository/android/UserDao.java
  3. 10
      src/main/java/com/community/pocket/util/LookupOperationUtil.java
  4. 7
      src/test/java/com/community/pocket/DemoApplicationTests.java

@ -6,7 +6,7 @@ import java.util.List;
public class Info { public class Info {
//用户名 //用户名
private String username; private String id;
//信用分 //信用分
private Integer creditScore; private Integer creditScore;
//头像 //头像
@ -22,12 +22,12 @@ public class Info {
//信用分历史记录 //信用分历史记录
private List<CreditScore> scoreHistory; private List<CreditScore> scoreHistory;
public String getUsername() { public String getId() {
return username; return id;
} }
public void setUsername(String username) { public void setId(String id) {
this.username = username; this.id = id;
} }
public Integer getCreditScore() { public Integer getCreditScore() {

@ -9,6 +9,7 @@ import com.community.pocket.repository.BaseDao;
import com.community.pocket.repository.CreditScoreDao; import com.community.pocket.repository.CreditScoreDao;
import com.community.pocket.repository.EmailDao; import com.community.pocket.repository.EmailDao;
import com.community.pocket.util.LookupOperationUtil; import com.community.pocket.util.LookupOperationUtil;
import com.community.pocket.util.TableName;
import com.mongodb.client.result.UpdateResult; import com.mongodb.client.result.UpdateResult;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -16,6 +17,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update; import org.springframework.data.mongodb.core.query.Update;
@ -209,22 +211,8 @@ public class UserDao extends BaseDao<MyInfo> {
//获取个人信息 //获取个人信息
public Info queryUser(String username) { public Info queryUser(String username) {
MyInfo myInfo = mongoTemplate.findOne(new Query(Criteria.where("username").is(username)), entityClass()); Aggregation aggregation = Aggregation.newAggregation(LookupOperationUtil.scoreHistoryLookup, Aggregation.match(Criteria.where(LookupOperationUtil.idKey).is(username)));
if (myInfo != null) { return mongoTemplate.aggregate(aggregation, TableName.info, Info.class).getUniqueMappedResult();
Info info = new Info();
info.setUsername(myInfo.getUsername());
info.setCreditScore(myInfo.getCreditScore());
info.setEmail(myInfo.getEmail());
info.setHeadImg(myInfo.getHeadImg());
info.setMobie(myInfo.getMobie());
info.setPosts(myInfo.getPosts());
info.setVisitors(myInfo.getVisitors());
info.setScoreHistory(myInfo.getScoreHistory());
return info;
} else {
return null;
}
} }
//修改密码 //修改密码

@ -10,19 +10,27 @@ public class LookupOperationUtil {
private static final String activeKey = "activeDto"; private static final String activeKey = "activeDto";
//关联 //关联
public static final LookupOperation activeforumLookup = LookupOperation.newLookup().from(TableName.active).localField(idKey).foreignField(idKey).as(activeKey); public static final LookupOperation activeforumLookup = LookupOperation.newLookup().from(TableName.active).localField(idKey).foreignField(idKey).as(activeKey);
//投诉贴 //投诉贴
//关联属性 //关联属性
private static final String complainKey = "complainDto"; private static final String complainKey = "complainDto";
//定义管道操作 //定义管道操作
public static final LookupOperation complainforumLookup = LookupOperation.newLookup().from(TableName.complain).localField(idKey).foreignField(idKey).as(complainKey); public static final LookupOperation complainforumLookup = LookupOperation.newLookup().from(TableName.complain).localField(idKey).foreignField(idKey).as(complainKey);
//结算贴 //结算贴
private static final String scoreKey = "score"; private static final String scoreKey = "score";
//定义管道操作 //定义管道操作
public static final LookupOperation scoreforumLookup = LookupOperation.newLookup().from(TableName.score).localField(idKey).foreignField(idKey).as(scoreKey); public static final LookupOperation scoreforumLookup = LookupOperation.newLookup().from(TableName.score).localField(idKey).foreignField(idKey).as(scoreKey);
//关联属性
//用户信息
private static final String infoKey = "info"; private static final String infoKey = "info";
//关联用户外键属性 //关联用户外键属性
private static final String usernameKey = "username"; private static final String usernameKey = "username";
//定义管道操作 //定义管道操作
public static final LookupOperation infoLookup = LookupOperation.newLookup().from(TableName.info).localField(usernameKey).foreignField(idKey).as(infoKey); public static final LookupOperation infoLookup = LookupOperation.newLookup().from(TableName.info).localField(usernameKey).foreignField(idKey).as(infoKey);
//信用分历史记录
private static final String scorehistoryKey = "scoreHistory";
public static final LookupOperation scoreHistoryLookup = LookupOperation.newLookup().from(TableName.creditScore).localField(idKey).foreignField(usernameKey).as(scorehistoryKey);
} }

@ -6,6 +6,7 @@ import com.community.pocket.entity.po.android.GarbageWastePrice;
import com.community.pocket.entity.po.android.MyInfo; import com.community.pocket.entity.po.android.MyInfo;
import com.community.pocket.entity.po.android.Token; import com.community.pocket.entity.po.android.Token;
import com.community.pocket.entity.vo.android.GarbageCateGory; import com.community.pocket.entity.vo.android.GarbageCateGory;
import com.community.pocket.entity.vo.android.Info;
import com.community.pocket.entity.vo.android.QueryUserForm; import com.community.pocket.entity.vo.android.QueryUserForm;
import com.community.pocket.repository.android.GarbageDao; import com.community.pocket.repository.android.GarbageDao;
import com.community.pocket.repository.android.GarbagePriceDao; import com.community.pocket.repository.android.GarbagePriceDao;
@ -233,4 +234,10 @@ class DemoApplicationTests {
.param("like", String.valueOf(false)) .param("like", String.valueOf(false))
).andDo(MockMvcResultHandlers.print()).andReturn().getResponse(); ).andDo(MockMvcResultHandlers.print()).andReturn().getResponse();
} }
//查询用户信息
@Test
void findUser() {
Info myInfo = userDao.queryUser("panqihua");
}
} }

Loading…
Cancel
Save