|
@@ -1,5 +1,6 @@
|
|
|
package thyyxxk.webserver.service.settings;
|
|
|
|
|
|
+import cn.hutool.core.io.file.FileNameUtil;
|
|
|
import cn.hutool.crypto.SecureUtil;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
@@ -7,7 +8,9 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.aspectj.apache.bcel.classfile.Code;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -30,6 +33,11 @@ import thyyxxk.webserver.service.externalhttp.WebSocketService;
|
|
|
import thyyxxk.webserver.service.redislike.RedisLikeService;
|
|
|
import thyyxxk.webserver.utils.*;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
+import java.nio.file.StandardCopyOption;
|
|
|
import java.util.*;
|
|
|
|
|
|
/**
|
|
@@ -44,6 +52,9 @@ public class SettingsService {
|
|
|
private final RedisLikeService redis;
|
|
|
private final WebSocketService socketService;
|
|
|
|
|
|
+ @Value("${is-prod}")
|
|
|
+ private boolean isProd;
|
|
|
+
|
|
|
@Autowired
|
|
|
public SettingsService(SettingsDao dao, CorpWxSrvc srvc, PublicServer publicServer, RedisLikeService redis, WebSocketService socketService) {
|
|
|
this.dao = dao;
|
|
@@ -291,30 +302,30 @@ public class SettingsService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Description 更新医生的签名
|
|
|
- * @Author hsh
|
|
|
* @param file 签名 code 人员编码
|
|
|
* @return map
|
|
|
+ * @Description 更新医生的签名
|
|
|
+ * @Author hsh
|
|
|
* @Date 2024/5/14 10:36
|
|
|
*/
|
|
|
public ResultVo<Map<String, Object>> setAutographImage(MultipartFile file, String code) {
|
|
|
- if(StringUtil.isBlank(code)){
|
|
|
+ if (StringUtil.isBlank(code)) {
|
|
|
return ResultVoUtil.fail(ExceptionEnum.INVALID_PARAM);
|
|
|
}
|
|
|
String img = base64Encode(file);
|
|
|
Map<String, Object> m = dao.selectAutographImageByCode(code);
|
|
|
int count;
|
|
|
- if(null == m || m.isEmpty()){
|
|
|
+ if (null == m || m.isEmpty()) {
|
|
|
EmployeeMi mi = dao.selectEmployeeMiByCode(code);
|
|
|
- if(null != mi){
|
|
|
- count = dao.intoAutographImage(code, img, mi.getSexCode() == null ? "9": mi.getSexCode());
|
|
|
+ if (null != mi) {
|
|
|
+ count = dao.intoAutographImage(code, img, mi.getSexCode() == null ? "9" : mi.getSexCode());
|
|
|
} else {
|
|
|
count = dao.intoAutographImage(code, img, "9");
|
|
|
}
|
|
|
} else {
|
|
|
count = dao.updateAutographImage(code, img);
|
|
|
}
|
|
|
- if(count > 0 ){
|
|
|
+ if (count > 0) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
Map<String, Object> imgMap = dao.selectAutographImageByCode(code);
|
|
|
map.put("data", imgMap);
|
|
@@ -325,17 +336,17 @@ public class SettingsService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @Description 查询医生签名图片
|
|
|
- * @Author hsh
|
|
|
* @param code 医生编码
|
|
|
* @return map
|
|
|
+ * @Description 查询医生签名图片
|
|
|
+ * @Author hsh
|
|
|
* @Date 2024/5/15 9:47
|
|
|
*/
|
|
|
public ResultVo<Map<String, Object>> selectAutographImageByCode(String code) {
|
|
|
return ResultVoUtil.success(dao.selectAutographImageByCode(code));
|
|
|
}
|
|
|
|
|
|
- private String base64Encode(MultipartFile file){
|
|
|
+ private String base64Encode(MultipartFile file) {
|
|
|
String ret = null;
|
|
|
if (file == null) {
|
|
|
return null;
|
|
@@ -348,4 +359,48 @@ public class SettingsService {
|
|
|
}
|
|
|
return ret;
|
|
|
}
|
|
|
+
|
|
|
+ public ResultVo<JSONObject> putAutographImage(MultipartFile file, String code) {
|
|
|
+ String codeRs = "";
|
|
|
+ if (code == null) {
|
|
|
+ codeRs = FileNameUtil.mainName(file.getOriginalFilename());
|
|
|
+ }
|
|
|
+ if (StringUtil.isBlank(code) && StringUtil.notBlank(codeRs)) {
|
|
|
+ code = dao.selectCodeByCodeRs(codeRs);
|
|
|
+ if (StringUtil.isBlank(code)) {
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "工号不存在");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String uploadDir;
|
|
|
+ if (isProd) {
|
|
|
+ uploadDir = "/home/doctorSignature";
|
|
|
+ } else {
|
|
|
+ uploadDir = "D:\\doctorSignature";
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject js = new JSONObject();
|
|
|
+
|
|
|
+ String name = FileNameUtil.extName(file.getOriginalFilename());
|
|
|
+ String fileName = code + "." + name;
|
|
|
+ Path uploadPath = Paths.get(uploadDir);
|
|
|
+ try {
|
|
|
+ Files.createDirectories(uploadPath);
|
|
|
+ Path filePath = uploadPath.resolve(fileName);
|
|
|
+ Files.copy(file.getInputStream(), filePath, StandardCopyOption.REPLACE_EXISTING);
|
|
|
+ log.info("文件:{}, code:{}", file.getName(), code);
|
|
|
+ String url = "http://172.16.32.167:8077/doctorSignatureImage/" + fileName;
|
|
|
+ dao.putAutographImage(code, url);
|
|
|
+
|
|
|
+ js.put("url", url);
|
|
|
+ js.put("name", fileName);
|
|
|
+
|
|
|
+ return ResultVoUtil.success(js);
|
|
|
+ } catch (IOException e) {
|
|
|
+ log.error("上传错误:{}", e.getMessage());
|
|
|
+ return ResultVoUtil.fail(ExceptionEnum.LOGICAL_ERROR, "上传错误请重新上传。");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|