Commit 8d8ebbc2 authored by liuyang's avatar liuyang

修改工程

parent 54084114
......@@ -7,6 +7,11 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.qiankun.annotation.Auth;
import com.qiankun.config.WxMaConfiguration;
import com.qiankun.config.WxMaProperties;
import com.qiankun.dao.RainbowPlanUserDao;
import com.qiankun.dao.WishDao;
import com.qiankun.entity.RainbowPlanUser;
import com.qiankun.entity.Wish;
import com.qiankun.utils.JwtTokenUtil;
import com.qiankun.vo.PublishWish;
import com.qiankun.vo.RegisterInfo;
......@@ -27,49 +32,53 @@ import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.ResourceBundle;
@RestController
@RequestMapping("/wx/rainbowplan/{appid}")
@RequestMapping("/wx/rainbowplan")
public class RainbowPlanController {
private final Logger logger = LoggerFactory.getLogger(RainbowPlanController.class);
private static Map<String, UserInfo> userInfoMap = Maps.newConcurrentMap();
private static Map<String, List<PublishWish>> wishMap = Maps.newConcurrentMap();
@Autowired
private JwtTokenUtil tokenUtil;
@Autowired
private RainbowPlanUserDao userDao;
@Autowired
private WishDao wishDao;
@Autowired
private WxMaProperties propertis;
private ResourceBundle rb = ResourceBundle.getBundle("system");
private String uploadAvatarPath = File.separator + "rainbowplan" + File.separator + "uploadAvatar";
private String uploadWishImagePath = File.separator + "rainbowplan" + File.separator + "wishUploadImage";
@Auth(verifyLogin = false,verifyURL = false)
@RequestMapping(value = "/validateExpired",method = RequestMethod.GET)
public Map<String,Object> validateToken(@PathVariable String appid,@RequestHeader("token") String token){
Map<String,Object> result = Maps.newConcurrentMap();
result.put("result",tokenUtil.isTokenExpired(token));
return result;
private String getAppid(){
return propertis.getConfigs().get(0).getAppid();
}
@Auth(verifyLogin = false,verifyURL = false)
@RequestMapping(value = "/login",method = RequestMethod.GET)
public Map<String,String> login(@PathVariable String appid, @RequestParam String code){
public Map<String,Object> login(@RequestParam String code){
if (StringUtils.isBlank(code)) {
return null;
}
final WxMaService wxService = WxMaConfiguration.getMaService(appid);
final WxMaService wxService = WxMaConfiguration.getMaService(getAppid());
try {
WxMaJscode2SessionResult session = wxService.getUserService().getSessionInfo(code);
this.logger.info(session.getSessionKey());
this.logger.info(session.getOpenid());
Map<String,String> result = Maps.newConcurrentMap();
//TODO 判断openid是否在数据库中存在
if (userInfoMap.containsKey(session.getOpenid())){
//生成sKey
String sKey = tokenUtil.generateToken(session.getOpenid());
// result.put("session",session);
Map<String,Object> result = Maps.newConcurrentMap();
RainbowPlanUser userInfo = userDao.findByOpenid(session.getOpenid());
if (userInfo != null){
String sKey = tokenUtil.generateToken(userInfo.getOpenid());
result.put("sKey",sKey);
result.put("userInfo",userInfo);
}else {
result.put("sKey","");
result.put("userInfo",null);
}
result.put("openid",session.getOpenid());
return result;
} catch (WxErrorException e) {
......@@ -79,132 +88,171 @@ public class RainbowPlanController {
}
@Auth(verifyLogin = false,verifyURL = false)
@RequestMapping(value = "/register",method = RequestMethod.POST)
public String register(@PathVariable String appid,@RequestBody RegisterInfo info){
public String register(@RequestBody RegisterInfo info) throws Exception {
if (Strings.isNullOrEmpty(info.getOpenid())){
throw new IllegalArgumentException("请求参数错误");
}
UserInfo userInfo = new UserInfo();
userInfo.setUid(UUID.randomUUID().toString());
userInfo.setPhone(info.getPhone());
userInfo.setName(info.getName());
userInfo.setGender(info.getGender());
userInfoMap.put(info.getOpenid(),userInfo);
RainbowPlanUser user = new RainbowPlanUser();
user.setPhone(info.getPhone());
user.setName(info.getName());
user.setGender(info.getGender());
if (Strings.isNullOrEmpty(info.getInviter())){
user.setStatus(RainbowPlanUser.STATUS_UNAUDIT);
}else if (inviterExist(info.getInviter())){
user.setStatus(RainbowPlanUser.STATUS_AUDIT);
user.setInviterId(info.getInviter());
}else {
throw new Exception("注册失败,邀请者不存在");
}
userDao.save(user);
return tokenUtil.generateToken(info.getOpenid());
}
private boolean inviterExist(String inviterId) {
//TODO 判断邀请人是否存在
return true;
}
@Auth(verifyLogin = false,verifyURL = false)
@RequestMapping(value = "/userInfo",method = RequestMethod.GET)
public UserInfo getUserInfo(@PathVariable String appid, @RequestHeader String sKey) throws Exception {
public RainbowPlanUser getUserInfo(@RequestHeader String sKey) throws Exception {
if (Strings.isNullOrEmpty(sKey)){
throw new IllegalArgumentException("请求参数错误");
}
String openid = tokenUtil.getUsernameFromToken(sKey);
if (!userInfoMap.containsKey(openid)) {
RainbowPlanUser user = userDao.findByOpenid(openid);
if (user == null) {
throw new Exception("请求的用户不存在");
}
return userInfoMap.get(openid);
return user;
}
@Auth(verifyLogin = false,verifyURL = false)
@RequestMapping(value = "/userInfo",method = RequestMethod.POST)
public String updateUserInfo(@PathVariable String appid,@RequestBody UserInfo info,@RequestHeader String sKey){
public String updateUserInfo(@RequestBody UserInfo info,@RequestHeader String sKey) throws Exception {
if (Strings.isNullOrEmpty(sKey)){
throw new IllegalArgumentException("请求参数错误");
}
String openid = tokenUtil.getUsernameFromToken(sKey);
UserInfo userInfo = findUserInfo(openid);
userInfo.setName(info.getName());
userInfo.setNickName(info.getNickName());
userInfo.setPhone(info.getPhone());
userInfo.setGender(info.getGender());
userInfo.setBirthday(info.getBirthday());
userInfo.setBedNum(info.getBedNum());
userInfo.setReceiveName(info.getReceiveName());
userInfo.setConnectTel(info.getConnectTel());
userInfo.setReceiveAddress(info.getReceiveAddress());
userInfo.setAvatar(info.getAvatar());
RainbowPlanUser user = userDao.findByOpenid(openid);
if (user != null){
user.setPhone(info.getPhone());
user.setName(info.getName());
user.setGender(info.getGender());
user.setBirthday(info.getBirthday());
user.setBedNum(info.getBedNum());
user.setReceiveName(info.getReceiveName());
user.setConnectTel(info.getConnectTel());
user.setReceiveAddress(info.getReceiveAddress());
}else {
throw new Exception("保存失败,请求用户不存在");
}
return "OK";
}
@Auth(verifyLogin = false,verifyURL = false)
@RequestMapping(value = "/userInfoWithAvatar",method = RequestMethod.POST)
public String updateUserInfoWithAvatar(@PathVariable String appid, UserInfo info, @RequestHeader String sKey) throws IOException {
public String updateUserInfoWithAvatar(UserInfo info, @RequestHeader String sKey) throws Exception {
if (Strings.isNullOrEmpty(sKey)){
throw new IllegalArgumentException("请求参数错误");
}
String openid = tokenUtil.getUsernameFromToken(sKey);
UserInfo userInfo = findUserInfo(openid);
RainbowPlanUser user = userDao.findByOpenid(openid);
if (user != null){
if (!info.getFile().isEmpty()){
// BASE64Encoder encoder = new BASE64Encoder();
// String imageData = encoder.encode(info.getFile().getBytes());
String originalFileName = info.getFile().getOriginalFilename();
String path = "/Users/liuyang/uploadImage";
File destFile = new File(path,originalFileName);
String rootPath = rb.getString("file_path");
File destFile = new File(rootPath + uploadAvatarPath,originalFileName);
FileUtils.writeByteArrayToFile(destFile,info.getFile().getBytes());
userInfo.setName(info.getName());
userInfo.setNickName(info.getNickName());
userInfo.setPhone(info.getPhone());
userInfo.setGender(info.getGender());
userInfo.setBirthday(info.getBirthday());
userInfo.setBedNum(info.getBedNum());
userInfo.setReceiveName(info.getReceiveName());
userInfo.setConnectTel(info.getConnectTel());
userInfo.setReceiveAddress(info.getReceiveAddress());
userInfo.setAvatar(info.getAvatar());
userInfo.setAvatar(originalFileName);
user.setPhone(info.getPhone());
user.setName(info.getName());
user.setGender(info.getGender());
user.setBirthday(info.getBirthday());
user.setBedNum(info.getBedNum());
user.setReceiveName(info.getReceiveName());
user.setConnectTel(info.getConnectTel());
user.setReceiveAddress(info.getReceiveAddress());
user.setAvatar(uploadAvatarPath + File.separator + originalFileName);
userDao.update(user);
}else {
throw new Exception("保存失败,请上传图片");
}
}else {
throw new Exception("保存失败,请求用户不存在");
}
return "OK";
}
@Auth(verifyLogin = false,verifyURL = false)
@RequestMapping(value = "/publishWish",method = RequestMethod.POST)
public String publishWish(@PathVariable String appid, PublishWish publishWish,@RequestHeader String sKey) throws IOException {
public String publishWish(PublishWish publishWish,@RequestHeader String sKey) throws Exception {
if (Strings.isNullOrEmpty(sKey)){
throw new IllegalArgumentException("请求参数错误");
}
String openid = tokenUtil.getUsernameFromToken(sKey);
RainbowPlanUser user = userDao.findByOpenid(openid);
if (user != null){
if (!publishWish.getFile().isEmpty()){
// BASE64Encoder encoder = new BASE64Encoder();
// String imageData = encoder.encode(info.getFile().getBytes());
String originalFileName = publishWish.getFile().getOriginalFilename();
String path = "/Users/liuyang/uploadImage";
File destFile = new File(path,originalFileName);
String rootPath = rb.getString("file_path");
File destFile = new File(rootPath + uploadWishImagePath,originalFileName);
FileUtils.writeByteArrayToFile(destFile,publishWish.getFile().getBytes());
List<PublishWish> wishList = Lists.newArrayList();
if (wishMap.containsKey(openid)){
wishList = wishMap.get(openid);
}
PublishWish wish = new PublishWish();
Wish wish = new Wish();
wish.setTitle(publishWish.getTitle());
wish.setWish(publishWish.getWish());
wish.setWishImage(originalFileName);
wishList.add(wish);
wishMap.put(openid,wishList);
wish.setContent(publishWish.getWish());
wish.setUploadImage(uploadWishImagePath + File.separator + originalFileName);
wish.setStatus(Wish.STATUS_PUBLISH);
wish.setRainbowPlanUserId(user.getId());
wishDao.save(wish);
}else {
throw new Exception("保存失败,请上传图片");
}
}else {
throw new Exception("保存失败,请求用户不存在");
}
return "OK";
}
@Auth(verifyLogin = false,verifyURL = false)
@RequestMapping(value = "/wish/list",method = RequestMethod.GET)
public List<PublishWish> wishList(@PathVariable String appid,@RequestHeader String sKey){
public List<Wish> wishList(@RequestHeader String sKey) throws Exception {
if (Strings.isNullOrEmpty(sKey)){
throw new IllegalArgumentException("请求参数错误");
}
String openid = tokenUtil.getUsernameFromToken(sKey);
return wishMap.get(openid);
RainbowPlanUser user = userDao.findByOpenid(openid);
List<Wish> resultList = Lists.newArrayList();
if (user != null){
wishDao.findByRainbowPlanUserId(user.getId());
}else {
throw new Exception("获取数据失败,请求用户不存在");
}
return resultList;
}
@Auth(verifyLogin = false,verifyURL = false)
@RequestMapping(value = "/wish",method = RequestMethod.GET)
public Wish getWish(@RequestParam String id,@RequestHeader String sKey){
if (Strings.isNullOrEmpty(sKey)){
throw new IllegalArgumentException("请求参数错误");
}
String openid = tokenUtil.getUsernameFromToken(sKey);
Wish wish = wishDao.findById(id);
return wish;
private UserInfo findUserInfo(String openid){
return userInfoMap.get(openid);
}
@Auth(verifyLogin = false,verifyURL = false)
@RequestMapping(value = "/loadResource",method = RequestMethod.GET)
public ResponseEntity<byte[]> loadResource(@RequestParam String imageName) throws IOException {
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
File file = new File("/Users/liuyang/uploadImage",imageName);
File file = new File(rb.getString("file_path"),imageName);
return new ResponseEntity<>(FileUtils.readFileToByteArray(file),headers, HttpStatus.OK);
}
}
package com.qiankun.dao;
import com.qiankun.dao.core.IDao;
import com.qiankun.entity.RainbowPlanUser;
public interface RainbowPlanUserDao extends IDao<RainbowPlanUser,String> {
RainbowPlanUser findByOpenid(String openid);
}
package com.qiankun.dao;
import com.qiankun.dao.core.AbsDao;
import com.qiankun.dao.core.Hints;
import com.qiankun.entity.RainbowPlanUser;
import org.springframework.stereotype.Repository;
@Repository
public class RainbowPlanUserDaoImpl extends AbsDao<RainbowPlanUser,String> implements RainbowPlanUserDao {
@Override
public RainbowPlanUser findByOpenid(String openid) {
return findUnique("from RainbowPlanUser where openid=?",new Hints(),openid);
}
}
package com.qiankun.dao;
import com.qiankun.dao.core.IDao;
import com.qiankun.entity.Wish;
import java.util.List;
public interface WishDao extends IDao<Wish,String> {
List<Wish> findByRainbowPlanUserId(String id);
Wish findById(String id);
}
package com.qiankun.dao;
import com.qiankun.dao.core.AbsDao;
import com.qiankun.dao.core.Hints;
import com.qiankun.entity.Wish;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public class WishDaoImpl extends AbsDao<Wish,String> implements WishDao {
@Override
public List<Wish> findByRainbowPlanUserId(String rainbowPlanUserId) {
return find(" from Wish where rainbowPlanUserId = ? order by createTime desc",new Hints(0),rainbowPlanUserId);
}
@Override
public Wish findById(String id) {
return findUnique("from Wish where id = ?",new Hints(),id);
}
}
package com.qiankun.entity;
import org.hibernate.annotations.GenericGenerator;
import org.omg.CORBA.PUBLIC_MEMBER;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Date;
@Entity
public class RainbowPlanUser {
public static final int STATUS_UNAUDIT = 0;
public static final int STATUS_AUDIT = 1;
@Id
@GenericGenerator(name = "systemUUID", strategy = "uuid2")
@GeneratedValue(generator = "systemUUID")
private String id;
private String openid;//小程序用户ID
private String unionid; //微信全局ID
private String phone; //注册手机号
private String name; //真实姓名
private String nickName; //昵称
private String gender; //性别
private String birthday; //出生日期
private String bedNum; //楼层床号
private String receiveName; //收件人姓名
private String connectTel;//联系方式
private String receiveAddress;//收件地址
private int status;//用户状态 0:已注册未审核,1:已审核
private String avatar;//头像图片名
private Date createTime = new Date();
private String inviterId;//邀请者ID
public String getInviterId() {
return inviterId;
}
public void setInviterId(String inviterId) {
this.inviterId = inviterId;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getOpenid() {
return openid;
}
public void setOpenid(String openid) {
this.openid = openid;
}
public String getUnionid() {
return unionid;
}
public void setUnionid(String unionid) {
this.unionid = unionid;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getNickName() {
return nickName;
}
public void setNickName(String nickName) {
this.nickName = nickName;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getBedNum() {
return bedNum;
}
public void setBedNum(String bedNum) {
this.bedNum = bedNum;
}
public String getReceiveName() {
return receiveName;
}
public void setReceiveName(String receiveName) {
this.receiveName = receiveName;
}
public String getConnectTel() {
return connectTel;
}
public void setConnectTel(String connectTel) {
this.connectTel = connectTel;
}
public String getReceiveAddress() {
return receiveAddress;
}
public void setReceiveAddress(String receiveAddress) {
this.receiveAddress = receiveAddress;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getAvatar() {
return avatar;
}
public void setAvatar(String avatar) {
this.avatar = avatar;
}
}
package com.qiankun.entity;
import org.hibernate.annotations.GenericGenerator;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import java.util.Date;
@Entity
public class Wish {
public static final int STATUS_PUBLISH = 0;
public static final int STATUS_RECEIVE = 1;
public static final int STATUS_COMPLETE = 2;
@Id
@GenericGenerator(name = "systemUUID", strategy = "uuid2")
@GeneratedValue(generator = "systemUUID")
private String id; //愿望ID
private String title;//愿望标题
private String content;//愿望内容
private String uploadImage; //上传的图片
private int status;//愿望状态,0:发布;1:领取;2:实现
private String volunteerId; //领取愿望的志愿者ID
private String rainbowPlanUserId; //小朋友ID
private Date createTime = new Date();
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
public String getRainbowPlanUserId() {
return rainbowPlanUserId;
}
public void setRainbowPlanUserId(String rainbowPlanUserId) {
this.rainbowPlanUserId = rainbowPlanUserId;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getUploadImage() {
return uploadImage;
}
public void setUploadImage(String uploadImage) {
this.uploadImage = uploadImage;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public String getVolunteerId() {
return volunteerId;
}
public void setVolunteerId(String volunteerId) {
this.volunteerId = volunteerId;
}
}
......@@ -4,11 +4,20 @@ import org.springframework.web.multipart.MultipartFile;
public class PublishWish {
public String id;
public String title;
public String wish;
public String wishImage;
public MultipartFile file;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTitle() {
return title;
}
......
file_path=D:/file/
#file_path=/usr/local/tomcat/upload/
#file_path=D:/file/
file_path=/Users/liuyang/work/argus_work/tjmdp/udata
account=admin
password=passed
rainbowplan.appid=wx7289ed9f69379a53
rainbowplan.secret=cc4df9e8a63d2b0faa2a25bbec79d2e3
rainbowplan.appid=wxd097672957e48ba8
rainbowplan.secret=6500d648cc5715f8829dab993de746f3
rainbowplan.token=
rainbowplan.aesKey=
rainbowplan.msgDataFormat: JSON
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment