Merge branch 'dev-nx' of http://192.168.0.56:3000/bonus/devicesmgt into dev-nx
This commit is contained in:
commit
81544d580c
|
|
@ -94,6 +94,14 @@ public class TokenController {
|
|||
|
||||
@PostMapping("sendCode")
|
||||
public R<?> sendCode(@RequestBody LoginBody form) {
|
||||
String uuid = form.getUuid();
|
||||
String captcha = redisService.getCacheObject(CacheConstants.CAPTCHA_CODE_KEY + uuid).toString();
|
||||
if (StringUtils.isBlank(captcha)) {
|
||||
return R.fail("验证码超时,请重新刷新");
|
||||
}
|
||||
if (form.getCode() != null && !form.getCode().equals(captcha)) {
|
||||
return R.fail("验证码错误");
|
||||
}
|
||||
R<Boolean> sendState = remoteUserService.sendCode(form.getPhone());
|
||||
return sendState;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,4 +87,9 @@ public class UserConstants
|
|||
* 手机号长度限制
|
||||
*/
|
||||
public static final int PHONE_DEFAULT_LENGTH_LOGIN = 11;
|
||||
|
||||
/**
|
||||
* 手机1天限制
|
||||
*/
|
||||
public static final String MOBILE_PHONE_1D_LIMIT_DIR = "mobilePhoneDay:";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package com.bonus.sgzb.material.config;
|
|||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* 后端生产随机编码通用方法(格式:今日年月日日期-随机4位编码 20240328-0001)
|
||||
|
|
@ -17,8 +16,8 @@ public class FieldGenerator {
|
|||
String currentDate = today.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
||||
// 生成UUID并取后4位,转换为纯数字类型
|
||||
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
||||
String uuidLast4Digits = uuid.substring(uuid.length() - 4);
|
||||
String uuidLast4Digits = uuid.substring(uuid.length() - 7);
|
||||
int uuidLast4DigitsNumeric = Integer.parseInt(uuidLast4Digits, 16);
|
||||
return currentDate + "-" + String.format("%04d", uuidLast4DigitsNumeric % 10000);
|
||||
return currentDate + "-" + String.format("%07d", uuidLast4DigitsNumeric % 10000);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,6 +81,10 @@ public class MachIneDto {
|
|||
@ApiModelProperty(value = "编码")
|
||||
private String code;
|
||||
|
||||
/** 二维码 */
|
||||
@ApiModelProperty(value = "二维码")
|
||||
private String qrCode;
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -72,4 +72,6 @@ public interface InventoryAndWarehousingMapper {
|
|||
* @return
|
||||
*/
|
||||
int selectTaskNumByMonth(@Param("date") Date nowDate);
|
||||
|
||||
int selectByCode(String code);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import com.bonus.sgzb.common.core.utils.DateUtils;
|
|||
import com.bonus.sgzb.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.sgzb.common.security.utils.SecurityUtils;
|
||||
import com.bonus.sgzb.material.config.ExceptionEnum;
|
||||
import com.bonus.sgzb.material.config.FieldGenerator;
|
||||
import com.bonus.sgzb.material.domain.MachIneDto;
|
||||
import com.bonus.sgzb.material.domain.PutInStorageBean;
|
||||
import com.bonus.sgzb.material.domain.SavePutInfoDto;
|
||||
|
|
@ -74,13 +75,23 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi
|
|||
log.info("新增入库盘点入参dto:{}", dto);
|
||||
Long userId = SecurityUtils.getLoginUser().getUserid();
|
||||
dto.setCreator(userId);
|
||||
List<String> codeList = new ArrayList<>();
|
||||
if (dto.getNum() != null) {
|
||||
while (codeList.size() < dto.getNum()) {
|
||||
String code = FieldGenerator.generateField();
|
||||
int count = selectByCode(code);
|
||||
if (count == 0 && !codeList.contains(code)) {
|
||||
codeList.add(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
String code = genderBackCode();
|
||||
int res;
|
||||
try {
|
||||
//1. 判断是数量还是编号入库,保存到不同表
|
||||
//1.1 如果是编号入库
|
||||
if (dto.getIsCode()) {
|
||||
res = insertMaMachineInfo(dto, code);
|
||||
res = insertMaMachineInfo(dto, codeList, code);
|
||||
if (res == 0) {
|
||||
log.error("insertMaMachineInfo方法插入异常");
|
||||
throw new RuntimeException("insertMaMachineInfo方法插入异常");
|
||||
|
|
@ -108,13 +119,22 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi
|
|||
return AjaxResult.success(res);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code从ma_machine表查询是否有数据,去重
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
private int selectByCode(String code) {
|
||||
return inventoryAndWarehousingMapper.selectByCode(code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 编号新增,插入ma_machine、ma_machine_label和ma_label_bind
|
||||
* @param dto
|
||||
* @param code
|
||||
* @return
|
||||
*/
|
||||
private int insertMaMachineInfo(SavePutInfoDto dto, String code) {
|
||||
private int insertMaMachineInfo(SavePutInfoDto dto, List<String> codeList, String code) {
|
||||
int res = 0;
|
||||
if (dto.getNum() != null) {
|
||||
MachIneDto machIneDto = dto.getMachIneDtoList().get(0);
|
||||
|
|
@ -129,6 +149,8 @@ public class InventoryAndWarehousingServiceImpl implements InventoryAndWarehousi
|
|||
for (int i = 0; i < dto.getMachIneDtoList().size(); i++) {
|
||||
MachIneDto machIneDto = dto.getMachIneDtoList().get(i);
|
||||
machIneDto.setCode(code);
|
||||
String qrCode = codeList.get(i);
|
||||
machIneDto.setQrCode(qrCode);
|
||||
machIneDto.setIsCode(dto.getIsCode());
|
||||
machIneDto.setTypeId(dto.getTypeId());
|
||||
machIneDto.setCreator(dto.getCreator());
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@
|
|||
<if test="typeId != null and typeId != '' ">type_id,</if>
|
||||
<if test="maCode != null and maCode != '' ">ma_code,</if>
|
||||
ma_status,
|
||||
<if test="code != null and code != ''">qr_code,</if>
|
||||
<if test="qrCode != null and qrCode != ''">qr_code,</if>
|
||||
<if test="buyPrice != null and buyPrice != ''">buy_price,</if>
|
||||
<if test="maVender != null and maVender != ''">ma_vender,</if>
|
||||
<if test="checkMan != null and checkMan != ''">check_man,</if>
|
||||
|
|
@ -140,7 +140,7 @@
|
|||
<if test="typeId != null and typeId != ''">#{typeId},</if>
|
||||
<if test="maCode != null and maCode != ''">#{maCode},</if>
|
||||
15,
|
||||
<if test="code != null and code != ''">#{code},</if>
|
||||
<if test="qrCode != null and qrCode != ''">#{qrCode},</if>
|
||||
<if test="buyPrice != null and buyPrice != ''">#{buyPrice},</if>
|
||||
<if test="maVender != null and maVender != ''">#{maVender},</if>
|
||||
<if test="checkMan != null and checkMan != ''">#{checkMan},</if>
|
||||
|
|
@ -153,14 +153,14 @@
|
|||
<insert id="insertMachineLabel">
|
||||
insert into ma_machine_label
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="code != null">label_code,</if>
|
||||
<if test="qrCode != null">label_code,</if>
|
||||
<if test="maId != null">ma_id,</if>
|
||||
is_bind,
|
||||
label_type,
|
||||
create_time
|
||||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="code != null">#{code},</if>
|
||||
<if test="qrCode != null">#{qrCode},</if>
|
||||
<if test="maId != null">#{maId},</if>
|
||||
1,
|
||||
9,
|
||||
|
|
@ -171,7 +171,7 @@
|
|||
insert into ma_label_bind
|
||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||
<if test="maId != null">ma_id,</if>
|
||||
<if test="code != null">label_code,</if>
|
||||
<if test="qrCode != null">label_code,</if>
|
||||
<if test="typeId != null">type_id,</if>
|
||||
<if test="creator != null">binder,</if>
|
||||
label_type,
|
||||
|
|
@ -180,7 +180,7 @@
|
|||
</trim>
|
||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||
<if test="maId != null">#{maId},</if>
|
||||
<if test="code != null">#{code},</if>
|
||||
<if test="qrCode != null">#{qrCode},</if>
|
||||
<if test="typeId != null">#{typeId},</if>
|
||||
<if test="creator != null">#{creator},</if>
|
||||
9,
|
||||
|
|
@ -231,4 +231,11 @@
|
|||
<select id="selectTaskNumByMonth" resultType="java.lang.Integer">
|
||||
select count(*) from ma_type_put_in_storage_info where DATE_FORMAT(CREATE_DATE,'%y%m') = DATE_FORMAT(#{date},'%y%m')
|
||||
</select>
|
||||
<select id="selectByCode" resultType="java.lang.Integer">
|
||||
select count(*)
|
||||
from ma_machine
|
||||
<where>
|
||||
<if test="code != null ">and qr_code = #{code}</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
|
|
@ -99,7 +99,7 @@ public class SysProfileController extends BaseController {
|
|||
@Log(title = "个人信息", businessType = BusinessType.UPDATE)
|
||||
@PutMapping("/updatePwd")
|
||||
public AjaxResult updatePwd(String oldPassword, String newPassword) {
|
||||
String username = SecurityUtils.getUsername();
|
||||
String username = SecurityUtils.getLoginUser().getUsername();
|
||||
SysUser user = userService.selectUserByUserName(username);
|
||||
String password = user.getPassword();
|
||||
if (!SecurityUtils.matchesPassword(oldPassword, password)) {
|
||||
|
|
|
|||
|
|
@ -136,6 +136,10 @@ public class SysSmsServiceImpl implements ISysSmsService {
|
|||
if (phone == null || phone.length() != UserConstants.PHONE_DEFAULT_LENGTH_LOGIN) {
|
||||
return AjaxResult.error("手机号格式错误,请输入11位数字号码");
|
||||
}
|
||||
// 检查发送次数是否超限
|
||||
if (isOverLimit(phone)) {
|
||||
throw new ServiceException("当天此手机号发送验证码次数超过限制", 1001);
|
||||
}
|
||||
String code = getSixBitCode();
|
||||
// 校验验证码
|
||||
if (code.length() != UserConstants.CODE_MIN_LENGTH_LOGIN) {
|
||||
|
|
@ -151,12 +155,33 @@ public class SysSmsServiceImpl implements ISysSmsService {
|
|||
}
|
||||
// 存储验证码至Redis中,键值为:code_15588886157 , 有效期5,时间颗粒度为MINUTES:分钟
|
||||
redisService.setCacheObject("code_" + phone, code, 5L, TimeUnit.MINUTES);
|
||||
return success("手机号:" + phone + ",用户登录验证码:" + code + ",返回结果:" + body);
|
||||
String key = UserConstants.MOBILE_PHONE_1D_LIMIT_DIR + phone;
|
||||
Integer sendCount = redisService.getCacheObject(key);
|
||||
if (sendCount == null) {
|
||||
sendCount = 1;
|
||||
} else {
|
||||
sendCount++;
|
||||
}
|
||||
//存储一天手机号发送验证码数据
|
||||
redisService.setCacheObject(key, sendCount, 1L, TimeUnit.DAYS);
|
||||
return success("手机号:" + phone + ",短信验证码发送成功 !");
|
||||
} catch (Exception e) {
|
||||
return AjaxResult.error("发送失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查发送次数是否超过限制
|
||||
* @param phone 手机号
|
||||
* @return
|
||||
*/
|
||||
private boolean isOverLimit(String phone) {
|
||||
String key = UserConstants.MOBILE_PHONE_1D_LIMIT_DIR + phone;
|
||||
Integer sendCount = redisService.getCacheObject(key);
|
||||
// 限制每个手机号每天最多发送10次
|
||||
return sendCount != null && sendCount >= 10;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断验证码是否存在Redis中
|
||||
|
|
|
|||
Loading…
Reference in New Issue