Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
134cb90a02
|
|
@ -128,6 +128,13 @@
|
|||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.aliyun</groupId>
|
||||
<artifactId>dysmsapi20170525</artifactId>
|
||||
<version>2.0.21</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
</dependencies>
|
||||
<profiles>
|
||||
<profile>
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class TbProskuConController {
|
|||
} catch (BadRequestException be) {
|
||||
throw new Exception(be.getMessage());
|
||||
}catch (Exception e){
|
||||
throw new Exception("系统异常");
|
||||
throw new Exception("相同商品耗材信息不允许添加");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,18 +16,31 @@
|
|||
package cn.ysk.cashier.controller;
|
||||
|
||||
import cn.ysk.cashier.annotation.Log;
|
||||
import cn.ysk.cashier.exception.BadRequestException;
|
||||
import cn.ysk.cashier.pojo.TbUserInfo;
|
||||
import cn.ysk.cashier.pojo.shop.TbMerchantAccount;
|
||||
import cn.ysk.cashier.repository.TbUserInfoRepository;
|
||||
import cn.ysk.cashier.repository.shop.TbMerchantAccountRepository;
|
||||
import cn.ysk.cashier.service.TbUserInfoService;
|
||||
import cn.ysk.cashier.dto.TbUserInfoQueryCriteria;
|
||||
import cn.ysk.cashier.utils.*;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import io.swagger.annotations.*;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
|
|
@ -75,4 +88,98 @@ public class TbUserInfoController {
|
|||
tbUserInfoService.deleteAll(ids);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
ValidateCodeUtil validateCodeUtil;
|
||||
|
||||
@Autowired
|
||||
RedisUtils redisUtils;
|
||||
|
||||
@GetMapping("sendMsg")
|
||||
public Object sendMsg(){
|
||||
Object o= SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
if(Objects.isNull(o)){
|
||||
throw new BadRequestException("用户登录信息失效");
|
||||
}
|
||||
JSONObject object=JSON.parseObject(JSON.toJSONString(o));
|
||||
if(Objects.isNull(object)){
|
||||
throw new BadRequestException("用户登录信息失效");
|
||||
}
|
||||
String regex="^\\d{11}$";
|
||||
|
||||
if(!object.containsKey("username")||Objects.isNull(object.getString("username"))||
|
||||
!object.getString("username").matches(regex)
|
||||
){
|
||||
throw new BadRequestException("用户登录信息失效");
|
||||
}
|
||||
String phone=object.getString("username");
|
||||
|
||||
String tempcode="SMS_244665149";
|
||||
|
||||
String random = StringUtil.random(6);
|
||||
try {
|
||||
validateCodeUtil.requestValidateCodeAli(phone, random,tempcode);
|
||||
redisUtils.set(phone.concat("#").concat(tempcode),random,300L);
|
||||
return "{\n" +
|
||||
" \"code\": 0,\n" +
|
||||
" \"msg\": \"成功\"\n" +
|
||||
"}";
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
TbMerchantAccountRepository tbMerchantAccountRepository;
|
||||
|
||||
|
||||
@RequestMapping(value = "modfiyUserInfo",method = RequestMethod.POST)
|
||||
public ResponseEntity<Object> modfiyUserInfo(@RequestBody Map<String,String> map){
|
||||
Object o= SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
if(Objects.isNull(o)){
|
||||
throw new BadRequestException("用户登录信息失效");
|
||||
}
|
||||
JSONObject object=JSON.parseObject(JSON.toJSONString(o));
|
||||
if(Objects.isNull(object)){
|
||||
throw new BadRequestException("用户登录信息失效");
|
||||
}
|
||||
String regex="^\\d{11}$";
|
||||
|
||||
if(!object.containsKey("username")||Objects.isNull(object.getString("username"))||
|
||||
!object.getString("username").matches(regex)
|
||||
){
|
||||
throw new BadRequestException("用户登录信息失效");
|
||||
}
|
||||
|
||||
String tempcode="SMS_244665149";
|
||||
String phone=object.getString("username");
|
||||
Object redisCode= redisUtils.get(phone.concat("#").concat(tempcode));
|
||||
if(Objects.isNull(redisCode)){
|
||||
throw new BadRequestException("短信验证码已过期");
|
||||
}
|
||||
|
||||
|
||||
String code= map.get("code");
|
||||
|
||||
if(!redisCode.toString().equals(code)){
|
||||
throw new BadRequestException("短信验证码错误");
|
||||
}
|
||||
redisUtils.del(phone.concat("#").concat(tempcode));
|
||||
String pwd= map.get("pwd");
|
||||
|
||||
TbMerchantAccount account= tbMerchantAccountRepository.findByAccount(phone);
|
||||
if(Objects.isNull(account)){
|
||||
throw new BadRequestException("账户不存在");
|
||||
}
|
||||
|
||||
account.setPwd(MD5Utils.md5(pwd.concat(account.getAccount()).concat(account.getId().toString())));
|
||||
account.setUpdatedAt(System.currentTimeMillis());
|
||||
tbMerchantAccountRepository.save(account);
|
||||
|
||||
|
||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -127,6 +127,10 @@ public class TbMerchantAccount implements Serializable {
|
|||
@ApiModelProperty(value = "updatedAt")
|
||||
private Long updatedAt;
|
||||
|
||||
@Column(name = "`pwd`")
|
||||
@ApiModelProperty(value = "操作密码")
|
||||
private String pwd;
|
||||
|
||||
public void copy(TbMerchantAccount source){
|
||||
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,4 +25,6 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
|||
* @date 2023-11-13
|
||||
**/
|
||||
public interface TbUserInfoRepository extends JpaRepository<TbUserInfo, Integer>, JpaSpecificationExecutor<TbUserInfo> {
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -38,4 +38,7 @@ public interface TbMerchantAccountRepository extends JpaRepository<TbMerchantAcc
|
|||
@Modifying
|
||||
@Query(value = "update tb_merchant_account set password = ?2 , updated_at = ?3 where account = ?1",nativeQuery = true)
|
||||
void updatePass(String account, String password, Long lastPasswordResetTime);
|
||||
|
||||
|
||||
TbMerchantAccount findByAccount(String account);
|
||||
}
|
||||
|
|
@ -80,4 +80,7 @@ public interface TbUserInfoService {
|
|||
* @throws IOException /
|
||||
*/
|
||||
void download(List<TbUserInfoDto> all, HttpServletResponse response) throws IOException;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
package cn.ysk.cashier.utils;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Random;
|
||||
|
||||
/**
|
||||
* @author lyf
|
||||
*/
|
||||
public class StringUtil {
|
||||
/**
|
||||
* 生成指定长度的随机数
|
||||
* @param length
|
||||
* @return
|
||||
*/
|
||||
public static String genRandomNum(int length) {
|
||||
int maxNum = 36;
|
||||
int i;
|
||||
int count = 0;
|
||||
char[] str = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
|
||||
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
|
||||
'X', 'Y', 'Z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
|
||||
StringBuffer pwd = new StringBuffer("");
|
||||
Random r = new Random();
|
||||
while (count < length) {
|
||||
i = Math.abs(r.nextInt(maxNum));
|
||||
pwd.append(str[i]);
|
||||
count++;
|
||||
}
|
||||
return pwd.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成订单号
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static synchronized String getBillno() {
|
||||
StringBuilder billno = new StringBuilder();
|
||||
|
||||
// 日期(格式:20080524)
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmssSSS");
|
||||
billno.append(format.format(new Date()));
|
||||
return billno.toString();
|
||||
}
|
||||
public static JSONArray stringChangeList(String listString){
|
||||
// 使用Fastjson将JSON字符串转换为JSONArray对象
|
||||
return JSON.parseArray(listString);
|
||||
|
||||
}
|
||||
|
||||
public static String random(int length) {
|
||||
Random random = new Random();
|
||||
String result = "";
|
||||
for (int i = 0; i < length; i++) {
|
||||
result += random.nextInt(10);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static final String CHINESE_CHARS = "你我他她它们这里那里多少是否好坏快慢上下左右前后高低大小长短方圆胖瘦黑白红绿蓝黄紫粉红桔红橙黄棕灰褐";
|
||||
|
||||
// 生成随机中文昵称
|
||||
public static String generateRandomNickname(int length) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < length; i++) {
|
||||
int index = random.nextInt(CHINESE_CHARS.length());
|
||||
char randomChar = CHINESE_CHARS.charAt(index);
|
||||
sb.append(randomChar);
|
||||
}
|
||||
return desensitizeNickname(sb.toString());
|
||||
}
|
||||
|
||||
// 对昵称进行脱敏处理
|
||||
public static String desensitizeNickname(String nickname) {
|
||||
if (nickname == null || nickname.length() != 5) {
|
||||
return nickname;
|
||||
}
|
||||
return nickname.charAt(0) + "***" + nickname.charAt(4);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,76 @@
|
|||
package cn.ysk.cashier.utils;
|
||||
|
||||
import com.aliyun.dysmsapi20170525.Client;
|
||||
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
|
||||
import com.aliyun.teaopenapi.models.Config;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
* 获取验证码相关工具
|
||||
* @author 12847
|
||||
*/
|
||||
@Component
|
||||
public class ValidateCodeUtil {
|
||||
/**
|
||||
* 阿里云key
|
||||
*/
|
||||
@Value("${aliyun.keyid}")
|
||||
private String ACCESSKEYID;
|
||||
/**
|
||||
* 阿里云secret
|
||||
*/
|
||||
@Value("${aliyun.keysecret}")
|
||||
private String ACCESSKEYSECRET;
|
||||
/**
|
||||
* 十小时
|
||||
*/
|
||||
protected static final long MILLIS_MINUTE = 10 *60 * 60 *1000;
|
||||
|
||||
@Autowired
|
||||
private HttpServletRequest request;
|
||||
|
||||
|
||||
/**
|
||||
* 获取验证码(阿里云)
|
||||
*/
|
||||
public SendSmsResponse requestValidateCodeAli(String phone, String checkCode,String templateCode) throws Exception {
|
||||
Client client = null;
|
||||
try {
|
||||
client = createClient();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 1.发送短信
|
||||
com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
|
||||
.setSignName("银收客")
|
||||
.setTemplateCode(templateCode)
|
||||
.setTemplateParam("{\"code\":" +"'"+checkCode +"'"+"}")
|
||||
.setPhoneNumbers(phone);
|
||||
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
|
||||
try {
|
||||
assert client != null;
|
||||
return client.sendSmsWithOptions(sendSmsRequest, runtime);
|
||||
} catch (Exception e) {
|
||||
throw new Exception(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 发送短信(阿里云)
|
||||
*
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public Client createClient() throws Exception {
|
||||
Config config = new Config();
|
||||
config.accessKeyId = ACCESSKEYID;
|
||||
config.accessKeySecret = ACCESSKEYSECRET;
|
||||
return new com.aliyun.dysmsapi20170525.Client(config);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -72,3 +72,9 @@ mybatis-plus:
|
|||
global-config:
|
||||
db-config:
|
||||
id-type: auto
|
||||
aliyun:
|
||||
keyid: LTAI5tPdEfYSZcqHbjCrtPRD
|
||||
keysecret: DZjyHBq3nTujF0NMLxnZgsecU8ZCvy
|
||||
oss:
|
||||
bucketname: cashier-oss
|
||||
endpoint: oss-cn-beijing.aliyuncs.com
|
||||
|
|
|
|||
Loading…
Reference in New Issue