fast()补充唯一

car-ser
王熙朝 2024-06-11 22:16:11 +08:00
parent a560229583
commit d3f9814aba
11 changed files with 173 additions and 6 deletions

View File

@ -136,6 +136,7 @@
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -29,6 +29,14 @@
<artifactId>muyu-modules-system</artifactId>
<version>3.6.3</version>
</dependency>
<!-- MQ依赖-->
<!-- rabbitmq-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -109,6 +109,36 @@ public class EnterpriseController extends BaseController
return toAjax(enterpriseService.updateEnterprise(enterprise));
}
/**
*
* @param enterpriseName
* @return
*/
@PostMapping("oneName")
public Result<Integer> oneName(String enterpriseName) {
return success(enterpriseService.oneName(enterpriseName));
}
/**
*
* @param contactPhone
* @return
*/
@PostMapping("onePhone")
public Result<Integer> onePhone(String contactPhone) {
return success(enterpriseService.onePhone(contactPhone));
}
/**
*
* @param email
* @return
*/
@PostMapping("oneEmail")
public Result<Integer> oneEmail(String email) {
return success(enterpriseService.oneEmail(email));
}
/**
*
* @param id
@ -174,4 +204,13 @@ public class EnterpriseController extends BaseController
return success(enterpriseService.indexCustom(custom));
}
/**
*
* @return
*/
@PostMapping("listCustom")
public Result<List<Custom>> listCustom() {
return success(enterpriseService.listCustom());
}
}

View File

@ -70,6 +70,16 @@ public interface EnterpriseMapper
Enterprise queryDateEnterprise();
/**
*
* @param enterpriseName
* @return
*/
Integer oneName(@Param("enterpriseName") String enterpriseName);
Integer onePhone(@Param("contactPhone") String contactPhone);
Integer oneEmail(@Param("email") String email);
int getLevel(@Param("id") Long id, @Param("serviceLevel") Integer serviceLevel);
@ -78,4 +88,7 @@ public interface EnterpriseMapper
List<Sources> listSources(QueryWrapper<Object> objectQueryWrapper);
int indexCustom(Custom custom);
List<Custom> listCustom();
}

View File

@ -0,0 +1,18 @@
package com.muyu.goods.mq;
import com.alibaba.csp.sentinel.command.annotation.CommandMapping;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class Producer {
@Autowired
private RabbitTemplate rabbitTemplate;
public void datasource(String ip) {
rabbitTemplate.convertAndSend("datasource",ip);
}
}

View File

