feat:项目优化,细节处理

master
hbr 2024-06-09 20:26:19 +08:00
parent 06fbdd9fdb
commit aa8d06e57d
34 changed files with 511 additions and 63 deletions

View File

@ -10,6 +10,10 @@
</parent> </parent>
<artifactId>zhiLian-business</artifactId> <artifactId>zhiLian-business</artifactId>
<packaging>pom</packaging>
<modules>
<module>zhiLian-data-plus</module>
</modules>
<properties> <properties>
<maven.compiler.source>17</maven.compiler.source> <maven.compiler.source>17</maven.compiler.source>
@ -19,7 +23,5 @@
<description> <description>
zhiLian-business系统模块 zhiLian-business系统模块
</description> </description>
</project> </project>

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.zhiLian</groupId>
<artifactId>zhiLian-business</artifactId>
<version>3.6.3</version>
</parent>
<artifactId>zhiLian-data-plus</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

View File

@ -20,6 +20,16 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<dependencies> <dependencies>
<dependency>
<groupId>com.github.yulichang</groupId>
<artifactId>mybatis-plus-join</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<!--rabbitMQ--> <!--rabbitMQ-->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>

View File

@ -28,7 +28,7 @@ public class ManyJob {
@Autowired @Autowired
private EntinfoServiceImpl entinfoService; private EntinfoServiceImpl entinfoService;
@Scheduled(cron = "*/10 * * * * *") // 每10分钟执行一次 // @Scheduled(cron = "*/10 * * * * *") // 每10分钟执行一次
public void manyJob(){ public void manyJob(){
redisService.deleteObject("entinfo"); redisService.deleteObject("entinfo");
List<Entinfo> list = entinfoService.list(); List<Entinfo> list = entinfoService.list();

View File

@ -10,6 +10,7 @@ public class RabbitmqConfig {
// 消息转换配置 // 消息转换配置
@Bean @Bean
public MessageConverter jsonMessageConverter() { public MessageConverter jsonMessageConverter() {
// 使用json序列化方式进行消息转换
return new Jackson2JsonMessageConverter(); return new Jackson2JsonMessageConverter();
} }
} }

View File

@ -4,8 +4,12 @@ import java.util.List;
import java.io.IOException; import java.io.IOException;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import com.zhiLian.business.domain.Cart;
import com.zhiLian.business.domain.CartVo;
import com.zhiLian.business.domain.Entinfo; import com.zhiLian.business.domain.Entinfo;
import com.zhiLian.business.service.IEntinfoService; import com.zhiLian.business.service.IEntinfoService;
import com.zhiLian.business.service.PlusService;
import com.zhiLian.business.service.impl.PlusServiceImpl;
import com.zhiLian.common.core.domain.Result; import com.zhiLian.common.core.domain.Result;
import com.zhiLian.common.core.utils.poi.ExcelUtil; import com.zhiLian.common.core.utils.poi.ExcelUtil;
import com.zhiLian.common.core.web.controller.BaseController; import com.zhiLian.common.core.web.controller.BaseController;
@ -36,6 +40,16 @@ public class EntinfoController extends BaseController
@Autowired @Autowired
private IEntinfoService entinfoService; private IEntinfoService entinfoService;
@Autowired
private PlusService plusService;
@PostMapping("cartLiat")
public Result cartList(@RequestBody CartVo cartVo){
List<Cart> list = plusService.list();
System.out.println(list);
return plusService.cartList();
}
/** /**
* *
*/ */

View File

@ -0,0 +1,15 @@
package com.zhiLian.business.controller;
import com.zhiLian.business.domain.Business;
import com.zhiLian.business.mapper.BusinessMapper;
/**
* BingRui.Hou
*
* @Description
* @ClassName PlusController
* @Date 2024/06/09 15:28
*/
public class PlusController{
}

View File

@ -0,0 +1,35 @@
package com.zhiLian.business.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* BingRui.Hou
*
* @Description
* @ClassName Cart
* @Date 2024/06/09 15:40
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@TableName("cart")
public class Cart {
// @TableId
private Long id;
// @TableField(value = "name")
private String name;
// @TableField(value = "type_id")
private Long typeId;
}

View File

@ -0,0 +1,30 @@
package com.zhiLian.business.domain;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.zhiLian.common.core.annotation.Excel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
import java.util.Date;
/**
* BingRui.Hou
*
* @Description
* @ClassName BusinessVo
* @Date 2024/06/09 15:34
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class CartVo {
private Long id;
private String name;
private String typeName;
}

View File

@ -0,0 +1,31 @@
package com.zhiLian.business.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* BingRui.Hou
*
* @Description
* @ClassName Type
* @Date 2024/06/09 15:40
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@TableName("type")
public class Type {
// @TableId
private Long id;
// @TableField(value = "type_name")
private String typeName;
}

View File

@ -10,8 +10,6 @@ import java.util.List;
/** /**
* Mapper * Mapper
*
* @author muyu
* @date 2024-05-26 * @date 2024-05-26
*/ */
public interface BusinessMapper extends BaseMapper<Business> public interface BusinessMapper extends BaseMapper<Business>

View File

@ -60,4 +60,6 @@ public interface EntinfoMapper extends BaseMapper<Entinfo>
* @return * @return
*/ */
public int deleteEntinfoByIds(Long[] ids); public int deleteEntinfoByIds(Long[] ids);
Entinfo selectEntinfo(Entinfo business);
} }

