105 changed files with 1336 additions and 1043 deletions
@ -0,0 +1,124 @@ |
|||
package com.elink.esua.epdc.commons.tools.utils; |
|||
|
|||
import cn.hutool.http.HttpResponse; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import org.apache.commons.codec.binary.Base64; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.http.HttpEntity; |
|||
import sun.net.www.http.HttpClient; |
|||
|
|||
import java.io.*; |
|||
import java.net.HttpURLConnection; |
|||
import java.net.URL; |
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* @Author LC |
|||
* @Date 2019/9/11 14:53 |
|||
*/ |
|||
public class UploadImageUtils { |
|||
|
|||
/** |
|||
* 从微信下载图片 |
|||
* @Params: [params] |
|||
* @Return: java.lang.String |
|||
* @Author: liuchuang |
|||
* @Date: 2019/9/11 17:04 |
|||
*/ |
|||
public static String downloadImageFromWx(Map<String, String> params) throws Exception { |
|||
InputStream inputStream = getMediaStream(params.get("accessTokenUrl"), params.get("mediaUrl"), params.get("mediaId"), params.get("appid"), params.get("secret")); |
|||
if (null == inputStream) { |
|||
return null; |
|||
} |
|||
byte[] data = null; |
|||
ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); |
|||
byte[] buffer = new byte[1024]; |
|||
int len = 0; |
|||
while((len = inputStream.read(buffer, 0, 1024)) != -1){ |
|||
swapStream.write(buffer, 0, len); |
|||
} |
|||
data = swapStream.toByteArray(); |
|||
String base64 = "data:image/png;base64,"+Base64.encodeBase64String(data); |
|||
return base64; |
|||
} |
|||
|
|||
/** |
|||
* 获取临时素材 |
|||
*/ |
|||
private static InputStream getMediaStream(String accessTokenUrl, String mediaUrl, String mediaId, String appid, String secret)throws IOException { |
|||
String access_token = getAccessToken(accessTokenUrl, appid, secret); |
|||
String params = "access_token=" + access_token + "&media_id=" + mediaId; |
|||
InputStream is = null; |
|||
try { |
|||
String urlNameString = mediaUrl + "?" + params; |
|||
URL urlGet = new URL(urlNameString); |
|||
HttpURLConnection http = (HttpURLConnection) urlGet.openConnection(); |
|||
http.setRequestMethod("GET"); // 必须是get方式请求
|
|||
http.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); |
|||
http.setDoOutput(true); |
|||
http.setDoInput(true); |
|||
http.connect(); |
|||
if (!http.getContentType().contains("image")) { |
|||
return null; |
|||
} |
|||
// 获取文件转化为byte流
|
|||
is = http.getInputStream(); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
return is; |
|||
} |
|||
|
|||
/** |
|||
* 获取微信Jsapi的accessToken |
|||
* 这里获取的获取微信Jsapi的accessToken跟小程序以及其他的不一样 |
|||
*/ |
|||
public static String getAccessToken(String accessTokenUrl, String appId, String secret) { |
|||
accessTokenUrl = accessTokenUrl.replace("APPID", appId).replace("APPSECRET", secret); |
|||
JSONObject jsonObj = doHttpGet(accessTokenUrl); |
|||
String accessToken = jsonObj.getString("access_token"); |
|||
return accessToken; |
|||
} |
|||
|
|||
/** |
|||
* 发送GET请求 |
|||
* @Params: [requestUrl, params] |
|||
* @Return: java.lang.String |
|||
* @Author: liuchuang |
|||
* @Date: 2019/8/5 14:25 |
|||
*/ |
|||
public static JSONObject doHttpGet(String requestUrl) { |
|||
JSONObject jsonObj = null; |
|||
// buffer用于接受返回的字符
|
|||
StringBuffer buffer = new StringBuffer(); |
|||
try { |
|||
// 建立URL,把请求地址给补全,其中urlEncode()方法用于把params里的参数给取出来
|
|||
URL url = new URL(requestUrl); |
|||
// 打开http连接
|
|||
HttpURLConnection httpUrlConn = (HttpURLConnection) url.openConnection(); |
|||
httpUrlConn.setDoInput(true); |
|||
httpUrlConn.setRequestMethod("GET"); |
|||
httpUrlConn.connect(); |
|||
// 获得输入
|
|||
InputStream inputStream = httpUrlConn.getInputStream(); |
|||
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "UTF-8"); |
|||
BufferedReader bufferedReader = new BufferedReader(inputStreamReader); |
|||
// 将bufferReader的值给放到buffer里
|
|||
String str = null; |
|||
while ((str = bufferedReader.readLine()) != null) { |
|||
buffer.append(str); |
|||
} |
|||
// 关闭bufferReader和输入流
|
|||
bufferedReader.close(); |
|||
inputStreamReader.close(); |
|||
inputStream.close(); |
|||
// 断开连接
|
|||
httpUrlConn.disconnect(); |
|||
} catch (Exception e) { |
|||
e.printStackTrace(); |
|||
} |
|||
jsonObj = JSONObject.parseObject(buffer.toString()); |
|||
return jsonObj; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,38 @@ |
|||
package com.elink.esua.epdc.dto.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* 图片上传Form DTO |
|||
* @Author LC |
|||
* @Date 2019/9/11 16:27 |
|||
*/ |
|||
@Data |
|||
public class UploadImageFormDTO implements Serializable { |
|||
private static final long serialVersionUID = -4670602967272919640L; |
|||
|
|||
/** |
|||
* 文件标识 |
|||
*/ |
|||
@NotBlank(message = "文件标识不能为空") |
|||
private String mediaId; |
|||
/** |
|||
* 获取accessToken地址 |
|||
*/ |
|||
private String accessTokenUrl; |
|||
/** |
|||
* 下载文件地址 |
|||
*/ |
|||
private String mediaUrl; |
|||
/** |
|||
* appid |
|||
*/ |
|||
private String appid; |
|||
/** |
|||
* secret |
|||
*/ |
|||
private String secret; |
|||
} |
|||
@ -1,67 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* <p> |
|||
* https://www.renren.io
|
|||
* <p> |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.controller; |
|||
|
|||
|
|||
import com.elink.esua.epdc.common.token.annotation.Login; |
|||
import com.elink.esua.epdc.commons.tools.utils.Result; |
|||
import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils; |
|||
import com.elink.esua.epdc.dto.LoginDTO; |
|||
import com.elink.esua.epdc.service.TokenService; |
|||
import com.elink.esua.epdc.service.UserService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 登录接口 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("auth") |
|||
public class ApiLoginController { |
|||
@Autowired |
|||
private UserService userService; |
|||
@Autowired |
|||
private TokenService tokenService; |
|||
|
|||
|
|||
/** |
|||
* 登录 |
|||
* |
|||
* @param dto |
|||
* @return |
|||
*/ |
|||
@PostMapping("login") |
|||
public Result<Map<String, Object>> login(@RequestBody LoginDTO dto) { |
|||
//表单校验
|
|||
ValidatorUtils.validateEntity(dto); |
|||
|
|||
//用户登录
|
|||
Map<String, Object> map = userService.login(dto); |
|||
|
|||
return new Result().ok(map); |
|||
} |
|||
|
|||
/** |
|||
* 退出 |
|||
* |
|||
* @param userId |
|||
* @return |
|||
*/ |
|||
@Login |
|||
@PostMapping("logout") |
|||
public Result logout(@RequestAttribute("userId") Long userId) { |
|||
tokenService.expireToken(userId); |
|||
return new Result(); |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
package com.elink.esua.epdc.controller; |
|||
|
|||
import com.elink.esua.epdc.commons.tools.utils.Result; |
|||
import com.elink.esua.epdc.service.MessageService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
/** |
|||
* @author yujintao |
|||
* @email yujintao@elink-cn.com |
|||
* @date 2019/9/11 20:56 |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("message") |
|||
public class ApiMessageController { |
|||
|
|||
@Autowired |
|||
private MessageService messageService; |
|||
|
|||
/** |
|||
* 发送短信验证码 |
|||
* |
|||
* @param mobile |
|||
* @return com.elink.esua.epdc.commons.tools.utils.Result |
|||
* @author yujintao |
|||
* @date 2019/9/11 21:03 |
|||
*/ |
|||
@GetMapping("sms/sendCode") |
|||
public Result sendSmsCode(String mobile) { |
|||
return messageService.sendSmsCode(mobile); |
|||
} |
|||
} |
|||
@ -1,67 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* <p> |
|||
* https://www.renren.io
|
|||
* <p> |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.controller; |
|||
|
|||
import com.elink.esua.epdc.commons.tools.utils.Result; |
|||
import com.elink.esua.epdc.commons.tools.validator.ValidatorUtils; |
|||
import com.elink.esua.epdc.dto.RegisterDTO; |
|||
import com.elink.esua.epdc.entity.UserEntity; |
|||
import com.elink.esua.epdc.service.UserService; |
|||
import org.apache.commons.codec.digest.DigestUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.PostMapping; |
|||
import org.springframework.web.bind.annotation.RequestBody; |
|||
import org.springframework.web.bind.annotation.RequestMapping; |
|||
import org.springframework.web.bind.annotation.RestController; |
|||
|
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 注册接口 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@RestController |
|||
@RequestMapping("register") |
|||
public class ApiRegisterController { |
|||
@Autowired |
|||
private UserService userService; |
|||
|
|||
/** |
|||
* 注册 |
|||
* |
|||
* @param dto |
|||
* @return |
|||
*/ |
|||
@PostMapping |
|||
public Result register(@RequestBody RegisterDTO dto) { |
|||
//表单校验
|
|||
ValidatorUtils.validateEntity(dto); |
|||
|
|||
UserEntity user = new UserEntity(); |
|||
user.setMobile(dto.getMobile()); |
|||
user.setUsername(dto.getMobile()); |
|||
user.setPassword(DigestUtils.sha256Hex(dto.getPassword())); |
|||
user.setCreateDate(new Date()); |
|||
userService.insert(user); |
|||
|
|||
return new Result(); |
|||
} |
|||
|
|||
/** |
|||
* 注册 |
|||
* |
|||
* @param dto |
|||
* @return |
|||
*/ |
|||
@PostMapping("register2") |
|||
public Result register2(@RequestBody RegisterDTO dto) { |
|||
return userService.register2(dto); |
|||
} |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.dao; |
|||
|
|||
import com.elink.esua.epdc.commons.mybatis.dao.BaseDao; |
|||
import com.elink.esua.epdc.entity.TokenEntity; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
/** |
|||
* 用户Token |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@Mapper |
|||
public interface TokenDao extends BaseDao<TokenEntity> { |
|||
TokenEntity getByToken(String token); |
|||
|
|||
TokenEntity getByUserId(Long userId); |
|||
} |
|||
@ -1,25 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.dao; |
|||
|
|||
import com.elink.esua.epdc.commons.mybatis.dao.BaseDao; |
|||
import com.elink.esua.epdc.entity.UserEntity; |
|||
import org.apache.ibatis.annotations.Mapper; |
|||
|
|||
/** |
|||
* 用户 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
@Mapper |
|||
public interface UserDao extends BaseDao<UserEntity> { |
|||
UserEntity getUserByMobile(String mobile); |
|||
|
|||
UserEntity getUserByUserId(Long userId); |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
package com.elink.esua.epdc.feign; |
|||
|
|||
import com.elink.esua.epdc.commons.tools.constant.ServiceConstant; |
|||
import com.elink.esua.epdc.commons.tools.utils.Result; |
|||
import com.elink.esua.epdc.feign.fallback.MessageFeignClientFallback; |
|||
import org.springframework.cloud.openfeign.FeignClient; |
|||
import org.springframework.web.bind.annotation.GetMapping; |
|||
|
|||
/** |
|||
* 文件对象模块 |
|||
* |
|||
* @Author LC |
|||
* @Date 2019/9/8 18:24 |
|||
*/ |
|||
@FeignClient(name = ServiceConstant.EPDC_MESSAGE_SERVER, fallback = MessageFeignClientFallback.class) |
|||
public interface MessageFeignClient { |
|||
|
|||
/** |
|||
* 发送短信验证码 |
|||
* |
|||
* @param mobile |
|||
* @return com.elink.esua.epdc.commons.tools.utils.Result |
|||
* @author yujintao |
|||
* @date 2019/9/11 20:59 |
|||
*/ |
|||
@GetMapping(value = "message/sms/sendCode") |
|||
Result sendCode(String mobile); |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
package com.elink.esua.epdc.feign.fallback; |
|||
|
|||
import com.elink.esua.epdc.commons.tools.constant.ServiceConstant; |
|||
import com.elink.esua.epdc.commons.tools.utils.ModuleUtils; |
|||
import com.elink.esua.epdc.commons.tools.utils.Result; |
|||
import com.elink.esua.epdc.feign.MessageFeignClient; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
/** |
|||
* 文件对象模块 |
|||
* |
|||
* @Author LC |
|||
* @Date 2019/9/8 18:25 |
|||
*/ |
|||
@Component |
|||
public class MessageFeignClientFallback implements MessageFeignClient { |
|||
|
|||
@Override |
|||
public Result sendCode(String mobile) { |
|||
return ModuleUtils.feignConError(ServiceConstant.EPDC_MESSAGE_SERVER, "sendCode", mobile); |
|||
} |
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
package com.elink.esua.epdc.service; |
|||
|
|||
import com.elink.esua.epdc.commons.tools.utils.Result; |
|||
|
|||
/** |
|||
* @author yujintao |
|||
* @email yujintao@elink-cn.com |
|||
* @date 2019/9/11 21:01 |
|||
*/ |
|||
public interface MessageService { |
|||
/** |
|||
* 发送短信验证码 |
|||
* |
|||
* @param mobile |
|||
* @return com.elink.esua.epdc.commons.tools.utils.Result |
|||
* @author yujintao |
|||
* @date 2019/9/11 21:04 |
|||
*/ |
|||
Result sendSmsCode(String mobile); |
|||
} |
|||
@ -1,36 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.service; |
|||
|
|||
import com.elink.esua.epdc.commons.mybatis.service.BaseService; |
|||
import com.elink.esua.epdc.entity.TokenEntity; |
|||
|
|||
/** |
|||
* 用户Token |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
public interface TokenService extends BaseService<TokenEntity> { |
|||
|
|||
TokenEntity getByToken(String token); |
|||
|
|||
/** |
|||
* 生成token |
|||
* @param userId 用户ID |
|||
* @return 返回token信息 |
|||
*/ |
|||
TokenEntity createToken(Long userId); |
|||
|
|||
/** |
|||
* 设置token过期 |
|||
* @param userId 用户ID |
|||
*/ |
|||
void expireToken(Long userId); |
|||
|
|||
} |
|||
@ -1,38 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.service; |
|||
|
|||
import com.elink.esua.epdc.commons.mybatis.service.BaseService; |
|||
import com.elink.esua.epdc.commons.tools.utils.Result; |
|||
import com.elink.esua.epdc.dto.RegisterDTO; |
|||
import com.elink.esua.epdc.entity.UserEntity; |
|||
import com.elink.esua.epdc.dto.LoginDTO; |
|||
|
|||
import java.util.Map; |
|||
|
|||
/** |
|||
* 用户 |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
*/ |
|||
public interface UserService extends BaseService<UserEntity> { |
|||
|
|||
UserEntity getByMobile(String mobile); |
|||
|
|||
UserEntity getUserByUserId(Long userId); |
|||
|
|||
/** |
|||
* 用户登录 |
|||
* @param dto 登录表单 |
|||
* @return 返回登录信息 |
|||
*/ |
|||
Map<String, Object> login(LoginDTO dto); |
|||
|
|||
Result register2(RegisterDTO dto); |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
package com.elink.esua.epdc.service.impl; |
|||
|
|||
import com.elink.esua.epdc.commons.tools.utils.Result; |
|||
import com.elink.esua.epdc.feign.MessageFeignClient; |
|||
import com.elink.esua.epdc.service.MessageService; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
/** |
|||
* @author yujintao |
|||
* @email yujintao@elink-cn.com |
|||
* @date 2019/9/11 21:03 |
|||
*/ |
|||
@Service |
|||
public class MessageServiceImpl implements MessageService { |
|||
|
|||
@Autowired |
|||
private MessageFeignClient messageFeignClient; |
|||
|
|||
/** |
|||
* 发送六位短信验证码 |
|||
* |
|||
* @param mobile |
|||
* @return com.elink.esua.epdc.commons.tools.utils.Result |
|||
* @author yujintao |
|||
* @date 2019/9/12 09:21 |
|||
*/ |
|||
@Override |
|||
public Result sendSmsCode(String mobile) { |
|||
return messageFeignClient.sendCode(mobile); |
|||
} |
|||
} |
|||
@ -1,94 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.service.impl; |
|||
|
|||
import com.elink.esua.epdc.dao.TokenDao; |
|||
import com.elink.esua.epdc.service.TokenService; |
|||
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|||
import com.elink.esua.epdc.dao.TokenDao; |
|||
import com.elink.esua.epdc.entity.TokenEntity; |
|||
import com.elink.esua.epdc.service.TokenService; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.Date; |
|||
import java.util.UUID; |
|||
|
|||
|
|||
@Service |
|||
public class TokenServiceImpl extends BaseServiceImpl<TokenDao, TokenEntity> implements TokenService { |
|||
/** |
|||
* 12小时后过期 |
|||
*/ |
|||
private final static int EXPIRE = 3600 * 12; |
|||
|
|||
@Override |
|||
public TokenEntity getByToken(String token) { |
|||
return baseDao.getByToken(token); |
|||
} |
|||
|
|||
@Override |
|||
public TokenEntity createToken(Long userId) { |
|||
//当前时间
|
|||
Date now = new Date(); |
|||
//过期时间
|
|||
Date expireTime = new Date(now.getTime() + EXPIRE * 1000); |
|||
|
|||
//用户token
|
|||
String token; |
|||
|
|||
//判断是否生成过token
|
|||
TokenEntity tokenEntity = baseDao.getByUserId(userId); |
|||
if(tokenEntity == null){ |
|||
//生成一个token
|
|||
token = generateToken(); |
|||
|
|||
tokenEntity = new TokenEntity(); |
|||
tokenEntity.setUserId(userId); |
|||
tokenEntity.setToken(token); |
|||
tokenEntity.setUpdateDate(now); |
|||
tokenEntity.setExpireDate(expireTime); |
|||
|
|||
//保存token
|
|||
this.insert(tokenEntity); |
|||
}else{ |
|||
//判断token是否过期
|
|||
if(tokenEntity.getExpireDate().getTime() < System.currentTimeMillis()){ |
|||
//token过期,重新生成token
|
|||
token = generateToken(); |
|||
}else { |
|||
token = tokenEntity.getToken(); |
|||
} |
|||
|
|||
tokenEntity.setToken(token); |
|||
tokenEntity.setUpdateDate(now); |
|||
tokenEntity.setExpireDate(expireTime); |
|||
|
|||
//更新token
|
|||
this.updateById(tokenEntity); |
|||
} |
|||
|
|||
return tokenEntity; |
|||
} |
|||
|
|||
@Override |
|||
public void expireToken(Long userId){ |
|||
Date now = new Date(); |
|||
|
|||
TokenEntity tokenEntity = new TokenEntity(); |
|||
tokenEntity.setUserId(userId); |
|||
tokenEntity.setUpdateDate(now); |
|||
tokenEntity.setExpireDate(now); |
|||
|
|||
this.updateById(tokenEntity); |
|||
} |
|||
|
|||
private String generateToken(){ |
|||
return UUID.randomUUID().toString().replace("-", ""); |
|||
} |
|||
} |
|||
@ -1,91 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* <p> |
|||
* https://www.renren.io
|
|||
* <p> |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.service.impl; |
|||
|
|||
import com.elink.esua.epdc.commons.mybatis.service.impl.BaseServiceImpl; |
|||
import com.elink.esua.epdc.commons.tools.exception.ErrorCode; |
|||
import com.elink.esua.epdc.commons.tools.exception.RenException; |
|||
import com.elink.esua.epdc.commons.tools.utils.Result; |
|||
import com.elink.esua.epdc.commons.tools.validator.AssertUtils; |
|||
import com.elink.esua.epdc.dao.UserDao; |
|||
import com.elink.esua.epdc.dto.RegisterDTO; |
|||
import com.elink.esua.epdc.entity.TokenEntity; |
|||
import com.elink.esua.epdc.entity.UserEntity; |
|||
import com.elink.esua.epdc.dto.LoginDTO; |
|||
import com.elink.esua.epdc.feign.DemoFeignClient; |
|||
import com.elink.esua.epdc.service.TokenService; |
|||
import com.elink.esua.epdc.service.UserService; |
|||
import io.seata.spring.annotation.GlobalTransactional; |
|||
import org.apache.commons.codec.digest.DigestUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
|
|||
import java.util.Date; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
@Service |
|||
public class UserServiceImpl extends BaseServiceImpl<UserDao, UserEntity> implements UserService { |
|||
|
|||
@Autowired |
|||
private DemoFeignClient demoFeignClient; |
|||
|
|||
@Autowired |
|||
private TokenService tokenService; |
|||
|
|||
@Override |
|||
public UserEntity getByMobile(String mobile) { |
|||
return baseDao.getUserByMobile(mobile); |
|||
} |
|||
|
|||
@Override |
|||
public UserEntity getUserByUserId(Long userId) { |
|||
return baseDao.getUserByUserId(userId); |
|||
} |
|||
|
|||
@Override |
|||
public Map<String, Object> login(LoginDTO dto) { |
|||
UserEntity user = getByMobile(dto.getMobile()); |
|||
AssertUtils.isNull(user, ErrorCode.ACCOUNT_PASSWORD_ERROR); |
|||
|
|||
//密码错误
|
|||
if (!user.getPassword().equals(DigestUtils.sha256Hex(dto.getPassword()))) { |
|||
throw new RenException(ErrorCode.ACCOUNT_PASSWORD_ERROR); |
|||
} |
|||
|
|||
//获取登录token
|
|||
TokenEntity tokenEntity = tokenService.createToken(user.getId()); |
|||
|
|||
Map<String, Object> map = new HashMap<>(2); |
|||
map.put("token", tokenEntity.getToken()); |
|||
map.put("expire", tokenEntity.getExpireDate().getTime() - System.currentTimeMillis()); |
|||
|
|||
return map; |
|||
} |
|||
|
|||
@Override |
|||
@GlobalTransactional |
|||
public Result register2(RegisterDTO dto) { |
|||
UserEntity user = new UserEntity(); |
|||
user.setMobile(dto.getMobile()); |
|||
user.setUsername(dto.getMobile()); |
|||
user.setPassword(DigestUtils.sha256Hex(dto.getPassword())); |
|||
user.setCreateDate(new Date()); |
|||
boolean success = this.insert(user); |
|||
if (success) { |
|||
Result<String> result = demoFeignClient.seata(dto.getMobile(), 1405); |
|||
if (!result.success()) { |
|||
throw new RuntimeException("失败lelelelellele"); |
|||
} |
|||
return new Result(); |
|||
} |
|||
return new Result().error(); |
|||
} |
|||
|
|||
} |
|||
@ -1,14 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
|
|||
<mapper namespace="com.elink.esua.epdc.dao.TokenDao"> |
|||
|
|||
<select id="getByToken" resultType="com.elink.esua.epdc.entity.TokenEntity"> |
|||
select * from tb_token where token = #{value} |
|||
</select> |
|||
|
|||
<select id="getByUserId" resultType="com.elink.esua.epdc.entity.TokenEntity"> |
|||
select * from tb_token where user_id = #{value} |
|||
</select> |
|||
|
|||
</mapper> |
|||
@ -1,13 +0,0 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
|
|||
<mapper namespace="com.elink.esua.epdc.dao.UserDao"> |
|||
|
|||
<select id="getUserByMobile" resultType="com.elink.esua.epdc.entity.UserEntity"> |
|||
select * from tb_user where mobile = #{value} |
|||
</select> |
|||
|
|||
<select id="getUserByUserId" resultType="com.elink.esua.epdc.entity.UserEntity"> |
|||
select * from tb_user where id = #{value} |
|||
</select> |
|||
</mapper> |
|||
@ -0,0 +1,58 @@ |
|||
package com.elink.esua.epdc.dto.item; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* 项目处理列表DTO |
|||
* @Author LC |
|||
* @Date 2019/9/12 17:42 |
|||
*/ |
|||
@Data |
|||
public class ItemPendingHandleDTO implements Serializable { |
|||
private static final long serialVersionUID = -5197394552788076724L; |
|||
|
|||
/** |
|||
* 项目ID |
|||
*/ |
|||
private String id; |
|||
/** |
|||
* 项目内容 |
|||
*/ |
|||
private String itemContent; |
|||
/** |
|||
* 转项目时间 |
|||
*/ |
|||
private Date createdTime; |
|||
/** |
|||
* 提交人 |
|||
*/ |
|||
private String nickName; |
|||
/** |
|||
* 项目评分 |
|||
*/ |
|||
private Integer evaluationScore; |
|||
/** |
|||
* 支持数 |
|||
*/ |
|||
private Integer approveNum; |
|||
/** |
|||
* 反对数 |
|||
*/ |
|||
private Integer opposeNum; |
|||
/** |
|||
* 评论数 |
|||
*/ |
|||
private Integer commentNum; |
|||
/** |
|||
* 浏览数 |
|||
*/ |
|||
private Integer browseNum; |
|||
/** |
|||
* 参与数 |
|||
*/ |
|||
private Integer participantsNum; |
|||
|
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
package com.elink.esua.epdc.dto.item.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.Min; |
|||
import javax.validation.constraints.NotBlank; |
|||
import java.io.Serializable; |
|||
import java.util.Date; |
|||
|
|||
/** |
|||
* @Author LC |
|||
* @Date 2019/9/9 16:24 |
|||
*/ |
|||
@Data |
|||
public class EvaluationFormDTO implements Serializable { |
|||
private static final long serialVersionUID = -3034807666143092535L; |
|||
|
|||
@NotBlank(message = "项目ID不能为空") |
|||
private String itemId; |
|||
|
|||
@NotBlank(message = "满意度评价得分不能为空") |
|||
private int evaluationScore; |
|||
|
|||
@NotBlank(message = "满意度评价内容不能为空") |
|||
private String evaluationContent; |
|||
|
|||
private String userId; |
|||
|
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
package com.elink.esua.epdc.dto.item.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import javax.validation.constraints.NotNull; |
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* 项目分类统计表单DTO |
|||
* @Author LC |
|||
* @Date 2019/9/12 13:21 |
|||
*/ |
|||
@Data |
|||
public class ItemCategoryStatisticsFormDTO implements Serializable { |
|||
private static final long serialVersionUID = 2999035593195412516L; |
|||
|
|||
/** |
|||
* 网格ID |
|||
*/ |
|||
@NotNull(message = "网格ID不能为空") |
|||
private Long gridId; |
|||
/** |
|||
* 议题类别ID |
|||
*/ |
|||
@NotBlank(message = "议题类别ID不能为空") |
|||
private String categoryId; |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
package com.elink.esua.epdc.dto.item.result; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* 项目分类统计DTO |
|||
* @Author LC |
|||
* @Date 2019/9/12 13:22 |
|||
*/ |
|||
@Data |
|||
public class ItemCategoryStatisticsResultDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1156180616337484819L; |
|||
/** |
|||
* 类别ID |
|||
*/ |
|||
private String categoryId; |
|||
/** |
|||
* 类别名称 |
|||
*/ |
|||
private String categoryName; |
|||
/** |
|||
* 项目个数 |
|||
*/ |
|||
private String itemNum; |
|||
/** |
|||
* 态度总数 |
|||
*/ |
|||
private String attitudeNum; |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
package com.elink.esua.epdc.dto.epdc.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import javax.validation.constraints.NotNull; |
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @author: qushutong |
|||
* @Date: 2019/9/11 17:10 |
|||
* @Description: banner列表 |
|||
*/ |
|||
@Data |
|||
public class EpdcBannerListFromDTO implements Serializable { |
|||
private static final long serialVersionUID = -178835849989066589L; |
|||
|
|||
@NotBlank(message = "新闻位置不能为空") |
|||
private String position; |
|||
/** |
|||
* 网格ID |
|||
*/ |
|||
@NotNull(message = "网格ID不能为空") |
|||
private Long deptId; |
|||
|
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
package com.elink.esua.epdc.dto.epdc.form; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* 新闻详情 |
|||
* |
|||
* @author yujintao |
|||
* @email yujintao@elink-cn.com |
|||
* @date 2019/9/12 10:37 |
|||
*/ |
|||
@Data |
|||
public class EpdcNewsDetailFormDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = -1361194389875631869L; |
|||
|
|||
@NotBlank(message = "新闻ID不能为空") |
|||
private String newsId; |
|||
|
|||
@NotBlank(message = "用户ID不能为空") |
|||
private String userId; |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
package com.elink.esua.epdc.dto.epdc.result; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @author: qushutong 首页第一条消息数据 |
|||
* @Date: 2019/9/11 18:59 |
|||
* @Description: |
|||
*/ |
|||
@Data |
|||
public class EpdcIFristInfoResultDTO implements Serializable { |
|||
|
|||
private static final long serialVersionUID = -8249847977818930805L; |
|||
/** |
|||
* id : 55864 |
|||
* title : FSqWVB8jbB |
|||
* time : 1568199504633 |
|||
* amount : 90109 |
|||
*/ |
|||
|
|||
private String id; |
|||
private String title; |
|||
private String time; |
|||
private int amount; |
|||
|
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
package com.elink.esua.epdc.dto; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @Author LC |
|||
* @Date 2019/9/11 19:22 |
|||
*/ |
|||
@Data |
|||
public class UploadFormDTO implements Serializable { |
|||
private static final long serialVersionUID = -3595962954673866413L; |
|||
|
|||
private String base64String; |
|||
} |
|||
@ -1,45 +0,0 @@ |
|||
package com.elink.esua.epdc.config; |
|||
|
|||
import com.elink.esua.epdc.config.property.WxMpProperties; |
|||
import me.chanjar.weixin.mp.api.WxMpConfigStorage; |
|||
import me.chanjar.weixin.mp.api.WxMpInMemoryConfigStorage; |
|||
import me.chanjar.weixin.mp.api.WxMpService; |
|||
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.boot.context.properties.EnableConfigurationProperties; |
|||
import org.springframework.context.annotation.Bean; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
/** |
|||
* 微信公众号配置 |
|||
* |
|||
* @author yujintao |
|||
* @date 2019/6/17 17:38 |
|||
*/ |
|||
@Configuration |
|||
@EnableConfigurationProperties(WxMpProperties.class) |
|||
public class WxMpConfig { |
|||
|
|||
private WxMpProperties properties; |
|||
|
|||
@Autowired |
|||
public WxMpConfig(WxMpProperties properties) { |
|||
this.properties = properties; |
|||
} |
|||
|
|||
@Bean |
|||
public WxMpService wxMpService() { |
|||
WxMpService wxMpService = new WxMpServiceImpl(); |
|||
wxMpService.setWxMpConfigStorage(wxMpConfigStorage()); |
|||
return wxMpService; |
|||
} |
|||
|
|||
@Bean |
|||
public WxMpConfigStorage wxMpConfigStorage() { |
|||
WxMpInMemoryConfigStorage wxMpConfigStorage = new WxMpInMemoryConfigStorage(); |
|||
wxMpConfigStorage.setAppId(properties.getAppid()); |
|||
wxMpConfigStorage.setSecret(properties.getSecret()); |
|||
return wxMpConfigStorage; |
|||
} |
|||
|
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
package com.elink.esua.epdc.config.property; |
|||
|
|||
import lombok.Data; |
|||
import org.springframework.boot.context.properties.ConfigurationProperties; |
|||
|
|||
/** |
|||
* 微信公众号框架配置类 |
|||
* |
|||
* @author |
|||
* @Date |
|||
*/ |
|||
@Data |
|||
@ConfigurationProperties(prefix = "wx.mp") |
|||
public class WxMpProperties { |
|||
|
|||
/** |
|||
* 设置微信公众号的appid |
|||
*/ |
|||
private String appid; |
|||
|
|||
/** |
|||
* 设置微信公众号的Secret |
|||
*/ |
|||
private String secret; |
|||
|
|||
} |
|||
@ -1,43 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2018 人人开源 All rights reserved. |
|||
* |
|||
* https://www.renren.io
|
|||
* |
|||
* 版权所有,侵权必究! |
|||
*/ |
|||
|
|||
package com.elink.esua.epdc.jwt; |
|||
|
|||
import org.springframework.boot.context.properties.ConfigurationProperties; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
/** |
|||
* Jwt |
|||
* |
|||
* @author Mark sunlightcs@gmail.com |
|||
* @since 1.0.0 |
|||
*/ |
|||
@Configuration |
|||
@ConfigurationProperties(prefix = "jwt") |
|||
public class JwtProperties { |
|||
|
|||
private String secret; |
|||
|
|||
private int expire; |
|||
|
|||
public String getSecret() { |
|||
return secret; |
|||
} |
|||
|
|||
public void setSecret(String secret) { |
|||
this.secret = secret; |
|||
} |
|||
|
|||
public int getExpire() { |
|||
return expire; |
|||
} |
|||
|
|||
public void setExpire(int expire) { |
|||
this.expire = expire; |
|||
} |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue