diff --git a/doctor-modules/doctor-health/pom.xml b/doctor-modules/doctor-health/pom.xml index a4e24e3..af2698a 100644 --- a/doctor-modules/doctor-health/pom.xml +++ b/doctor-modules/doctor-health/pom.xml @@ -137,6 +137,36 @@ ${mapstruct.version} + + + + com.google.zxing + core + 3.4.0 + + + + com.alibaba + fastjson + 1.2.80 + + + + com.aliyun + facebody20191230 + 4.0.0 + + + com.google.zxing + core + 3.4.1 + + + com.google.zxing + javase + 3.4.1 + + diff --git a/doctor-modules/doctor-health/src/main/java/doctor/controller/CollectSickController.java b/doctor-modules/doctor-health/src/main/java/doctor/controller/CollectSickController.java index 3b87e44..dd34074 100644 --- a/doctor-modules/doctor-health/src/main/java/doctor/controller/CollectSickController.java +++ b/doctor-modules/doctor-health/src/main/java/doctor/controller/CollectSickController.java @@ -2,6 +2,13 @@ package doctor.controller; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import com.alibaba.nacos.api.model.v2.Result; +import com.aliyun.oss.OSS; +import com.aliyun.oss.OSSClientBuilder; +import com.google.zxing.BarcodeFormat; +import com.google.zxing.WriterException; +import com.google.zxing.common.BitMatrix; +import com.google.zxing.qrcode.QRCodeWriter; import doctor.common.core.domain.HealthR; import doctor.domain.entity.SickCircleEntity; import doctor.service.CollectSickService; @@ -15,9 +22,21 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import javax.crypto.Cipher; +import javax.crypto.spec.SecretKeySpec; +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.MessageDigest; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.PreparedStatement; import java.util.HashMap; import java.util.Map; @@ -54,11 +73,13 @@ public class CollectSickController { //----------------------------------------------------------------------------------------------------------------------------------------- + + //----------------------------------------------------------------------------------------------------------------------------------------- /** * orc身份证识别 * @param file */ - @PostMapping("/file") + @PostMapping("/files") public void file(MultipartFile file) { String s = OssUtil.uploadMultipartFile(file); @@ -145,4 +166,197 @@ public class CollectSickController { return imgBase64; } + + + private static final String AES_KEY = "1234567890123456"; + + @PostMapping("file") + public HealthR hao(@RequestParam("file") String hao){ +// // 验证主机号长度 +// if (hao.length() != 32) { +// HealthR.fail("主机号长度不合法,操作失败!"); +// } +// // AES加密 +// String encryptedHostNumber = encryptAES(hao, AES_KEY); +// // Base64编码 +// String base64Encoded = java.util.Base64.getEncoder().encodeToString(encryptedHostNumber.getBytes(StandardCharsets.UTF_8)); +// // MD5加密 +// String md5Hash = generateMD5Hash(base64Encoded); + + String s = OssUtil.uploadFile(hao); +// 生成二维码(这里省略生成二维码的步骤) + try { + // 二维码内容 + String qrCodeData =s; + + // 设置二维码的宽度和高度 + int width = 300; + int height = 300; + + // 设置二维码图片保存路径 + String filePath = "C:\\Users\\栗永斌\\Desktop\\二维码.png";//自己的 + + + String endpoint="oss-cn-shanghai.aliyuncs.com";//自己的 + String accessKeyId="LTAI5tLE4XbyvvbuT7D2stCk";//自己的 + String accessKeySecret="W7ZeT4dMrMPP0c8BBwcyIPnhe3P4E8";//自己的 + OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); + + try { + File file = new File(filePath); + String objectName = "身份证"; // OSS 对象名称 + + String bucketName="lyb1314"; + // 上传文件 + ossClient.putObject(bucketName, objectName, file); + + System.out.println("文件上传成功!"); + + // 如果需要获取上传后的文件 URL,可以使用以下代码 + String fileUrl = "https://" + bucketName + "." + endpoint + "/" + objectName; + System.out.println("文件访问地址:" + fileUrl); + } finally { + // 关闭 OSS 客户端 + ossClient.shutdown(); + } + + // 存储到数据库 +// saveToDatabase(hao, md5Hash,filePath); +// System.out.println("操作成功!生成的序列号为:" + md5Hash); + + // 设置二维码图片格式 + String fileType = "png"; + + // 创建 BitMatrix 对象 + BitMatrix bitMatrix = new QRCodeWriter().encode(qrCodeData, BarcodeFormat.QR_CODE, width, height); + + // 将 BitMatrix 转换为 BufferedImage + Path path = Paths.get(filePath); + CollectSickController.MatrixToImageWriter.writeToPath(bitMatrix, fileType, path); + + + } catch (WriterException e) { + throw new RuntimeException("生成二维码失败", e); + } + + return null; + + } + + + + public static class MatrixToImageWriter { + private static final int BLACK = 0xFF000000; + private static final int WHITE = 0xFFFFFFFF; + + private MatrixToImageWriter() {} + + public static void writeToPath(BitMatrix matrix, String format, Path path) { + try { + CollectSickController.MatrixToImageWriter.MatrixToImageConfig config = new CollectSickController.MatrixToImageWriter.MatrixToImageConfig(BLACK, WHITE); + CollectSickController.MatrixToImageWriter.writeToPath(matrix, format, path, config); + } catch (Exception e) { + throw new RuntimeException("写入二维码图片失败", e); + } + } + + public static void writeToPath(BitMatrix matrix, String format, Path path, CollectSickController.MatrixToImageWriter.MatrixToImageConfig config) { + try { + BufferedImage image = toBufferedImage(matrix, config); + if (!ImageIO.write(image, format, path.toFile())) { + throw new RuntimeException("写入二维码图片失败"); + } + } catch (IOException e) { + throw new RuntimeException("写入二维码图片失败", e); + } + } + + private static BufferedImage toBufferedImage(BitMatrix matrix, CollectSickController.MatrixToImageWriter.MatrixToImageConfig config) { + int width = matrix.getWidth(); + int height = matrix.getHeight(); + BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + for (int x = 0; x < width; x++) { + for (int y = 0; y < height; y++) { + image.setRGB(x, y, matrix.get(x, y) ? config.getPixelOnColor() : config.getPixelOffColor()); + } + } + return image; + } + + public static class MatrixToImageConfig { + private final int onColor; + private final int offColor; + + public MatrixToImageConfig(int onColor, int offColor) { + this.onColor = onColor; + this.offColor = offColor; + } + + public int getPixelOnColor() { + return onColor; + } + + public int getPixelOffColor() { + return offColor; + } + } + } + + private static void saveToDatabase(String hostNumber, String serialNumber,String filePath) { + try { + // 假设你有一个数据库连接,并且有一个表用于存储主机号和序列号 + String jdbcUrl = "jdbc:mysql://101.34.77.101:3306/dome1"; + String username = "root"; + String password = "cbx@123"; + + Connection connection = DriverManager.getConnection(jdbcUrl, username, password); + + // 插入数据 + String sql = "INSERT INTO `dome1`.`t_list` ( `host_number`, `serial_number`,`img`) VALUES (?, ?,?)"; + + + try (PreparedStatement preparedStatement = connection.prepareStatement(sql)) { + preparedStatement.setString(1, hostNumber); + preparedStatement.setString(2, serialNumber); + preparedStatement.setString(3, filePath); + preparedStatement.executeUpdate(); + + } + + connection.close(); + } catch (Exception e) { + throw new RuntimeException("存储到数据库失败", e); + } + } + + + private static String encryptAES(String input, String key) { + try { + Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); + SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(StandardCharsets.UTF_8), "AES"); + cipher.init(Cipher.ENCRYPT_MODE, secretKey); + return new String(cipher.doFinal(input.getBytes(StandardCharsets.UTF_8)), StandardCharsets.UTF_8); + } catch (Exception e) { + throw new RuntimeException("AES加密失败", e); + } + } + + private static String generateMD5Hash(String input) { + try { + MessageDigest md = MessageDigest.getInstance("MD5"); + byte[] hashBytes = md.digest(input.getBytes(StandardCharsets.UTF_8)); + StringBuilder hexString = new StringBuilder(); + for (byte b : hashBytes) { + String hex = Integer.toHexString(0xFF & b); + if (hex.length() == 1) { + hexString.append('0'); + } + hexString.append(hex); + } + return hexString.toString(); + } catch (Exception e) { + throw new RuntimeException("MD5加密失败", e); + } + } + } diff --git a/doctor-modules/doctor-health/src/main/java/doctor/controller/DiseaseKnowledgeController.java b/doctor-modules/doctor-health/src/main/java/doctor/controller/DiseaseKnowledgeController.java index 6ffee33..13c5b1f 100644 --- a/doctor-modules/doctor-health/src/main/java/doctor/controller/DiseaseKnowledgeController.java +++ b/doctor-modules/doctor-health/src/main/java/doctor/controller/DiseaseKnowledgeController.java @@ -36,14 +36,7 @@ public class DiseaseKnowledgeController { List departments= diseaseKnowledgeService.findDepartment(); return HealthR.ok(departments); } - @Autowired - private DiseaseCategoryService diseaseCategoryService; - @GetMapping("/findDiseaseCategory") - public HealthR> findDiseaseCategory(@RequestParam Integer departmentId){ - List list=diseaseCategoryService.findDiseaseCategory(departmentId); - return HealthR.ok(list); - } //罕见病症详情 @GetMapping("/findDiseaseKnowledge") diff --git a/doctor-modules/doctor-health/src/main/java/doctor/controller/PatientController.java b/doctor-modules/doctor-health/src/main/java/doctor/controller/PatientController.java index bcf2ddd..24c18b2 100644 --- a/doctor-modules/doctor-health/src/main/java/doctor/controller/PatientController.java +++ b/doctor-modules/doctor-health/src/main/java/doctor/controller/PatientController.java @@ -25,7 +25,7 @@ import java.util.List; * @Author 栗永斌 */ @RestController -@RequestMapping("/sickCircle/v1/") +@RequestMapping("/user/sickCircle/v1/") public class PatientController { @Autowired @@ -46,17 +46,7 @@ public class PatientController { } - /** - * 点采 - * @param opinion - * @return - */ - @PutMapping("expressOpinion") - public HealthR expressOpinion(@RequestParam("opinion") Integer opinion){ -// return sickCircleServer.expressOpinion(commentId, opinion); - System.out.println(opinion); - return null; - } + /** * 新增病友圈 @@ -69,7 +59,6 @@ public class PatientController { /** * 病友圈列表 - * * @param departmentId * @return */ @@ -77,6 +66,7 @@ public class PatientController { public HealthR> sickCircleList(@RequestParam(value = "departmentId",required = false) Integer departmentId, @RequestParam(value = "page") Integer page, @RequestParam(value = "count") Integer count) { + return patientService.sickCircleList(departmentId,page,count); } @@ -104,7 +94,7 @@ public class PatientController { /** - * 查询病友圈评论列表 + * 病友圈评论列表 */ @GetMapping("/findSickCircleCommentList") public HealthR> findSickCircleCommentList(@RequestParam(value = "sickCircleId",required = false) Integer sickCircleId, @@ -123,6 +113,13 @@ public class PatientController { @GetMapping("searchSickCircle") public HealthR> searchSickCircle(@RequestParam(value = "keyWord",required = false) String keyWord){ return patientService.searchSickCircle(keyWord); + } + @GetMapping("findPatientSickCircleList") + public HealthR> findPatientSickCircleList(@RequestParam(value = "patientUserId",required = false) Integer patientUserId, + @RequestParam(value = "page") Integer page, + @RequestParam(value = "count") Integer count) { + + return patientService.findPatientSickCircleList(patientUserId,page,count); } } diff --git a/doctor-modules/doctor-health/src/main/java/doctor/domain/entity/SickCommentEntity.java b/doctor-modules/doctor-health/src/main/java/doctor/domain/entity/SickCommentEntity.java index b633f52..cb5451c 100644 --- a/doctor-modules/doctor-health/src/main/java/doctor/domain/entity/SickCommentEntity.java +++ b/doctor-modules/doctor-health/src/main/java/doctor/domain/entity/SickCommentEntity.java @@ -32,10 +32,11 @@ public class SickCommentEntity { private Date createTime; private Integer patientUserId; private Integer whetherDoctor; - private Integer commentId; + private Integer commentUserId; private Integer opposeNum; private Integer supportNum; private Integer opinion; + private String headPic; diff --git a/doctor-modules/doctor-health/src/main/java/doctor/mapper/SickCircleMapper.java b/doctor-modules/doctor-health/src/main/java/doctor/mapper/SickCircleMapper.java index 84d12f3..bb55352 100644 --- a/doctor-modules/doctor-health/src/main/java/doctor/mapper/SickCircleMapper.java +++ b/doctor-modules/doctor-health/src/main/java/doctor/mapper/SickCircleMapper.java @@ -21,4 +21,17 @@ public interface SickCircleMapper { void expressOpinion(@Param("commentId") Integer commentId, @Param("opinion") Integer opinion, @Param("userid") Long userid); + + void ins(@Param("sickCircleId") Integer sickCircleId); + + void inss(@Param("sickCircleId") Integer sickCircleId, @Param("userid") Long userid); + + void jia(@Param("commentId") Integer commentId); + + void jian(@Param("commentId") Integer commentId); + + void jiann(@Param("commentId") Integer commentId); + + void jiaa(@Param("commentId") Integer commentId); + } diff --git a/doctor-modules/doctor-health/src/main/java/doctor/service/PatientService.java b/doctor-modules/doctor-health/src/main/java/doctor/service/PatientService.java index 3111e75..0e18055 100644 --- a/doctor-modules/doctor-health/src/main/java/doctor/service/PatientService.java +++ b/doctor-modules/doctor-health/src/main/java/doctor/service/PatientService.java @@ -38,4 +38,7 @@ public interface PatientService { HealthR> searchSickCircle(String keyWord); + HealthR> findPatientSickCircleList(Integer patientUserId, Integer page, Integer count); + + } diff --git a/doctor-modules/doctor-health/src/main/java/doctor/service/impl/PatientServiceImpl.java b/doctor-modules/doctor-health/src/main/java/doctor/service/impl/PatientServiceImpl.java index 166b5ff..12cfef5 100644 --- a/doctor-modules/doctor-health/src/main/java/doctor/service/impl/PatientServiceImpl.java +++ b/doctor-modules/doctor-health/src/main/java/doctor/service/impl/PatientServiceImpl.java @@ -64,12 +64,15 @@ public class PatientServiceImpl extends BaseController implements PatientService } @Override - public HealthR> findPatientSickCircleList(Integer patientUserId) { + public HealthR> findPatientSickCircleList(Integer patientUserId, Integer page, Integer count) { + startPage(page,count); List sickCircleEntity = patientMapper.findPatientSickCircleList(patientUserId); return HealthR.ok(sickCircleEntity); } + + @Override public SickCircleEntity findSickCircleInfo(Integer id) { SickCircleEntity sickCircleList = patientMapper.findSickCircleInfo(id); diff --git a/doctor-modules/doctor-health/src/main/java/doctor/service/impl/SickCircleServerImpl.java b/doctor-modules/doctor-health/src/main/java/doctor/service/impl/SickCircleServerImpl.java index 9382176..32bdfde 100644 --- a/doctor-modules/doctor-health/src/main/java/doctor/service/impl/SickCircleServerImpl.java +++ b/doctor-modules/doctor-health/src/main/java/doctor/service/impl/SickCircleServerImpl.java @@ -97,9 +97,18 @@ public class SickCircleServerImpl implements SickCircleServer { @Override public HealthR expressOpinion(Integer commentId, Integer opinion) { + if(opinion==1){ + mapper.jia(commentId); + mapper.jiann(commentId); + } + if(opinion==2){ + mapper.jiaa(commentId); + mapper.jian(commentId); + } LoginUser login = Login(); Long userid = login.getUserid(); - mapper.expressOpinion(commentId, opinion,userid); + + return HealthR.ok(); } diff --git a/doctor-modules/doctor-health/src/main/java/doctor/service/impl/SickCircleServiceImpl.java b/doctor-modules/doctor-health/src/main/java/doctor/service/impl/SickCircleServiceImpl.java index 94b7f59..0a08464 100644 --- a/doctor-modules/doctor-health/src/main/java/doctor/service/impl/SickCircleServiceImpl.java +++ b/doctor-modules/doctor-health/src/main/java/doctor/service/impl/SickCircleServiceImpl.java @@ -67,6 +67,11 @@ public class SickCircleServiceImpl extends BaseController implements SickCircleS LoginUser login = Login(); //获取用户id Long userid = login.getUserid(); + //病友圈评论计树 + sickCircleMapper.ins(sickCircleId); + //病友圈评论试图 + sickCircleMapper.inss(sickCircleId,userid); + sickCircleMapper.publishComment(sickCircleId,userid, content); return Result.success(null); diff --git a/doctor-modules/doctor-health/src/main/resources/mapper/doctor/PatientMapper.xml b/doctor-modules/doctor-health/src/main/resources/mapper/doctor/PatientMapper.xml index 21a7a0c..301243a 100644 --- a/doctor-modules/doctor-health/src/main/resources/mapper/doctor/PatientMapper.xml +++ b/doctor-modules/doctor-health/src/main/resources/mapper/doctor/PatientMapper.xml @@ -35,14 +35,18 @@ sick_circle_comment.create_time, sick_circle_comment.patient_user_id, sick_circle_comment.whether_doctor, - sick_circle_comment_count.comment_id, + sick_circle_comment_count.comment_id AS commentUserId, sick_circle_comment_count.oppose_num, sick_circle_comment_count.support_num, - sick_circle_comment_view.opinion + sick_circle_comment_view.opinion, + `user`.head_pic FROM sick_circle_comment - LEFT JOIN sick_circle_comment_count ON sick_circle_comment.patient_user_id = sick_circle_comment_count.comment_id LEFT JOIN sick_circle_comment_view on sick_circle_comment.patient_user_id=sick_circle_comment_view.opinion where - sick_circle_comment.sick_circle_id=#{sickCircleId} + LEFT JOIN sick_circle_comment_count ON sick_circle_comment.patient_user_id = sick_circle_comment_count.comment_id + LEFT JOIN sick_circle_comment_view ON sick_circle_comment.patient_user_id = sick_circle_comment_view.comment_id + LEFT JOIN `user` on sick_circle_comment.patient_user_id=`user`.id + WHERE + sick_circle_comment.sick_circle_id=#{sickCircleId} + @@ -21,11 +36,23 @@ - INSERT INTO `doctor`.`sick_circle_comment` ( `sick_circle_id`, `user_id`, `content`, `comment_time`, `whether_doctor`, `create_time`) + INSERT INTO `doctor`.`sick_circle_comment` ( `sick_circle_id`, `patient_user_id`, `content`, `comment_time`, `whether_doctor`, `create_time`) VALUES (#{sickCircleId},#{userid},#{content},now(),1,now()) + UPDATE sick_circle_comment_view set opinion=#{opinion} ,user_id=#{userid} WHERE comment_id=#{commentId} + + INSERT INTO `doctor`.`sick_circle_comment_count` ( `comment_id`, `support_num`, `oppose_num`, `create_time`) + VALUES (#{sickCircleId},0,0,now()); + + + + INSERT INTO `doctor`.`sick_circle_comment_view` ( `comment_id`, `user_id`, `opinion`, `create_time`) + VALUES (#{sickCircleId},#{userid},0,now()); + + +