fix: 优化逻辑

This commit is contained in:
tangwei 2026-04-27 15:55:24 +08:00
parent 6a0216c3bf
commit 3a7f89b9a0
13 changed files with 323 additions and 70 deletions

View File

@ -95,6 +95,19 @@ public class FishDraftData implements Serializable {
*/ */
private String picpth; private String picpth;
/**
* 过鱼视频文件路径
*/
@TableField(exist = false)
private String vdpthName;
/**
* 图片文件路径
*/
@TableField(exist = false)
private String picpthName;
/** /**
* 是否鱼苗0否 1是 * 是否鱼苗0否 1是
*/ */

View File

@ -42,16 +42,21 @@ public class FishImportResult {
private FishDraftData data; private FishDraftData data;
private List<String> unrecognizedFields; private List<String> unrecognizedFields;
private List<String> warnings; private List<String> warnings;
private List<String> vdpthsWarnings;
private List<String> picpthsWarnings;
public FishImportRow() { public FishImportRow() {
this.unrecognizedFields = new ArrayList<>(); this.unrecognizedFields = new ArrayList<>();
this.warnings = new ArrayList<>(); this.warnings = new ArrayList<>();
this.vdpthsWarnings = new ArrayList<>();
this.picpthsWarnings = new ArrayList<>();
} }
public FishImportRow(int rowIndex) { public FishImportRow(int rowIndex) {
this.rowIndex = rowIndex; this.rowIndex = rowIndex;
this.unrecognizedFields = new ArrayList<>(); this.unrecognizedFields = new ArrayList<>();
this.warnings = new ArrayList<>(); this.warnings = new ArrayList<>();
this.vdpthsWarnings = new ArrayList<>();
this.picpthsWarnings = new ArrayList<>();
} }
} }
} }

View File

