Compare commits
2 Commits
ec123412ee
...
dd87fe12b8
Author | SHA1 | Date |
---|---|---|
|
dd87fe12b8 | |
|
aa8d06e57d |
|
@ -28,6 +28,7 @@ public class ManyJob {
|
|||
@Autowired
|
||||
private EntinfoServiceImpl entinfoService;
|
||||
|
||||
|
||||
// @Scheduled(cron = "*/10 * * * * *") // 每10分钟执行一次
|
||||
public void manyJob(){
|
||||
redisService.deleteObject("entinfo");
|
||||
|
|
|
@ -10,6 +10,7 @@ public class RabbitmqConfig {
|
|||
// 消息转换配置
|
||||
@Bean
|
||||
public MessageConverter jsonMessageConverter() {
|
||||
// 使用json序列化方式,进行消息转换
|
||||
return new Jackson2JsonMessageConverter();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,12 +24,12 @@ import lombok.experimental.SuperBuilder;
|
|||
@TableName("cart")
|
||||
public class Cart {
|
||||
|
||||
@TableId
|
||||
// @TableId
|
||||
private Long id;
|
||||
|
||||
@TableField(value = "name")
|
||||
// @TableField(value = "name")
|
||||
private String name;
|
||||
|
||||
@TableField(value = "type_id")
|
||||
// @TableField(value = "type_id")
|
||||
private Long typeId;
|
||||
}
|
||||
|
|
|
@ -23,9 +23,9 @@ import lombok.experimental.SuperBuilder;
|
|||
@TableName("type")
|
||||
public class Type {
|
||||
|
||||
@TableId
|
||||
// @TableId
|
||||
private Long id;
|
||||
|
||||
@TableField(value = "type_name")
|
||||
// @TableField(value = "type_name")
|
||||
private String typeName;
|
||||
}
|
||||
|
|
|
@ -60,4 +60,6 @@ public interface EntinfoMapper extends BaseMapper<Entinfo>
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteEntinfoByIds(Long[] ids);
|
||||
|
||||
Entinfo selectEntinfo(Entinfo business);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.zhiLian.business.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zhiLian.business.domain.Business;
|
||||
import com.zhiLian.business.domain.Entinfo;
|
||||
|
||||
import java.util.List;
|
||||
|
@ -60,4 +61,6 @@ public interface IEntinfoService extends IService<Entinfo>
|
|||
* @return 结果
|
||||
*/
|
||||
public int deleteEntinfoById(Long id);
|
||||
|
||||
Entinfo selectEntinfo(Entinfo business);
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
|
|||
.email(business.getBusinessEmail())
|
||||
.phonenumber(business.getBusinessPhone())
|
||||
.loginIp("111.229.102.61")
|
||||
.roleId(Long.valueOf(2))
|
||||
.roleId(Long.valueOf(101))
|
||||
.userType(String.valueOf(business.getId()))
|
||||
.build();
|
||||
Result add = remoteUserService.add(sysUser);
|
||||
|
@ -139,16 +139,28 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
|
|||
public void httpConnectMysql(Business business){
|
||||
redisService.deleteObject("entinfo");
|
||||
List<Entinfo> list = entinfoService.list();
|
||||
redisService.setCacheList("entinfo",list);
|
||||
if (business.getBusinessStates().equals("2")) {
|
||||
extracted(business);
|
||||
if(list.size()!=0){
|
||||
redisService.setCacheList("entinfo",list);
|
||||
}
|
||||
if (business.getBusinessStates().equals("2")) {
|
||||
SysUser sysUser = remoteUserService.userById(business.getId());
|
||||
sysUser.setRoleId(Long.valueOf(2));
|
||||
remoteUserService.updateById(sysUser);
|
||||
Entinfo build = Entinfo.builder()
|
||||
.entCode("test_" + business.getId())
|
||||
.ip("192.168.120.128")
|
||||
.port(Integer.valueOf(3306 + Integer.valueOf(String.valueOf(business.getId())))).build();
|
||||
Entinfo entinfo =entinfoService.selectEntinfo(build);
|
||||
if (entinfo==null){
|
||||
extracted(business);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private RabbitTemplate rabbitTemplate;
|
||||
|
||||
|
||||
/**
|
||||
* http URL 链接
|
||||
* @param business
|
||||
|
@ -159,7 +171,6 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
|
|||
hashMap.put("businessId",business.getId()+ business.getName());
|
||||
hashMap.put("mysqlPort",String.valueOf(3306+ business.getId()));
|
||||
String json = JSON.toJSONString(hashMap);
|
||||
|
||||
// 3.创建连接与设置连接参数
|
||||
URL urlObj = null;
|
||||
try {
|
||||
|
@ -201,7 +212,6 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
|
|||
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
|
||||
return message;
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.zhiLian.business.service.impl;
|
|||
import java.util.List;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.zhiLian.business.domain.Business;
|
||||
import com.zhiLian.business.domain.Entinfo;
|
||||
import com.zhiLian.business.mapper.EntinfoMapper;
|
||||
import com.zhiLian.business.service.IEntinfoService;
|
||||
|
@ -93,4 +94,9 @@ public class EntinfoServiceImpl extends ServiceImpl<EntinfoMapper, Entinfo>
|
|||
{
|
||||
return entinfoMapper.deleteEntinfoById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entinfo selectEntinfo(Entinfo business) {
|
||||
return entinfoMapper.selectEntinfo(business);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,19 +40,18 @@ public class PlusServiceImpl extends MPJBaseServiceImpl<PlusMapper, Cart> implem
|
|||
.select(Type::getTypeName) //查询类型名称
|
||||
.leftJoin(Type.class, Type::getId, Cart::getTypeId);//左连接查询,相当于 left join type on dept.id=user.dept_id
|
||||
List<CartVo> cartList = plusMapper.selectJoinList(CartVo.class, mpjLambdaWrapper);
|
||||
// return Result.success(cartList);
|
||||
|
||||
|
||||
return Result.success(cartList);
|
||||
// MPJLambdaWrapper<Cart> mpjLambdaWrapper1 = new MPJLambdaWrapper<>();
|
||||
// MPJLambdaWrapper<Cart> lambdaWrapper = mpjLambdaWrapper1.eq(Cart::getId, "1");
|
||||
List<Cart> list = this.list();
|
||||
list.stream().forEach(cart -> {
|
||||
LambdaQueryWrapper<Type> typeLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
Type type = typeMapper.selectOne(typeLambdaQueryWrapper.eq(Type::getId, cart.getTypeId()));
|
||||
cart.setName(type.getTypeName());
|
||||
});
|
||||
System.out.println(list);
|
||||
return Result.success(list,cartList.toString());
|
||||
|
||||
|
||||
// List<Cart> list = this.list();
|
||||
// list.stream().forEach(cart -> {
|
||||
// LambdaQueryWrapper<Type> typeLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||
// Type type = typeMapper.selectOne(typeLambdaQueryWrapper.eq(Type::getId, cart.getTypeId()));
|
||||
// cart.setName(type.getTypeName());
|
||||
// });
|
||||
// System.out.println(list);
|
||||
// return Result.success(list,cartList.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ spring:
|
|||
password: guest
|
||||
virtualHost: /
|
||||
port: 5672
|
||||
host: 122.51.111.225
|
||||
host: 111.229.102.61
|
||||
listener:
|
||||
simple:
|
||||
prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条
|
||||
|
|
|
@ -28,6 +28,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<include refid="selectEntinfoVo"/>
|
||||
where id = #{id}
|
||||
</select>
|
||||
<select id="selectEntinfo" resultType="com.zhiLian.business.domain.Entinfo">
|
||||
<include refid="selectEntinfoVo"/>
|
||||
<where>
|
||||
<if test="entCode != null and entCode != ''"> and ent_code = #{entCode}</if>
|
||||
<if test="ip != null and ip != ''"> and ip = #{ip}</if>
|
||||
<if test="port != null "> and port = #{port}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<insert id="insertEntinfo" parameterType="com.zhiLian.business.domain.Entinfo" useGeneratedKeys="true" keyProperty="id">
|
||||
insert into entinfo
|
||||
|
|
|
@ -50,4 +50,9 @@ public interface RemoteUserService {
|
|||
|
||||
@GetMapping("/user/selectByUserId/{userId}")
|
||||
public SysUser selectByUserId (@PathVariable("userId") Long userId);
|
||||
|
||||
@GetMapping("/user/userById/{userId}")
|
||||
public SysUser userById (@PathVariable("userId") Long UserType);
|
||||
@PostMapping("/user/updateById")
|
||||
public Result updateById (@RequestBody SysUser user);
|
||||
}
|
||||
|
|
|
@ -51,6 +51,16 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser userById(Long userType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result updateById(SysUser user) {
|
||||
return null;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,7 +73,6 @@ public class GenController extends BaseController {
|
|||
List<GenTable> list = genTableService.selectDbTableList(genTable);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据表字段列表
|
||||
*/
|
||||
|
|
|
@ -18,6 +18,7 @@ import com.zhiLian.system.domain.resp.AuthRoleResp;
|
|||
import com.zhiLian.system.domain.resp.UserDetailInfoResp;
|
||||
import com.zhiLian.system.domain.resp.UserInfoResp;
|
||||
import com.zhiLian.system.service.*;
|
||||
import org.apache.catalina.User;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
@ -295,4 +296,14 @@ public class SysUserController extends BaseController {
|
|||
public Result deptTree (SysDept dept) {
|
||||
return success(deptService.selectDeptTreeList(dept));
|
||||
}
|
||||
|
||||
@GetMapping("/userById/{userId}")
|
||||
public SysUser userById (@PathVariable("userId") Long UserType) {
|
||||
SysUser user=userService.selectUserByUserType(UserType);
|
||||
return user;
|
||||
}
|
||||
@PostMapping("/updateById")
|
||||
public Result updateById (@RequestBody SysUser user) {
|
||||
return success(userService.updateByUserId(user));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,4 +139,8 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
|||
* @return 结果
|
||||
*/
|
||||
public SysUser checkEmailUnique (String email);
|
||||
|
||||
void updateByUserId(SysUser user);
|
||||
|
||||
SysUser selectUserByUserType(String userType);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.zhiLian.system.service;
|
|||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.zhiLian.common.system.domain.SysUser;
|
||||
import org.apache.catalina.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -225,4 +226,8 @@ public interface SysUserService extends IService<SysUser> {
|
|||
* @return 结果
|
||||
*/
|
||||
public String importUser (List<SysUser> userList, Boolean isUpdateSupport, String operName);
|
||||
|
||||
String updateByUserId(SysUser user);
|
||||
|
||||
SysUser selectUserByUserType(Long userType);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import com.zhiLian.system.domain.SysUserRole;
|
|||
import com.zhiLian.system.mapper.*;
|
||||
import com.zhiLian.system.service.SysUserService;
|
||||
import com.zhiLian.system.service.SysConfigService;
|
||||
import org.apache.catalina.User;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -241,9 +242,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
// 新增用户岗位关联
|
||||
insertUserPost(user);
|
||||
// 新增用户与角色管理
|
||||
if (2 == user.getRoleId()){
|
||||
if (101 == user.getRoleId()){
|
||||
SysUserRole sysUserRole = new SysUserRole();
|
||||
sysUserRole.setRoleId(Long.valueOf(2));
|
||||
sysUserRole.setRoleId(Long.valueOf(101));
|
||||
sysUserRole.setUserId(user.getUserId());
|
||||
userRoleMapper.insertUserRole(sysUserRole);
|
||||
}
|
||||
|
@ -506,4 +507,17 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
return successMsg.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String updateByUserId(SysUser user) {
|
||||
userMapper.updateByUserId(user);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SysUser selectUserByUserType(Long userType) {
|
||||
String userType1=String.valueOf(userType);
|
||||
SysUser user = userMapper.selectUserByUserType(userType1);
|
||||
return user;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -185,6 +185,12 @@
|
|||
and del_flag = '0'
|
||||
limit 1
|
||||
</select>
|
||||
<select id="selectUserByUserType" resultType="com.zhiLian.common.system.domain.SysUser">
|
||||
select user_id, user_type, nick_name, email, avatar, phonenumber, sex, status, create_time
|
||||
from sys_user
|
||||
where user_type = #{userType}
|
||||
</select>
|
||||
|
||||
|
||||
<insert id="insertUser" parameterType="com.zhiLian.common.system.domain.SysUser" useGeneratedKeys="true" keyProperty="userId">
|
||||
insert into sys_user(
|
||||
|
@ -259,6 +265,9 @@
|
|||
set password = #{password}
|
||||
where user_name = #{userName}
|
||||
</update>
|
||||
<update id="updateByUserId">
|
||||
update sys_user_role set role_id = #{roleId} where user_id = #{userId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteUserById" parameterType="Long">
|
||||
update sys_user
|
||||
|
|
|
@ -41,6 +41,21 @@ import java.util.Map;
|
|||
public class ManyDataSource {
|
||||
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String,String> redisTemplate;
|
||||
|
||||
|
@ -59,41 +74,17 @@ public class ManyDataSource {
|
|||
//添加成功 正常消费信息
|
||||
if (count == 1) {
|
||||
log.info("开始消费");
|
||||
DruidDataSourceFactory druidDataSourceFactory = SpringUtils.getBean(DruidDataSourceFactory.class);
|
||||
DynamicDataSource dynamicDataSource = SpringUtils.getBean(DynamicDataSource.class);
|
||||
Entinfo entinfo1 = JSON.parseObject(msg, Entinfo.class);
|
||||
DataSourceInfo dataSourceInfo = DataSourceInfo.hostAndPortBuild(entinfo1.getEntCode(), entinfo1.getIp(), entinfo1.getPort());
|
||||
DruidDataSource druidDataSource = druidDataSourceFactory.create(dataSourceInfo);
|
||||
dynamicDataSource.put(dataSourceInfo.getKey(), druidDataSource);
|
||||
new Thread(() -> {
|
||||
try {
|
||||
Thread.sleep(10000);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// List<String> entinfo = redisTemplate.opsForList().range("entinfo", 0, -1);
|
||||
// List<Entinfo> databaseNameList = new ArrayList<>();
|
||||
// entinfo.forEach(string -> {
|
||||
// Entinfo entInfo = JSON.parseObject(string, Entinfo.class);
|
||||
// databaseNameList.add(entInfo);
|
||||
// });
|
||||
// databaseNameList.forEach(enterpriseInfo -> {
|
||||
// DataSourceInfo dataSourceInfo = DataSourceInfo.hostAndPortBuild(enterpriseInfo.getEntCode(), enterpriseInfo.getIp(), enterpriseInfo.getPort());
|
||||
// DruidDataSource druidDataSource = druidDataSourceFactory.create(dataSourceInfo);
|
||||
// dynamicDataSource.put(dataSourceInfo.getKey(), druidDataSource);
|
||||
// });
|
||||
}).start();
|
||||
druidData(msg);
|
||||
//确认消费
|
||||
channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
|
||||
log.info("消费成功");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//删除队列ID
|
||||
log.info("消费失败");
|
||||
log.info("消费失败,尝试重连");
|
||||
try {
|
||||
//回退消息
|
||||
channel.basicReject(message.getMessageProperties().getDeliveryTag(),true);
|
||||
//回退消息,尝试重连
|
||||
druidData(msg);
|
||||
channel.basicReject(message.getMessageProperties().getDeliveryTag(),false);
|
||||
log.info("消费失败");
|
||||
} catch (IOException ex) {
|
||||
//回退失败
|
||||
|
@ -102,6 +93,16 @@ public class ManyDataSource {
|
|||
}
|
||||
}
|
||||
|
||||
private void druidData(String msg) {
|
||||
Entinfo entinfo1 = JSON.parseObject(msg, Entinfo.class);
|
||||
log.info("消息为:{}",entinfo1);
|
||||
DruidDataSourceFactory druidDataSourceFactory = SpringUtils.getBean(DruidDataSourceFactory.class);
|
||||
DynamicDataSource dynamicDataSource = SpringUtils.getBean(DynamicDataSource.class);
|
||||
DataSourceInfo dataSourceInfo = DataSourceInfo.hostAndPortBuild(entinfo1.getEntCode(), entinfo1.getIp(), entinfo1.getPort());
|
||||
DruidDataSource druidDataSource = druidDataSourceFactory.create(dataSourceInfo);
|
||||
dynamicDataSource.put(dataSourceInfo.getKey(), druidDataSource);
|
||||
}
|
||||
|
||||
@Lazy
|
||||
private List<Entinfo> dataSourceInfoList(){
|
||||
List<Entinfo> databaseNameList = new ArrayList<>(){{
|
||||
|
@ -114,7 +115,6 @@ public class ManyDataSource {
|
|||
// List<com.zhiLian.common.core.domain.Entinfo> entinfos = remoteFileService.listAll();
|
||||
// databaseNameList.a(entinfos)
|
||||
List<String> entinfo = redisTemplate.opsForList().range("entinfo", 0, -1);
|
||||
|
||||
entinfo.forEach(string -> {
|
||||
Entinfo entInfo = JSON.parseObject(string, Entinfo.class);
|
||||
databaseNameList.add(entInfo);
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.zhiLian.vehicle.datasource.config.factory;
|
|||
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.alibaba.druid.pool.DruidPooledConnection;
|
||||
import com.zhiLian.vehicle.datasource.domain.DataSourceInfo;
|
||||
import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
@ -31,13 +32,9 @@ public class DruidDataSourceFactory {
|
|||
druidDataSource.setPassword(dataSourceInfo.getPassword());
|
||||
druidDataSource.setBreakAfterAcquireFailure(true);
|
||||
druidDataSource.setConnectionErrorRetryAttempts(0);
|
||||
try {
|
||||
druidDataSource.getConnection(2000);
|
||||
log.info("{} -> 数据源连接成功", dataSourceInfo);
|
||||
return druidDataSource;
|
||||
} catch (SQLException throwables) {
|
||||
log.error("数据源 {} 连接失败,用户名:{},密码 {}",dataSourceInfo.getUrl(),dataSourceInfo.getUserName(),dataSourceInfo.getPassword());
|
||||
return null;
|
||||
}
|
||||
druidDataSource.setInitialSize(5);
|
||||
druidDataSource.setMaxActive(15);
|
||||
log.info("{} -> 数据源连接成功", dataSourceInfo);
|
||||
return druidDataSource;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ public class DynamicDataSource extends AbstractRoutingDataSource {
|
|||
*/
|
||||
private Map<Object, Object> defineTargetDataSources;
|
||||
|
||||
|
||||
/**
|
||||
* 决定当前线程使用哪个数据源
|
||||
*/
|
||||
|
@ -35,6 +36,7 @@ public class DynamicDataSource extends AbstractRoutingDataSource {
|
|||
return DynamicDataSourceHolder.getDynamicDataSourceKey();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 添加数据库
|
||||
* @param key 键
|
||||
|
|
|
@ -7,7 +7,7 @@ package com.zhiLian.vehicle.datasource.contents;
|
|||
*/
|
||||
public class DatasourceContent {
|
||||
|
||||
public final static String DATASOURCE_URL = "jdbc:mysql://{}:{}/zh iLian-cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8";
|
||||
public final static String DATASOURCE_URL = "jdbc:mysql://{}:{}/zhiLian-cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true&failOverReadOnly=false";
|
||||
|
||||
public final static String USER_NAME = "root";
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ spring:
|
|||
password: guest
|
||||
virtualHost: /
|
||||
port: 5672
|
||||
host: 122.51.111.225
|
||||
host: 111.229.102.61
|
||||
listener:
|
||||
simple:
|
||||
prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条
|
||||
|
|
Loading…
Reference in New Issue