杨海航 2 years ago
parent 50fca68a35
commit c83fe88bd5
  1. 1387
      db/dlp_reagent_managment.sql
  2. 37
      src/main/java/digital/laboratory/platform/reagent/Interceptor/FeignOauth2RequestInterceptor.java
  3. 122
      src/main/java/digital/laboratory/platform/reagent/config/QRCodeUtils.java
  4. 127
      src/main/java/digital/laboratory/platform/reagent/handle/AppStartupRunner.java
  5. 51
      src/main/java/digital/laboratory/platform/reagent/task/MaturityCalculation.java
  6. 10
      src/main/java/digital/laboratory/platform/reagent/vo/UserVO.java

File diff suppressed because it is too large Load Diff

@ -0,0 +1,37 @@
package digital.laboratory.platform.reagent.Interceptor;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;
/**
* Feign 请求拦截器
* Feign Client 向业务系统发出请求的时候, Token 带上, 以用户自己的身份调用业务系统
* 目的是在业务系统中识别用户是谁, 允许或禁止用户进行对应的操作
*/
@Configuration
public class FeignOauth2RequestInterceptor implements RequestInterceptor {
private final String AUTHORIZATION_HEADER = "Authorization";
private final String BEARER_TOKEN_TYPE = "Bearer";
@Override
public void apply(RequestTemplate requestTemplate) {
//System.out.println(String.format("dlp-entrustment, FeignOauth2RequestInterceptor()..."));
SecurityContext securityContext = SecurityContextHolder.getContext();
Authentication authentication = securityContext.getAuthentication();
if (authentication != null && authentication.getDetails() instanceof OAuth2AuthenticationDetails) {
OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) authentication.getDetails();
//System.out.println(String.format("FeignOauth2RequestInterceptor() Authorization, token=%s", details.getTokenValue()));
requestTemplate.header(AUTHORIZATION_HEADER, String.format("%s %s", BEARER_TOKEN_TYPE, details.getTokenValue()));
}
}
}

@ -0,0 +1,122 @@
package digital.laboratory.platform.reagent.config;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.oned.Code128Writer;
import com.google.zxing.qrcode.QRCodeWriter;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import org.springframework.util.StringUtils;
import sun.misc.BASE64Encoder;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.util.HashMap;
import java.util.Map;
public class QRCodeUtils {
//二维码
public static BufferedImage genQRCode(String content, int width, int height) {
if (!StringUtils.isEmpty(content)) {
HashMap<EncodeHintType, Comparable> hints = new HashMap<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.MARGIN, 0);
try {
QRCodeWriter writer = new QRCodeWriter();
BitMatrix bitMatrix = writer.encode(content, BarcodeFormat.QR_CODE, width, height, hints);
BufferedImage bufferedImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
return bufferedImage;
} catch (Exception e) {
} finally {
}
}
return null;
}
//打印条形码
public static String getBarCode128ImageBase64(String content, int width, int height) {
try {
Map<EncodeHintType, Object> hints = new HashMap<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.MARGIN, 0);
int realWidth = getBarCode128NoPaddingWidth(width, content, width);
BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.CODE_128, realWidth, height, hints);
BufferedImage bufferedImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "png", os);
BASE64Encoder encoder = new BASE64Encoder();
String resultImage = new String("data:image/png;base64," + encoder.encode(os.toByteArray()));
return resultImage;
} catch (Exception e) {
return null;
}
}
private static int getBarCode128NoPaddingWidth(int expectWidth, String contents, int maxWidth) {
boolean[] code = new Code128Writer().encode(contents);
int inputWidth = code.length;
double outputWidth = (double) Math.max(expectWidth, inputWidth);
double multiple = outputWidth / inputWidth;
//优先取大的
int returnVal = 0;
int ceil = (int) Math.ceil(multiple);
if (inputWidth * ceil <= maxWidth) {
returnVal = inputWidth * ceil;
} else {
int floor = (int) Math.floor(multiple);
returnVal = inputWidth * floor;
}
return returnVal;
}
public static String getBarCode93ImageBase64(String content, int width, int height) {
try {
Map<EncodeHintType, Object> hints = new HashMap<>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
hints.put(EncodeHintType.MARGIN, 0);
int realWidth = getBarCode128NoPaddingWidth(width, content, width);
BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.CODE_93, realWidth, height, hints);
BufferedImage bufferedImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "png", os);
BASE64Encoder encoder = new BASE64Encoder();
String resultImage = new String("data:image/png;base64," + encoder.encode(os.toByteArray()));
return resultImage;
} catch (Exception e) {
return null;
}
}
/**
* 打印条码
*
* @param
* @return
*/
}