@ -1,8 +1,12 @@
package com.yfd.platform.data.service; package com.yfd.platform.data.service;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
@ -10,6 +14,8 @@ import java.net.http.HttpClient;
import java.net.http.HttpRequest; import java.net.http.HttpRequest;
import java.net.http.HttpResponse; import java.net.http.HttpResponse;
import java.nio.file.Files; import java.nio.file.Files;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -42,19 +48,29 @@ public class AttachmentUploadService {
"Content-Type: application/octet-stream\r\n\r\n"; "Content-Type: application/octet-stream\r\n\r\n";
String footer = "\r\n--" + boundary + "--\r\n"; String footer = "\r\n--" + boundary + "--\r\n";
byte[] body; byte[] body = new byte[header.getBytes().length + fileContent.length + footer.getBytes().length];
if (fileName.toLowerCase().endsWith(".mp4") || fileName.toLowerCase().endsWith(".avi") ||
fileName.toLowerCase().endsWith(".mov") || fileName.toLowerCase().endsWith(".wmv")) {
body = new byte[header.getBytes().length + fileContent.length + footer.getBytes().length];
System.arraycopy(header.getBytes(), 0, body, 0, header.getBytes().length);
System.arraycopy(fileContent, 0, body, header.getBytes().length, fileContent.length);
System.arraycopy(footer.getBytes(), 0, body, header.getBytes().length + fileContent.length, footer.getBytes().length);
} else {
body = new byte[header.getBytes().length + fileContent.length + footer.getBytes().length];
System.arraycopy(header.getBytes(), 0, body, 0, header.getBytes().length); System.arraycopy(header.getBytes(), 0, body, 0, header.getBytes().length);
System.arraycopy(fileContent, 0, body, header.getBytes().length, fileContent.length); System.arraycopy(fileContent, 0, body, header.getBytes().length, fileContent.length);
System.arraycopy(footer.getBytes(), 0, body, header.getBytes().length + fileContent.length, footer.getBytes().length); System.arraycopy(footer.getBytes(), 0, body, header.getBytes().length + fileContent.length, footer.getBytes().length);
try {
// 1. 创建信任所有证书的 TrustManager
TrustManager[] trustAllCerts = new TrustManager[]{
new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) {}
public void checkServerTrusted(X509Certificate[] chain, String authType) {}
public X509Certificate[] getAcceptedIssuers() { return new X509Certificate[0]; }
} }
};
// 2. 初始化 SSLContext
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(null, trustAllCerts, new SecureRandom());
// 3. 构建支持 HTTPS 且忽略证书验证的 HttpClient
HttpClient secureClient = HttpClient.newBuilder()
.sslContext(sc)
.build();
HttpRequest request = HttpRequest.newBuilder() HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(UPLOAD_URL)) .uri(URI.create(UPLOAD_URL))
@ -62,7 +78,8 @@ public class AttachmentUploadService {
.POST(HttpRequest.BodyPublishers.ofByteArray(body)) .POST(HttpRequest.BodyPublishers.ofByteArray(body))
.build(); .build();
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); // 4. 使用新的 secureClient 发送请求
HttpResponse<String> response = secureClient.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == 200) { if (response.statusCode() == 200) {
String responseBody = response.body(); String responseBody = response.body();
@ -71,8 +88,11 @@ public class AttachmentUploadService {
log.error("上传文件失败: {}, 状态码: {}", fileName, response.statusCode()); log.error("上传文件失败: {}, 状态码: {}", fileName, response.statusCode());
return null; return null;
} }
} catch (Exception e) {
log.error("文件上传过程中发生异常: {}", e.getMessage(), e);
return null;
}
} }
public String uploadVideo(File file) throws IOException, InterruptedException { public String uploadVideo(File file) throws IOException, InterruptedException {
return uploadFile(file); return uploadFile(file);
} }
@ -137,19 +157,14 @@ public class AttachmentUploadService {
} }
try { try {
if (jsonResponse.contains("\"message\":")) { JSONObject json = JSONObject.parseObject(jsonResponse);
int start = jsonResponse.indexOf("\"message\":\"") + 11; // 尝试从常见的返回字段中获取 ID根据实际接口返回调整 key
int end = jsonResponse.indexOf("\"", start); if (json.containsKey("message")) {
if (start > 10 && end > start) { return json.getString("message");
return jsonResponse.substring(start, end); } else if (json.containsKey("data")) {
} return json.getString("data");
} } else if (json.containsKey("id")) {
if (jsonResponse.contains("\"message\":\"")) { return json.getString("id");
int start = jsonResponse.indexOf("\"message\":\"") + 11;
int end = jsonResponse.indexOf("\"", start);
if (start > 10 && end > start) {
return jsonResponse.substring(start, end);
}
} }
} catch (Exception e) { } catch (Exception e) {
log.error("解析附件ID失败: {}", jsonResponse, e); log.error("解析附件ID失败: {}", jsonResponse, e);

View File

@ -22,6 +22,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigDecimal;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.*; import java.util.*;
@ -105,6 +106,8 @@ public class FishImportServiceImpl implements IFishImportService {
EXCEL_COLUMN_INDEX_MAPPING.put(8, "fsz"); EXCEL_COLUMN_INDEX_MAPPING.put(8, "fsz");
EXCEL_COLUMN_INDEX_MAPPING.put(9, "fwet"); EXCEL_COLUMN_INDEX_MAPPING.put(9, "fwet");
EXCEL_COLUMN_INDEX_MAPPING.put(10, "wt"); EXCEL_COLUMN_INDEX_MAPPING.put(10, "wt");
EXCEL_COLUMN_INDEX_MAPPING.put(11, "picpth");
EXCEL_COLUMN_INDEX_MAPPING.put(12, "vdpth");
} }
@Override @Override
@ -269,6 +272,19 @@ public class FishImportServiceImpl implements IFishImportService {
data.setFcnt(fcnt); data.setFcnt(fcnt);
} }
break; break;
case "wt":
if (!StringUtils.hasText(cellValue)) {
importRow.getWarnings().add(fieldName);
data.setWt(parseBigDecimal(cellValue));
} else {
BigDecimal wt = parseBigDecimal(cellValue);
if (wt == null) {
importRow.getWarnings().add(fieldName);
data.setWt(parseBigDecimal(cellValue));
}
data.setWt(wt);
}
break;
case "fwet": case "fwet":
data.setFwet(cellValue.trim()); data.setFwet(cellValue.trim());
break; break;
@ -303,14 +319,16 @@ public class FishImportServiceImpl implements IFishImportService {
break; break;
case "vdpth": case "vdpth":
data.setVdpth(cellValue.trim()); data.setVdpth(cellValue.trim());
data.setVdpthName(cellValue.trim());
break; break;
case "picpth": case "picpth":
data.setPicpth(cellValue.trim()); data.setPicpth(cellValue.trim());
data.setPicpthName(cellValue.trim());
break; break;
case "isfs": case "isfs":
if (StringUtils.hasText(cellValue)) { if (StringUtils.hasText(cellValue)) {
String isfs = resolveIsfs(cellValue.trim(), importRow); String isfs = resolveIsfs(cellValue.trim(), importRow);
data.setIsfs("".equals(isfs) ? 1 : 0); data.setIsfs("1".equals(isfs) ? 1 : 0);
} }
break; break;
case "sourceType": case "sourceType":
@ -525,13 +543,13 @@ public class FishImportServiceImpl implements IFishImportService {
String lowerName = direction.toLowerCase().trim(); String lowerName = direction.toLowerCase().trim();
if (lowerName.contains("上行") && lowerName.contains("折返")) { if (lowerName.contains("上行") && lowerName.contains("折返")) {
return "03"; return "2";
} else if (lowerName.contains("下行") && lowerName.contains("折返")) { } else if (lowerName.contains("下行") && lowerName.contains("折返")) {
return "04"; return "3";
} else if (lowerName.contains("上行")) { } else if (lowerName.contains("上行")) {
return "01"; return "0";
} else if (lowerName.contains("下行")) { } else if (lowerName.contains("下行")) {
return "02"; return "1";
} }
importRow.getWarnings().add("direction"); importRow.getWarnings().add("direction");
return direction; return direction;
@ -677,6 +695,23 @@ public class FishImportServiceImpl implements IFishImportService {
} }
} }
/**
* 解析 BigDecimal 类型数据
* @param value 字符串数值
* @return BigDecimal 对象解析失败或为空时返回 null
*/
private BigDecimal parseBigDecimal(String value) {
if (!StringUtils.hasText(value)) {
return null;
}
try {
return new BigDecimal(value.trim());
} catch (NumberFormatException e) {
return null;
}
}
private String parseSourceType(String value) { private String parseSourceType(String value) {
if (!StringUtils.hasText(value)) { if (!StringUtils.hasText(value)) {
return "IMPORT"; return "IMPORT";
@ -732,8 +767,24 @@ public class FishImportServiceImpl implements IFishImportService {
} }
private void processAttachments(FishImportResult result, ZipFileUtil.ZipContent zipContent) { private void processAttachments(FishImportResult result, ZipFileUtil.ZipContent zipContent) {
if (result.getSuccessRows() == null || result.getSuccessRows().isEmpty()) { for (FishImportResult.FishImportRow importRow : result.getFailedRows()) {
return; FishDraftData data = importRow.getData();
if (data == null) {
continue;
}
String vdpth = data.getVdpth();
String picpth = data.getPicpth();
if (StringUtils.hasText(vdpth)) {
String uploadedVdpth = processVideoAttachments(importRow,vdpth, zipContent.videos);
data.setVdpth(uploadedVdpth);
}
if (StringUtils.hasText(picpth)) {
String uploadedPicpth = processImageAttachments(importRow,picpth, zipContent.images);
data.setPicpth(uploadedPicpth);
}
} }
for (FishImportResult.FishImportRow importRow : result.getSuccessRows()) { for (FishImportResult.FishImportRow importRow : result.getSuccessRows()) {
@ -746,18 +797,18 @@ public class FishImportServiceImpl implements IFishImportService {
String picpth = data.getPicpth(); String picpth = data.getPicpth();
if (StringUtils.hasText(vdpth)) { if (StringUtils.hasText(vdpth)) {
String uploadedVdpth = processVideoAttachments(vdpth, zipContent.videos); String uploadedVdpth = processVideoAttachments(importRow,vdpth, zipContent.videos);
data.setVdpth(uploadedVdpth); data.setVdpth(uploadedVdpth);
} }
if (StringUtils.hasText(picpth)) { if (StringUtils.hasText(picpth)) {
String uploadedPicpth = processImageAttachments(picpth, zipContent.images); String uploadedPicpth = processImageAttachments(importRow,picpth, zipContent.images);
data.setPicpth(uploadedPicpth); data.setPicpth(uploadedPicpth);
} }
} }
} }
private String processVideoAttachments(String videoNames, Map<String, String> videoMap) { private String processVideoAttachments(FishImportResult.FishImportRow importRow, String videoNames, Map<String, String> videoMap) {
if (videoNames == null || videoNames.isEmpty() || videoMap == null || videoMap.isEmpty()) { if (videoNames == null || videoNames.isEmpty() || videoMap == null || videoMap.isEmpty()) {
return videoNames; return videoNames;
} }
@ -778,20 +829,24 @@ public class FishImportServiceImpl implements IFishImportService {
if (attachmentId != null) { if (attachmentId != null) {
attachmentIds.add(attachmentId); attachmentIds.add(attachmentId);
} else { } else {
attachmentIds.add(fileName); importRow.getVdpthsWarnings().add(fileName);
// attachmentIds.add(fileName);
} }
} catch (Exception e) { } catch (Exception e) {
attachmentIds.add(fileName); e.printStackTrace();
importRow.getVdpthsWarnings().add(fileName);
// attachmentIds.add(fileName);
} }
} else { } else {
attachmentIds.add(fileName); importRow.getVdpthsWarnings().add(fileName);
// attachmentIds.add(fileName);
} }
} }
return String.join(",", attachmentIds); return String.join(",", attachmentIds);
} }
private String processImageAttachments(String imageNames, Map<String, String> imageMap) { private String processImageAttachments(FishImportResult.FishImportRow importRow,String imageNames, Map<String, String> imageMap) {
if (imageNames == null || imageNames.isEmpty() || imageMap == null || imageMap.isEmpty()) { if (imageNames == null || imageNames.isEmpty() || imageMap == null || imageMap.isEmpty()) {
return imageNames; return imageNames;
} }
@ -812,13 +867,17 @@ public class FishImportServiceImpl implements IFishImportService {
if (attachmentId != null) { if (attachmentId != null) {
attachmentIds.add(attachmentId); attachmentIds.add(attachmentId);
} else { } else {
attachmentIds.add(fileName); importRow.getPicpthsWarnings().add(fileName);
// attachmentIds.add(fileName);
} }
} catch (Exception e) { } catch (Exception e) {
attachmentIds.add(fileName); e.printStackTrace();
importRow.getPicpthsWarnings().add(fileName);
// attachmentIds.add(fileName);
} }
} else { } else {
attachmentIds.add(fileName); importRow.getPicpthsWarnings().add(fileName);
// attachmentIds.add(fileName);
} }
} }

