浏览代码

眼科版本更改

wangzhinan 3 天之前
父节点
当前提交
77806e7142

+ 85 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/iot/healthDevice/HealthDeviceData.java

@ -0,0 +1,85 @@
package com.yihu.jw.entity.iot.healthDevice;
import com.yihu.jw.entity.IdEntityWithCreateTime;
import javax.persistence.Entity;
import javax.persistence.Table;
@Entity
@Table(name = "iot_health_device_data")
public class HealthDeviceData extends IdEntityWithCreateTime {
    private String deviceSn; //设备编码
    private String hospital; //机构编码
    private Integer status; //状态1处理0未处理
    private String data; //上传数据
    private String name; //姓名
    private String mobile; //手机号
    private String idcard; //身份证
    private String serNum; //数据唯一性
    public String getSerNum() {
        return serNum;
    }
    public void setSerNum(String serNum) {
        this.serNum = serNum;
    }
    public String getDeviceSn() {
        return deviceSn;
    }
    public void setDeviceSn(String deviceSn) {
        this.deviceSn = deviceSn;
    }
    public String getHospital() {
        return hospital;
    }
    public void setHospital(String hospital) {
        this.hospital = hospital;
    }
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
    public String getData() {
        return data;
    }
    public void setData(String data) {
        this.data = data;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getMobile() {
        return mobile;
    }
    public void setMobile(String mobile) {
        this.mobile = mobile;
    }
    public String getIdcard() {
        return idcard;
    }
    public void setIdcard(String idcard) {
        this.idcard = idcard;
    }
}

+ 40 - 16
gateway/ag-basic/src/main/java/com/yihu/jw/gateway/AesEncryptUtils.java

@ -5,6 +5,9 @@ import org.apache.commons.codec.binary.Base64;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.spec.SecretKeySpec;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
/**
 * 前后端数据传输加密工具类
@ -60,25 +63,46 @@ public class AesEncryptUtils {
    public static String decrypt(String encryptStr) throws Exception {
        return decrypt(encryptStr, KEY);
    }
 
 
    public static void main(String[] args) throws Exception {
        /*Map map=new HashMap<String,String>();
        map.put("idcard","350322198812052545");
        map.put("price","1");
        map.put("type","1");*/
        String content = "{\"idcard\":\"350322198812052545\",\"price\":\"1\",\"type\":\"1\"}";
        System.out.println("加密前:" + content);
    public static void main(String[] args) {
        double totalAmount = 1; // 总金额
        int count = 1; // 红包数量
        double minAmount = 1.0; // 最小红包金额
        double maxAmount = 3.0; // 最大红包金额
        List<Double> redPackets = distributeRedPackets(totalAmount, count, minAmount, maxAmount);
        for (double amount : redPackets) {
            System.out.println(String.format("红包金额: %.2f", amount));
        }
    }
    public static List<Double> distributeRedPackets(double totalAmount, int count, double minAmount, double maxAmount) {
        List<Double> redPackets = new ArrayList<>();
        Random random = new Random();
        double remainingAmount = totalAmount;
        double perMaxAmount = (totalAmount - count * minAmount) / count; // 计算除去所有最小值后,每个红包最多可以有多少金额
        perMaxAmount = Math.min(perMaxAmount, maxAmount - minAmount); // 取perMaxAmount和maxAmount-minAmount的最小值,防止超出最大限制
        double perMinAmount = minAmount; // 每个红包的最小金额
        String encrypt = encrypt(content, KEY);
        System.out.println("加密后:" + encrypt);
        for (int i = 0; i < count; i++) {
            // 计算当前红包的金额范围
            double currentMax = Math.min(perMaxAmount + perMinAmount, maxAmount); // 当前红包的最大值(不能超过设定的最大值)
            double currentMin = perMinAmount; // 当前红包的最小值
            double currentAmount = currentMin + random.nextDouble() * (currentMax - currentMin); // 在当前范围内随机分配金额
            redPackets.add(currentAmount);
            remainingAmount -= currentAmount; // 减去已分配的金额
        }
        /**
         * WibZYHSxGPdkw8z37G/kyZLO6PwBxDzQBbTZig+m/gBTsvLSoVgp2fgf4fUgenTMfTxbZMbGfrQI969ZpS2Esg==
         */
        String decrypt = decrypt(encrypt, KEY);
        System.out.println("解密后:" + decrypt);
        // 如果还有剩余金额,则重新分配给前面的红包,直到用完所有剩余金额或达到设定的最大值限制
        if (remainingAmount > 0) {
            for (int i = 0; i < count && remainingAmount > 0; i++) {
                double additionalAmount = Math.min(remainingAmount, maxAmount - redPackets.get(i)); // 最多只能增加到maxAmount
                redPackets.set(i, redPackets.get(i) + additionalAmount);
                remainingAmount -= additionalAmount;
            }
        }
        return redPackets;
    }
}

+ 85 - 0
svr/svr-iot/src/main/java/com/yihu/iot/controller/third/HealthDeviceDataController.java

