feat:多数据源模块

master
hbr 2024-06-06 18:23:42 +08:00
parent 931c5a4634
commit 3fccdf3da0
21 changed files with 593 additions and 86 deletions

View File

@ -0,0 +1,106 @@
package com.zhiLian.business.controller;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import com.zhiLian.business.domain.Entinfo;
import com.zhiLian.business.service.IEntinfoService;
import com.zhiLian.common.core.domain.Result;
import com.zhiLian.common.core.utils.poi.ExcelUtil;
import com.zhiLian.common.core.web.controller.BaseController;
import com.zhiLian.common.core.web.page.TableDataInfo;
import com.zhiLian.common.log.annotation.Log;
import com.zhiLian.common.log.enums.BusinessType;
import com.zhiLian.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* Controller
*
* @author muyu
* @date 2024-06-06
*/
@RestController
@RequestMapping("/entinfo")
public class EntinfoController extends BaseController
{
@Autowired
private IEntinfoService entinfoService;
/**
*
*/
// @RequiresPermissions("system:entinfo:list")
@GetMapping("/list")
public Result<TableDataInfo<Entinfo>> list(Entinfo entinfo)
{
startPage();
List<Entinfo> list = entinfoService.selectEntinfoList(entinfo);
return getDataTable(list);
}
/**
*
*/
// @RequiresPermissions("system:entinfo:export")
@Log(title = "多数据源", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, Entinfo entinfo)
{
List<Entinfo> list = entinfoService.selectEntinfoList(entinfo);
ExcelUtil<Entinfo> util = new ExcelUtil<Entinfo>(Entinfo.class);
util.exportExcel(response, list, "多数据源数据");
}
/**
*
*/
// @RequiresPermissions("system:entinfo:query")
@GetMapping(value = "/{id}")
public Result getInfo(@PathVariable("id") Long id)
{
return success(entinfoService.selectEntinfoById(id));
}
/**
*
*/
// @RequiresPermissions("system:entinfo:add")
@Log(title = "多数据源", businessType = BusinessType.INSERT)
@PostMapping
public Result add(@RequestBody Entinfo entinfo)
{
return toAjax(entinfoService.insertEntinfo(entinfo));
}
/**
*
*/
// @RequiresPermissions("system:entinfo:edit")
@Log(title = "多数据源", businessType = BusinessType.UPDATE)
@PutMapping
public Result edit(@RequestBody Entinfo entinfo)
{
return toAjax(entinfoService.updateEntinfo(entinfo));
}
/**
*
*/
// @RequiresPermissions("system:entinfo:remove")
@Log(title = "多数据源", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public Result remove(@PathVariable Long[] ids)
{
return toAjax(entinfoService.deleteEntinfoByIds(ids));
}
}

View File

@ -0,0 +1,46 @@
package com.zhiLian.business.domain;
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;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
/**
* entinfo
*
* @author muyu
* @date 2024-06-06
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName("entinfo")
public class Entinfo extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 数据源key */
@Excel(name = "数据源key")
private String entCode;
/** 数据源ip */
@Excel(name = "数据源ip")
private String ip;
/** 数据源端口 */
@Excel(name = "数据源端口")
private Integer port;
/** 数据源ID */
private Long id;
}

View File

@ -0,0 +1,63 @@
package com.zhiLian.business.mapper;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zhiLian.business.domain.Entinfo;
/**
* Mapper
*
* @author muyu
* @date 2024-06-06
*/
public interface EntinfoMapper extends BaseMapper<Entinfo>
{
/**
*
*
* @param id
* @return
*/
public Entinfo selectEntinfoById(Long id);
/**
*
*
* @param entinfo
* @return
*/
public List<Entinfo> selectEntinfoList(Entinfo entinfo);
/**
*
*
* @param entinfo
* @return
*/
public int insertEntinfo(Entinfo entinfo);
/**
*
*
* @param entinfo
* @return
*/
public int updateEntinfo(Entinfo entinfo);
/**
*
*
* @param id
* @return
*/
public int deleteEntinfoById(Long id);
/**
*
*
* @param ids
* @return
*/
public int deleteEntinfoByIds(Long[] ids);
}