View File

@ -96,4 +96,12 @@ public class SdHbrvDicController {
boolean result = hbrvDicService.deleteHbrvDic(hbrvcd, baseid); boolean result = hbrvDicService.deleteHbrvDic(hbrvcd, baseid);
return result ? ResponseResult.success("删除成功") : ResponseResult.error("删除失败"); return result ? ResponseResult.success("删除成功") : ResponseResult.error("删除失败");
} }
@GetMapping("/selectForDropdown")
@Operation(summary = "下拉框列表查询")
public ResponseResult selectForDropdown(
@RequestParam(required = false) String hbrvnm,
@RequestParam(required = false) String baseid) {
return ResponseResult.successData(hbrvDicService.selectForDropdown(hbrvnm, baseid));
}
} }

View File

@ -47,4 +47,9 @@ public interface ISdHbrvDicService extends IService<SdHbrvDic> {
* 删除流域 * 删除流域
*/ */
boolean deleteHbrvDic(String hbrvcd, String baseid); boolean deleteHbrvDic(String hbrvcd, String baseid);
/**
* 下拉框列表查询支持名称模糊查询
*/
List<SdHbrvDic> selectForDropdown(String hbrvnm, String baseid);
} }

View File

@ -71,4 +71,14 @@ public class SdHbrvDicServiceImpl extends ServiceImpl<SdHbrvDicMapper, SdHbrvDic
public boolean deleteHbrvDic(String hbrvcd, String baseid) { public boolean deleteHbrvDic(String hbrvcd, String baseid) {
return this.removeById(hbrvcd); return this.removeById(hbrvcd);
} }
@Override
public List<SdHbrvDic> selectForDropdown(String hbrvnm, String baseid) {
return this.lambdaQuery()
.like(hbrvnm != null && !hbrvnm.isEmpty(), SdHbrvDic::getHbrvnm, hbrvnm)
.eq(baseid != null && !baseid.isEmpty(), SdHbrvDic::getBaseid, baseid)
.eq(SdHbrvDic::getEnabled, 1)
.orderByAsc(SdHbrvDic::getOrderIndex)
.list();
}
} }

