Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Commit

Permalink
Merge pull request #6 from TGclub/jc
Browse files Browse the repository at this point in the history
Jc
  • Loading branch information
Kikyou1997 authored Oct 27, 2018
2 parents 2e00d19 + f25fbd5 commit 2236bb4
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 40 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@
<version>1.0.2.Final</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.1.0</version>
<scope>test</scope>
</dependency>

<!--JWT-->
<dependency>
<groupId>com.auth0</groupId>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/wizzstudio/substitute/dao/UserDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
@Repository
public interface UserDao extends JpaRepository<User, String> {
User findByOpenid(String id);
User findUserById(String id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ModifyUserInfoDTO implements Serializable {
private String userName;
private String trueName;
private Long phoneNumber;
private String school;
private Integer school;
private Gender gender;


Expand Down Expand Up @@ -45,11 +45,11 @@ public void setPhoneNumber(Long phoneNumber) {
this.phoneNumber = phoneNumber;
}

public String getSchool() {
public Integer getSchool() {
return school;
}

public void setSchool(String school) {
public void setSchool(Integer school) {
this.school = school;
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/wizzstudio/substitute/dto/ResultDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ public ResultDTO(Integer code, String msg, T data) {
this.msg = msg;
this.data = data;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,36 @@

import java.io.Serializable;

public class ApprenticeBasicInfo implements Serializable {
public class UserBasicInfo implements Serializable {

private static final long serialVersionUID = -179070031366192478L;

private String id;

private String userName;

private Long phone;

private String avatar;

private String school;

private Gender gender;

public ApprenticeBasicInfo() {
public UserBasicInfo() {
}


public ApprenticeBasicInfo(String id, String userName, String avatar, String school, Gender gender) {
public UserBasicInfo(String id, String userName, Long phone, String avatar, String school, Gender gender) {
this.id = id;
this.userName = userName;
this.phone = phone;
this.avatar = avatar;
this.school = school;
this.gender = gender;
}

private ApprenticeBasicInfo(Builder builder) {
private UserBasicInfo(Builder builder) {
setId(builder.id);
setUserName(builder.userName);
setAvatar(builder.avatar);
Expand All @@ -42,7 +45,7 @@ public static Builder newBuilder() {
return new Builder();
}

public static Builder newBuilder(ApprenticeBasicInfo copy) {
public static Builder newBuilder(UserBasicInfo copy) {
Builder builder = new Builder();
builder.id = copy.getId();
builder.userName = copy.getUserName();
Expand Down Expand Up @@ -92,6 +95,13 @@ public void setGender(Gender gender) {
this.gender = gender;
}

public Long getPhone() {
return phone;
}

public void setPhone(Long phone) {
this.phone = phone;
}

public static final class Builder {
private String id;
Expand Down Expand Up @@ -128,8 +138,8 @@ public Builder setGender(Gender gender) {
return this;
}

public ApprenticeBasicInfo build() {
return new ApprenticeBasicInfo(this);
public UserBasicInfo build() {
return new UserBasicInfo(this);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.wizzstudio.substitute.service;


import com.wizzstudio.substitute.pojo.Address;
import com.wizzstudio.substitute.pojo.School;

import java.util.List;

public interface AddressService {
void addUsualAddress(String userId);
//List<Address> searchAddress();
List<Address> getUsualAddress(String userId);
List<School> getSchoolInFuzzyMatching(String school);


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import com.wizzstudio.substitute.dao.UserDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;

@Service
public class BaseService {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.wizzstudio.substitute.service;

import com.wizzstudio.substitute.dto.ApprenticeBasicInfo;
import com.wizzstudio.substitute.dto.UserBasicInfo;
import com.wizzstudio.substitute.dto.ModifyUserInfoDTO;
import com.wizzstudio.substitute.pojo.User;

Expand Down Expand Up @@ -42,11 +42,13 @@ public interface UserService {
/**
* 获取用户所有徒弟的基本信息
* @param userId 徒弟id
* @param type 指定返回类型
* @return 用户的基本信息
*/
List<ApprenticeBasicInfo> getApprenticeInfo(String userId);
<T>T getBasicInfo(T type, String userId);

User findUserByOpenId(String openid);

User findUserById(String id);

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.wizzstudio.substitute.service.impl;

import com.wizzstudio.substitute.dto.ApprenticeBasicInfo;
import com.wizzstudio.substitute.dto.UserBasicInfo;
import com.wizzstudio.substitute.dto.ModifyUserInfoDTO;
import com.wizzstudio.substitute.enums.Gender;
import com.wizzstudio.substitute.pojo.User;
Expand Down Expand Up @@ -31,12 +31,12 @@ public User getUserInfo(String openId) {
public User modifyUserInfo(String id, ModifyUserInfoDTO newInfo) {
User user = findUserById(id);
Gender gender = newInfo.getGender();
String school = newInfo.getSchool();
Integer school = newInfo.getSchool();
Long phoneNumber = newInfo.getPhoneNumber();
String trueName = newInfo.getTrueName();
String userName = newInfo.getUserName();
if (gender != null) user.setGender(gender);
if (school != null) user.setSchool(school);
if (school != null) user.setSchoolId(school);
if (phoneNumber != null) user.setPhone(phoneNumber);
if (trueName != null) user.setTrueName(trueName);
if (userName != null) user.setUserName(userName);
Expand All @@ -45,28 +45,52 @@ public User modifyUserInfo(String id, ModifyUserInfoDTO newInfo) {

@Override
public boolean addReferrer(String userId, String masterId) {
User master = userDao.getOne(masterId);
User user = userDao.getOne(userId);
if (master != null) {
User master = findUserById(masterId);
User user = findUserById(userId);
if (master != null && user != null) {
user.setMasterId(masterId);
return true;
} else {
return false;
}
}

/**
* 获取徒弟或师傅的基本信息
* @param returnType 传入一个实例指定返回类型,list作为徒弟处理,UserBasicInfo作为师傅处理
* @param userId 徒弟id
* @return 返回一个list或者UserBasicInfo
*/
@Override
public List<ApprenticeBasicInfo> getApprenticeInfo(String userId) {
Query query = entityManager.createNamedQuery
("getAllApprentice", User.class).setParameter("account", userId);
List<User> apprentices = (List<User>) query.getResultList();
List<ApprenticeBasicInfo> basicInfos = new ArrayList<>();
apprentices.forEach(x -> {
ApprenticeBasicInfo basicInfo = new ApprenticeBasicInfo();
BeanUtils.copyProperties(apprentices, basicInfo);
basicInfos.add(basicInfo);
});
return basicInfos;
@SuppressWarnings(value = "unchecked")
public <T> T getBasicInfo(T returnType, String userId) {
User user = findUserById(userId);
if (user == null) return null;
if (returnType instanceof List) {
Query query = entityManager.createNamedQuery
("getAllApprentice", User.class).setParameter("account", userId);
List<User> apprentices = (List<User>) query.getResultList();
List<UserBasicInfo> basicInfos = new ArrayList<>();
apprentices.forEach(x -> {
UserBasicInfo basicInfo = new UserBasicInfo();
BeanUtils.copyProperties(apprentices, basicInfo);
basicInfos.add(basicInfo);
});
return (T)basicInfos;
} else if (returnType instanceof UserBasicInfo) {
String masterId = user.getMasterId();
if (masterId != null) {
User master = findUserById(masterId);
UserBasicInfo basicInfo = new UserBasicInfo();
BeanUtils.copyProperties(master, basicInfo);
return (T) basicInfo;
} else {
return null;
}
} else {
return null;
}


}

Expand All @@ -77,6 +101,8 @@ public User findUserByOpenId(String openid) {

@Override
public User findUserById(String id) {
return userDao.getOne(id);
return userDao.findUserById(id);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
import com.wizzstudio.substitute.constants.Constants;
import com.wizzstudio.substitute.dto.ApprenticeBasicInfo;
import com.wizzstudio.substitute.dto.UserBasicInfo;
import com.wizzstudio.substitute.dto.ModifyUserInfoDTO;
import com.wizzstudio.substitute.dto.WxInfo;
import com.wizzstudio.substitute.dto.ResultDTO;
Expand All @@ -19,16 +19,22 @@
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/user")
@Slf4j
public class UserController extends BaseController{
public class UserController extends BaseController {

@Autowired
private WxMaService wxService;

/**
* 用户注册
* @param loginData
* @return
*/

@RequestMapping(value = "/login", method = RequestMethod.POST)
public @ResponseBody
Expand Down Expand Up @@ -60,6 +66,11 @@ ResponseEntity login(@NotNull @RequestBody WxInfo loginData) {
}
}

/**
* 用户基本信息获取
* @param openid
* @return
*/
@RequestMapping(value = "/{openid}", method = RequestMethod.GET)
public @ResponseBody
ResponseEntity getUseInfo(@PathVariable String openid) {
Expand All @@ -72,6 +83,12 @@ ResponseEntity getUseInfo(@PathVariable String openid) {
}
}

/**
* 修改用户信息
* @param userId
* @param modifyUserInfoDTO
* @return
*/
@RequestMapping(value = "/info/{userId}", method = RequestMethod.POST)
public @ResponseBody
ResponseEntity modifyUserInfo(@PathVariable String userId, @RequestBody ModifyUserInfoDTO modifyUserInfoDTO) {
Expand All @@ -83,10 +100,50 @@ ResponseEntity modifyUserInfo(@PathVariable String userId, @RequestBody ModifyUs
}
}

/**
* 获取徒弟信息
* @param userId
* @return
*/
@RequestMapping(value = "/apprentices/{userId}", method = RequestMethod.GET)
public @ResponseBody ResponseEntity getAllApprenticesInfo(@PathVariable String userId) {
return new ResponseEntity<ResultDTO<List<ApprenticeBasicInfo>>>(new ResultDTO<List<ApprenticeBasicInfo>>
(Constants.REQUEST_SUCCEED, Constants.QUERY_SUCCESSFULLY,userService.getApprenticeInfo(userId)), HttpStatus.OK);
public @ResponseBody
ResponseEntity getAllApprenticesInfo(@PathVariable String userId) {
return new ResponseEntity<ResultDTO<List<UserBasicInfo>>>(new ResultDTO<List<UserBasicInfo>>
(Constants.REQUEST_SUCCEED, Constants.QUERY_SUCCESSFULLY, userService
.getBasicInfo(new ArrayList<UserBasicInfo>(), userId)), HttpStatus.OK);
}

/**
* 获取师傅信息
* @param userId
* @return
*/
@RequestMapping(value = "/master/{userId}", method = RequestMethod.GET)
public @ResponseBody
ResponseEntity getMasterInfo(@PathVariable String userId) {

return new ResponseEntity<ResultDTO>(
new ResultDTO<UserBasicInfo>(Constants.REQUEST_SUCCEED, Constants.QUERY_SUCCESSFULLY, userService.getBasicInfo
(new UserBasicInfo(), userId)), HttpStatus.OK);
}

/**
* 添加师傅
* @param userId
* @param masterId
* @return
*/
@RequestMapping(value = "/master/{userId}/{masterId}", method = RequestMethod.POST)
public @ResponseBody ResponseEntity addMaster(@PathVariable String userId, @PathVariable String masterId) {
ResultDTO resultDTO = new ResultDTO();
if (userService.addReferrer(userId, masterId)) {
resultDTO.setCode(Constants.REQUEST_SUCCEED);
resultDTO.setMsg(Constants.QUERY_SUCCESSFULLY);
} else {
resultDTO.setCode(Constants.SYSTEM_BUSY);
resultDTO.setMsg(Constants.QUERY_FAILED);
}
return new ResponseEntity<ResultDTO>(resultDTO, HttpStatus.OK);
}

}
Loading

0 comments on commit 2236bb4

Please sign in to comment.