@ -0,0 +1,85 @@
package com.yihu.iot.controller.third;
import com.alibaba.fastjson.JSONObject;
import com.yihu.iot.dao.healthDevice.HealthDeviceDataDao;
import com.yihu.iot.datainput.service.HealthDeviceDataService;
import com.yihu.iot.datainput.util.DesAndSignIdongUtil;
import com.yihu.jw.entity.iot.healthDevice.HealthDeviceData;
import com.yihu.jw.util.entity.ServiceException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.*;
import static org.springframework.http.MediaType.*;
/**
 * 健康一体机设备数据
 */
@RestController
@RequestMapping("weixin/healthDevice")
@Api(tags = "开放接口-健康一体机设备", description = "开放接口-健康一体机设备")
public class HealthDeviceDataController {
    private static final Logger logger = LoggerFactory.getLogger(HealthDeviceDataController.class);
    @Autowired
    private HealthDeviceDataService healthDeviceDataService;
    @Autowired
    private HealthDeviceDataDao healthDeviceDataDao;
    @PostMapping(value = "uploadHealthHourseData")
    @ApiOperation(value = "集美健康小屋设备数据上传", notes = "集美健康小屋设备数据上传")
    public JSONObject uploadHealthHourseData(@RequestBody String data){
        JSONObject jsonObject = new JSONObject();
        try{
            healthDeviceDataService.uploadHealthHourseData(data);
            jsonObject.put("success",true);
            jsonObject.put("message","上传成功");
            return jsonObject;
        }  catch (Exception e){
            jsonObject.put("success",false);
            jsonObject.put("message",e.getMessage());
            return jsonObject;
        }
    }
    @PostMapping(value = "uploadIdongDeviceData")
    @ApiOperation(value = "开元体侧设备数据上传", notes = "开元体侧设备数据上传")
    public JSONObject uploadIdongDeviceData(String content,String version,Long serNum,String sign){
        JSONObject jsonObject = new JSONObject();
        try{
            Map<String,Object> params = new HashMap<>();
            String signLocal= DesAndSignIdongUtil.getSign(content,serNum,version);
            if (sign.equalsIgnoreCase(signLocal)){
                List<HealthDeviceData> healthDeviceDataList = healthDeviceDataDao.selectBySerNum(serNum+"");
                if (healthDeviceDataList!=null&&healthDeviceDataList.size()>0){
                    jsonObject.put("result",4);
                    jsonObject.put("Msg","重复数据");
                    return jsonObject;
                }
                healthDeviceDataService.uploadIdongDeviceData(content,serNum);
            }else{
                jsonObject.put("result",-1);
                jsonObject.put("Msg","程序异常");
                return jsonObject;
            }
            jsonObject.put("result",0);
            jsonObject.put("Msg","成功");
            return jsonObject;
        } catch (Exception e){
            e.printStackTrace();
            jsonObject.put("result",-1);
            jsonObject.put("Msg","程序异常");
            return jsonObject;
        }
    }
}

+ 17 - 0
svr/svr-iot/src/main/java/com/yihu/iot/dao/healthDevice/HealthDeviceDataDao.java

@ -0,0 +1,17 @@
package com.yihu.iot.dao.healthDevice;
import com.yihu.jw.entity.iot.datainput.DataStandardDO;
import com.yihu.jw.entity.iot.healthDevice.HealthDeviceData;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface HealthDeviceDataDao extends PagingAndSortingRepository<HealthDeviceData,Long>,
        JpaSpecificationExecutor<HealthDeviceData> {
    @Query("from HealthDeviceData where serNum = ?1" )
    List<HealthDeviceData> selectBySerNum(String serNum);
}

+ 85 - 0
svr/svr-iot/src/main/java/com/yihu/iot/datainput/service/HealthDeviceDataService.java

@ -0,0 +1,85 @@
package com.yihu.iot.datainput.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.iot.dao.healthDevice.HealthDeviceDataDao;
import com.yihu.iot.datainput.util.DesAndSignIdongUtil;
import com.yihu.jw.entity.iot.healthDevice.HealthDeviceData;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
/**
 * 一体机设备上传
 */