View File

@ -0,0 +1,19 @@
package com.zhiLian.business.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.zhiLian.business.domain.Cart;
import com.zhiLian.business.domain.CartVo;
import org.apache.ibatis.annotations.Mapper;
/**
* BingRui.Hou
*
* @Description
* @ClassName PlusMapper
* @Date 2024/06/09 15:33
*/
@Mapper
public interface PlusMapper extends MPJBaseMapper<Cart> {
}

View File

@ -0,0 +1,20 @@
package com.zhiLian.business.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.yulichang.base.MPJBaseMapper;
import com.zhiLian.business.domain.Cart;
import com.zhiLian.business.domain.Type;
import org.apache.ibatis.annotations.Mapper;
import org.apache.poi.ss.formula.functions.T;
/**
* BingRui.Hou
*
* @Description
* @ClassName PlusMapper
* @Date 2024/06/09 15:33
*/
@Mapper
public interface TypeMapper extends BaseMapper<Type> {
}

View File

@ -1,6 +1,7 @@
package com.zhiLian.business.service; package com.zhiLian.business.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.zhiLian.business.domain.Business;
import com.zhiLian.business.domain.Entinfo; import com.zhiLian.business.domain.Entinfo;
import java.util.List; import java.util.List;
@ -60,4 +61,6 @@ public interface IEntinfoService extends IService<Entinfo>
* @return * @return
*/ */
public int deleteEntinfoById(Long id); public int deleteEntinfoById(Long id);
Entinfo selectEntinfo(Entinfo business);
} }

View File

@ -0,0 +1,19 @@
package com.zhiLian.business.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.github.yulichang.base.MPJBaseMapper;
import com.github.yulichang.base.MPJBaseService;
import com.zhiLian.business.domain.Cart;
import com.zhiLian.business.domain.CartVo;
import com.zhiLian.common.core.domain.Result;
/**
* @ClassName PlusService
* @Description
* @Author BingRui.Hou
* @Date 2024/06/09 15:36
*/
public interface PlusService extends IService<Cart> {
Result cartList();
}

View File

