Commit a4185125 authored by liuchao's avatar liuchao
parents f21e7523 ffb9af80
......@@ -16,13 +16,12 @@ import com.qiankun.entity.RainbowPlanUser;
import com.qiankun.entity.Wish;
import com.qiankun.entity.WishReply;
import com.qiankun.utils.JwtTokenUtil;
import com.qiankun.vo.PublishWish;
import com.qiankun.vo.RegisterInfo;
import com.qiankun.vo.UserInfo;
import com.qiankun.vo.WishDetailVo;
import com.qiankun.vo.*;
import com.sun.org.apache.regexp.internal.REUtil;
import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.dom4j.util.UserDataDocumentFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -34,6 +33,7 @@ import org.springframework.web.bind.annotation.*;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
......@@ -95,27 +95,60 @@ public class RainbowPlanController {
}
@Auth(verifyLogin = false,verifyURL = false)
@RequestMapping(value = "/register",method = RequestMethod.POST)
public String register(@RequestBody RegisterInfo info) throws Exception {
public Map<String,Object> register(@RequestBody RegisterInfo info) throws Exception {
Map<String,Object> result = Maps.newConcurrentMap();
if (Strings.isNullOrEmpty(info.getOpenid())){
throw new IllegalArgumentException("请求参数错误");
result.put("status","error");
result.put("errorMsg","请求参数错误");
return result;
}
RainbowPlanUser user = new RainbowPlanUser();
user.setPhone(info.getPhone());
user.setName(info.getName());
user.setGender(info.getGender());
user.setOpenid(info.getOpenid());
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("注册失败,邀请者不存在");
RainbowPlanUser user = userDao.findByPhone(info.getPhone());
if (info.getType() == RainbowPlanUser.TYPE_BABY && user != null){
//红会人员录入过信息
user.setName(info.getName());
user.setGender(info.getGender());
user.setOpenid(info.getOpenid());
result.put("isExist",true);
userDao.update(user);
}else if (info.getType() == RainbowPlanUser.TYPE_BABY && user == null){
//新注册用户
user = new RainbowPlanUser();
user.setPhone(info.getPhone());
user.setName(info.getName());
user.setGender(info.getGender());
user.setOpenid(info.getOpenid());
user.setType(info.getType());
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 {
result.put("status","error");
result.put("errorMsg","注册失败,邀请者不存在");
return result;
}
userDao.save(user);
}else if (info.getType() == RainbowPlanUser.TYPE_LOVE && user == null){
//爱心人士
user = new RainbowPlanUser();
user.setPhone(info.getPhone());
user.setName(info.getName());
user.setType(info.getType());
user.setOpenid(info.getOpenid());
userDao.save(user);
}else if (info.getType() == RainbowPlanUser.TYPE_LOVE && user != null){
result.put("status","error");
result.put("errorMsg","该手机号已存在");
return result;
}
userDao.save(user);
return tokenUtil.generateToken(info.getOpenid());
result.put("status","OK");
result.put("userInfo",user);
result.put("sKey",tokenUtil.generateToken(info.getOpenid()));
return result;
}
private boolean inviterExist(String inviterId) {
......@@ -321,4 +354,42 @@ public class RainbowPlanController {
File file = new File(rb.getString("file_path"),imageName);
return new ResponseEntity<>(FileUtils.readFileToByteArray(file),headers, HttpStatus.OK);
}
@Auth(verifyLogin = false,verifyURL = false)
@RequestMapping(value = "/importWish",method = RequestMethod.POST)
public @ResponseBody Map<String,Object> importWish(ImportWishVo importWishVo) throws Exception {
Map<String,Object> result = Maps.newConcurrentMap();
RainbowPlanUser user = new RainbowPlanUser();
user.setPhone(importWishVo.getPhone());
user.setName(importWishVo.getName());
user.setNickName(importWishVo.getNickName());
user.setReceiveAddress(importWishVo.getReceiveAddress());
user.setConnectTel(importWishVo.getConnectTel());
user.setReceiveName(importWishVo.getReceiveName());
user.setBedNum(importWishVo.getBedNum());
user.setBirthday(importWishVo.getBirthday());
user.setGender(importWishVo.getGender());
user.setCreateTime(new Date());
user.setType(RainbowPlanUser.TYPE_BABY);
user.setStatus(RainbowPlanUser.STATUS_AUDIT);
userDao.save(user);
if (!importWishVo.getFile().isEmpty()){
String originalFileName = importWishVo.getFile().getOriginalFilename();
String rootPath = rb.getString("file_path");
File destFile = new File(rootPath + uploadWishImagePath,originalFileName);
FileUtils.writeByteArrayToFile(destFile,importWishVo.getFile().getBytes());
Wish wish = new Wish();
wish.setContent(importWishVo.getWish());
wish.setUploadImage(uploadWishImagePath + File.separator + originalFileName);
wish.setStatus(Wish.STATUS_PUBLISH);
wish.setRainbowPlanUserId(user.getId());
wishDao.save(wish);
}else {
throw new Exception("保存失败,请上传图片");
}
result.put("status","OK");
return result;
}
}
......@@ -5,4 +5,6 @@ import com.qiankun.entity.RainbowPlanUser;
public interface RainbowPlanUserDao extends IDao<RainbowPlanUser,String> {
RainbowPlanUser findByOpenid(String openid);
RainbowPlanUser findByPhone(String phone);
}
......@@ -24,4 +24,9 @@ public class RainbowPlanUserDaoImpl extends AbsDao<RainbowPlanUser,String> imple
public void update(RainbowPlanUser entity) {
super.update(entity);
}
@Override
public RainbowPlanUser findByPhone(String phone) {
return findUnique("from RainbowPlanUser where phone = ?",new Hints(),phone);
}
}
package com.qiankun.entity;
import org.hibernate.annotations.GenericGenerator;
import org.omg.CORBA.PUBLIC_MEMBER;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
......@@ -12,6 +11,8 @@ import java.util.Date;
public class RainbowPlanUser {
public static final int STATUS_UNAUDIT = 0;
public static final int STATUS_AUDIT = 1;
public static final int TYPE_BABY = 0;
public static final int TYPE_LOVE = 1;
@Id
@GenericGenerator(name = "systemUUID", strategy = "uuid2")
@GeneratedValue(generator = "systemUUID")
......@@ -31,6 +32,7 @@ public class RainbowPlanUser {
private String avatar;//头像图片名
private Date createTime = new Date();
private String inviterId;//邀请者ID
private int type;//0:小朋友;1:爱心人士
public String getInviterId() {
return inviterId;
......@@ -159,4 +161,12 @@ public class RainbowPlanUser {
public void setAvatar(String avatar) {
this.avatar = avatar;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
}
......@@ -19,7 +19,7 @@ public class Wish {
private String title;//愿望标题
private String content;//愿望内容
private String uploadImage; //上传的图片
private int status;//愿望状态,0:发布;1:领取;2:实现
private int status;//愿望状态,0:发布;1:领取;2.寄送中;3:实现
private String volunteerId; //领取愿望的志愿者ID
private String rainbowPlanUserId; //小朋友ID
private Date createTime = new Date();
......
package com.qiankun.vo;
import org.springframework.web.multipart.MultipartFile;
public class ImportWishVo {
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;//收件地址
public String wish;//心愿
public MultipartFile file;//心愿图片
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 String getWish() {
return wish;
}
public void setWish(String wish) {
this.wish = wish;
}
public MultipartFile getFile() {
return file;
}
public void setFile(MultipartFile file) {
this.file = file;
}
}
......@@ -6,6 +6,7 @@ public class RegisterInfo {
public String gender;
public String openid;
public String inviter;
public int type;
public String getName() {
return name;
......@@ -46,4 +47,12 @@ public class RegisterInfo {
public void setInviter(String inviter) {
this.inviter = inviter;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
}
#file_path=D:/file/
file_path=/Users/liuyang/work/argus_work/tjmdp/udata
#file_path=/var/tjmdp/udata
#file_path=/Users/liuyang/work/argus_work/tjmdp/udata
file_path=/var/tjmdp/udata
account=admin
......
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