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.bean.WxMaPhoneNumberInfo;
import cn.binarywang.wx.miniapp.util.WxMaConfigHolder; import cn.binarywang.wx.miniapp.util.WxMaConfigHolder;
import cn.dev33.satoken.annotation.SaIgnore; import cn.dev33.satoken.annotation.SaIgnore;
import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.stp.StpUtil; import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
@ -30,6 +31,7 @@ import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.SysLoginService; import com.ruoyi.system.service.SysLoginService;
import lombok.Data; import lombok.Data;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -48,30 +50,32 @@ import java.util.Map;
@Validated @Validated
@RequiredArgsConstructor @RequiredArgsConstructor
@RestController @RestController
@Slf4j
public class SysLoginController { public class SysLoginController {
private final SysLoginService loginService; private final SysLoginService loginService;
private final ISysMenuService menuService; private final ISysMenuService menuService;
private final ISysUserService userService; private final ISysUserService userService;
private final RSAProperties properties; private final RSAProperties properties;
private final WxMaService wxMaService; private final WxMaService wxMaService;
private final RuoYiConfig config; private final RuoYiConfig config;
private final ISysConfigService configService; private final ISysConfigService configService;
/**
* /**
* *
* @param loginBody *
* @return * @param loginBody
*/ * @return
@SaIgnore */
@PostMapping("/login") @SaIgnore
public R<?> login(@Validated @RequestBody LoginBody loginBody) { @PostMapping("/login")
String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), public R<?> login(@Validated @RequestBody LoginBody loginBody) {
loginBody.getUuid()); String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),
return R.map().put(Constants.TOKEN, token); loginBody.getUuid());
} return R.map().put(Constants.TOKEN, token);
}
@Data @Data
public static class EmqxLoginBody { public static class EmqxLoginBody {
@ -101,134 +105,136 @@ public class SysLoginController {
} }
return ret; return ret;
} }
/** /**
* *
*
* @param username * @param username
* @param password 使RSA * @param password 使RSA
* @return * @return
*/ */
@PostMapping("/login-pwd") @PostMapping("/login-pwd")
@SaIgnore @SaIgnore
public R login(String username,String password) { public R login(String username, String password) {
if(StrUtil.hasBlank(username,password)) { if (StrUtil.hasBlank(username, password)) {
throw new ServiceException("用户名或密码不能为空",1); throw new ServiceException("用户名或密码不能为空", 1);
} }
try { try {
password = properties.getRsa().decryptStr(password, KeyType.PrivateKey); password = properties.getRsa().decryptStr(password, KeyType.PrivateKey);
}catch (Exception ex){ } catch (Exception ex) {
throw new ServiceException("密码必须为RSA加密后",2); 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 * @param smsLoginBody
* @return * @return
*/ */
@SaIgnore @SaIgnore
@PostMapping("/smsLogin") @PostMapping("/smsLogin")
public R<?> smsLogin(@Validated @RequestBody SmsLoginBody smsLoginBody) { public R<?> smsLogin(@Validated @RequestBody SmsLoginBody smsLoginBody) {
String token = loginService.smsLogin(smsLoginBody.getPhonenumber(), smsLoginBody.getSmsCode()); String token = loginService.smsLogin(smsLoginBody.getPhonenumber(), smsLoginBody.getSmsCode());
return R.map().put(Constants.TOKEN,token); return R.map().put(Constants.TOKEN, token);
} }
/** /**
* () * ()
* *
* @param xcxCode code * @param xcxCode code
* @return * @return
*/ */
@SaIgnore @SaIgnore
@PostMapping("/xcxLogin") @PostMapping("/xcxLogin")
public R<?> xcxLogin(@NotBlank(message = "{xcx.code.not.blank}") String xcxCode) { public R<?> xcxLogin(@NotBlank(message = "{xcx.code.not.blank}") String xcxCode) {
String token = loginService.xcxLoginByOpenId(xcxCode); String token = loginService.xcxLoginByOpenId(xcxCode);
return R.map().put(Constants.TOKEN,token); return R.map().put(Constants.TOKEN, token);
} }
@SaIgnore @SaIgnore
@PostMapping("/openid") @PostMapping("/openid")
@Dev @Dev
public R<?> xcxOpenid(@NotBlank(message = "{xcx.code.not.blank}") String openid) { public R<?> xcxOpenid(@NotBlank(message = "{xcx.code.not.blank}") String openid) {
String token = loginService.xcxLoginByOpenId(openid); String token = loginService.xcxLoginByOpenId(openid);
return R.map().put(Constants.TOKEN,token); return R.map().put(Constants.TOKEN, token);
} }
@SaIgnore @SaIgnore
@PostMapping("/xcxRegLogin") @PostMapping("/xcxRegLogin")
public R<?> xcxRegLogin(@NotBlank(message = "{xcx.code.not.blank}") String code, public R<?> xcxRegLogin(@NotBlank(message = "{xcx.code.not.blank}") String code,
MultipartFile avatar, MultipartFile avatar,
@NotBlank(message = "{not.null}") String nickname, @NotBlank(message = "{not.null}") String nickname,
@NotBlank(message = "邀请码不能为空") String regCode @NotBlank(message = "邀请码不能为空") String regCode
) { ) {
if(!regCode.equals(configService.selectConfigByKey("reg.code"))){ if (!regCode.equals(configService.selectConfigByKey("reg.code"))) {
throw new RuntimeException("邀请码不正确"); throw new RuntimeException("邀请码不正确");
}
String token = loginService.xcxRegLoginByOpenid(code,avatar,nickname);
return R.map().put(Constants.TOKEN,token);
} }
String token = loginService.xcxRegLoginByOpenid(code, avatar, nickname);
return R.map().put(Constants.TOKEN, token);
}
@SaIgnore @SaIgnore
@PostMapping("/xcxRegLoginByOpenid") @PostMapping("/xcxRegLoginByOpenid")
@Dev @Dev
public R<?> xcxRegLoginByOpenid(String openid, MultipartFile avatar, String nickname) { public R<?> xcxRegLoginByOpenid(String openid, MultipartFile avatar, String nickname) {
String token = loginService.xcxRegLoginByOpenid(openid,avatar,nickname); String token = loginService.xcxRegLoginByOpenid(openid, avatar, nickname);
return R.map().put(Constants.TOKEN,token); return R.map().put(Constants.TOKEN, token);
} }
/**
* 退
*/
@RequestMapping(value = "/logout",method = {RequestMethod.POST,RequestMethod.GET})
public R<Void> logout() {
loginService.logout();
return R.ok("退出成功");
}
/** /**
* * 退
* */
* @return @RequestMapping(value = "/logout", method = {RequestMethod.POST, RequestMethod.GET})
*/ public R<Void> logout() {
@GetMapping("getInfo") loginService.logout();
public R<?> getInfo() { return R.ok("退出成功");
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 * @return
*/ */
@GetMapping("getRouters") @GetMapping("getInfo")
public R<List<RouterVo>> getRouters() { public R<?> getInfo() {
Long userId = LoginHelper.getUserId(); LoginUser loginUser = LoginHelper.getLoginUser();
List<SysMenu> menus = menuService.selectMenuTreeByUserId(userId); SysUser user = userService.selectUserById(loginUser.getUserId());
return R.ok(menuService.buildMenus(menus)); 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); @Log(title = "获取微信手机号码", businessType = BusinessType.GRANT)
WxMaConfigHolder.remove();//清理ThreadLocal @PostMapping("xcxPhone")
return R.ok(phoneNoInfo); @SaIgnore
} catch (WxErrorException e) { public R<?> xcxPhone(@NotBlank(message = "{xcx.code.not.blank}") String code) {
throw new RuntimeException(e); 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 { public void generate() throws Exception {
// List<BaseInfo> entityList = scan(); //所有编写了@Info的实体类 // 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)); System.out.println(new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(entityList));
generate(entityList); generate(entityList);
@ -64,6 +64,14 @@ public class MongoGenerator {
*/ */
File javaRoot = fs[1]; 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) { 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}的分页数据 * 获取${entity.name}的分页数据
* @param page 分页对象 * @param page 分页对象
* @param ${entity.toLowerName()} 完全匹配条件 * @param ${entity.toLowerName()} 完全匹配条件
* @param ${entity.toUpperName()}Query 其他条件 * @param query 其他条件
* @return ${entity.name}的分页数据 * @return ${entity.name}的分页数据
*/ */
@SaCheckPermission("${moduleName}:${entity.toSimpleLowerName()}:page") @SaCheckPermission("${moduleName}:${entity.toSimpleLowerName()}:page")

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

@ -11,8 +11,8 @@ public class DynConfigUtils {
* @return bean * @return bean
* @param <T> * @param <T>
*/ */
public static <T> T toBean(T config) { public static <T> T toBean(T config, Class<T> clazz) {
return (T)BeanUtil.toBean(config, config.getClass()); return (T)BeanUtil.toBean(config, clazz);
} }
/** /**
@ -21,6 +21,6 @@ public class DynConfigUtils {
* @param config bean * @param config bean
*/ */
public static void setBean(Object bean, Object config) { 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> * <pre>
* auto : Integer (increment),Long (increment),String(date_id) * auto : Integer (increment),Long (snowflake),String(snowflake)
* increment : Integer,Long * increment : Integer,Long
* date_id : Long,String(date_id) * date_id : Long,String(date_id)
* uuid : String * uuid : String
* snowflake: Long String
* </pre> * </pre>
*/ */
public static enum FillIdType { 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) { } else if (f.getType() == Long.class) {
if (type == FillIdType.date_id) { if (type == FillIdType.date_id) {
ReflectUtil.setFieldValue(entity, f, IdUtils.nextDateIdLong(entity.getClass(), 17)); ReflectUtil.setFieldValue(entity, f, IdUtils.nextDateIdLong(entity.getClass(), 17));
} else { } else if(type == FillIdType.increment) {
if (!IdUtils.nextIdInit(entity.getClass())) { if (!IdUtils.nextIdInit(entity.getClass())) {
IdUtils.nextIdInit(entity.getClass(), findMaxId(entity.getClass())); IdUtils.nextIdInit(entity.getClass(), findMaxId(entity.getClass()));
} }
ReflectUtil.setFieldValue(entity, f, IdUtils.nextId(entity.getClass())); ReflectUtil.setFieldValue(entity, f, IdUtils.nextId(entity.getClass()));
}else {
ReflectUtil.setFieldValue(entity, f, IdUtil.getSnowflakeNextId());
} }
} else if (f.getType() == String.class) { } else if (f.getType() == String.class) {
if (type == FillIdType.date_id) { if (type == FillIdType.date_id) {
ReflectUtil.setFieldValue(entity, f, IdUtils.nextDateId(entity.getClass(), 17)); ReflectUtil.setFieldValue(entity, f, IdUtils.nextDateId(entity.getClass(), 17));
} else { } else if(type == FillIdType.uuid) {
ReflectUtil.setFieldValue(entity, f, UUID.fastUUID().toString(true)); ReflectUtil.setFieldValue(entity, f, UUID.fastUUID().toString(true));
}else{
ReflectUtil.setFieldValue(entity, f, IdUtil.getSnowflakeNextIdStr());
} }
} }
return entity; return entity;

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

@ -115,7 +115,7 @@ public class GlobalExceptionHandler {
*/ */
@ExceptionHandler(RuntimeException.class) @ExceptionHandler(RuntimeException.class)
public R<Void> handleRuntimeException(RuntimeException e, HttpServletRequest request, HttpServletResponse response) { 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; return null;
} }
String requestURI = request.getRequestURI(); String requestURI = request.getRequestURI();
@ -125,7 +125,7 @@ public class GlobalExceptionHandler {
@ExceptionHandler(AsyncRequestTimeoutException.class) @ExceptionHandler(AsyncRequestTimeoutException.class)
public R<Void> handleAsyncRequestTimeoutException(AsyncRequestTimeoutException e, HttpServletResponse response) { 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 null;
} }
return R.fail(e.getMessage()); return R.fail(e.getMessage());
@ -136,7 +136,7 @@ public class GlobalExceptionHandler {
*/ */
@ExceptionHandler(Exception.class) @ExceptionHandler(Exception.class)
public R<Void> handleException(Exception e, HttpServletRequest request,HttpServletResponse response) { 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; return null;
} }
String requestURI = request.getRequestURI(); String requestURI = request.getRequestURI();

Loading…
Cancel
Save