@ -108,7 +108,7 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
.email(business.getBusinessEmail()) .email(business.getBusinessEmail())
.phonenumber(business.getBusinessPhone()) .phonenumber(business.getBusinessPhone())
.loginIp("111.229.102.61") .loginIp("111.229.102.61")
.roleId(Long.valueOf(2)) .roleId(Long.valueOf(101))
.userType(String.valueOf(business.getId())) .userType(String.valueOf(business.getId()))
.build(); .build();
Result add = remoteUserService.add(sysUser); Result add = remoteUserService.add(sysUser);
@ -139,11 +139,22 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
public void httpConnectMysql(Business business){ public void httpConnectMysql(Business business){
redisService.deleteObject("entinfo"); redisService.deleteObject("entinfo");
List<Entinfo> list = entinfoService.list(); List<Entinfo> list = entinfoService.list();
redisService.setCacheList("entinfo",list); if(list.size()!=0){
if (business.getBusinessStates().equals("2")) { redisService.setCacheList("entinfo",list);
extracted(business); }
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 @Autowired
@ -159,7 +170,6 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
hashMap.put("businessId",business.getId()+ business.getName()); hashMap.put("businessId",business.getId()+ business.getName());
hashMap.put("mysqlPort",String.valueOf(3306+ business.getId())); hashMap.put("mysqlPort",String.valueOf(3306+ business.getId()));
String json = JSON.toJSONString(hashMap); String json = JSON.toJSONString(hashMap);
// 3.创建连接与设置连接参数 // 3.创建连接与设置连接参数
URL urlObj = null; URL urlObj = null;
try { try {
@ -186,21 +196,21 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
new InputStreamReader(httpConn.getInputStream())); new InputStreamReader(httpConn.getInputStream()));
String resultData = br.readLine(); String resultData = br.readLine();
System.out.println("从服务端返回结果: " + resultData); System.out.println("从服务端返回结果: " + resultData);
Entinfo build = Entinfo.builder()
.entCode("test_" + business.getId())
.ip("192.168.120.128")
.port(Integer.valueOf(3306 + Integer.valueOf(String.valueOf(business.getId())))).build();
entinfoService.insertEntinfo(build);
rabbitTemplate.convertAndSend("zhiLian-vehicle-exchange",JSON.toJSONString(build),message ->{
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
return message;
} );
// 7.关闭HttpURLConnection连接 // 7.关闭HttpURLConnection连接
httpConn.disconnect(); httpConn.disconnect();
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
Entinfo build = Entinfo.builder()
.entCode("test_" + business.getId())
.ip("192.168.120.128")
.port(Integer.valueOf(3306 + Integer.valueOf(String.valueOf(business.getId())))).build();
entinfoService.insertEntinfo(build);
rabbitTemplate.convertAndSend("zhiLian-vehicle-exchange",JSON.toJSONString(build),message ->{
message.getMessageProperties().setMessageId(UUID.randomUUID().toString());
return message;
} );
} }
/** /**

View File

@ -3,6 +3,7 @@ package com.zhiLian.business.service.impl;
import java.util.List; import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhiLian.business.domain.Business;
import com.zhiLian.business.domain.Entinfo; import com.zhiLian.business.domain.Entinfo;
import com.zhiLian.business.mapper.EntinfoMapper; import com.zhiLian.business.mapper.EntinfoMapper;
import com.zhiLian.business.service.IEntinfoService; import com.zhiLian.business.service.IEntinfoService;
@ -93,4 +94,9 @@ public class EntinfoServiceImpl extends ServiceImpl<EntinfoMapper, Entinfo>
{ {
return entinfoMapper.deleteEntinfoById(id); return entinfoMapper.deleteEntinfoById(id);
} }
@Override
public Entinfo selectEntinfo(Entinfo business) {
return entinfoMapper.selectEntinfo(business);
}
} }

View File

@ -0,0 +1,57 @@
package com.zhiLian.business.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.zhiLian.business.domain.Cart;
import com.zhiLian.business.domain.CartVo;
import com.zhiLian.business.domain.Type;
import com.zhiLian.business.mapper.PlusMapper;
import com.zhiLian.business.mapper.TypeMapper;
import com.zhiLian.business.service.PlusService;
import com.zhiLian.common.core.domain.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* BingRui.Hou
*
* @Description
* @ClassName PlusServiceImpl
* @Date 2024/06/09 15:37
*/
@Service
public class PlusServiceImpl extends MPJBaseServiceImpl<PlusMapper, Cart> implements PlusService {
@Autowired
private PlusMapper plusMapper;
@Autowired
private TypeMapper typeMapper;
@Override
public Result cartList() {
MPJLambdaWrapper<Cart> mpjLambdaWrapper = new MPJLambdaWrapper<Cart>()
.selectAll( Cart.class) //查询主表所有的字段
.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);
// 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());
}
}

View File

@ -9,7 +9,7 @@ spring:
password: guest password: guest
virtualHost: / virtualHost: /
port: 5672 port: 5672
host: 192.168.120.128 host: 111.229.102.61
listener: listener:
simple: simple:
prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条 prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条

View File

@ -28,6 +28,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<include refid="selectEntinfoVo"/> <include refid="selectEntinfoVo"/>
where id = #{id} where id = #{id}
</select> </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 id="insertEntinfo" parameterType="com.zhiLian.business.domain.Entinfo" useGeneratedKeys="true" keyProperty="id">
insert into entinfo insert into entinfo

View File

@ -50,4 +50,9 @@ public interface RemoteUserService {
@GetMapping("/user/selectByUserId/{userId}") @GetMapping("/user/selectByUserId/{userId}")
public SysUser selectByUserId (@PathVariable("userId") Long 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);
} }

View File

@ -51,6 +51,16 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
return null; return null;
} }
@Override
public SysUser userById(Long userType) {
return null;
}
@Override
public Result updateById(SysUser user) {
return null;
}
}; };
} }
} }

View File