@ -48,6 +48,15 @@ public interface IEnterpriseService
*/
public int updateEnterprise(Enterprise enterprise);
/**
*
*/
Integer oneName(String enterpriseName);
Integer onePhone(String contactPhone);
Integer oneEmail(String email);
/**
*
* @param id
@ -85,4 +94,7 @@ public interface IEnterpriseService
List<Sources> listSources();
int indexCustom(Custom custom);
List<Custom> listCustom();
}

View File

@ -4,6 +4,7 @@ import java.io.IOException;
import java.util.List;
import java.util.UUID;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.muyu.common.core.utils.DateUtils;
import com.muyu.common.security.utils.SecurityUtils;
@ -11,10 +12,12 @@ import com.muyu.common.system.domain.LoginUser;
import com.muyu.common.system.domain.SysUser;
import com.muyu.goods.domain.Custom;
import com.muyu.goods.domain.Sources;
import com.muyu.goods.mq.Producer;
import com.muyu.goods.pojo.HttpClient;
import com.muyu.system.remote.RemoteSystemManageService;
import muyu.goods.enterprise.client.config.EnterpriseConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import com.muyu.goods.mapper.EnterpriseMapper;
import com.muyu.goods.domain.Enterprise;
@ -35,6 +38,8 @@ public class EnterpriseServiceImpl implements IEnterpriseService
private RemoteSystemManageService remoteSystemManageService;
@Autowired
private EnterpriseConfig enterpriseConfig;
@Autowired
private Producer producer;
/**
*
@ -97,6 +102,21 @@ public class EnterpriseServiceImpl implements IEnterpriseService
return enterpriseMapper.updateEnterprise(enterprise);
}
@Override
public Integer oneName(String enterpriseName) {
return enterpriseMapper.oneName(enterpriseName);
}
@Override
public Integer onePhone(String contactPhone) {
return enterpriseMapper.onePhone(contactPhone);
}
@Override
public Integer oneEmail(String email) {
return enterpriseMapper.oneEmail(email);
}
/**
*
* @param id
@ -121,6 +141,8 @@ public class EnterpriseServiceImpl implements IEnterpriseService
Sources sources = Sources.index(enterprise1.getId(),"enterprise" + enterprise1.getId(), String.valueOf((int) (enterprise.getId() + 3306)));
System.out.println(sources);
enterpriseMapper.indexSources(sources);
System.out.println(sources.getIp());
producer.datasource(sources.getIp());
}
return i;
}
@ -209,14 +231,19 @@ public class EnterpriseServiceImpl implements IEnterpriseService
@Override
public List<Sources> listSources() {
// producer.datasource("3306");
return enterpriseMapper.listSources(new QueryWrapper<>());
}
@Override
public int indexCustom(Custom custom) {
System.out.println(custom);
// int i = enterpriseMapper.indexCustom(custom);
return 0;
int i = enterpriseMapper.indexCustom(custom);
return i;
}
@Override
public List<Custom> listCustom() {
return enterpriseMapper.listCustom();
}
}

View File

@ -55,6 +55,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="listSources" resultType="com.muyu.goods.domain.Sources">
select * from sources
</select>
<select id="listCustom" resultType="com.muyu.goods.domain.Custom">
select *
from custom
</select>
<select id="oneName" resultType="java.lang.Integer">
select count(enterprise_name) from enterprise where enterprise_name = #{enterpriseName}
</select>
<select id="onePhone" resultType="java.lang.Integer">
select count(contact_phone) from enterprise where contact_phone = #{contactPhone}
</select>
<select id="oneEmail" resultType="java.lang.Integer">
select count(email) from enterprise where email = #{email}
</select>
<insert id="insertEnterprise" parameterType="com.muyu.goods.domain.Enterprise" useGeneratedKeys="true" keyProperty="id">

View File

@ -95,6 +95,13 @@
<scope>compile</scope>
</dependency>
<!-- rabbitmq-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
</dependencies>
<build>

View File

@ -31,7 +31,7 @@ public class DruidConfig {
*
* @return
*/
private List<DataSourceInfo> getDataSourceInfoList(){
public List<DataSourceInfo> getDataSourceInfoList(){
List<Sources> listResult = remoteSourcesService.listSources().getData();
System.out.println(listResult);
List<String> databaseNameList = new ArrayList<>();
@ -79,11 +79,11 @@ public class DruidConfig {
@Primary
public DynamicDataSource dynamicDataSource() {
//获取列表 获取多数据源信息
Map<Object, Object> dataSourceMap = new HashMap<>();
getDataSourceInfoList().forEach(dataSourceInfo -> {
dataSourceMap.put(dataSourceInfo.getIp(), createDataSourceConnection(dataSourceInfo));
});
System.out.println(getDataSourceInfoList());
// System.out.println(dataSourceMap);
//设置动态数据源
DynamicDataSource dynamicDataSource = new DynamicDataSource();
@ -92,6 +92,5 @@ public class DruidConfig {
//将数据源信息备份在defineTargetDataSources中
dynamicDataSource.setDefineTargetDataSources(dataSourceMap);
return dynamicDataSource;
}
}

View File

@ -0,0 +1,30 @@
package com.muyu.cloud.mq;
import com.muyu.cloud.controller.CloudController;
import com.muyu.cloud.datasource.config.DruidConfig;
import com.muyu.cloud.datasource.config.DynamicDataSource;
import com.muyu.cloud.datasource.config.contents.DataSourceInfo;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
@Log4j2
public class Consumer {
@Autowired
private DruidConfig druidConfig;
@Autowired
private CloudController controller;
@RabbitListener(queuesToDeclare = {@Queue("datasource")})
public void dataSource(String ip){
System.out.println(ip);
DynamicDataSource dynamicDataSource = druidConfig.dynamicDataSource();
log.info("初始化:{}",dynamicDataSource);
// druidConfig.getDataSourceInfoList();
}
}