Browse Source

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

wangzhinan 1 year ago
parent
commit
8a026d8b23

+ 50 - 2
svr/svr-iot/src/main/java/com/yihu/iot/controller/third/ThirdDataInputController.java

@ -16,17 +16,22 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.net.URLDecoder;
@RestController
//@RequestMapping(IotRequestMapping.Common.openThird)
@RequestMapping("open")
@RequestMapping(IotRequestMapping.Common.openThird)
//@RequestMapping("open")
@Api(tags = "开放接口-数据上传操作", description = "开放接口-数据上传操作")
public class ThirdDataInputController {
    private static final Logger logger = LoggerFactory.getLogger(ThirdDataInputController.class);
    @Autowired
    private DataInputService dataInputService;
    @Autowired
@ -54,6 +59,16 @@ public class ThirdDataInputController {
    public Envelop deviceRegistration(@ApiParam(name = "jsonData", value = "", defaultValue = "")
                                      @RequestBody String jsonData){
        try{
            if(StringUtils.isNotBlank(jsonData)){
                jsonData = jsonData.replace("jsonData=","");
                if(jsonData.indexOf("&accesstoken")>0){
                    jsonData = jsonData.substring(0,jsonData.indexOf("&accesstoken"));
                }
                String decodedString = URLDecoder.decode(jsonData, "UTF-8");
                if (!decodedString.equals(jsonData)) {
                    jsonData = decodedString;
                }
            }
            dataInputService.deviceRegistration(jsonData);
            return Envelop.getSuccess("设备注册成功");
        } catch (ServiceException e){
@ -69,6 +84,16 @@ public class ThirdDataInputController {
    public Envelop uploadDeviceData(@ApiParam(name = "jsonData", value = "", defaultValue = "")
                                    @RequestBody String jsonData){
        try{
            if(StringUtils.isNotBlank(jsonData)){
                jsonData = jsonData.replace("jsonData=","");
                if(jsonData.indexOf("&accesstoken")>0){
                    jsonData = jsonData.substring(0,jsonData.indexOf("&accesstoken"));
                }
                String decodedString = URLDecoder.decode(jsonData, "UTF-8");
                if (!decodedString.equals(jsonData)) {
                    jsonData = decodedString;
                }
            }
            return Envelop.getSuccess(dataInputService.uploadDeviceData(jsonData));
        } catch (ServiceException e){
            return Envelop.getError(e.getMessage());
@ -78,6 +103,29 @@ public class ThirdDataInputController {
        }
    }
    @PostMapping(value = "uploadDeviceInfo")
    @ApiOperation(value = "设备状态信息上传", notes = "设备状态信息上传")
    public Envelop uploadDeviceInfo(@ApiParam(name = "jsonData", value = "", defaultValue = "")
                                    @RequestBody String jsonData){
        try{
            if(StringUtils.isNotBlank(jsonData)){
                jsonData = jsonData.replace("jsonData=","");
                if(jsonData.indexOf("&accesstoken")>0){
                    jsonData = jsonData.substring(0,jsonData.indexOf("&accesstoken"));
                }
                String decodedString = URLDecoder.decode(jsonData, "UTF-8");
                if (!decodedString.equals(jsonData)) {
                    jsonData = decodedString;
                }
            }
            return Envelop.getSuccess(dataInputService.uploadDeviceInfo(jsonData));
        } catch (ServiceException e){
            return Envelop.getError(e.getMessage());
        } catch (Exception e){
            e.printStackTrace();
            return Envelop.getError("上传设备失败");
        }
    }
    /************************************************************************/

+ 37 - 6
svr/svr-iot/src/main/java/com/yihu/iot/datainput/service/DataInputService.java

@ -97,19 +97,19 @@ public class DataInputService {
        if(StringUtils.isBlank(categoryName)){
            throw new ServiceException("设备类型名称不能为空");
        }
        int count = iotDeviceService.countByDeviceSn(deviceSn);
        if(count > 0){
            throw new ServiceException("设备唯一码已存在,请检查是否已经上传过,或者换一个编码");
        }
        String result = "";
        try {
            IotDeviceDO iotDeviceDO = new IotDeviceDO();
            IotDeviceDO iotDeviceDO = iotDeviceService.findByDeviceSn(deviceSn);
            if(iotDeviceDO==null){
                iotDeviceDO = new IotDeviceDO();
                iotDeviceDO.setCreateTime(new Date());
            }
            iotDeviceDO.setDeviceSn(deviceSn);
            iotDeviceDO.setCategoryCode(categoryCode);
            iotDeviceDO.setCategoryName(categoryName);
            iotDeviceDO.setDel(1);
            iotDeviceDO.setStatus("1");
            iotDeviceDO.setCreateTime(new Date());
            iotDeviceDO.setUpdateTime(new Date());
            iotDeviceDO.setDeviceSource("4");
            iotDeviceDO.setHospital(hospital);
            iotDeviceDO.setHospitalName(hospitalName);
@ -120,6 +120,37 @@ public class DataInputService {
        return result;
    }
    //{ “deviceSn”:” 设备唯一
    //码”,“name”:” 设备名称”,
    //"networkStatus ":” 网 络
    //状态”,
    //"powerStatus ":”电源状
    //态”,“faultStatus”:”故障状
    //态”
    //}
    /**
     * 设备状态信息上传
     */
    public String uploadDeviceInfo(String json){
        JSONObject jsonObject = JSONObject.parseObject(json);
        String deviceSn = jsonObject.getString("deviceSn");
        try {
            IotDeviceUploadRecordDO recordDO = new IotDeviceUploadRecordDO();
            recordDO.setDeviceSn(deviceSn);
            recordDO.setJsonData(json);
            recordDO.setCategoryCode("uploadDeviceInfo");
            recordDO.setStatus(0);
            recordDO.setCreateTime(new Date());
            iotDeviceUploadRecordDao.save(recordDO);
        }catch (Exception e){
            e.printStackTrace();
            logger.error("设备状态信息上传失败");
            //保存日志
            return "fail";
        }
        return "success";
    }
    /**
     * 上传设备数据
     */