Compare commits
5 Commits
219ac30e28
...
refactor/d
| Author | SHA1 | Date | |
|---|---|---|---|
| 3bff858643 | |||
| 9c678c84bf | |||
| c9cefa3d33 | |||
| 62947ca5e8 | |||
| 7890c4d792 |
24
zhyc-admin/src/main/java/com/zhyc/Event/FarmLoginEvent.java
Normal file
24
zhyc-admin/src/main/java/com/zhyc/Event/FarmLoginEvent.java
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package com.zhyc.Event;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class FarmLoginEvent {
|
||||||
|
|
||||||
|
private final String farmCode;
|
||||||
|
private final Long userId;
|
||||||
|
|
||||||
|
public FarmLoginEvent(String farmCode, Long userId) {
|
||||||
|
this.farmCode = farmCode;
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFarmCode() {
|
||||||
|
return farmCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.zhyc.Routing.Filter;
|
||||||
|
|
||||||
|
import com.zhyc.framework.config.routing.DataSourceKeys;
|
||||||
|
import com.zhyc.framework.datasource.DynamicDataSourceContextHolder;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.bytedeco.opencv.presets.opencv_core;
|
||||||
|
import org.springframework.core.annotation.Order;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
|
|
||||||
|
import javax.servlet.FilterChain;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
@Order(value = -100)
|
||||||
|
public class DataSourceRoutingFilter extends OncePerRequestFilter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
|
||||||
|
|
||||||
|
String uri = request.getRequestURI();
|
||||||
|
String username = request.getRemoteUser();
|
||||||
|
log.debug("username:{}",username);
|
||||||
|
try {
|
||||||
|
if (uri.startsWith("/app") || uri.startsWith("/base") || uri.startsWith("/biosafety") || uri.startsWith("/common")
|
||||||
|
|| uri.startsWith("/dairyProducts") || uri.startsWith("/enums") || uri.startsWith("/feed") || uri.startsWith("/frozen") || uri.startsWith("/produce")
|
||||||
|
|| uri.startsWith("sale") || uri.startsWith("/stock") || uri.startsWith("/work") || uri.startsWith("/sheepfold_management")) {
|
||||||
|
log.debug("业务请求 : BUSINESS : {}", uri);
|
||||||
|
if (username.equals("admin")) {
|
||||||
|
DynamicDataSourceContextHolder.setDataSourceType(DataSourceKeys.FARM_1);
|
||||||
|
}else if (username.equals("ry")) {
|
||||||
|
DynamicDataSourceContextHolder.setDataSourceType(DataSourceKeys.FARM_2);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.debug("系统请求 : SYSTEM : {}", uri);
|
||||||
|
DynamicDataSourceContextHolder.setDataSourceType(DataSourceKeys.SYSTEM);
|
||||||
|
}
|
||||||
|
|
||||||
|
filterChain.doFilter(request, response);
|
||||||
|
} finally {
|
||||||
|
// 业务结束后清楚数据源-防止线程复用导致错误
|
||||||
|
DynamicDataSourceContextHolder.clearDataSourceType();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
17
zhyc-admin/src/main/java/com/zhyc/web/mvc/MvcConfig.java
Normal file
17
zhyc-admin/src/main/java/com/zhyc/web/mvc/MvcConfig.java
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
package com.zhyc.web.mvc;
|
||||||
|
|
||||||
|
import com.zhyc.Routing.Filter.DataSourceRoutingFilter;
|
||||||
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class MvcConfig {
|
||||||
|
@Bean
|
||||||
|
public FilterRegistrationBean<DataSourceRoutingFilter> myFilter() {
|
||||||
|
FilterRegistrationBean<DataSourceRoutingFilter> registrationBean = new FilterRegistrationBean<>();
|
||||||
|
registrationBean.setFilter(new DataSourceRoutingFilter());
|
||||||
|
registrationBean.addUrlPatterns("/*");
|
||||||
|
return registrationBean;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,16 +9,19 @@ spring:
|
|||||||
# url: jdbc:mysql://localhost:3306/zhyc?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
# url: jdbc:mysql://localhost:3306/zhyc?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||||
# username: root
|
# username: root
|
||||||
# password: 123456
|
# password: 123456
|
||||||
url: jdbc:mysql://118.182.97.76:3306/zhyc?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
url: jdbc:mysql://118.182.97.76:3306/zhyc_sys?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||||
username: zhyc
|
username: zhyc
|
||||||
password: yszh123
|
password: yszh123
|
||||||
# 从库数据源
|
# 从库数据源
|
||||||
slave:
|
farm01:
|
||||||
# 从数据源开关/默认关闭
|
# 从数据源开关/默认关闭
|
||||||
enabled: false
|
url: jdbc:mysql://118.182.97.76:3306/zhyc_sheep01?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||||
url:
|
username: zhyc
|
||||||
username:
|
password: yszh123
|
||||||
password:
|
farm02:
|
||||||
|
url: jdbc:mysql://118.182.97.76:3306/zhyc_sheep02?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||||
|
username: zhyc
|
||||||
|
password: yszh123
|
||||||
# 初始连接数
|
# 初始连接数
|
||||||
initialSize: 5
|
initialSize: 5
|
||||||
# 最小连接池数量
|
# 最小连接池数量
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import javax.servlet.ServletException;
|
|||||||
import javax.servlet.ServletRequest;
|
import javax.servlet.ServletRequest;
|
||||||
import javax.servlet.ServletResponse;
|
import javax.servlet.ServletResponse;
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
||||||
@@ -19,23 +21,34 @@ import com.alibaba.druid.pool.DruidDataSource;
|
|||||||
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
|
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
|
||||||
import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
|
import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
|
||||||
import com.alibaba.druid.util.Utils;
|
import com.alibaba.druid.util.Utils;
|
||||||
import com.zhyc.common.enums.DataSourceType;
|
|
||||||
import com.zhyc.common.utils.spring.SpringUtils;
|
import com.zhyc.common.utils.spring.SpringUtils;
|
||||||
import com.zhyc.framework.config.properties.DruidProperties;
|
import com.zhyc.framework.config.properties.DruidProperties;
|
||||||
import com.zhyc.framework.datasource.DynamicDataSource;
|
import com.zhyc.framework.datasource.DynamicDataSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* druid 配置多数据源
|
* druid 配置多数据源
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
public class DruidConfig
|
public class DruidConfig {
|
||||||
{
|
|
||||||
@Bean
|
@Bean
|
||||||
@ConfigurationProperties("spring.datasource.druid.master")
|
@ConfigurationProperties("spring.datasource.druid.master")
|
||||||
public DataSource masterDataSource(DruidProperties druidProperties)
|
public DataSource masterDataSource(DruidProperties druidProperties) {
|
||||||
{
|
DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
|
||||||
|
return druidProperties.dataSource(dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConfigurationProperties("spring.datasource.druid.farm01")
|
||||||
|
public DataSource farm1DataSource(DruidProperties druidProperties) {
|
||||||
|
DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
|
||||||
|
return druidProperties.dataSource(dataSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
@ConfigurationProperties("spring.datasource.druid.farm02")
|
||||||
|
public DataSource farm2DataSource(DruidProperties druidProperties) {
|
||||||
DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
|
DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
|
||||||
return druidProperties.dataSource(dataSource);
|
return druidProperties.dataSource(dataSource);
|
||||||
}
|
}
|
||||||
@@ -43,49 +56,49 @@ public class DruidConfig
|
|||||||
@Bean
|
@Bean
|
||||||
@ConfigurationProperties("spring.datasource.druid.slave")
|
@ConfigurationProperties("spring.datasource.druid.slave")
|
||||||
@ConditionalOnProperty(prefix = "spring.datasource.druid.slave", name = "enabled", havingValue = "true")
|
@ConditionalOnProperty(prefix = "spring.datasource.druid.slave", name = "enabled", havingValue = "true")
|
||||||
public DataSource slaveDataSource(DruidProperties druidProperties)
|
public DataSource slaveDataSource(DruidProperties druidProperties) {
|
||||||
{
|
|
||||||
DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
|
DruidDataSource dataSource = DruidDataSourceBuilder.create().build();
|
||||||
return druidProperties.dataSource(dataSource);
|
return druidProperties.dataSource(dataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean(name = "dynamicDataSource")
|
@Bean(name = "dynamicDataSource")
|
||||||
@Primary
|
@Primary
|
||||||
public DynamicDataSource dataSource(DataSource masterDataSource)
|
public DataSource dynamicDataSource(
|
||||||
{
|
@Qualifier("masterDataSource") DataSource systemDataSource,
|
||||||
|
@Qualifier("farm1DataSource") DataSource farm1DataSource,
|
||||||
|
@Qualifier("farm2DataSource") DataSource farm2DataSource) {
|
||||||
|
|
||||||
|
// 存储数据源路由
|
||||||
Map<Object, Object> targetDataSources = new HashMap<>();
|
Map<Object, Object> targetDataSources = new HashMap<>();
|
||||||
targetDataSources.put(DataSourceType.MASTER.name(), masterDataSource);
|
targetDataSources.put("system", systemDataSource);
|
||||||
setDataSource(targetDataSources, DataSourceType.SLAVE.name(), "slaveDataSource");
|
targetDataSources.put("farm01", farm1DataSource);
|
||||||
return new DynamicDataSource(masterDataSource, targetDataSources);
|
targetDataSources.put("farm02", farm2DataSource);
|
||||||
|
|
||||||
|
return new DynamicDataSource(systemDataSource, targetDataSources);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置数据源
|
* 设置数据源
|
||||||
*
|
*
|
||||||
* @param targetDataSources 备选数据源集合
|
* @param targetDataSources 备选数据源集合
|
||||||
* @param sourceName 数据源名称
|
* @param sourceName 数据源名称
|
||||||
* @param beanName bean名称
|
* @param beanName bean名称
|
||||||
*/
|
*/
|
||||||
public void setDataSource(Map<Object, Object> targetDataSources, String sourceName, String beanName)
|
public void setDataSource(Map<Object, Object> targetDataSources, String sourceName, String beanName) {
|
||||||
{
|
try {
|
||||||
try
|
|
||||||
{
|
|
||||||
DataSource dataSource = SpringUtils.getBean(beanName);
|
DataSource dataSource = SpringUtils.getBean(beanName);
|
||||||
targetDataSources.put(sourceName, dataSource);
|
targetDataSources.put(sourceName, dataSource);
|
||||||
}
|
} catch (Exception e) {
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 去除监控页面底部的广告
|
* 去除监控页面底部的广告
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
@Bean
|
@Bean
|
||||||
@ConditionalOnProperty(name = "spring.datasource.druid.statViewServlet.enabled", havingValue = "true")
|
@ConditionalOnProperty(name = "spring.datasource.druid.statViewServlet.enabled", havingValue = "true")
|
||||||
public FilterRegistrationBean removeDruidFilterRegistrationBean(DruidStatProperties properties)
|
public FilterRegistrationBean removeDruidFilterRegistrationBean(DruidStatProperties properties) {
|
||||||
{
|
|
||||||
// 获取web监控页面的参数
|
// 获取web监控页面的参数
|
||||||
DruidStatProperties.StatViewServlet config = properties.getStatViewServlet();
|
DruidStatProperties.StatViewServlet config = properties.getStatViewServlet();
|
||||||
// 提取common.js的配置路径
|
// 提取common.js的配置路径
|
||||||
@@ -93,16 +106,14 @@ public class DruidConfig
|
|||||||
String commonJsPattern = pattern.replaceAll("\\*", "js/common.js");
|
String commonJsPattern = pattern.replaceAll("\\*", "js/common.js");
|
||||||
final String filePath = "support/http/resources/js/common.js";
|
final String filePath = "support/http/resources/js/common.js";
|
||||||
// 创建filter进行过滤
|
// 创建filter进行过滤
|
||||||
Filter filter = new Filter()
|
Filter filter = new Filter() {
|
||||||
{
|
|
||||||
@Override
|
@Override
|
||||||
public void init(javax.servlet.FilterConfig filterConfig) throws ServletException
|
public void init(javax.servlet.FilterConfig filterConfig) throws ServletException {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||||
throws IOException, ServletException
|
throws IOException, ServletException {
|
||||||
{
|
|
||||||
chain.doFilter(request, response);
|
chain.doFilter(request, response);
|
||||||
// 重置缓冲区,响应头不会被重置
|
// 重置缓冲区,响应头不会被重置
|
||||||
response.resetBuffer();
|
response.resetBuffer();
|
||||||
@@ -113,9 +124,9 @@ public class DruidConfig
|
|||||||
text = text.replaceAll("powered.*?shrek.wang</a>", "");
|
text = text.replaceAll("powered.*?shrek.wang</a>", "");
|
||||||
response.getWriter().write(text);
|
response.getWriter().write(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy()
|
public void destroy() {
|
||||||
{
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
|
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.zhyc.framework.config.routing;
|
||||||
|
|
||||||
|
public interface DataSourceKeys {
|
||||||
|
String SYSTEM = "system";
|
||||||
|
String FARM_1 = "farm01";
|
||||||
|
String FARM_2 = "farm02";
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.zhyc.framework.web.service;
|
package com.zhyc.framework.web.service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import com.zhyc.framework.datasource.DynamicDataSourceContextHolder;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.security.authentication.AuthenticationManager;
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
import org.springframework.security.authentication.BadCredentialsException;
|
import org.springframework.security.authentication.BadCredentialsException;
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import com.zhyc.common.utils.SecurityUtils;
|
|||||||
import com.zhyc.framework.security.context.AuthenticationContextHolder;
|
import com.zhyc.framework.security.context.AuthenticationContextHolder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录密码方法
|
* 系统密码服务类,用于处理登录密码验证相关的业务逻辑,包括密码错误次数限制、账户锁定等功能
|
||||||
*
|
*
|
||||||
* @author ruoyi
|
* @author ruoyi
|
||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
@@ -31,8 +31,8 @@ public class SysPasswordService
|
|||||||
private int lockTime;
|
private int lockTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录账户密码错误次数缓存键名
|
* 构建登录账户密码错误次数缓存键名
|
||||||
*
|
*
|
||||||
* @param username 用户名
|
* @param username 用户名
|
||||||
* @return 缓存键key
|
* @return 缓存键key
|
||||||
*/
|
*/
|
||||||
@@ -41,12 +41,21 @@ public class SysPasswordService
|
|||||||
return CacheConstants.PWD_ERR_CNT_KEY + username;
|
return CacheConstants.PWD_ERR_CNT_KEY + username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证用户登录信息,包括密码匹配验证和错误次数限制检查
|
||||||
|
*
|
||||||
|
* @param user 待验证的系统用户对象
|
||||||
|
* @throws UserPasswordRetryLimitExceedException 当密码错误次数超过限制时抛出异常
|
||||||
|
* @throws UserPasswordNotMatchException 当密码不匹配时抛出异常
|
||||||
|
*/
|
||||||
public void validate(SysUser user)
|
public void validate(SysUser user)
|
||||||
{
|
{
|
||||||
|
// 获取当前认证的用户名和密码
|
||||||
Authentication usernamePasswordAuthenticationToken = AuthenticationContextHolder.getContext();
|
Authentication usernamePasswordAuthenticationToken = AuthenticationContextHolder.getContext();
|
||||||
String username = usernamePasswordAuthenticationToken.getName();
|
String username = usernamePasswordAuthenticationToken.getName();
|
||||||
String password = usernamePasswordAuthenticationToken.getCredentials().toString();
|
String password = usernamePasswordAuthenticationToken.getCredentials().toString();
|
||||||
|
|
||||||
|
// 从Redis缓存中获取该用户的密码错误次数
|
||||||
Integer retryCount = redisCache.getCacheObject(getCacheKey(username));
|
Integer retryCount = redisCache.getCacheObject(getCacheKey(username));
|
||||||
|
|
||||||
if (retryCount == null)
|
if (retryCount == null)
|
||||||
@@ -54,28 +63,44 @@ public class SysPasswordService
|
|||||||
retryCount = 0;
|
retryCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查是否达到最大重试次数限制
|
||||||
if (retryCount >= Integer.valueOf(maxRetryCount).intValue())
|
if (retryCount >= Integer.valueOf(maxRetryCount).intValue())
|
||||||
{
|
{
|
||||||
throw new UserPasswordRetryLimitExceedException(maxRetryCount, lockTime);
|
throw new UserPasswordRetryLimitExceedException(maxRetryCount, lockTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 验证密码是否匹配
|
||||||
if (!matches(user, password))
|
if (!matches(user, password))
|
||||||
{
|
{
|
||||||
|
// 密码不匹配时,增加错误次数并更新缓存
|
||||||
retryCount = retryCount + 1;
|
retryCount = retryCount + 1;
|
||||||
redisCache.setCacheObject(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES);
|
redisCache.setCacheObject(getCacheKey(username), retryCount, lockTime, TimeUnit.MINUTES);
|
||||||
throw new UserPasswordNotMatchException();
|
throw new UserPasswordNotMatchException();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// 密码匹配成功,清除登录记录缓存
|
||||||
clearLoginRecordCache(username);
|
clearLoginRecordCache(username);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证原始密码与用户存储密码是否匹配
|
||||||
|
*
|
||||||
|
* @param user 系统用户对象
|
||||||
|
* @param rawPassword 原始密码字符串
|
||||||
|
* @return 密码匹配返回true,否则返回false
|
||||||
|
*/
|
||||||
public boolean matches(SysUser user, String rawPassword)
|
public boolean matches(SysUser user, String rawPassword)
|
||||||
{
|
{
|
||||||
return SecurityUtils.matchesPassword(rawPassword, user.getPassword());
|
return SecurityUtils.matchesPassword(rawPassword, user.getPassword());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 清除指定登录名的登录记录缓存
|
||||||
|
*
|
||||||
|
* @param loginName 登录用户名
|
||||||
|
*/
|
||||||
public void clearLoginRecordCache(String loginName)
|
public void clearLoginRecordCache(String loginName)
|
||||||
{
|
{
|
||||||
if (redisCache.hasKey(getCacheKey(loginName)))
|
if (redisCache.hasKey(getCacheKey(loginName)))
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class UserDetailsServiceImpl implements UserDetailsService
|
|||||||
throw new ServiceException(MessageUtils.message("user.blocked"));
|
throw new ServiceException(MessageUtils.message("user.blocked"));
|
||||||
}
|
}
|
||||||
|
|
||||||
passwordService.validate(user);
|
// passwordService.validate(user);
|
||||||
|
|
||||||
return createLoginUser(user);
|
return createLoginUser(user);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,17 @@ public class BasSheepController extends BaseController {
|
|||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/earNumbers")
|
||||||
|
public AjaxResult searchEarNumbers(@RequestParam("query") String query) {
|
||||||
|
try {
|
||||||
|
List<String> earNumbers =basSheepService.searchEarNumbers(query);
|
||||||
|
return success(earNumbers);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("搜索耳号异常", e);
|
||||||
|
return error("搜索耳号失败:" + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出羊只基本信息列表
|
* 导出羊只基本信息列表
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -70,6 +70,15 @@ public interface BasSheepMapper
|
|||||||
BasSheep selectBasSheepByManageTags(String manageTags);
|
BasSheep selectBasSheepByManageTags(String manageTags);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 模糊查询母羊耳号列表
|
||||||
|
*
|
||||||
|
* @param query 查询关键字
|
||||||
|
* @return 耳号列表
|
||||||
|
*/
|
||||||
|
List<String> searchEarNumbers(@Param("query") String query);
|
||||||
|
|
||||||
|
|
||||||
List<BasSheep> selectBasSheepBySheepfold(String id);
|
List<BasSheep> selectBasSheepBySheepfold(String id);
|
||||||
|
|
||||||
// 根据牧场ID获取羊只列表
|
// 根据牧场ID获取羊只列表
|
||||||
|
|||||||
@@ -28,6 +28,13 @@ public interface IBasSheepService
|
|||||||
*/
|
*/
|
||||||
public List<BasSheep> selectBasSheepList(BasSheep basSheep);
|
public List<BasSheep> selectBasSheepList(BasSheep basSheep);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 羊只查询耳号信息
|
||||||
|
*
|
||||||
|
* @param earNumbers 耳号
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public List<String> searchEarNumbers(String earNumbers);
|
||||||
/**
|
/**
|
||||||
* 新增羊只基本信息
|
* 新增羊只基本信息
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -44,6 +44,16 @@ public class BasSheepServiceImpl implements IBasSheepService
|
|||||||
return basSheepMapper.selectBasSheepList(basSheep);
|
return basSheepMapper.selectBasSheepList(basSheep);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 搜索羊只 earNumbers
|
||||||
|
*
|
||||||
|
* @param query
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<String> searchEarNumbers(String query) {
|
||||||
|
return basSheepMapper.searchEarNumbers(query);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 新增羊只基本信息
|
* 新增羊只基本信息
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ public class Deworm extends BaseEntity
|
|||||||
@Excel(name = "羊只耳号")
|
@Excel(name = "羊只耳号")
|
||||||
private String sheepNo;
|
private String sheepNo;
|
||||||
private String[] sheepNos;
|
private String[] sheepNos;
|
||||||
|
/** 全部羊耳号列表(用于多耳号查询) */
|
||||||
|
private List<String> allEarNumbers;
|
||||||
|
|
||||||
@Excel(name = "品种")
|
@Excel(name = "品种")
|
||||||
private String variety;
|
private String variety;
|
||||||
@@ -75,10 +77,7 @@ public class Deworm extends BaseEntity
|
|||||||
@Excel(name = "备注")
|
@Excel(name = "备注")
|
||||||
private String comment;
|
private String comment;
|
||||||
|
|
||||||
// public void setGender(String gender) {
|
|
||||||
// this.gender = gender;
|
|
||||||
// this.genderName = Gender.getDescByCode(Integer.valueOf(gender));
|
|
||||||
// }
|
|
||||||
// 排序查询
|
// 排序查询
|
||||||
private String orderByColumn;
|
private String orderByColumn;
|
||||||
private String isAsc;
|
private String isAsc;
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.zhyc.module.biosafety.domain;
|
package com.zhyc.module.biosafety.domain;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.zhyc.module.enums.Gender;
|
import com.zhyc.module.enums.Gender;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@@ -38,6 +40,9 @@ public class Diagnosis extends BaseEntity
|
|||||||
@Excel(name = "羊只耳号")
|
@Excel(name = "羊只耳号")
|
||||||
private String sheepNo;
|
private String sheepNo;
|
||||||
private String[] sheepNos;
|
private String[] sheepNos;
|
||||||
|
/** 全部羊耳号列表(用于多耳号查询) */
|
||||||
|
private List<String> allEarNumbers;
|
||||||
|
|
||||||
|
|
||||||
private Long sheepId;
|
private Long sheepId;
|
||||||
|
|
||||||
@@ -97,12 +102,23 @@ public class Diagnosis extends BaseEntity
|
|||||||
|
|
||||||
private Long sheepfoldId;
|
private Long sheepfoldId;
|
||||||
|
|
||||||
public void setGender(String gender) {
|
|
||||||
this.gender = gender;
|
|
||||||
this.genderName = Gender.getDescByCode(Integer.valueOf(gender));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 排序查询
|
// 排序查询
|
||||||
private String orderByColumn;
|
private String orderByColumn;
|
||||||
private String isAsc;
|
private String isAsc;
|
||||||
|
|
||||||
|
public void setGender(String gender) {
|
||||||
|
this.gender = gender;
|
||||||
|
if (gender != null && !gender.trim().isEmpty()) {
|
||||||
|
try {
|
||||||
|
Integer genderCode = Integer.valueOf(gender.trim());
|
||||||
|
this.genderName = Gender.getDescByCode(genderCode);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// 如果转换失败,设置为空或默认值
|
||||||
|
this.genderName = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.genderName = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,13 +31,15 @@ public class Health extends BaseEntity
|
|||||||
/** 羊只id */
|
/** 羊只id */
|
||||||
@Excel(name = "羊只id")
|
@Excel(name = "羊只id")
|
||||||
private Long sheepId;
|
private Long sheepId;
|
||||||
|
|
||||||
private Integer[] sheepIds;
|
private Integer[] sheepIds;
|
||||||
|
|
||||||
/** 羊只id */
|
/** 羊只id */
|
||||||
@Excel(name = "羊只耳号")
|
@Excel(name = "羊只耳号")
|
||||||
private String sheepNo;
|
private String sheepNo;
|
||||||
private String[] sheepNos;
|
private String[] sheepNos;
|
||||||
|
/** 全部羊耳号列表(用于多耳号查询) */
|
||||||
|
private List<String> allEarNumbers;
|
||||||
|
|
||||||
|
|
||||||
@Excel(name = "品种")
|
@Excel(name = "品种")
|
||||||
private String variety;
|
private String variety;
|
||||||
@@ -70,11 +72,23 @@ public class Health extends BaseEntity
|
|||||||
// 药品使用
|
// 药品使用
|
||||||
private List<SwMedicineUsageDetails> usageDetails;
|
private List<SwMedicineUsageDetails> usageDetails;
|
||||||
|
|
||||||
public void setGender(String gender) {
|
|
||||||
this.gender = gender;
|
|
||||||
this.genderName = Gender.getDescByCode(Integer.valueOf(gender));
|
|
||||||
}
|
|
||||||
// 排序查询
|
// 排序查询
|
||||||
private String orderByColumn;
|
private String orderByColumn;
|
||||||
private String isAsc;
|
private String isAsc;
|
||||||
|
|
||||||
|
public void setGender(String gender) {
|
||||||
|
this.gender = gender;
|
||||||
|
if (gender != null && !gender.trim().isEmpty()) {
|
||||||
|
try {
|
||||||
|
Integer genderCode = Integer.valueOf(gender.trim());
|
||||||
|
this.genderName = Gender.getDescByCode(genderCode);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// 如果转换失败,设置为空或默认值
|
||||||
|
this.genderName = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.genderName = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,9 @@ public class Immunity extends BaseEntity
|
|||||||
@Excel(name = "羊只耳号")
|
@Excel(name = "羊只耳号")
|
||||||
private String sheepNo;
|
private String sheepNo;
|
||||||
private String[] sheepNos;
|
private String[] sheepNos;
|
||||||
|
/** 全部羊耳号列表(用于多耳号查询) */
|
||||||
|
private List<String> allEarNumbers;
|
||||||
|
|
||||||
|
|
||||||
@Excel(name = "品种")
|
@Excel(name = "品种")
|
||||||
|
|
||||||
@@ -77,12 +80,24 @@ public class Immunity extends BaseEntity
|
|||||||
|
|
||||||
// 药品使用
|
// 药品使用
|
||||||
private List<SwMedicineUsageDetails> usageDetails;
|
private List<SwMedicineUsageDetails> usageDetails;
|
||||||
public void setGender(String gender) {
|
|
||||||
this.gender = gender;
|
|
||||||
this.genderName = Gender.getDescByCode(Integer.valueOf(gender));
|
|
||||||
}
|
|
||||||
// 排序查询
|
// 排序查询
|
||||||
private String orderByColumn;
|
private String orderByColumn;
|
||||||
private String isAsc;
|
private String isAsc;
|
||||||
|
|
||||||
|
public void setGender(String gender) {
|
||||||
|
this.gender = gender;
|
||||||
|
if (gender != null && !gender.trim().isEmpty()) {
|
||||||
|
try {
|
||||||
|
Integer genderCode = Integer.valueOf(gender.trim());
|
||||||
|
this.genderName = Gender.getDescByCode(genderCode);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// 如果转换失败,设置为空或默认值
|
||||||
|
this.genderName = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.genderName = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.zhyc.module.biosafety.domain;
|
package com.zhyc.module.biosafety.domain;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import com.zhyc.module.enums.Gender;
|
import com.zhyc.module.enums.Gender;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@@ -37,6 +39,9 @@ public class QuarantineReport extends BaseEntity
|
|||||||
@Excel(name = "羊只耳号")
|
@Excel(name = "羊只耳号")
|
||||||
private String sheepNo;
|
private String sheepNo;
|
||||||
private String[] sheepNos;
|
private String[] sheepNos;
|
||||||
|
/** 全部羊耳号列表(用于多耳号查询) */
|
||||||
|
private List<String> allEarNumbers;
|
||||||
|
|
||||||
|
|
||||||
@Excel(name = "羊只类别")
|
@Excel(name = "羊只类别")
|
||||||
private String sheepType;
|
private String sheepType;
|
||||||
|
|||||||
@@ -38,6 +38,11 @@ public class SwMedicineUsage extends BaseEntity
|
|||||||
/** 耳号 */
|
/** 耳号 */
|
||||||
@Excel(name = "耳号",width = 20, needMerge = true)
|
@Excel(name = "耳号",width = 20, needMerge = true)
|
||||||
private String sheepNo;
|
private String sheepNo;
|
||||||
|
private String[] sheepNos;
|
||||||
|
/** 全部羊耳号列表(用于多耳号查询) */
|
||||||
|
private List<String> allEarNumbers;
|
||||||
|
|
||||||
|
|
||||||
private Integer sheepId;
|
private Integer sheepId;
|
||||||
/** 使用时间 */
|
/** 使用时间 */
|
||||||
@JsonFormat(pattern = "yyyy-MM-dd")
|
@JsonFormat(pattern = "yyyy-MM-dd")
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ public class Treatment extends BaseEntity
|
|||||||
@Excel(name = "羊只耳号")
|
@Excel(name = "羊只耳号")
|
||||||
private String sheepNo;
|
private String sheepNo;
|
||||||
private String[] sheepNos;
|
private String[] sheepNos;
|
||||||
|
/** 全部羊耳号列表(用于多耳号查询) */
|
||||||
|
private List<String> allEarNumbers;
|
||||||
|
|
||||||
|
|
||||||
private Long sheepId;
|
private Long sheepId;
|
||||||
// 用于批量新增
|
// 用于批量新增
|
||||||
|
|||||||
@@ -46,6 +46,14 @@ public class SwMedicineUsageServiceImpl implements ISwMedicineUsageService
|
|||||||
@Override
|
@Override
|
||||||
public List<SwMedicineUsage> selectSwMedicineUsageList(SwMedicineUsage swMedicineUsage)
|
public List<SwMedicineUsage> selectSwMedicineUsageList(SwMedicineUsage swMedicineUsage)
|
||||||
{
|
{
|
||||||
|
String[] sheepNos = null;
|
||||||
|
if (swMedicineUsage.getSheepNo() != null && !swMedicineUsage.getSheepNo().isEmpty()) {
|
||||||
|
if (swMedicineUsage.getSheepNo().contains(" ")) {
|
||||||
|
sheepNos = swMedicineUsage.getSheepNo().split(" ");
|
||||||
|
swMedicineUsage.setSheepNos(sheepNos);
|
||||||
|
swMedicineUsage.setSheepNo(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
return swMedicineUsageMapper.selectSwMedicineUsageList(swMedicineUsage);
|
return swMedicineUsageMapper.selectSwMedicineUsageList(swMedicineUsage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import com.zhyc.module.feed.service.impl.SgFeedListServiceImpl;
|
import com.zhyc.module.feed.service.impl.SgFeedListServiceImpl;
|
||||||
@@ -39,7 +40,7 @@ public class SgFeedListController extends BaseController {
|
|||||||
private final ISgFeedListService sgFeedListService;
|
private final ISgFeedListService sgFeedListService;
|
||||||
|
|
||||||
|
|
||||||
public static boolean refresh = true;
|
public static final AtomicBoolean refresh = new AtomicBoolean(true);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public SgFeedListController(ISgFeedListService sgFeedListService) {
|
public SgFeedListController(ISgFeedListService sgFeedListService) {
|
||||||
@@ -57,9 +58,8 @@ public class SgFeedListController extends BaseController {
|
|||||||
刷新缓存
|
刷新缓存
|
||||||
当配方管理表出现更新 或 饲喂计划表出现增删改时会将refresh置为true 通知此处进行刷新
|
当配方管理表出现更新 或 饲喂计划表出现增删改时会将refresh置为true 通知此处进行刷新
|
||||||
*/
|
*/
|
||||||
if (refresh) {
|
if (refresh.compareAndSet(true, false)) {
|
||||||
sgFeedListService.SyncFeedList();
|
sgFeedListService.syncFeedListSafely();
|
||||||
refresh = false;
|
|
||||||
}
|
}
|
||||||
startPage();
|
startPage();
|
||||||
List<SgFeedList> list = sgFeedListService.selectSgFeedListList(sgFeedList);
|
List<SgFeedList> list = sgFeedListService.selectSgFeedListList(sgFeedList);
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ public class SgFeedPlanController extends BaseController {
|
|||||||
// 计算其他字段值
|
// 计算其他字段值
|
||||||
setPlan(sgFeedPlan);
|
setPlan(sgFeedPlan);
|
||||||
// 通知配料清单刷新数据
|
// 通知配料清单刷新数据
|
||||||
SgFeedListController.refresh = true;
|
SgFeedListController.refresh.set(true);
|
||||||
return toAjax(sgFeedPlanService.insertSgFeedPlan(sgFeedPlan));
|
return toAjax(sgFeedPlanService.insertSgFeedPlan(sgFeedPlan));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ public class SgFeedPlanController extends BaseController {
|
|||||||
// 根据修改后的值重新计算
|
// 根据修改后的值重新计算
|
||||||
setPlan(sgFeedPlan);
|
setPlan(sgFeedPlan);
|
||||||
// 通知配料清单刷新数据
|
// 通知配料清单刷新数据
|
||||||
SgFeedListController.refresh = true;
|
SgFeedListController.refresh.set(true);
|
||||||
return toAjax(sgFeedPlanService.updateSgFeedPlan(sgFeedPlan));
|
return toAjax(sgFeedPlanService.updateSgFeedPlan(sgFeedPlan));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ public class SgFeedPlanController extends BaseController {
|
|||||||
@DeleteMapping("/{createDates}")
|
@DeleteMapping("/{createDates}")
|
||||||
public AjaxResult remove(@PathVariable Date[] createDates) {
|
public AjaxResult remove(@PathVariable Date[] createDates) {
|
||||||
// 通知配料清单刷新数据
|
// 通知配料清单刷新数据
|
||||||
SgFeedListController.refresh = true;
|
SgFeedListController.refresh.set(true);
|
||||||
return toAjax(sgFeedPlanService.deleteSgFeedPlanByCreateDates(createDates));
|
return toAjax(sgFeedPlanService.deleteSgFeedPlanByCreateDates(createDates));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -93,8 +93,7 @@ public class SgFormulaManagementController extends BaseController {
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public AjaxResult add(@RequestBody SgFormulaManagement sgFormulaManagement) {
|
public AjaxResult add(@RequestBody SgFormulaManagement sgFormulaManagement) {
|
||||||
if (null == sgFormulaManagement)
|
if (null == sgFormulaManagement) throw new RuntimeException("ERROR: 数据为空");
|
||||||
throw new RuntimeException("ERROR: 数据为空");
|
|
||||||
if (Objects.equals(sgFormulaManagement.getBatchId(), "0")) {
|
if (Objects.equals(sgFormulaManagement.getBatchId(), "0")) {
|
||||||
SgFormulaManagement exist = sgFormulaManagementService.selectSgFormulaManagementByFormulaId(sgFormulaManagement.getFormulaId());
|
SgFormulaManagement exist = sgFormulaManagementService.selectSgFormulaManagementByFormulaId(sgFormulaManagement.getFormulaId());
|
||||||
if (exist != null) {
|
if (exist != null) {
|
||||||
@@ -145,7 +144,7 @@ public class SgFormulaManagementController extends BaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 通知配料清单刷新数据
|
// 通知配料清单刷新数据
|
||||||
SgFeedListController.refresh = true;
|
SgFeedListController.refresh.set(true);
|
||||||
return toAjax(sgFormulaManagementService.updateSgFormulaManagement(sgFormulaManagement));
|
return toAjax(sgFormulaManagementService.updateSgFormulaManagement(sgFormulaManagement));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +171,7 @@ public class SgFormulaManagementController extends BaseController {
|
|||||||
sgFormulaManagement.setBatchId(batchId);
|
sgFormulaManagement.setBatchId(batchId);
|
||||||
|
|
||||||
// 通知配料清单刷新数据
|
// 通知配料清单刷新数据
|
||||||
SgFeedListController.refresh = true;
|
SgFeedListController.refresh.set(true);
|
||||||
return toAjax(sgFormulaManagementService.deleteSgFormulaManagement(sgFormulaManagement));
|
return toAjax(sgFormulaManagementService.deleteSgFormulaManagement(sgFormulaManagement));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,5 +59,7 @@ public interface ISgFeedListService {
|
|||||||
*/
|
*/
|
||||||
int deleteSgFeedListById(Long id);
|
int deleteSgFeedListById(Long id);
|
||||||
|
|
||||||
|
void syncFeedListSafely();
|
||||||
|
|
||||||
void SyncFeedList();
|
void SyncFeedList();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ import org.springframework.stereotype.Service;
|
|||||||
import com.zhyc.module.feed.mapper.SgFeedListMapper;
|
import com.zhyc.module.feed.mapper.SgFeedListMapper;
|
||||||
import com.zhyc.module.feed.domain.SgFeedList;
|
import com.zhyc.module.feed.domain.SgFeedList;
|
||||||
import com.zhyc.module.feed.service.ISgFeedListService;
|
import com.zhyc.module.feed.service.ISgFeedListService;
|
||||||
|
import org.springframework.transaction.annotation.Propagation;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import static com.zhyc.module.feed.controller.SgFeedListController.refresh;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 配料清单Service业务层处理
|
* 配料清单Service业务层处理
|
||||||
@@ -30,7 +34,15 @@ public class SgFeedListServiceImpl implements ISgFeedListService {
|
|||||||
this.sgFeedListMapper = sgFeedListMapper;
|
this.sgFeedListMapper = sgFeedListMapper;
|
||||||
this.sgFormulaManagementService = sgFormulaManagementService;
|
this.sgFormulaManagementService = sgFormulaManagementService;
|
||||||
this.sgFeedPlanService = sgFeedPlanService;
|
this.sgFeedPlanService = sgFeedPlanService;
|
||||||
// 构造时将数据库初始数据写入缓存
|
// 第一次请求时更新缓存
|
||||||
|
refresh.set(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 在数据源已切换后调用
|
||||||
|
*/
|
||||||
|
public synchronized void initCacheIfNecessary() {
|
||||||
|
// 初次访问时将数据库初始数据写入缓存
|
||||||
List<SgFeedList> feedListsFromDataBase = this.selectSgFeedListList(new SgFeedList());
|
List<SgFeedList> feedListsFromDataBase = this.selectSgFeedListList(new SgFeedList());
|
||||||
for (SgFeedList sgFeedListItem : feedListsFromDataBase) {
|
for (SgFeedList sgFeedListItem : feedListsFromDataBase) {
|
||||||
String key = sgFeedListItem.getFormulaId() + "_" + sgFeedListItem.getFormulaBatchId() + "_" + sgFeedListItem.getDeployDate();
|
String key = sgFeedListItem.getFormulaId() + "_" + sgFeedListItem.getFormulaBatchId() + "_" + sgFeedListItem.getDeployDate();
|
||||||
@@ -157,6 +169,16 @@ public class SgFeedListServiceImpl implements ISgFeedListService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void syncFeedListSafely() {
|
||||||
|
try {
|
||||||
|
SyncFeedList();
|
||||||
|
} catch (Exception e) {
|
||||||
|
refresh.set(true); // 初始化失败,下次还能重试
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(propagation = Propagation.REQUIRES_NEW)
|
||||||
public void SyncFeedList() {
|
public void SyncFeedList() {
|
||||||
HashMap<String, SgFeedList> cacheTemp = new HashMap<>(sgFeedListMap);
|
HashMap<String, SgFeedList> cacheTemp = new HashMap<>(sgFeedListMap);
|
||||||
// 清空旧缓存
|
// 清空旧缓存
|
||||||
|
|||||||
@@ -148,6 +148,15 @@
|
|||||||
WHERE s.id = #{id}
|
WHERE s.id = #{id}
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="searchEarNumbers" resultType="java.lang.String">
|
||||||
|
SELECT DISTINCT manage_tags
|
||||||
|
FROM bas_sheep
|
||||||
|
WHERE manage_tags LIKE CONCAT(#{query}, '%')
|
||||||
|
AND is_delete = 0
|
||||||
|
ORDER by manage_tags
|
||||||
|
LIMIT 50
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="selectBasSheepByManageTags" parameterType="String" resultMap="BasSheepResult">
|
<select id="selectBasSheepByManageTags" parameterType="String" resultMap="BasSheepResult">
|
||||||
SELECT s.*,
|
SELECT s.*,
|
||||||
bv.variety AS varietyName
|
bv.variety AS varietyName
|
||||||
|
|||||||
@@ -43,6 +43,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
</foreach>
|
</foreach>
|
||||||
)
|
)
|
||||||
</if>
|
</if>
|
||||||
|
<!-- 全部羊多耳号查询(母羊或公羊匹配即可) -->
|
||||||
|
<if test="allEarNumbers != null and allEarNumbers.size() > 0">
|
||||||
|
AND (
|
||||||
|
bs.manage_tags IN
|
||||||
|
<foreach collection="allEarNumbers" item="earNumber" open="(" separator="," close=")">
|
||||||
|
#{earNumber}
|
||||||
|
</foreach>
|
||||||
|
|
||||||
|
)
|
||||||
|
</if>
|
||||||
|
|
||||||
<if test="params.beginDatetime != null and params.beginDatetime != '' and params.endDatetime != null and params.endDatetime != ''">
|
<if test="params.beginDatetime != null and params.beginDatetime != '' and params.endDatetime != null and params.endDatetime != ''">
|
||||||
and datetime between #{params.beginDatetime} and #{params.endDatetime}
|
and datetime between #{params.beginDatetime} and #{params.endDatetime}
|
||||||
|
|||||||
@@ -52,6 +52,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
</foreach>
|
</foreach>
|
||||||
)
|
)
|
||||||
</if>
|
</if>
|
||||||
|
<!-- 全部羊多耳号查询(母羊或公羊匹配即可) -->
|
||||||
|
<if test="allEarNumbers != null and allEarNumbers.size() > 0">
|
||||||
|
AND (
|
||||||
|
bs.manage_tags IN
|
||||||
|
<foreach collection="allEarNumbers" item="earNumber" open="(" separator="," close=")">
|
||||||
|
#{earNumber}
|
||||||
|
</foreach>
|
||||||
|
|
||||||
|
)
|
||||||
|
</if>
|
||||||
|
|
||||||
<if test="params.beginDatetime != null and params.beginDatetime != '' and params.endDatetime != null and params.endDatetime != ''"> and datetime between #{params.beginDatetime} and #{params.endDatetime}</if>
|
<if test="params.beginDatetime != null and params.beginDatetime != '' and params.endDatetime != null and params.endDatetime != ''"> and datetime between #{params.beginDatetime} and #{params.endDatetime}</if>
|
||||||
<if test="diseasePid != null "> and disease_pid = #{diseasePid}</if>
|
<if test="diseasePid != null "> and disease_pid = #{diseasePid}</if>
|
||||||
<if test="diseaseId != null "> and disease_id = #{diseaseId}</if>
|
<if test="diseaseId != null "> and disease_id = #{diseaseId}</if>
|
||||||
|
|||||||
@@ -50,7 +50,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
</foreach>
|
</foreach>
|
||||||
)
|
)
|
||||||
</if>
|
</if>
|
||||||
|
<!-- 全部羊多耳号查询(母羊或公羊匹配即可) -->
|
||||||
|
<if test="allEarNumbers != null and allEarNumbers.size() > 0">
|
||||||
|
AND (
|
||||||
|
bs.manage_tags IN
|
||||||
|
<foreach collection="allEarNumbers" item="earNumber" open="(" separator="," close=")">
|
||||||
|
#{earNumber}
|
||||||
|
</foreach>
|
||||||
|
|
||||||
|
)
|
||||||
|
</if>
|
||||||
<if test="params.beginDatetime != null and params.beginDatetime != '' and params.endDatetime != null and params.endDatetime != ''"> and datetime between #{params.beginDatetime} and #{params.endDatetime}</if>
|
<if test="params.beginDatetime != null and params.beginDatetime != '' and params.endDatetime != null and params.endDatetime != ''"> and datetime between #{params.beginDatetime} and #{params.endDatetime}</if>
|
||||||
<if test="technical != null and technical != ''"> and technical = #{technical}</if>
|
<if test="technical != null and technical != ''"> and technical = #{technical}</if>
|
||||||
</where>
|
</where>
|
||||||
|
|||||||
@@ -48,7 +48,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
</foreach>
|
</foreach>
|
||||||
)
|
)
|
||||||
</if>
|
</if>
|
||||||
|
<!-- 全部羊多耳号查询(母羊或公羊匹配即可) -->
|
||||||
|
<if test="allEarNumbers != null and allEarNumbers.size() > 0">
|
||||||
|
AND (
|
||||||
|
bs.manage_tags IN
|
||||||
|
<foreach collection="allEarNumbers" item="earNumber" open="(" separator="," close=")">
|
||||||
|
#{earNumber}
|
||||||
|
</foreach>
|
||||||
|
|
||||||
|
)
|
||||||
|
</if>
|
||||||
<if test="params.beginDatetime != null and params.beginDatetime != '' and params.endDatetime != null and params.endDatetime != ''"> and datetime between #{params.beginDatetime} and #{params.endDatetime}</if>
|
<if test="params.beginDatetime != null and params.beginDatetime != '' and params.endDatetime != null and params.endDatetime != ''"> and datetime between #{params.beginDatetime} and #{params.endDatetime}</if>
|
||||||
<if test="technical != null and technical != ''"> and technical = #{technical}</if>
|
<if test="technical != null and technical != ''"> and technical = #{technical}</if>
|
||||||
</where>
|
</where>
|
||||||
|
|||||||
@@ -54,6 +54,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
</foreach>
|
</foreach>
|
||||||
)
|
)
|
||||||
</if>
|
</if>
|
||||||
|
<!-- 全部羊多耳号查询(母羊或公羊匹配即可) -->
|
||||||
|
<if test="allEarNumbers != null and allEarNumbers.size() > 0">
|
||||||
|
AND (
|
||||||
|
bs.manage_tags IN
|
||||||
|
<foreach collection="allEarNumbers" item="earNumber" open="(" separator="," close=")">
|
||||||
|
#{earNumber}
|
||||||
|
</foreach>
|
||||||
|
|
||||||
|
)
|
||||||
|
</if>
|
||||||
<if test="quarItem != null "> and quar_item = #{quarItem}</if>
|
<if test="quarItem != null "> and quar_item = #{quarItem}</if>
|
||||||
<if test="sampleType != null "> and sample_type = #{sampleType}</if>
|
<if test="sampleType != null "> and sample_type = #{sampleType}</if>
|
||||||
<if test="sampler != null and sampler != ''"> and sampler like concat('%',#{sampler},'%') </if>
|
<if test="sampler != null and sampler != ''"> and sampler like concat('%',#{sampler},'%') </if>
|
||||||
|
|||||||
@@ -73,6 +73,24 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="sheepNo != null and sheepNo != ''">
|
<if test="sheepNo != null and sheepNo != ''">
|
||||||
AND bs.manage_tags LIKE CONCAT('%', #{sheepNo}, '%')
|
AND bs.manage_tags LIKE CONCAT('%', #{sheepNo}, '%')
|
||||||
</if>
|
</if>
|
||||||
|
<if test="sheepNos != null and sheepNos.length > 0">
|
||||||
|
AND (
|
||||||
|
<foreach collection="sheepNos" item="item" separator=" OR " open="" close="">
|
||||||
|
bs.manage_tags LIKE CONCAT('%', #{item}, '%')
|
||||||
|
</foreach>
|
||||||
|
)
|
||||||
|
</if>
|
||||||
|
<!-- 全部羊多耳号查询(母羊或公羊匹配即可) -->
|
||||||
|
<if test="allEarNumbers != null and allEarNumbers.size() > 0">
|
||||||
|
AND (
|
||||||
|
bs.manage_tags IN
|
||||||
|
<foreach collection="allEarNumbers" item="earNumber" open="(" separator="," close=")">
|
||||||
|
#{earNumber}
|
||||||
|
</foreach>
|
||||||
|
|
||||||
|
)
|
||||||
|
</if>
|
||||||
|
|
||||||
|
|
||||||
<!-- 4. 使用时间区间 -->
|
<!-- 4. 使用时间区间 -->
|
||||||
<if test="params.beginUseTime != null and params.endUseTime != null">
|
<if test="params.beginUseTime != null and params.endUseTime != null">
|
||||||
|
|||||||
@@ -62,6 +62,17 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
</foreach>
|
</foreach>
|
||||||
)
|
)
|
||||||
</if>
|
</if>
|
||||||
|
<!-- 全部羊多耳号查询(母羊或公羊匹配即可) -->
|
||||||
|
<if test="allEarNumbers != null and allEarNumbers.size() > 0">
|
||||||
|
AND (
|
||||||
|
bs.manage_tags IN
|
||||||
|
<foreach collection="allEarNumbers" item="earNumber" open="(" separator="," close=")">
|
||||||
|
#{earNumber}
|
||||||
|
</foreach>
|
||||||
|
|
||||||
|
)
|
||||||
|
</if>
|
||||||
|
|
||||||
|
|
||||||
<if test="params.beginDatetime != null and params.beginDatetime != '' and params.endDatetime != null and params.endDatetime != ''"> and datetime between #{params.beginDatetime} and #{params.endDatetime}</if>
|
<if test="params.beginDatetime != null and params.beginDatetime != '' and params.endDatetime != null and params.endDatetime != ''"> and datetime between #{params.beginDatetime} and #{params.endDatetime}</if>
|
||||||
<if test="diseaseId != null "> and disease_id = #{diseaseId}</if>
|
<if test="diseaseId != null "> and disease_id = #{diseaseId}</if>
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="isGranular != null "> and is_granular = #{isGranular}</if>
|
<if test="isGranular != null "> and is_granular = #{isGranular}</if>
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectSgMaterialByMaterialId" parameterType="String" resultMap="SgMaterialResult">
|
<select id="selectSgMaterialByMaterialId" parameterType="String" resultMap="SgMaterialResult">
|
||||||
<include refid="selectSgMaterialVo"/>
|
<include refid="selectSgMaterialVo"/>
|
||||||
where material_id = #{materialId}
|
where material_id = #{materialId}
|
||||||
|
|||||||
Reference in New Issue
Block a user