@ -0,0 +1,127 @@
package digital.laboratory.platform.reagent.handle;
import digital.laboratory.platform.common.core.constant.CommonConstants;
import digital.laboratory.platform.common.core.util.R;
import digital.laboratory.platform.sys.entity.Dictionary;
import digital.laboratory.platform.sys.feign.RemoteDictionaryService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* App 启动类
* Spring Application 启动完成后, 会调用这个类的 run() 方法进行一些最后的初始化
* 我们在这个方法中从数据库加载一些全局的配置
*
* @author Zhang Xiaolong
*/
@Component
@RequiredArgsConstructor
public class AppStartupRunner implements ApplicationRunner {
// @Value("${dlp.entrustment.processDefinitionId}")
// public static String processDefinitionId;
//public static boolean clientChoiceCheckers;
//public static boolean checkerChoiceApprovers;
//public static boolean singleOperateUser;
// @Value("${dlp.entrustment.temporaryPath}")
//public static String temporaryPath;
private final RemoteDictionaryService remoteDictionaryService;
public static Map<String, String> reagentManagmentConfig = new HashMap<>();
public static String getCfg(String code) {
return reagentManagmentConfig.get(code);
}
/**
*
* @param args 参数
* @throws Exception 异常
*
* // @SysLog("委托受理模块初始化") 这里不能使用 @SysLog(), 因为 SysLog 还没有初始化
*/
@Override
public void run(ApplicationArguments args) throws Exception {
// BusinessCodeUtils.removeSymbols("x-*/)——0*&……%¥#@xasdf!*&^&%^ 中文、/+)(()\n\\xx\rx");
{
// 加载 entrustment 在字典中的配置
R<List<Dictionary>> r = remoteDictionaryService.getDictionaryByType("dlp_reagent_managment");
if (Optional.ofNullable(r).isPresent() && (r.getData() != null)) {
List<Dictionary> itemList = r.getData();
for (Dictionary item : itemList) {
reagentManagmentConfig.put(item.getCode(), item.getLabel());
}
}
for (String key : reagentManagmentConfig.keySet()) {
System.out.println(String.format("reagentManagmentConfig[%s]=%s", key, reagentManagmentConfig.get(key)));
}
}
// {
// R<HashMap<String, String>> r = remoteDictionaryService.innerGetById(CommonConstants.DLP_ENTRUSTMENT_PROCESS_DEFINITION_ID);
// if (Optional.ofNullable(r).isPresent() && (r.getData() != null)) {
// processDefinitionId = r.getData().get("label");
// }
// }
// {
// R<HashMap<String, String>> r = remoteDictionaryService.innerGetById(CommonConstants.DLP_ENTRUSTMENT_CLIENT_CHOICE_CHECKERS);
// if (Optional.ofNullable(r).isPresent() && (r.getData() != null)) {
// clientChoiceCheckers = "1".equals(r.getData().get("label"));
// }
// }
// {
// R<HashMap<String, String>> r = remoteDictionaryService.innerGetById(CommonConstants.DLP_ENTRUSTMENT_CHECKER_CHOICE_APPROVERS);
// if (Optional.ofNullable(r).isPresent() && (r.getData() != null)) {
// checkerChoiceApprovers = "1".equals(r.getData().get("label"));
// }
// }
// {
// R<HashMap<String, String>> r = remoteDictionaryService.innerGetById(CommonConstants.DLP_ENTRUSTMENT_CLIENT_SINGLE_OPERATE_USER);
// if (Optional.ofNullable(r).isPresent() && (r.getData() != null)) {
// singleOperateUser = "1".equals(r.getData().get("label"));
// }
// }
// {
// R<HashMap<String, String>> r = remoteDictionaryService.innerGetById(CommonConstants.DLP_ENTRUSTMENT_TEMPORARY_PATH);
// if (Optional.ofNullable(r).isPresent() && (r.getData() != null)) {
// temporaryPath = r.getData().get("label");
// }
// if (StrUtil.isEmpty(temporaryPath)) {
// temporaryPath =new File(System.getProperty("user.dir")+"/temp").getCanonicalPath();
// }
//
// System.out.printf("临时目录是 %s%n", temporaryPath);
// File tempPathFile = new File(temporaryPath);
// if (! tempPathFile.exists()) {
// System.out.printf("临时目录 %s 不存在, 创建之...%n", tempPathFile.getCanonicalPath());
// if (!tempPathFile.mkdirs()) {
// System.out.printf("创建临时目录 %s 失败!%n", tempPathFile.getCanonicalPath());
// }
// }
// }
// {
// R<HashMap<String, String>> r = remoteDictionaryService.innerGetById(CommonConstants.DLP_ENTRUSTMENT_LETTER_TEMPLATE_PATH);
// if (Optional.ofNullable(r).isPresent() && (r.getData() != null)) {
// entrustmentLetterTemplate = r.getData().get("label");
// }
// }
}
}

@ -0,0 +1,51 @@
package digital.laboratory.platform.reagent.task;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import digital.laboratory.platform.reagent.entity.BatchDetails;
import digital.laboratory.platform.reagent.service.BatchDetailsService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
@Configuration
@EnableScheduling
@RequiredArgsConstructor
public class MaturityCalculation {
private final BatchDetailsService batchDetailsService;
@Scheduled(cron ="0 0 0 * * ? ")
public void calculate(){
//查找出有库存量的物品所有批次信息(状态为1)
List<BatchDetails> list1 = batchDetailsService.list(Wrappers.<BatchDetails>query().eq("service_status",1));
String warningInformation = null;
for (BatchDetails batchDetails : list1) {
//提前一周进行到期提醒
if (batchDetails.getExpirationDate().plusDays(7).isAfter(LocalDate.now())){
warningInformation = "即将过期";
batchDetails.setWarningInformation(warningInformation);
batchDetailsService.updateById(batchDetails);
}else if (batchDetails.getExpirationDate().isAfter(LocalDate.now())){
warningInformation = "已过期";
batchDetails.setWarningInformation(warningInformation);
batchDetailsService.updateById(batchDetails);
}
if (batchDetails.getCreateTime().plusMonths(Integer.valueOf(batchDetails.getLimitDate())).plusDays(7).isAfter(LocalDateTime.now())){
batchDetails.setWarningInformation(batchDetails.getWarningInformation()+",即将到达存储期限");
}else if(batchDetails.getCreateTime().plusMonths(Integer.valueOf(batchDetails.getLimitDate())).isAfter(LocalDateTime.now())){
batchDetails.setWarningInformation("已超过存储期限");
}
}
}
}

@ -0,0 +1,10 @@
package digital.laboratory.platform.reagent.vo;
import lombok.Data;
@Data
public class UserVO {
private String name;
private String UserId;
}
Loading…
Cancel
Save