@Service
public class HealthDeviceDataService {
    @Autowired
    private HealthDeviceDataDao healthDeviceDataDao;
    /**
     * 集美健康小屋数据上传
     * @param data 上传数据 集美街道 编码:3502110100
     * @throws Exception
     */
    public HealthDeviceData uploadHealthHourseData(String data) throws Exception {
        HealthDeviceData healthDeviceData = new HealthDeviceData();
        if (StringUtils.isNoneBlank(data)){
            JSONObject jsonObject = JSON.parseObject(data);
            String deviceSn = jsonObject.getString("MachineId");
            healthDeviceData.setDeviceSn(deviceSn);
            JSONObject member = jsonObject.getJSONObject("Member");
            if(member!=null){
                String name = member.getString("Name");
                String mobile = member.getString("Mobile");
                String idcard = member.getString("IdCode");
                healthDeviceData.setName(name);
                healthDeviceData.setMobile(mobile);
                healthDeviceData.setIdcard(idcard);
            }
            healthDeviceData.setHospital("3502110100");
            healthDeviceData.setStatus(0);
            healthDeviceData.setCreateTime(new Date());
            healthDeviceData.setData(data);
            return healthDeviceDataDao.save(healthDeviceData);
        }else {
            throw new Exception("上传数据未成功");
        }
    }
    /**
     * 开元体侧设备数据上传
     * @param content 设备编码 3502030300
     * @return
     * @throws Exception
     */
    public HealthDeviceData uploadIdongDeviceData(String content,Long serNum) throws Exception {
        HealthDeviceData healthDeviceData = new HealthDeviceData();
        if (StringUtils.isNoneBlank(content)){
            JSONObject jsonObject = JSON.parseObject(content);
            String deviceSn = jsonObject.getString("serialNum");
            String userNum = jsonObject.getString("userNum");
            if (StringUtils.isNoneBlank(userNum)){
                String idcard =  DesAndSignIdongUtil.decryptUserIdNoDes(userNum);
                healthDeviceData.setIdcard(idcard);
            }
            healthDeviceData.setName(jsonObject.getString("name"));
            healthDeviceData.setMobile(jsonObject.getString("mobile"));
            healthDeviceData.setDeviceSn(deviceSn);
            healthDeviceData.setHospital("3502030300");
            healthDeviceData.setStatus(0);
            healthDeviceData.setCreateTime(new Date());
            healthDeviceData.setData(content);
            healthDeviceData.setSerNum(serNum+"");
            return healthDeviceDataDao.save(healthDeviceData);
        }else {
            throw new Exception("上传数据未空");
        }
    }
}

+ 60 - 0
svr/svr-iot/src/main/java/com/yihu/iot/datainput/util/DESUtils.java

@ -0,0 +1,60 @@
package com.yihu.iot.datainput.util;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
import java.security.SecureRandom;
public class DESUtils {
    /**
     * 加密
     * @param datasource byte[] 待加密内容
     * @param password String
     * @return byte[]
     */
    public static byte[] encrypt(byte[] datasource, String password) {
        try{
            //1. DES算法要求有一个可信任的随机数源
            SecureRandom random = new SecureRandom();
            //2. 创建一个DESKeySpec对象
            DESKeySpec desKey = new DESKeySpec(password.getBytes("utf-8"));
            //3.创建一个密匙工厂,然后用它把DESKeySpec转换成
            SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
            SecretKey securekey = keyFactory.generateSecret(desKey);
            //4.Cipher对象实际完成加密操作
            Cipher cipher = Cipher.getInstance("DES");
            //5.用密匙初始化Cipher对象
            cipher.init(Cipher.ENCRYPT_MODE, securekey, random);
            //6.正式执行加密操作
            return cipher.doFinal(datasource);
        }catch(Exception e){
            e.printStackTrace();
        }
        return null;
    }
    /**
     * 解密
     * @param src byte[]    待解密内容
     * @param password String
     * @return byte[]
     * @throws Exception
     */
    public static byte[] decrypt(byte[] src, String password) throws Exception {
        //1. DES算法要求有一个可信任的随机数源
        SecureRandom random = new SecureRandom();
        //2. 创建一个DESKeySpec对象
        DESKeySpec desKey = new DESKeySpec(password.getBytes("utf-8"));
        //3. 创建一个密匙工厂
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
        //4. 将DESKeySpec对象转换成SecretKey对象
        SecretKey securekey = keyFactory.generateSecret(desKey);
        //5. Cipher对象实际完成解密操作
        Cipher cipher = Cipher.getInstance("DES");
        //6. 用密匙初始化Cipher对象
        cipher.init(Cipher.DECRYPT_MODE, securekey, random);
        //7. 真正开始解密操作
        return cipher.doFinal(src);
    }
}

文件差异内容过多而无法显示
+ 86 - 0
svr/svr-iot/src/main/java/com/yihu/iot/datainput/util/DesAndSignIdongUtil.java


+ 39 - 0
svr/svr-iot/src/main/java/com/yihu/iot/datainput/util/MD5.java

@ -0,0 +1,39 @@
package com.yihu.iot.datainput.util;
import java.security.MessageDigest;
public class MD5 {
    /**
     * 将源字符串通过MD5加密成32位16进制数
     *
     * @param str
     * @return
     */
    public static String toDigest(String str) {
        try {
            //将源字符串通过MD5进行加密为字节数组
            MessageDigest alga = MessageDigest.getInstance("MD5");
            alga.update(str.getBytes("UTF-8"));
            byte[] digesta = alga.digest();
            return byte2hex(digesta);
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }
    public static String byte2hex(byte[] b) {
        String hs = "";
        String stmp = "";
        for (int n = 0; n < b.length; n++) {
            stmp = (Integer.toHexString(b[n] & 0XFF));
            if (stmp.length() == 1)
                hs = hs + "0" + stmp;
            else
                hs = hs + stmp;
            if (n < b.length - 1)
                hs = hs + "";
        }
        return hs;
    }
}