@ -18,6 +18,7 @@ import com.zhiLian.system.domain.resp.AuthRoleResp;
import com.zhiLian.system.domain.resp.UserDetailInfoResp; import com.zhiLian.system.domain.resp.UserDetailInfoResp;
import com.zhiLian.system.domain.resp.UserInfoResp; import com.zhiLian.system.domain.resp.UserInfoResp;
import com.zhiLian.system.service.*; import com.zhiLian.system.service.*;
import org.apache.catalina.User;
import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
@ -295,4 +296,14 @@ public class SysUserController extends BaseController {
public Result deptTree (SysDept dept) { public Result deptTree (SysDept dept) {
return success(deptService.selectDeptTreeList(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));
}
} }

View File

@ -139,4 +139,8 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
* @return * @return
*/ */
public SysUser checkEmailUnique (String email); public SysUser checkEmailUnique (String email);
void updateByUserId(SysUser user);
SysUser selectUserByUserType(String userType);
} }

View File

@ -2,6 +2,7 @@ package com.zhiLian.system.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.zhiLian.common.system.domain.SysUser; import com.zhiLian.common.system.domain.SysUser;
import org.apache.catalina.User;
import java.util.List; import java.util.List;
@ -225,4 +226,8 @@ public interface SysUserService extends IService<SysUser> {
* @return * @return
*/ */
public String importUser (List<SysUser> userList, Boolean isUpdateSupport, String operName); public String importUser (List<SysUser> userList, Boolean isUpdateSupport, String operName);
String updateByUserId(SysUser user);
SysUser selectUserByUserType(Long userType);
} }

View File

@ -16,6 +16,7 @@ import com.zhiLian.system.domain.SysUserRole;
import com.zhiLian.system.mapper.*; import com.zhiLian.system.mapper.*;
import com.zhiLian.system.service.SysUserService; import com.zhiLian.system.service.SysUserService;
import com.zhiLian.system.service.SysConfigService; import com.zhiLian.system.service.SysConfigService;
import org.apache.catalina.User;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -241,9 +242,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
// 新增用户岗位关联 // 新增用户岗位关联
insertUserPost(user); insertUserPost(user);
// 新增用户与角色管理 // 新增用户与角色管理
if (2 == user.getRoleId()){ if (101 == user.getRoleId()){
SysUserRole sysUserRole = new SysUserRole(); SysUserRole sysUserRole = new SysUserRole();
sysUserRole.setRoleId(Long.valueOf(2)); sysUserRole.setRoleId(Long.valueOf(101));
sysUserRole.setUserId(user.getUserId()); sysUserRole.setUserId(user.getUserId());
userRoleMapper.insertUserRole(sysUserRole); userRoleMapper.insertUserRole(sysUserRole);
} }
@ -506,4 +507,17 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
return successMsg.toString(); 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;
}
} }

View File

