master
管理员 8 months ago
parent 605c0bc184
commit 7d9141bcb6

@ -4,6 +4,7 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
import cn.binarywang.wx.miniapp.util.WxMaConfigHolder;
import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil;
@ -30,6 +31,7 @@ import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.SysLoginService;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@ -48,30 +50,32 @@ import java.util.Map;
@Validated
@RequiredArgsConstructor
@RestController
@Slf4j
public class SysLoginController {
private final SysLoginService loginService;
private final ISysMenuService menuService;
private final ISysUserService userService;
private final RSAProperties properties;
private final WxMaService wxMaService;
private final RuoYiConfig config;
private final ISysConfigService configService;
/**
*
*
* @param loginBody
* @return
*/
@SaIgnore
@PostMapping("/login")
public R<?> login(@Validated @RequestBody LoginBody loginBody) {
String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
loginBody.getUuid());
return R.map().put(Constants.TOKEN, token);
}
private final SysLoginService loginService;
private final ISysMenuService menuService;
private final ISysUserService userService;
private final RSAProperties properties;
private final WxMaService wxMaService;
private final RuoYiConfig config;
private final ISysConfigService configService;
/**
*
*
* @param loginBody
* @return
*/
@SaIgnore
@PostMapping("/login")
public R<?> login(@Validated @RequestBody LoginBody loginBody) {
String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
loginBody.getUuid());
return R.map().put(Constants.TOKEN, token);
}
@Data
public static class EmqxLoginBody {
@ -101,134 +105,136 @@ public class SysLoginController {
}
return ret;
}
/**
*
*
* @param username
* @param password 使RSA
* @return
*/
@PostMapping("/login-pwd")
@SaIgnore
public R login(String username,String password) {
if(StrUtil.hasBlank(username,password)) {
throw new ServiceException("用户名或密码不能为空",1);
public R login(String username, String password) {
if (StrUtil.hasBlank(username, password)) {
throw new ServiceException("用户名或密码不能为空", 1);
}
try {
password = properties.getRsa().decryptStr(password, KeyType.PrivateKey);
}catch (Exception ex){
throw new ServiceException("密码必须为RSA加密后",2);
} catch (Exception ex) {
throw new ServiceException("密码必须为RSA加密后", 2);
}
return R.ok().setMsg("登录成功").setData(loginService.login(username,password));
return R.ok().setMsg("登录成功").setData(loginService.login(username, password));
}
/**
* ()
*
* @param smsLoginBody
* @return
*/
@SaIgnore
@PostMapping("/smsLogin")
public R<?> smsLogin(@Validated @RequestBody SmsLoginBody smsLoginBody) {
String token = loginService.smsLogin(smsLoginBody.getPhonenumber(), smsLoginBody.getSmsCode());
return R.map().put(Constants.TOKEN,token);
}
/**
* ()
*
* @param smsLoginBody
* @return
*/
@SaIgnore
@PostMapping("/smsLogin")
public R<?> smsLogin(@Validated @RequestBody SmsLoginBody smsLoginBody) {
String token = loginService.smsLogin(smsLoginBody.getPhonenumber(), smsLoginBody.getSmsCode());
return R.map().put(Constants.TOKEN, token);
}
/**
* ()
*
* @param xcxCode code
* @return
*/
@SaIgnore
@PostMapping("/xcxLogin")
public R<?> xcxLogin(@NotBlank(message = "{xcx.code.not.blank}") String xcxCode) {
String token = loginService.xcxLoginByOpenId(xcxCode);
return R.map().put(Constants.TOKEN,token);
}
/**
* ()
*
* @param xcxCode code
* @return
*/
@SaIgnore
@PostMapping("/xcxLogin")
public R<?> xcxLogin(@NotBlank(message = "{xcx.code.not.blank}") String xcxCode) {
String token = loginService.xcxLoginByOpenId(xcxCode);
return R.map().put(Constants.TOKEN, token);
}
@SaIgnore
@PostMapping("/openid")
@Dev
public R<?> xcxOpenid(@NotBlank(message = "{xcx.code.not.blank}") String openid) {
String token = loginService.xcxLoginByOpenId(openid);
return R.map().put(Constants.TOKEN,token);
}
@SaIgnore
@PostMapping("/openid")
@Dev
public R<?> xcxOpenid(@NotBlank(message = "{xcx.code.not.blank}") String openid) {
String token = loginService.xcxLoginByOpenId(openid);
return R.map().put(Constants.TOKEN, token);
}
@SaIgnore
@PostMapping("/xcxRegLogin")
public R<?> xcxRegLogin(@NotBlank(message = "{xcx.code.not.blank}") String code,
MultipartFile avatar,
@NotBlank(message = "{not.null}") String nickname,
@NotBlank(message = "邀请码不能为空") String regCode
) {
if(!regCode.equals(configService.selectConfigByKey("reg.code"))){
throw new RuntimeException("邀请码不正确");
}
String token = loginService.xcxRegLoginByOpenid(code,avatar,nickname);
return R.map().put(Constants.TOKEN,token);
@SaIgnore
@PostMapping("/xcxRegLogin")
public R<?> xcxRegLogin(@NotBlank(message = "{xcx.code.not.blank}") String code,
MultipartFile avatar,
@NotBlank(message = "{not.null}") String nickname,
@NotBlank(message = "邀请码不能为空") String regCode
) {
if (!regCode.equals(configService.selectConfigByKey("reg.code"))) {
throw new RuntimeException("邀请码不正确");
}
String token = loginService.xcxRegLoginByOpenid(code, avatar, nickname);
return R.map().put(Constants.TOKEN, token);
}
@SaIgnore
@PostMapping("/xcxRegLoginByOpenid")
@Dev
public R<?> xcxRegLoginByOpenid(String openid, MultipartFile avatar, String nickname) {
String token = loginService.xcxRegLoginByOpenid(openid,avatar,nickname);
return R.map().put(Constants.TOKEN,token);
}
/**
* 退
*/
@RequestMapping(value = "/logout",method = {RequestMethod.POST,RequestMethod.GET})
public R<Void> logout() {
loginService.logout();
return R.ok("退出成功");
}
@SaIgnore
@PostMapping("/xcxRegLoginByOpenid")
@Dev
public R<?> xcxRegLoginByOpenid(String openid, MultipartFile avatar, String nickname) {
String token = loginService.xcxRegLoginByOpenid(openid, avatar, nickname);
return R.map().put(Constants.TOKEN, token);
}
/**
*
*
* @return
*/
@GetMapping("getInfo")
public R<?> getInfo() {
LoginUser loginUser = LoginHelper.getLoginUser();
SysUser user = userService.selectUserById(loginUser.getUserId());
return R.map().put("user", user)
.put("roles", loginUser.getRolePermission())
.put("permissions", loginUser.getMenuPermission());
}
/**
* 退
*/
@RequestMapping(value = "/logout", method = {RequestMethod.POST, RequestMethod.GET})
public R<Void> logout() {
loginService.logout();
return R.ok("退出成功");
}
/**
*
*
* @return
*/
@GetMapping("getRouters")
public R<List<RouterVo>> getRouters() {
Long userId = LoginHelper.getUserId();
List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId);
return R.ok(menuService.buildMenus(menus));
}
/**
*
*
* @return
*/
@GetMapping("getInfo")
public R<?> getInfo() {
LoginUser loginUser = LoginHelper.getLoginUser();
SysUser user = userService.selectUserById(loginUser.getUserId());
return R.map().put("user", user)
.put("roles", loginUser.getRolePermission())
.put("permissions", loginUser.getMenuPermission());
}
/**
*
*
* @return
*/
@GetMapping("getRouters")
public R<List<RouterVo>> getRouters() {
Long userId = LoginHelper.getUserId();
List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId);
return R.ok(menuService.buildMenus(menus));
}
@Log(title = "获取微信手机号码", businessType = BusinessType.GRANT)
@PostMapping("xcxPhone")
@SaIgnore
public R<?> xcxPhone(@NotBlank(message = "{xcx.code.not.blank}") String code) {
try {
WxMaPhoneNumberInfo phoneNoInfo = wxMaService.getUserService().getNewPhoneNoInfo(code);
WxMaConfigHolder.remove();//清理ThreadLocal
return R.ok(phoneNoInfo);
} catch (WxErrorException e) {
throw new RuntimeException(e);
}
@Log(title = "获取微信手机号码", businessType = BusinessType.GRANT)
@PostMapping("xcxPhone")
@SaIgnore
public R<?> xcxPhone(@NotBlank(message = "{xcx.code.not.blank}") String code) {
try {
WxMaPhoneNumberInfo phoneNoInfo = wxMaService.getUserService().getNewPhoneNoInfo(code);
WxMaConfigHolder.remove();//清理ThreadLocal
return R.ok(phoneNoInfo);
} catch (WxErrorException e) {
throw new RuntimeException(e);
}
}
}

@ -44,7 +44,7 @@ public class MongoGenerator {
public void generate() throws Exception {
// List<BaseInfo> entityList = scan(); //所有编写了@Info的实体类
List<BaseInfo> entityList = scan("DeviceWarn");//编写了@Info的实体类中的某些类
List<BaseInfo> entityList = scan("DeviceType");//编写了@Info的实体类中的某些类
System.out.println(new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(entityList));
generate(entityList);
@ -64,6 +64,14 @@ public class MongoGenerator {
*/
File javaRoot = fs[1];
String rd = generate("README.md.vm", null, entityList);
FileUtil.writeString(rd, new File(root, "README-"+moduleName + ".md"), "UTF-8");
// if(true){
// return;
// }
for (BaseInfo entity : entityList) {

@ -0,0 +1,16 @@
#set($a = "#")
#set($b = 0)
#foreach($item in $list)
#set($b = $b + 1)
${a}${a}${a} 5.2.$b ${item.name} - mongodb
集合5.2.$b - ${item.name} - $item.toUpperName()
| **字段名** | **类型** | **说明** | **可为空** |
| -- | -- | ---| - |
#foreach($col in $item.all)
| ${col.toLowerName()} | ${col.clazz.getSimpleName()} | ${col.name} | #if($col.isId)Y #else N #end |
#end
#end

@ -46,7 +46,7 @@ public class ${entity.toUpperName()}Api {
* 获取${entity.name}的分页数据
* @param page 分页对象
* @param ${entity.toLowerName()} 完全匹配条件
* @param ${entity.toUpperName()}Query 其他条件
* @param query 其他条件
* @return ${entity.name}的分页数据
*/
@SaCheckPermission("${moduleName}:${entity.toSimpleLowerName()}:page")

@ -3,7 +3,7 @@ package com.ruoyi.common.event;
import org.springframework.context.ApplicationEvent;
/**
* base2024
* energy2
*/
public class QaEvent extends ApplicationEvent {

@ -11,8 +11,8 @@ public class DynConfigUtils {
* @return bean
* @param <T>
*/
public static <T> T toBean(T config) {
return (T)BeanUtil.toBean(config, config.getClass());
public static <T> T toBean(T config, Class<T> clazz) {
return (T)BeanUtil.toBean(config, clazz);
}
/**
@ -21,6 +21,6 @@ public class DynConfigUtils {
* @param config bean
*/
public static void setBean(Object bean, Object config) {
BeanUtil.copyProperties(bean,config, CopyOptions.create(config.getClass(),true));
BeanUtil.copyProperties(bean,config, CopyOptions.create(bean.getClass(),true));
}
}

@ -485,16 +485,19 @@ public class MongoUtil {
/**
* <pre>
* auto : Integer (increment),Long (increment),String(date_id)
* auto : Integer (increment),Long (snowflake),String(snowflake)
* increment : Integer,Long
* date_id : Long,String(date_id)
* uuid : String
* snowflake: Long String
* </pre>
*/
public static enum FillIdType {
auto, increment, date_id, uuid;
auto, increment, date_id, uuid, snowflake;
}
/**
@ -532,17 +535,21 @@ public class MongoUtil {
} else if (f.getType() == Long.class) {
if (type == FillIdType.date_id) {
ReflectUtil.setFieldValue(entity, f, IdUtils.nextDateIdLong(entity.getClass(), 17));
} else {
} else if(type == FillIdType.increment) {
if (!IdUtils.nextIdInit(entity.getClass())) {
IdUtils.nextIdInit(entity.getClass(), findMaxId(entity.getClass()));
}
ReflectUtil.setFieldValue(entity, f, IdUtils.nextId(entity.getClass()));
}else {
ReflectUtil.setFieldValue(entity, f, IdUtil.getSnowflakeNextId());
}
} else if (f.getType() == String.class) {
if (type == FillIdType.date_id) {
ReflectUtil.setFieldValue(entity, f, IdUtils.nextDateId(entity.getClass(), 17));
} else {
} else if(type == FillIdType.uuid) {
ReflectUtil.setFieldValue(entity, f, UUID.fastUUID().toString(true));
}else{
ReflectUtil.setFieldValue(entity, f, IdUtil.getSnowflakeNextIdStr());
}
}
return entity;

@ -11,8 +11,10 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
@ -21,7 +23,7 @@ import java.util.concurrent.ThreadPoolExecutor;
/**
* 线
*
* @author Lion Li
* @author bing huang
**/
@Configuration
@Slf4j
@ -76,7 +78,7 @@ public class ThreadPoolConfig {
t.setPoolSize(core * 2 + 1); // 线程池大小
t.setThreadNamePrefix("t-"); // 线程名称
t.setAwaitTerminationSeconds(60); // 等待时长
t.setWaitForTasksToCompleteOnShutdown(true); // 调度器shutdown被调用时等待当前被调度的任务完成
t.setWaitForTasksToCompleteOnShutdown(false); // 调度器shutdown被调用时等待当前被调度的任务完成
t.initialize();
log.info("创建了自定义线程池{}*size:{}" , t.getThreadNamePrefix(), t.getPoolSize());
return t;

@ -115,7 +115,7 @@ public class GlobalExceptionHandler {
*/
@ExceptionHandler(RuntimeException.class)
public R<Void> handleRuntimeException(RuntimeException e, HttpServletRequest request, HttpServletResponse response) {
if (response.getContentType().contains("text/event-stream")) {
if (response.getContentType()!=null && response.getContentType().contains("text/event-stream")) {
return null;
}
String requestURI = request.getRequestURI();
@ -125,7 +125,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(AsyncRequestTimeoutException.class)
public R<Void> handleAsyncRequestTimeoutException(AsyncRequestTimeoutException e, HttpServletResponse response) {
if (response.getContentType().contains("text/event-stream")) {
if (response.getContentType()!=null && response.getContentType().contains("text/event-stream")) {
return null;
}
return R.fail(e.getMessage());
@ -136,7 +136,7 @@ public class GlobalExceptionHandler {
*/
@ExceptionHandler(Exception.class)
public R<Void> handleException(Exception e, HttpServletRequest request,HttpServletResponse response) {
if (response.getContentType().contains("text/event-stream")) {
if (response.getContentType()!=null && response.getContentType().contains("text/event-stream")) {
return null;
}
String requestURI = request.getRequestURI();

Loading…
Cancel
Save