View File

@ -0,0 +1,63 @@
package com.zhiLian.business.service;
import com.baomidou.mybatisplus.extension.service.IService;
import com.zhiLian.business.domain.Entinfo;
import java.util.List;
/**
* Service
*
* @author muyu
* @date 2024-06-06
*/
public interface IEntinfoService extends IService<Entinfo>
{
/**
*
*
* @param id
* @return
*/
public Entinfo selectEntinfoById(Long id);
/**
*
*
* @param entinfo
* @return
*/
public List<Entinfo> selectEntinfoList(Entinfo entinfo);
/**
*
*
* @param entinfo
* @return
*/
public int insertEntinfo(Entinfo entinfo);
/**
*
*
* @param entinfo
* @return
*/
public int updateEntinfo(Entinfo entinfo);
/**
*
*
* @param ids
* @return
*/
public int deleteEntinfoByIds(Long[] ids);
/**
*
*
* @param id
* @return
*/
public int deleteEntinfoById(Long id);
}

View File

@ -3,13 +3,16 @@ package com.zhiLian.business.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhiLian.business.domain.AuthRoleResp;
import com.zhiLian.business.domain.Business; import com.zhiLian.business.domain.Business;
import com.zhiLian.business.domain.Entinfo;
import com.zhiLian.business.mapper.BusinessMapper; import com.zhiLian.business.mapper.BusinessMapper;
import com.zhiLian.business.remote.factory.RemoteUserLoginFactory; import com.zhiLian.business.remote.factory.RemoteUserLoginFactory;
import com.zhiLian.business.service.IBusinessService; import com.zhiLian.business.service.IBusinessService;
import com.zhiLian.common.core.domain.Result; import com.zhiLian.common.core.domain.Result;
import com.zhiLian.common.core.utils.DateUtils; import com.zhiLian.common.core.utils.DateUtils;
import com.zhiLian.common.redis.service.RedisService;
import com.zhiLian.common.security.utils.SecurityUtils; import com.zhiLian.common.security.utils.SecurityUtils;
import com.zhiLian.common.system.domain.LoginUser; import com.zhiLian.common.system.domain.LoginUser;
import com.zhiLian.common.system.domain.SysUser; import com.zhiLian.common.system.domain.SysUser;
@ -29,6 +32,7 @@ import java.net.ProtocolException;
import java.net.URL; import java.net.URL;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
/** /**
* Service * Service
@ -47,7 +51,7 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
private RemoteUserService remoteUserService; private RemoteUserService remoteUserService;
@Autowired @Autowired
private RedisTemplate<String,String> redisTemplate; private RedisService redisService;
/** /**
* *
@ -71,7 +75,6 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
@Override @Override
public List<Business> selectBusinessList(Business business) public List<Business> selectBusinessList(Business business)
{ {
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
SysUser user = remoteUserService.selectByUserId(loginUser.getUserid()); SysUser user = remoteUserService.selectByUserId(loginUser.getUserid());
if (user.getUserType().equals("00")) { if (user.getUserType().equals("00")) {
@ -122,17 +125,25 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
httpConnectMysql(business); httpConnectMysql(business);
return businessMapper.updateBusiness(business); return businessMapper.updateBusiness(business);
} }
@Autowired
private EntinfoServiceImpl entinfoService;
/** /**
* redis * redis
* @param business * @param business
*/ */
public void httpConnectMysql(Business business){ public void httpConnectMysql(Business business){
redisService.deleteObject("entinfo");
List<Entinfo> list = entinfoService.list();
redisService.setCacheList("entinfo",list);
if (business.getBusinessStates().equals(2) ) { if (business.getBusinessStates().equals(2) ) {
if (!redisTemplate.hasKey(business.getId()+business.getName())){ Entinfo build = Entinfo.builder()
redisTemplate.opsForValue().set(business.getId()+business.getName(),String.valueOf(3306+business.getId())); .entCode("test_" + business.getId())
extracted(business); .ip("192.168.120.128")
} .port(Integer.valueOf(3306 + Integer.valueOf(String.valueOf(business.getId())))).build();
entinfoService.insertEntinfo(build);
// redisService.setCacheObject(String.valueOf(business.getId()),JSON.toJSONString(build));
extracted(business);
} }
} }
@ -142,11 +153,12 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
* @param business * @param business
*/ */
private static void extracted(Business business) { private static void extracted(Business business) {
String postUrl="http://122.51.111.225:10006/webhook/%E6%96%B0%E5%BB%BA%E4%BC%81%E4%B8%9A%E6%95%B0%E6%8D%AE%E6%BA%90"; String postUrl="http://192.168.120.128/webhook/%E6%96%B0%E5%BB%BAmysql%E6%9C%8D%E5%8A%A1";
HashMap<String, String> hashMap = new HashMap<>(); HashMap<String, String> hashMap = new HashMap<>();
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 {
@ -178,6 +190,7 @@ public class BusinessServiceImpl extends ServiceImpl<BusinessMapper, Business>
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
/** /**

View File

@ -0,0 +1,96 @@
package com.zhiLian.business.service.impl;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhiLian.business.domain.Entinfo;
import com.zhiLian.business.mapper.EntinfoMapper;
import com.zhiLian.business.service.IEntinfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Service
*
* @author muyu
* @date 2024-06-06
*/
@Service
public class EntinfoServiceImpl extends ServiceImpl<EntinfoMapper, Entinfo>
implements IEntinfoService
{
@Autowired
private EntinfoMapper entinfoMapper;
/**
*
*
* @param id
* @return
*/
@Override
public Entinfo selectEntinfoById(Long id)
{
return entinfoMapper.selectEntinfoById(id);
}
/**
*
*
* @param entinfo
* @return
*/
@Override
public List<Entinfo> selectEntinfoList(Entinfo entinfo)
{
return entinfoMapper.selectEntinfoList(entinfo);
}
/**
*
*
* @param entinfo
* @return
*/
@Override
public int insertEntinfo(Entinfo entinfo)
{
return entinfoMapper.insertEntinfo(entinfo);
}
/**
*
*
* @param entinfo
* @return
*/
@Override
public int updateEntinfo(Entinfo entinfo)
{
return entinfoMapper.updateEntinfo(entinfo);
}
/**
*
*
* @param ids
* @return
*/
@Override
public int deleteEntinfoByIds(Long[] ids)
{
return entinfoMapper.deleteEntinfoByIds(ids);
}
/**
*
*
* @param id
* @return
*/
@Override
public int deleteEntinfoById(Long id)
{
return entinfoMapper.deleteEntinfoById(id);
}
}

View File

@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zhiLian.business.mapper.EntinfoMapper">
<resultMap type="com.zhiLian.business.domain.Entinfo" id="EntinfoResult">
<result property="entCode" column="ent_code" />
<result property="ip" column="ip" />
<result property="port" column="port" />
<result property="id" column="id" />
</resultMap>
<sql id="selectEntinfoVo">
select ent_code, ip, port, id from entinfo
</sql>
<select id="selectEntinfoList" parameterType="com.zhiLian.business.domain.Entinfo" resultMap="EntinfoResult">
<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>
<select id="selectEntinfoById" parameterType="Long" resultMap="EntinfoResult">
<include refid="selectEntinfoVo"/>
where id = #{id}
</select>
<insert id="insertEntinfo" parameterType="com.zhiLian.business.domain.Entinfo" useGeneratedKeys="true" keyProperty="id">
insert into entinfo
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="entCode != null">ent_code,</if>
<if test="ip != null">ip,</if>
<if test="port != null">port,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="entCode != null">#{entCode},</if>
<if test="ip != null">#{ip},</if>
<if test="port != null">#{port},</if>
</trim>
</insert>
<update id="updateEntinfo" parameterType="com.zhiLian.business.domain.Entinfo">
update entinfo
<trim prefix="SET" suffixOverrides=",">
<if test="entCode != null">ent_code = #{entCode},</if>
<if test="ip != null">ip = #{ip},</if>
<if test="port != null">port = #{port},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteEntinfoById" parameterType="Long">
delete from entinfo where id = #{id}
</delete>
<delete id="deleteEntinfoByIds" parameterType="String">
delete from entinfo where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>

View File

@ -241,7 +241,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
// 新增用户岗位关联 // 新增用户岗位关联
insertUserPost(user); insertUserPost(user);
// 新增用户与角色管理 // 新增用户与角色管理
if (user.getRoleId()==null&& user.getRoleId().equals("")){ if (null == user.getRoleId()|| user.getRoleId().equals("")){
user.setRoleId(Long.valueOf(2)); user.setRoleId(Long.valueOf(2));
insertUserRole(user); insertUserRole(user);
return rows; return rows;

View File

@ -190,8 +190,8 @@
insert into sys_user( insert into sys_user(
<if test="userId != null and userId != 0">user_id,</if> <if test="userId != null and userId != 0">user_id,</if>
<if test="deptId != null and deptId != 0">dept_id,</if> <if test="deptId != null and deptId != 0">dept_id,</if>
<if test="userType != null and userType != 0">user_type,</if>
<if test="userName != null and userName != ''">user_name,</if> <if test="userName != null and userName != ''">user_name,</if>
<if test="userType != null and userType != 0">user_type,</if>
<if test="nickName != null and nickName != ''">nick_name,</if> <if test="nickName != null and nickName != ''">nick_name,</if>
<if test="email != null and email != ''">email,</if> <if test="email != null and email != ''">email,</if>
<if test="avatar != null and avatar != ''">avatar,</if> <if test="avatar != null and avatar != ''">avatar,</if>

View File

@ -1,14 +1,23 @@
package com.zhiLian.vehicle.datasource; package com.zhiLian.vehicle.datasource;
import com.alibaba.fastjson2.JSON;
import com.zhiLian.common.redis.service.RedisService;
import com.zhiLian.common.system.remote.RemoteUserService;
import com.zhiLian.vehicle.datasource.config.factory.DruidDataSourceFactory; import com.zhiLian.vehicle.datasource.config.factory.DruidDataSourceFactory;
import com.zhiLian.vehicle.datasource.config.role.DynamicDataSource; import com.zhiLian.vehicle.datasource.config.role.DynamicDataSource;
import com.zhiLian.vehicle.datasource.domain.DataSourceInfo; import com.zhiLian.vehicle.datasource.domain.DataSourceInfo;
import com.zhiLian.vehicle.datasource.domain.EntInfo; import com.zhiLian.vehicle.datasource.domain.Entinfo;
import lombok.extern.log4j.Log4j2; import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Primary; import org.springframework.context.annotation.Primary;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import springfox.documentation.spring.web.json.Json;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -16,33 +25,46 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* @author DongZl * BingRui.Hou
* @description: *
* @Date 2023-8-1 11:05
*/ */
@Log4j2 @Log4j2
@Configuration @Component
@AutoConfigureBefore(RedisService.class)
public class ManyDataSource { public class ManyDataSource {
@Autowired
private RedisService redisService;
private List<EntInfo> dataSourceInfoList(){ @Autowired
List<EntInfo> databaseNameList = new ArrayList<>(){{ private RedisTemplate<String,String> redisTemplate;
add(EntInfo.builder()
.entCode("test_1")
@Lazy
private List<Entinfo> dataSourceInfoList(){
List<Entinfo> databaseNameList = new ArrayList<>(){{
add(Entinfo.builder()
.entCode("test_00")
.ip("192.168.120.128") .ip("192.168.120.128")
.port(3306) .port(3306)
.build()); .build());
add(EntInfo.builder()
.entCode("test_2")
.ip("122.51.111.225")
.port(6666)
.build());
add(EntInfo.builder()
.entCode("test_3")
.ip("122.51.111.225")
.port(3333)
.build());
}}; }};
List<String> entinfo = redisTemplate.opsForList().range("entinfo", 0, -1);
entinfo.forEach(string -> {
Entinfo entInfo = JSON.parseObject(string, Entinfo.class);
databaseNameList.add(entInfo);
});
// if(SecurityUtils.getLoginUser() == null){
// return databaseNameList;
// }else{
// Long storeId = SecurityUtils.getLoginUser().getUserid();
// SysUser sysUser = remoteUserService.selectByUserId(storeId);
// String s = redisService.getCacheObject(String.valueOf(sysUser.getUserType()));
// EntInfo entInfo = JSON.parseObject(s, EntInfo.class);
// databaseNameList.add(entInfo);
// return databaseNameList;
// }
return databaseNameList; return databaseNameList;
} }

View File

@ -1,17 +1,22 @@
package com.zhiLian.vehicle.datasource.config; package com.zhiLian.vehicle.datasource.config;
import com.zhiLian.common.security.utils.SecurityUtils; import com.zhiLian.common.security.utils.SecurityUtils;
import com.zhiLian.common.system.domain.SysUser;
import com.zhiLian.common.system.remote.RemoteUserService;
import com.zhiLian.vehicle.datasource.config.holder.DynamicDataSourceHolder; import com.zhiLian.vehicle.datasource.config.holder.DynamicDataSourceHolder;
import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
* @author DongZl * BingRui.Hou
* @description: *
* @Date 2023-8-2 08:26 *
*/ */
@Aspect @Aspect
@Component @Component
@ -21,14 +26,24 @@ public class DataSourceAsp {
public void pointcut () { public void pointcut () {
} }
@Lazy
@Autowired
private RemoteUserService remoteUserService;
/** /**
* *
*/ */
@Before("pointcut()") @Before("pointcut()")
public void beforeMethod() { public void beforeMethod() {
// EntInfo build = EntInfo.builder()
// .entCode("test_" + 12)
// .ip("192.168.120.128")
// .port(Integer.valueOf(3307)).build();
// redisService.setCacheObject(String.valueOf(12), JSON.toJSONString(build));
Long storeId = SecurityUtils.getLoginUser().getUserid(); Long storeId = SecurityUtils.getLoginUser().getUserid();
DynamicDataSourceHolder.setDynamicDataSourceKey("test_"+storeId); SysUser sysUser = remoteUserService.selectByUserId(storeId);
DynamicDataSourceHolder.setDynamicDataSourceKey("test_"+sysUser.getUserType());
} }
/** /**
* *

View File

@ -14,7 +14,7 @@ import java.util.Map;
* *
* AddDefineDataSourceaddDefineDynamicDataSourcetargetdatasourcesmapmaptargetdatasourcesmap * AddDefineDataSourceaddDefineDynamicDataSourcetargetdatasourcesmapmaptargetdatasourcesmap
* 使@DataSource(value = "数据源名称")DynamicDataSourceContextHolder.setContextKey("数据源名称") * 使@DataSource(value = "数据源名称")DynamicDataSourceContextHolder.setContextKey("数据源名称")
* @author Dongzl * @author BingRui.Hou
*/ */
@Data @Data
@AllArgsConstructor @AllArgsConstructor

View File

@ -1,9 +1,9 @@
package com.zhiLian.vehicle.datasource.contents; package com.zhiLian.vehicle.datasource.contents;
/** /**
* @author DongZl * BingRui.Hou
* @description: *
* @Date 2023-8-1 11:02 *
*/ */
public class DatasourceContent { public class DatasourceContent {

View File

@ -11,9 +11,9 @@ import static com.zhiLian.vehicle.datasource.contents.DatasourceContent.*;
/** /**
* @author DongZl * BingRui.Hou
* @description: *
* @Date 2023-8-1 11:15 *
*/ */
@Data @Data
@Builder @Builder

View File

@ -1,29 +0,0 @@
package com.zhiLian.vehicle.datasource.domain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* BingRui.Hou
*
* @Description
* @ClassName EntInfo
* @Date 2024/06/04 14:34
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class EntInfo {
private String entCode;
//ip
private String ip;
//端口
private Integer port;
}

View File

@ -0,0 +1,44 @@
package com.zhiLian.vehicle.datasource.domain;
import com.baomidou.mybatisplus.annotation.TableName;
import com.zhiLian.common.core.annotation.Excel;
import com.zhiLian.common.core.web.domain.BaseEntity;
import lombok.*;
import lombok.experimental.SuperBuilder;
import java.io.Serializable;
/**
* BingRui.Hou
*
* @Description
* EntInfo
* @Date 2024/06/04 14:34
*/
@Data
@SuperBuilder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
public class Entinfo extends BaseEntity implements Serializable
{
private static final long serialVersionUID = 1L;
/** 数据源key */
@Excel(name = "数据源key")
private String entCode;
/** 数据源ip */
@Excel(name = "数据源ip")
private String ip;
/** 数据源端口 */
@Excel(name = "数据源端口")
private Integer port;
/** 数据源ID */
private Long id;
}

View File

@ -13,9 +13,9 @@ import javax.annotation.Resource;
import java.util.Map; import java.util.Map;
/** /**
* @Description: *
* @Author Dongzl * BingRui.Hou
* @Date 2022/8/18 17:20 *
* *
*/ */
@Slf4j @Slf4j

View File

@ -59,8 +59,8 @@ public class Vehicle extends BaseEntity
private Long batteryNumber; private Long batteryNumber;
/** 企业ID */ /** 企业ID */
@Excel(name = "企业ID") // @Excel(name = "企业ID")
private Long businessId; // private Long businessId;
@Excel(name="围栏组ID") @Excel(name="围栏组ID")
private Long groupId; private Long groupId;

View File

@ -66,7 +66,7 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle>
if (user.getUserType().equals("00")) { if (user.getUserType().equals("00")) {
return vehicleMapper.selectVehicleList(vehicle); return vehicleMapper.selectVehicleList(vehicle);
} }
vehicle.setBusinessId(Long.valueOf(user.getUserType())); // vehicle.setBusinessId(Long.valueOf(user.getUserType()));
List<Vehicle> vehicles = vehicleMapper.selectVehicleList(vehicle); List<Vehicle> vehicles = vehicleMapper.selectVehicleList(vehicle);
// vehicles.forEach(vehicle1 -> { // vehicles.forEach(vehicle1 -> {
// Result result = remoteFileService.getInfo(vehicle1.getId()); // Result result = remoteFileService.getInfo(vehicle1.getId());
@ -86,9 +86,9 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle>
@Override @Override
public int insertVehicle(Vehicle vehicle) public int insertVehicle(Vehicle vehicle)
{ {
LoginUser loginUser = SecurityUtils.getLoginUser(); // LoginUser loginUser = SecurityUtils.getLoginUser();
SysUser user = remoteUserService.selectByUserId(loginUser.getUserid()); // SysUser user = remoteUserService.selectByUserId(loginUser.getUserid());
vehicle.setBusinessId(Long.valueOf(user.getUserType())); // vehicle.setBusinessId(Long.valueOf(user.getUserType()));
vehicle.setCreateTime(DateUtils.getNowDate()); vehicle.setCreateTime(DateUtils.getNowDate());
return vehicleMapper.insertVehicle(vehicle); return vehicleMapper.insertVehicle(vehicle);
} }
@ -104,7 +104,7 @@ public class VehicleServiceImpl extends ServiceImpl<VehicleMapper, Vehicle>
{ {
LoginUser loginUser = SecurityUtils.getLoginUser(); LoginUser loginUser = SecurityUtils.getLoginUser();
SysUser user = remoteUserService.selectByUserId(loginUser.getUserid()); SysUser user = remoteUserService.selectByUserId(loginUser.getUserid());
vehicle.setBusinessId(Long.valueOf(user.getUserType())); // vehicle.setBusinessId(Long.valueOf(user.getUserType()));
vehicle.setCreateTime(DateUtils.getNowDate()); vehicle.setCreateTime(DateUtils.getNowDate());
vehicle.setUpdateTime(DateUtils.getNowDate()); vehicle.setUpdateTime(DateUtils.getNowDate());
return vehicleMapper.updateVehicle(vehicle); return vehicleMapper.updateVehicle(vehicle);

View File

@ -4,6 +4,8 @@ server:
# Spring # Spring
spring: spring:
main:
allow-circular-references: true
application: application:
# 应用名称 # 应用名称
name: zhiLian-vehicle name: zhiLian-vehicle

View File

@ -13,7 +13,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="battery" column="battery" /> <result property="battery" column="battery" />
<result property="motorNumber" column="motor_number" /> <result property="motorNumber" column="motor_number" />
<result property="batteryNumber" column="battery_number" /> <result property="batteryNumber" column="battery_number" />
<result property="businessId" column="business_id" /> <!-- <result property="businessId" column="business_id" />-->
<result property="remark" column="remark" /> <result property="remark" column="remark" />
<result property="createBy" column="create_by" /> <result property="createBy" column="create_by" />
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time" />
@ -23,7 +23,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap> </resultMap>
<sql id="selectVehicleVo"> <sql id="selectVehicleVo">
select id, number,group_id, type_id, electonic_id, motor, battery, motor_number, battery_number, business_id, remark, create_by, create_time, update_by, update_time from vehicle select id, number,group_id, type_id, electonic_id, motor, battery, motor_number, battery_number, remark, create_by, create_time, update_by, update_time from vehicle
</sql> </sql>
<select id="selectVehicleList" parameterType="com.zhiLian.vehicle.domain.Vehicle" resultMap="VehicleResult"> <select id="selectVehicleList" parameterType="com.zhiLian.vehicle.domain.Vehicle" resultMap="VehicleResult">
@ -37,7 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="battery != null and battery != ''"> and battery = #{battery}</if> <if test="battery != null and battery != ''"> and battery = #{battery}</if>
<if test="motorNumber != null "> and motor_number = #{motorNumber}</if> <if test="motorNumber != null "> and motor_number = #{motorNumber}</if>
<if test="batteryNumber != null "> and battery_number = #{batteryNumber}</if> <if test="batteryNumber != null "> and battery_number = #{batteryNumber}</if>
<if test="businessId != null "> and business_id = #{businessId}</if> <!-- <if test="businessId != null "> and business_id = #{businessId}</if>-->
<if test="groupId != null "> and group_id = #{groupId}</if> <if test="groupId != null "> and group_id = #{groupId}</if>
</where> </where>
</select> </select>
@ -58,7 +58,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="battery != null">battery,</if> <if test="battery != null">battery,</if>
<if test="motorNumber != null">motor_number,</if> <if test="motorNumber != null">motor_number,</if>
<if test="batteryNumber != null">battery_number,</if> <if test="batteryNumber != null">battery_number,</if>
<if test="businessId != null">business_id,</if> <!-- <if test="businessId != null">business_id,</if>-->
<if test="remark != null">remark,</if> <if test="remark != null">remark,</if>
<if test="createBy != null">create_by,</if> <if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if> <if test="createTime != null">create_time,</if>
@ -75,7 +75,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="battery != null">#{battery},</if> <if test="battery != null">#{battery},</if>
<if test="motorNumber != null">#{motorNumber},</if> <if test="motorNumber != null">#{motorNumber},</if>
<if test="batteryNumber != null">#{batteryNumber},</if> <if test="batteryNumber != null">#{batteryNumber},</if>
<if test="businessId != null">#{businessId},</if> <!-- <if test="businessId != null">#{businessId},</if>-->
<if test="remark != null">#{remark},</if> <if test="remark != null">#{remark},</if>
<if test="createBy != null">#{createBy},</if> <if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if> <if test="createTime != null">#{createTime},</if>
@ -95,7 +95,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="battery != null">battery = #{battery},</if> <if test="battery != null">battery = #{battery},</if>
<if test="motorNumber != null">motor_number = #{motorNumber},</if> <if test="motorNumber != null">motor_number = #{motorNumber},</if>
<if test="batteryNumber != null">battery_number = #{batteryNumber},</if> <if test="batteryNumber != null">battery_number = #{batteryNumber},</if>
<if test="businessId != null">business_id = #{businessId},</if> <!-- <if test="businessId != null">business_id = #{businessId},</if>-->
<if test="remark != null">remark = #{remark},</if> <if test="remark != null">remark = #{remark},</if>
<if test="createBy != null">create_by = #{createBy},</if> <if test="createBy != null">create_by = #{createBy},</if>
<if test="createTime != null">create_time = #{createTime},</if> <if test="createTime != null">create_time = #{createTime},</if>