@ -185,6 +185,12 @@
and del_flag = '0' and del_flag = '0'
limit 1 limit 1
</select> </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 id="insertUser" parameterType="com.zhiLian.common.system.domain.SysUser" useGeneratedKeys="true" keyProperty="userId">
insert into sys_user( insert into sys_user(
@ -259,6 +265,9 @@
set password = #{password} set password = #{password}
where user_name = #{userName} where user_name = #{userName}
</update> </update>
<update id="updateByUserId">
update sys_user_role set role_id = #{roleId} where user_id = #{userId}
</update>
<delete id="deleteUserById" parameterType="Long"> <delete id="deleteUserById" parameterType="Long">
update sys_user update sys_user

View File

@ -41,6 +41,21 @@ import java.util.Map;
public class ManyDataSource { public class ManyDataSource {
@PostConstruct
public void init() {
new Thread(() -> {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}).start();
}
@Autowired @Autowired
private RedisTemplate<String,String> redisTemplate; private RedisTemplate<String,String> redisTemplate;
@ -52,6 +67,13 @@ public class ManyDataSource {
@RabbitListener(queuesToDeclare = {@Queue(name = "zhiLian-vehicle-exchange")}) @RabbitListener(queuesToDeclare = {@Queue(name = "zhiLian-vehicle-exchange")})
public void smsConfig(String msg, Message message, Channel channel){ public void smsConfig(String msg, Message message, Channel channel){
//获取消息的ID //获取消息的ID
// new Thread(() -> {
// try {
// Thread.sleep(10000);
// } catch (InterruptedException e) {
// throw new RuntimeException(e);
// }
// }).start();
String messageId = message.getMessageProperties().getMessageId(); String messageId = message.getMessageProperties().getMessageId();
try { try {
//添加消息id到redis set集合中 添加成功返回1 表示未消费 添加失败返回0 表示已消费 //添加消息id到redis set集合中 添加成功返回1 表示未消费 添加失败返回0 表示已消费
@ -59,41 +81,17 @@ public class ManyDataSource {
//添加成功 正常消费信息 //添加成功 正常消费信息
if (count == 1) { if (count == 1) {
log.info("开始消费"); log.info("开始消费");
DruidDataSourceFactory druidDataSourceFactory = SpringUtils.getBean(DruidDataSourceFactory.class); druidData(msg);
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();
//确认消费 //确认消费
channel.basicAck(message.getMessageProperties().getDeliveryTag(),false); channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
log.info("消费成功"); log.info("消费成功");
} }
} catch (Exception e) { } catch (Exception e) {
//删除队列ID log.info("消费失败,尝试重连");
log.info("消费重复");
try { try {
//回退消息 //回退消息,尝试重连
channel.basicReject(message.getMessageProperties().getDeliveryTag(),true); druidData(msg);
channel.basicReject(message.getMessageProperties().getDeliveryTag(),false);
log.info("消费失败"); log.info("消费失败");
} catch (IOException ex) { } catch (IOException ex) {
//回退失败 //回退失败
@ -102,6 +100,17 @@ 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 @Lazy
private List<Entinfo> dataSourceInfoList(){ private List<Entinfo> dataSourceInfoList(){
List<Entinfo> databaseNameList = new ArrayList<>(){{ List<Entinfo> databaseNameList = new ArrayList<>(){{

View File

@ -2,6 +2,7 @@ package com.zhiLian.vehicle.datasource.config.factory;
import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import com.zhiLian.vehicle.datasource.domain.DataSourceInfo; import com.zhiLian.vehicle.datasource.domain.DataSourceInfo;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -31,13 +32,9 @@ public class DruidDataSourceFactory {
druidDataSource.setPassword(dataSourceInfo.getPassword()); druidDataSource.setPassword(dataSourceInfo.getPassword());
druidDataSource.setBreakAfterAcquireFailure(true); druidDataSource.setBreakAfterAcquireFailure(true);
druidDataSource.setConnectionErrorRetryAttempts(0); druidDataSource.setConnectionErrorRetryAttempts(0);
try { druidDataSource.setInitialSize(5);
druidDataSource.getConnection(2000); druidDataSource.setMaxActive(15);
log.info("{} -> 数据源连接成功", dataSourceInfo); log.info("{} -> 数据源连接成功", dataSourceInfo);
return druidDataSource; return druidDataSource;
} catch (SQLException throwables) {
log.error("数据源 {} 连接失败,用户名:{},密码 {}",dataSourceInfo.getUrl(),dataSourceInfo.getUserName(),dataSourceInfo.getPassword());
return null;
}
} }
} }

View File

@ -7,7 +7,7 @@ package com.zhiLian.vehicle.datasource.contents;
*/ */
public class DatasourceContent { public class DatasourceContent {
public final static String DATASOURCE_URL = "jdbc:mysql://{}:{}/zhiLian-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"; public final static String USER_NAME = "root";

View File

@ -0,0 +1,31 @@
package com.zhiLian.vehicle.domain;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* BingRui.Hou
*
* @Description
* @ClassName Type
* @Date 2024/06/09 15:40
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@TableName("type")
public class Type {
@TableId
private Long id;
@TableField(value = "type_name")
private String typeName;
}

View File

@ -0,0 +1,54 @@
package com.zhiLian.vehicle.domain.vo;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zhiLian.common.core.annotation.Excel;
import com.zhiLian.common.core.web.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
/**
* vehicle
*
* @author muyu
* @date 2024-05-27
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
public class VehicleVo extends BaseEntity
{
/** 车辆主键 */
private Long id;
/** 车辆vin */
private String number;
/** 电子围栏ID */
private Long electonicId;
/** 电机厂商 */
private String motor;
/** 电池厂商 */
private String battery;
/** 电机编号 */
private Long motorNumber;
/** 电池编号 */
private Long batteryNumber;
/** 企业ID */
// @Excel(name = "企业ID")
// private Long businessId;
private Long groupId;
private String typeName;
}

View File

@ -9,7 +9,7 @@ spring:
password: guest password: guest
virtualHost: / virtualHost: /
port: 5672 port: 5672
host: 192.168.120.128 host: 111.229.102.61
listener: listener:
simple: simple:
prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条 prefetch: 1 # 每次只能获取一条,处理完成才能获取下一条