View File

@ -1,19 +1,30 @@
package com.yfd.platform.system.controller; package com.yfd.platform.system.controller;
import cn.hutool.json.JSONUtil;
import cn.hutool.jwt.JWTUtil;
import com.yfd.platform.config.ResponseResult; import com.yfd.platform.config.ResponseResult;
import com.yfd.platform.system.domain.SmsVerifyCode; import com.yfd.platform.config.WebConfig;
import com.yfd.platform.system.domain.SysUser; import com.yfd.platform.system.domain.*;
import com.yfd.platform.system.service.ISmsVerifyCodeService; import com.yfd.platform.system.service.ISmsVerifyCodeService;
import com.yfd.platform.system.service.ISysLogService;
import com.yfd.platform.system.service.IUserService; import com.yfd.platform.system.service.IUserService;
import com.yfd.platform.utils.RequestHolder;
import com.yfd.platform.utils.StringUtils;
import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.Date; import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/** /**
* <p> * <p>
@ -31,6 +42,12 @@ public class SmsVerifyCodeController {
@Resource @Resource
private IUserService userService; private IUserService userService;
@Resource
private WebConfig webConfig;
@Resource
private ISysLogService sysLogService;
@Value("${rsa.private_key}") @Value("${rsa.private_key}")
private String privateKey; private String privateKey;
@ -39,8 +56,9 @@ public class SmsVerifyCodeController {
*/ */
@PostMapping("/sendCode") @PostMapping("/sendCode")
@Operation(summary = "发送验证码") @Operation(summary = "发送验证码")
public ResponseResult sendVerifyCode(@RequestParam String phone, public ResponseResult sendVerifyCode(@RequestBody SmsVerifyCodeRequest smsVerifyCodeRequest) {
@RequestParam Integer type) { String phone = smsVerifyCodeRequest.getPhone();
Integer type = smsVerifyCodeRequest.getType();
if (phone == null || phone.isEmpty()) { if (phone == null || phone.isEmpty()) {
return ResponseResult.error("手机号不能为空"); return ResponseResult.error("手机号不能为空");
} }
@ -75,8 +93,9 @@ public class SmsVerifyCodeController {
*/ */
@PostMapping("/register") @PostMapping("/register")
@Operation(summary = "注册用户") @Operation(summary = "注册用户")
public ResponseResult register(@RequestBody SysUser user, public ResponseResult register(@RequestBody SmsVerifyCodeRequest smsVerifyCodeRequest) {
@RequestParam String code) { SysUser user = smsVerifyCodeRequest.getUser();
String code = smsVerifyCodeRequest.getCode();
if (user.getPhone() == null || user.getPhone().isEmpty()) { if (user.getPhone() == null || user.getPhone().isEmpty()) {
return ResponseResult.error("手机号不能为空"); return ResponseResult.error("手机号不能为空");
} }
@ -126,9 +145,10 @@ public class SmsVerifyCodeController {
*/ */
@PostMapping("/resetPassword") @PostMapping("/resetPassword")
@Operation(summary = "找回密码") @Operation(summary = "找回密码")
public ResponseResult resetPassword(@RequestParam String phone, public ResponseResult resetPassword(@RequestBody SmsVerifyCodeRequest smsVerifyCodeRequest) {
@RequestParam String code, String password = smsVerifyCodeRequest.getPassword();
@RequestParam String password) { String phone = smsVerifyCodeRequest.getPhone();
String code = smsVerifyCodeRequest.getCode();
if (phone == null || phone.isEmpty()) { if (phone == null || phone.isEmpty()) {
return ResponseResult.error("手机号不能为空"); return ResponseResult.error("手机号不能为空");
} }
@ -165,9 +185,10 @@ public class SmsVerifyCodeController {
*/ */
@GetMapping("/verifyCode") @GetMapping("/verifyCode")
@Operation(summary = "验证验证码") @Operation(summary = "验证验证码")
public ResponseResult verifyCode(@RequestParam String phone, public ResponseResult verifyCode(@RequestBody SmsVerifyCodeRequest smsVerifyCodeRequest) {
@RequestParam String code, String phone = smsVerifyCodeRequest.getPhone();
@RequestParam Integer type) { String code = smsVerifyCodeRequest.getCode();
Integer type = smsVerifyCodeRequest.getType();
boolean valid = smsVerifyCodeService.verifyCode(phone, code, type); boolean valid = smsVerifyCodeService.verifyCode(phone, code, type);
if (valid) { if (valid) {
return ResponseResult.success(); return ResponseResult.success();
@ -175,4 +196,87 @@ public class SmsVerifyCodeController {
return ResponseResult.error("验证码错误或已过期"); return ResponseResult.error("验证码错误或已过期");
} }
} }
/**
* 短信验证码登录
*/
@PostMapping("/login")
@Operation(summary = "短信验证码登录")
public ResponseResult smsLogin(@RequestBody SmsVerifyCodeRequest smsVerifyCodeRequest) {
String phone = smsVerifyCodeRequest.getPhone();
String code = smsVerifyCodeRequest.getCode();
if (phone == null || phone.isEmpty()) {
return ResponseResult.error("手机号不能为空");
}
if (code == null || code.isEmpty()) {
return ResponseResult.error("验证码不能为空");
}
boolean verified = smsVerifyCodeService.verifyCode(phone, code, SmsVerifyCode.TYPE_REGISTER);
if (!verified) {
return ResponseResult.error("验证码错误或已过期");
}
SysUser user = userService.getUserByPhone(phone);
if (user == null) {
return ResponseResult.error("该手机号未注册");
}
if (user.getStatus() != null && user.getStatus() == 0) {
return ResponseResult.error("账号已停用");
}
if (user.getRegStatus() != null && user.getRegStatus() == 0) {
return ResponseResult.error("账号待审核,请联系管理员");
}
if (user.getRegStatus() != null && user.getRegStatus() == 2) {
return ResponseResult.error("账号审核未通过");
}
UsernamePasswordAuthenticationToken authenticationToken =
new UsernamePasswordAuthenticationToken(user.getUsername(), user.getPassword());
Authentication authenticate = new UsernamePasswordAuthenticationToken(user, null, authenticationToken.getAuthorities());
SecurityContextHolder.getContext().setAuthentication(authenticate);
LoginUser loginUser = new LoginUser();
loginUser.setUser(user);
loginUser.setUsername(user.getUsername());
HttpServletRequest request = RequestHolder.getHttpServletRequest();
SysLog sysLog = new SysLog();
sysLog.setUsercode(user.getUsername());
sysLog.setUsername(user.getNickname());
sysLog.setRequestip(StringUtils.getIp(request));
sysLog.setBrowser(StringUtils.getBrowser(request));
sysLog.setOpttype("登录(login)");
sysLog.setModule("短信验证码登录");
sysLog.setMethod(this.getClass().getName() + ".smsLogin()");
sysLog.setDescription(user.getNickname() + "使用短信验证码登录系统!");
sysLog.setLogtime(new Timestamp(System.currentTimeMillis()));
sysLogService.save(sysLog);
String userId = user.getId();
Map<String, Object> map = new HashMap<>(10) {
private static final long serialVersionUID = 1L;
{
put("userid", userId);
put("username", loginUser.getUsername());
long expireTime = System.currentTimeMillis() + (30L * 24L * 60L * 60L * 1000L);
put("expire_time", expireTime);
}
};
String token = JWTUtil.createToken(map, "12345678".getBytes());
map.put("token", token);
String jsonStr = JSONUtil.toJsonStr(loginUser);
webConfig.loginuserCache().put("login:" + userId, jsonStr);
webConfig.loginuserCache().put("expire_time:" + userId, map.get("expire_time").toString());
map.put("user", user);
return ResponseResult.successData(map);
}
} }

View File

@ -20,6 +20,8 @@ public class LoginUser implements UserDetails {
private SysUser user; private SysUser user;
private String username;
private List<String> permissions; private List<String> permissions;
public LoginUser(SysUser user, List<String> permissions) { public LoginUser(SysUser user, List<String> permissions) {

View File

@ -0,0 +1,31 @@
package com.yfd.platform.system.domain;
import lombok.Data;
@Data
public class SmsVerifyCodeRequest {
/**
* 验证码类型
*/
private Integer type;
/**
* 手机号
*/
private String phone;
/**
* 验证码
*/
private String code;
/**
* 密码
*/
private String password;
/**
* 用户
*/
private SysUser user;
}

View File

@ -21,7 +21,7 @@ import java.util.Random;
@Service @Service
public class SmsVerifyCodeServiceImpl extends ServiceImpl<SmsVerifyCodeMapper, SmsVerifyCode> implements ISmsVerifyCodeService { public class SmsVerifyCodeServiceImpl extends ServiceImpl<SmsVerifyCodeMapper, SmsVerifyCode> implements ISmsVerifyCodeService {
private static final int CODE_VALID_MINUTES = 5; private static final int CODE_VALID_MINUTES = 1;
private static final Random RANDOM = new Random(); private static final Random RANDOM = new Random();
@Resource @Resource

View File

@ -1,6 +1,6 @@
spring: spring:
profiles: profiles:
active: prod active: devtw
jasypt: jasypt:
encryptor: encryptor:

View File

@ -6,6 +6,7 @@
<resultMap id="BaseResultMap" type="com.yfd.platform.data.domain.FishDraftData"> <resultMap id="BaseResultMap" type="com.yfd.platform.data.domain.FishDraftData">
<id column="ID" property="id"/> <id column="ID" property="id"/>
<result column="STCD" property="stcd"/> <result column="STCD" property="stcd"/>
<result column="WT" property="wt"/>
<result column="TM" property="tm"/> <result column="TM" property="tm"/>
<result column="FTP" property="ftp"/> <result column="FTP" property="ftp"/>
<result column="FSZ" property="fsz"/> <result column="FSZ" property="fsz"/>