Kaynağa Gözat

Merge branch 'dev' of http://192.168.1.220:10080/jiwei/jw2.0 into dev

Conflicts:
	app/app-iot-server/pom.xml
yeshijie 7 yıl önce
ebeveyn
işleme
6ed55ce9e6
37 değiştirilmiş dosya ile 1836 ekleme ve 285 silme
  1. 10 0
      app/app-iot-server/pom.xml
  2. 9 0
      app/app-iot-server/readme.MD
  3. 2 0
      app/app-iot-server/src/main/java/com/yihu/ehr/iot/AppIotServer.java
  4. 8 4
      app/app-iot-server/src/main/java/com/yihu/ehr/iot/config/SwaggerConfig.java
  5. 2 1
      app/app-iot-server/src/main/java/com/yihu/ehr/iot/constant/ServiceApi.java
  6. 176 0
      app/app-iot-server/src/main/java/com/yihu/ehr/iot/controller/common/FileUploadController.java
  7. 35 0
      app/app-iot-server/src/main/java/com/yihu/ehr/iot/controller/common/IotSystemDictController.java
  8. 120 135
      app/app-iot-server/src/main/java/com/yihu/ehr/iot/controller/company/IotCompanyController.java
  9. 154 0
      app/app-iot-server/src/main/java/com/yihu/ehr/iot/controller/device/IotDeviceController.java
  10. 121 0
      app/app-iot-server/src/main/java/com/yihu/ehr/iot/controller/device/IotDeviceOrderController.java
  11. 124 0
      app/app-iot-server/src/main/java/com/yihu/ehr/iot/controller/product/IotProductController.java
  12. 9 9
      app/app-iot-server/src/main/java/com/yihu/ehr/iot/interceptor/LoginInterceptor.java
  13. 79 0
      app/app-iot-server/src/main/java/com/yihu/ehr/iot/service/common/FileUploadService.java
  14. 34 0
      app/app-iot-server/src/main/java/com/yihu/ehr/iot/service/common/SystemDictService.java
  15. 133 1
      app/app-iot-server/src/main/java/com/yihu/ehr/iot/service/company/CompanyService.java
  16. 117 0
      app/app-iot-server/src/main/java/com/yihu/ehr/iot/service/device/DeviceOrderService.java
  17. 212 0
      app/app-iot-server/src/main/java/com/yihu/ehr/iot/service/device/DeviceService.java
  18. 123 0
      app/app-iot-server/src/main/java/com/yihu/ehr/iot/service/product/ProductService.java
  19. 70 0
      app/app-iot-server/src/main/java/com/yihu/ehr/iot/util/excel/AExcelReader.java
  20. 33 0
      app/app-iot-server/src/main/java/com/yihu/ehr/iot/util/excel/reader/IotDeviceImportVOReader.java
  21. 20 0
      app/app-iot-server/src/main/java/com/yihu/ehr/iot/util/http/HttpClientUtil.java
  22. 39 0
      app/app-iot-server/src/main/java/com/yihu/ehr/iot/util/http/HttpHelper.java
  23. 19 50
      app/app-iot-server/src/main/resources/application.yml
  24. 1 0
      common/common-request-mapping/src/main/java/com/yihu/jw/rm/iot/IotRequestMapping.java
  25. 1 1
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/common/ExistVO.java
  26. 46 0
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/device/IotDeviceImportVO.java
  27. 2 1
      svr/svr-iot/src/main/java/com/yihu/iot/controller/common/FileUploadController.java
  28. 1 1
      svr/svr-iot/src/main/java/com/yihu/iot/controller/company/IotCompanyController.java
  29. 31 38
      svr/svr-iot/src/main/java/com/yihu/iot/controller/device/IotDeviceController.java
  30. 1 1
      svr/svr-iot/src/main/java/com/yihu/iot/controller/device/IotDeviceOrderController.java
  31. 72 22
      svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotDeviceImportRecordService.java
  32. 3 3
      svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotDeviceService.java
  33. 1 1
      web-gateway/src/main/java/com/yihu/jw/controller/iot/company/IotCompanyController.java
  34. 12 7
      web-gateway/src/main/java/com/yihu/jw/controller/iot/device/IotDeviceController.java
  35. 1 1
      web-gateway/src/main/java/com/yihu/jw/controller/iot/device/IotDeviceOrderController.java
  36. 11 4
      web-gateway/src/main/java/com/yihu/jw/feign/fallbackfactory/iot/device/IotDeviceFallbackFactory.java
  37. 4 5
      web-gateway/src/main/java/com/yihu/jw/feign/iot/device/IotDeviceFeign.java

+ 10 - 0
app/app-iot-server/pom.xml

@ -185,6 +185,11 @@
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>
        <dependency>
            <groupId>net.sourceforge.jexcelapi</groupId>
            <artifactId>jxl</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>com.yihu.ehr</groupId>
@ -222,6 +227,11 @@
            <artifactId>common-rest-model</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.yihu.base</groupId>
            <artifactId>common-data-fastdfs</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>

+ 9 - 0
app/app-iot-server/readme.MD

@ -0,0 +1,9 @@
文件上传:
    ehr的处理:
        1、图片上传是把图片转成base64位,在到微服务处理的把base64字符串转成图片
        2、excel导入,在总支撑品台解析成要导入的对象的json传在传到微服务
    物联网:
        参照ehr,图片上传直接在和前端对接的项目中处理,直接把url传到微服务,微服务直接保存。
        

+ 2 - 0
app/app-iot-server/src/main/java/com/yihu/ehr/iot/AppIotServer.java

@ -10,6 +10,7 @@ import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfigurat
import org.springframework.boot.autoconfigure.security.SecurityAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@EnableAutoConfiguration(exclude = {
@ -18,6 +19,7 @@ import org.springframework.boot.context.web.SpringBootServletInitializer;
        DataSourceAutoConfiguration.class,
        HibernateJpaAutoConfiguration.class,
        DataSourceTransactionManagerAutoConfiguration.class})
@ComponentScan(basePackages={"com.yihu.base","com.yihu.ehr.iot"})
public class AppIotServer extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {

+ 8 - 4
app/app-iot-server/src/main/java/com/yihu/ehr/iot/config/SwaggerConfig.java

@ -4,7 +4,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
@ -16,9 +15,14 @@ public class SwaggerConfig {
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo())
                .select().apis(RequestHandlerSelectors.basePackage("com.yihu.ehr.eme.controller")).paths(PathSelectors.any())
                .build();
        return new Docket(DocumentationType.SWAGGER_2)
                .useDefaultResponseMessages(false)
                .forCodeGeneration(false)
                .pathMapping("/")
                .select()
                .paths(PathSelectors.any())
                .build()
                .apiInfo(apiInfo());
    }
    private ApiInfo apiInfo() {

+ 2 - 1
app/app-iot-server/src/main/java/com/yihu/ehr/iot/constant/ServiceApi.java

@ -54,7 +54,7 @@ public class ServiceApi {
    }
    public static class Device{
        public static final String Base = "wg/product/";
        public static final String Base = "wg/device/";
        public static final String CreateDevice = Base +"createDevice";
        public static final String GetDeviceById = Base +"getDeviceById";
        public static final String QueryDevicePage = Base +"queryDevicePage";
@ -63,6 +63,7 @@ public class ServiceApi {
        public static final String IsSnExist = Base +"isSnExist";
        public static final String IsSimExist = Base +"isSimExist";
        public static final String ImportDevice = Base +"importDevice";
        public static final String IsImportDevice = Base +"isImportDevice";
        public static final String QueryImportRecordPage = Base +"queryImportRecordPage";

+ 176 - 0
app/app-iot-server/src/main/java/com/yihu/ehr/iot/controller/common/FileUploadController.java

@ -0,0 +1,176 @@
package com.yihu.ehr.iot.controller.common;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.base.fastdfs.FastDFSHelper;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.exception.code.ExceptionCode;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.iot.common.UploadVO;
import com.yihu.jw.rm.iot.IotRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.net.URLDecoder;
import java.util.Base64;
/**
 * @author yeshijie on 2017/12/7.
 */
@RestController
@RequestMapping(IotRequestMapping.Common.file_upload)
@Api(tags = "文件上传相关操作", description = "文件上传相关操作")
public class FileUploadController extends BaseController {
    @Autowired
    private FastDFSHelper fastDFSHelper;
    @Value("${fast-dfs.public-server}")
    private String fastdfs_file_url;
    @PostMapping(value = IotRequestMapping.FileUpload.api_upload_stream_img)
    @ApiOperation(value = "文件流上传图片", notes = "文件流上传图片")
    public Envelop<UploadVO> uploadImg(@ApiParam(value = "文件", required = true)
                                       @RequestParam(value = "file", required = true) MultipartFile file){
        try {
            // 得到文件的完整名称  xxx.txt
            String fullName = file.getOriginalFilename();
            if(StringUtils.isBlank(fullName)){
                return Envelop.getError(IotRequestMapping.FileUpload.message_fail_upload_format,IotRequestMapping.api_iot_fail);
            }
            //得到文件类型
            String fileType = fullName.substring(fullName.lastIndexOf(".") + 1).toLowerCase();
            if(StringUtils.isBlank(fileType)||!"jpg,jpeg,png".contains(fileType)){
                return Envelop.getError(IotRequestMapping.FileUpload.message_fail_upload_format,IotRequestMapping.api_iot_fail);
            }
            long size = file.getSize();
            long max = 5*1024*1024;
            if(size>max){
                return Envelop.getError("文件大小不超过5M",IotRequestMapping.api_iot_fail);
            }
            String fileName = fullName.substring(0, fullName.lastIndexOf("."));
            //上传到fastdfs
            ObjectNode objectNode = fastDFSHelper.upload(file.getInputStream(), fileType, "");
            //解析返回的objectNode
            UploadVO uploadVO = new UploadVO();
            uploadVO.setFileName(fileName);
            uploadVO.setFileType(fileType);
            uploadVO.setFullUri(objectNode.get("fid").toString().replaceAll("\"", ""));
            uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fid").toString().replaceAll("\"", ""));
            return Envelop.getSuccess(IotRequestMapping.Common.message_success_create, uploadVO);
        }catch (Exception e){
            e.printStackTrace();
            return Envelop.getError(IotRequestMapping.FileUpload.message_fail_upload, IotRequestMapping.api_iot_fail);
        }
    }
    @PostMapping(value = IotRequestMapping.FileUpload.api_upload_stream_attachment)
    @ApiOperation(value = "文件流上传附件", notes = "文件流上传附件")
    public Envelop<UploadVO> uploadAttachment(@ApiParam(value = "文件", required = true)
                                              @RequestParam(value = "file", required = true) MultipartFile file){
        try {
            // 得到文件的完整名称  xxx.txt
            String fullName = file.getOriginalFilename();
            if(StringUtils.isBlank(fullName)){
                return Envelop.getError(IotRequestMapping.FileUpload.message_fail_upload_format,IotRequestMapping.api_iot_fail);
            }
            //得到文件类型
            String fileType = fullName.substring(fullName.lastIndexOf(".") + 1).toLowerCase();
            if(StringUtils.isBlank(fileType)||!"doc、docx、pdf、xls、xlsx、jpg、jpeg、png".contains(fileType)){
                return Envelop.getError(IotRequestMapping.FileUpload.message_fail_upload_format,IotRequestMapping.api_iot_fail);
            }
            long size = file.getSize();
            long max = 5*1024*1024;
            if(size>max){
                return Envelop.getError("文件大小不超过5M",IotRequestMapping.api_iot_fail);
            }
            String fileName = fullName.substring(0, fullName.lastIndexOf("."));
            //上传到fastdfs
            ObjectNode objectNode = fastDFSHelper.upload(file.getInputStream(), fileType, "");
            //解析返回的objectNode
            UploadVO uploadVO = new UploadVO();
            uploadVO.setFileName(fileName);
            uploadVO.setFileType(fileType);
            uploadVO.setFullUri(objectNode.get("fid").toString().replaceAll("\"", ""));
            uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fid").toString().replaceAll("\"", ""));
            return Envelop.getSuccess(IotRequestMapping.Common.message_success_create, uploadVO);
        }catch (Exception e){
            e.printStackTrace();
            return Envelop.getError(IotRequestMapping.FileUpload.message_fail_upload, IotRequestMapping.api_iot_fail);
        }
    }
    @PostMapping(value = IotRequestMapping.FileUpload.api_upload_stream)
    @ApiOperation(value = "文件流上传文件", notes = "文件流上传文件")
    public Envelop<UploadVO> uploadStream(@ApiParam(value = "文件", required = true) @RequestParam(value = "file", required = true) MultipartFile file) {
        try {
            // 得到文件的完整名称  xxx.txt
            String fullName = file.getOriginalFilename();
            //得到文件类型
            String fileType = fullName.substring(fullName.lastIndexOf(".") + 1).toLowerCase();
            String fileName = fullName.substring(0, fullName.lastIndexOf("."));
            //上传到fastdfs
            ObjectNode objectNode = fastDFSHelper.upload(file.getInputStream(), fileType, "");
            //解析返回的objectNode
            UploadVO uploadVO = new UploadVO();
            uploadVO.setFileName(fileName);
            uploadVO.setFileType(fileType);
            uploadVO.setFullUri(objectNode.get("fid").toString().replaceAll("\"", ""));
            uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fid").toString().replaceAll("\"", ""));
            return Envelop.getSuccess(IotRequestMapping.Common.message_success_create, uploadVO);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(IotRequestMapping.FileUpload.message_fail_upload, IotRequestMapping.api_iot_fail);
        }
    }
    @PostMapping(value = IotRequestMapping.FileUpload.api_upload_string)
    @ApiOperation(value = "base64上传图片",notes = "base64上传图片")
    public Envelop<UploadVO> uploadImages(@ApiParam(name = "jsonData", value = "头像转化后的输入流") @RequestBody String jsonData) throws Exception {
        try {
            if(jsonData == null){
                return Envelop.getError(IotRequestMapping.FileUpload.message_fail_jsonData_is_null, ExceptionCode.common_error_params_code);
            }
            String date = URLDecoder.decode(jsonData,"UTF-8");
            String[] fileStreams = date.split(",");
            String is = URLDecoder.decode(fileStreams[1],"UTF-8").replace(" ","+");
            byte[] in = Base64.getDecoder().decode(is);
            String pictureName = fileStreams[0].substring(0,fileStreams[0].length()-1);
            String fileExtension = pictureName.substring(pictureName.lastIndexOf(".") + 1).toLowerCase();
            String description = null;
            if ((pictureName != null) && (pictureName.length() > 0)) {
                int dot = pictureName.lastIndexOf('.');
                if ((dot > -1) && (dot < (pictureName.length()))) {
                    description = pictureName.substring(0, dot);
                }
            }
            InputStream inputStream = new ByteArrayInputStream(in);
            ObjectNode objectNode = fastDFSHelper.upload(inputStream, "png", "");
            String groupName = objectNode.get("groupName").toString();
            String remoteFileName = objectNode.get("remoteFileName").toString();
            //解析返回的objectNode
            UploadVO uploadVO = new UploadVO();
            uploadVO.setFileName(remoteFileName);
            uploadVO.setFileType(groupName);
            uploadVO.setFullUri(objectNode.get("fid").toString().replaceAll("\"", ""));
            uploadVO.setFullUrl(fastdfs_file_url + objectNode.get("fid").toString().replaceAll("\"", ""));
            //返回文件路径
            return Envelop.getSuccess(IotRequestMapping.FileUpload.message_success_upload, uploadVO);
        }catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
}

+ 35 - 0
app/app-iot-server/src/main/java/com/yihu/ehr/iot/controller/common/IotSystemDictController.java

@ -0,0 +1,35 @@
package com.yihu.ehr.iot.controller.common;
import com.yihu.ehr.iot.service.common.SystemDictService;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.iot.dict.IotSystemDictVO;
import com.yihu.jw.rm.iot.IotRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
/**
 * @author yeshijie on 2018/1/16.
 */
@RestController
@RequestMapping(IotRequestMapping.Common.system_dict)
@Api(tags = "系统字典相关操作", description = "系统字典相关操作")
public class IotSystemDictController  extends BaseController{
    @Autowired
    private SystemDictService systemDictService;
    @GetMapping(value = IotRequestMapping.System.findDictByCode)
    @ApiOperation(value = "获取字典列表(不分页)")
    public Envelop<IotSystemDictVO> getList(
            @ApiParam(name = "dictName", value = "字典名称", defaultValue = "COMPANY_TYPE")
            @RequestParam(value = "dictName", required = true) String dictName) throws Exception {
        return systemDictService.getList(dictName);
    }
}

+ 120 - 135
app/app-iot-server/src/main/java/com/yihu/ehr/iot/controller/company/IotCompanyController.java

@ -3,16 +3,14 @@ package com.yihu.ehr.iot.controller.company;
import com.yihu.ehr.iot.controller.common.BaseController;
import com.yihu.ehr.iot.service.company.CompanyService;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.iot.company.IotCompanyCertificateVO;
import com.yihu.jw.restmodel.iot.company.IotCompanyVO;
import com.yihu.jw.rm.iot.IotRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
/**
 * @author yeshijie on 2018/1/16.
@ -45,136 +43,123 @@ public class IotCompanyController extends BaseController {
        }
    }
//    @PostMapping(value = IotRequestMapping.Company.addCompany)
//    @ApiOperation(value = "创建企业", notes = "创建企业")
//    public Envelop<IotCompanyVO> addCompany(@ApiParam(name = "jsonData", value = "json", defaultValue = "")
//                                            @RequestParam(value = "jsonData", required = false)String jsonData) {
//        try {
//            IotCompanyDO iotCompany = toEntity(jsonData, IotCompanyDO.class);
//            return Envelop.getSuccess(IotRequestMapping.Company.message_success_create, iotCompanyService.create(iotCompany));
//        } catch (Exception e) {
//            e.printStackTrace();
//            return Envelop.getError(e.getMessage());
//        }
//    }
//
//    @GetMapping(value = IotRequestMapping.Company.findCompanyById)
//    @ApiOperation(value = "根据id查找企业", notes = "根据id查找企业")
//    public Envelop<IotCompanyVO> findByCode(@ApiParam(name = "id", value = "id")
//                                            @RequestParam(value = "id", required = true) String id) {
//        try {
//            IotCompanyDO iotCompanyDO = iotCompanyService.findById(id);
//            IotCompanyVO vo = iotCompanyService.convertToModelVO(iotCompanyDO);
//            return Envelop.getSuccess(IotRequestMapping.Company.message_success_find, vo);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return Envelop.getError(e.getMessage());
//        }
//    }
//
//    @GetMapping(value = IotRequestMapping.Company.findByBusinessLicense)
//    @ApiOperation(value = "根据营业执照号查找企业", notes = "根据营业执照号查找企业")
//    public Envelop<IotCompanyVO> findByBusinessLicense(@ApiParam(name = "businessLicense", value = "businessLicense")
//                                                       @RequestParam(value = "businessLicense", required = true) String businessLicense) {
//        try {
//            IotCompanyDO iotCompanyDO = iotCompanyService.findByBusinessLicense(businessLicense);
//            IotCompanyVO vo = iotCompanyService.convertToModelVO(iotCompanyDO);
//            return Envelop.getSuccess(IotRequestMapping.Company.message_success_find, vo);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return Envelop.getError(e.getMessage());
//        }
//    }
//
//    @PostMapping(value = IotRequestMapping.Company.delCompany)
//    @ApiOperation(value = "删除企业", notes = "删除企业")
//    public Envelop<IotCompanyVO> delCompany(@ApiParam(name = "id", value = "id")
//                                            @RequestParam(value = "id", required = true) String id) {
//        try {
//            iotCompanyService.delCompany(id);
//            return Envelop.getSuccess(IotRequestMapping.Company.message_success_find);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return Envelop.getError(e.getMessage());
//        }
//    }
//
//    @PostMapping(value = IotRequestMapping.Company.updCompany)
//    @ApiOperation(value = "修改企业信息", notes = "修改企业信息")
//    public Envelop<IotCompanyVO> updCompany(@ApiParam(name = "jsonData", value = "json", defaultValue = "")
//                                            @RequestParam(value = "jsonData", required = false)String jsonData) {
//        try {
//            IotCompanyDO iotCompany = toEntity(jsonData, IotCompanyDO.class);
//            iotCompanyService.updCompany(iotCompany);
//            return Envelop.getSuccess(IotRequestMapping.Company.message_success_find);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return Envelop.getError(e.getMessage());
//        }
//    }
//
//    @PostMapping(value = IotRequestMapping.Company.findCompanyCertPage)
//    @ApiOperation(value = "分页获取企业证书", notes = "分页获取企业证书")
//    public Envelop<IotCompanyCertificateVO> findCompanyCertPage
//            (@ApiParam(name = "name", value = "证书名称", defaultValue = "")
//             @RequestParam(value = "name", required = false) String name,
//             @ApiParam(name = "page", value = "第几页", defaultValue = "")
//             @RequestParam(value = "page", required = false) Integer page,
//             @ApiParam(name = "size", value = "每页记录数", defaultValue = "")
//             @RequestParam(value = "size", required = false) Integer size){
//        try {
//            if(page == null|| page < 0){
//                page = 1;
//            }
//            if(size == null){
//                size = 10;
//            }
//            return iotCompanyCertificateService.queryPage(page,size,name);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return Envelop.getError(e.getMessage());
//        }
//    }
//
//    @GetMapping(value = IotRequestMapping.Company.findCompanyCertById)
//    @ApiOperation(value = "根据id查找企业证书", notes = "根据id查找企业证书")
//    public Envelop<IotCompanyCertificateVO> findCompanyCertById(@ApiParam(name = "id", value = "id")
//                                                                @RequestParam(value = "id", required = true) String id) {
//        try {
//            IotCompanyCertificateDO iotCompanyCertificateDO = iotCompanyCertificateService.findById(id);
//            IotCompanyCertificateVO vo = convertToModel(iotCompanyCertificateDO,IotCompanyCertificateVO.class);
//            return Envelop.getSuccess(IotRequestMapping.Common.message_success_find, vo);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return Envelop.getError(e.getMessage());
//        }
//    }
//
//    @GetMapping(value = IotRequestMapping.Company.findCompanyCertByCompanyId)
//    @ApiOperation(value = "根据企业id查找企业证书", notes = "根据企业id查找企业证书")
//    public Envelop<IotCompanyCertificateVO> findCompanyCertByCompanyId(@ApiParam(name = "companyId", value = "companyId")
//                                                                       @RequestParam(value = "companyId", required = true) String companyId) {
//        try {
//            List<IotCompanyCertificateDO> iotCompanyCertificateDOList = iotCompanyCertificateService.findByCompanyId(companyId);
//            List<IotCompanyCertificateVO> voList = convertToModels(iotCompanyCertificateDOList,new ArrayList<>(iotCompanyCertificateDOList.size()),IotCompanyCertificateVO.class);
//            return Envelop.getSuccessList(IotRequestMapping.Common.message_success_find, voList);
//        } catch (Exception e) {
//            e.printStackTrace();
//            return Envelop.getError(e.getMessage());
//        }
//    }
//
//    @PostMapping(value = IotRequestMapping.Company.addCompanyCert)
//    @ApiOperation(value = "创建企业证书", notes = "创建企业证书")
//    public Envelop<IotCompanyCertificateVO> addCompanyCert(@ApiParam(name = "jsonData", value = "json", defaultValue = "")
//                                                           @RequestParam(value = "jsonData", required = false)String jsonData) {
//        try {
//            IotCompanyCertificateDO iotCompanyCertificate = toEntity(jsonData, IotCompanyCertificateDO.class);
//            return Envelop.getSuccess(IotRequestMapping.Common.message_success_create, iotCompanyCertificateService.create(iotCompanyCertificate));
//        } catch (Exception e) {
//            e.printStackTrace();
//            return Envelop.getError(e.getMessage());
//        }
//    }
    @PostMapping(value = IotRequestMapping.Company.addCompany)
    @ApiOperation(value = "创建企业", notes = "创建企业")
    public Envelop<IotCompanyVO> addCompany(@ApiParam(name = "jsonData", value = "json", defaultValue = "")
                                            @RequestParam(value = "jsonData", required = false)String jsonData) {
        try {
            return companyService.addCompany(jsonData);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.Company.findCompanyById)
    @ApiOperation(value = "根据id查找企业", notes = "根据id查找企业")
    public Envelop<IotCompanyVO> findByCode(@ApiParam(name = "id", value = "id")
                                            @RequestParam(value = "id", required = true) String id) {
        try {
            return companyService.findByCode(id);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.Company.findByBusinessLicense)
    @ApiOperation(value = "根据营业执照号查找企业", notes = "根据营业执照号查找企业")
    public Envelop<IotCompanyVO> findByBusinessLicense(@ApiParam(name = "businessLicense", value = "businessLicense")
                                                       @RequestParam(value = "businessLicense", required = true) String businessLicense) {
        try {
            return companyService.findByBusinessLicense(businessLicense);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.Company.delCompany)
    @ApiOperation(value = "删除企业", notes = "删除企业")
    public Envelop<IotCompanyVO> delCompany(@ApiParam(name = "id", value = "id")
                                            @RequestParam(value = "id", required = true) String id) {
        try {
            return companyService.delCompany(id);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.Company.updCompany)
    @ApiOperation(value = "修改企业信息", notes = "修改企业信息")
    public Envelop<IotCompanyVO> updCompany(@ApiParam(name = "jsonData", value = "json", defaultValue = "")
                                            @RequestParam(value = "jsonData", required = false)String jsonData) {
        try {
            return companyService.updCompany(jsonData);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.Company.findCompanyCertPage)
    @ApiOperation(value = "分页获取企业证书", notes = "分页获取企业证书")
    public Envelop<IotCompanyCertificateVO> findCompanyCertPage
            (@ApiParam(name = "name", value = "证书名称", defaultValue = "")
             @RequestParam(value = "name", required = false) String name,
             @ApiParam(name = "page", value = "第几页", defaultValue = "")
             @RequestParam(value = "page", required = false) Integer page,
             @ApiParam(name = "size", value = "每页记录数", defaultValue = "")
             @RequestParam(value = "size", required = false) Integer size){
        try {
            if(page == null|| page < 0){
                page = 1;
            }
            if(size == null){
                size = 10;
            }
            return companyService.findCompanyCertPage(name,page,size);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.Company.findCompanyCertById)
    @ApiOperation(value = "根据id查找企业证书", notes = "根据id查找企业证书")
    public Envelop<IotCompanyCertificateVO> findCompanyCertById(@ApiParam(name = "id", value = "id")
                                                                @RequestParam(value = "id", required = true) String id) {
        try {
            return companyService.findCompanyCertById(id);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.Company.findCompanyCertByCompanyId)
    @ApiOperation(value = "根据企业id查找企业证书", notes = "根据企业id查找企业证书")
    public Envelop<IotCompanyCertificateVO> findCompanyCertByCompanyId(@ApiParam(name = "companyId", value = "companyId")
                                                                       @RequestParam(value = "companyId", required = true) String companyId) {
        try {
            return companyService.findCompanyCertByCompanyId(companyId);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.Company.addCompanyCert)
    @ApiOperation(value = "创建企业证书", notes = "创建企业证书")
    public Envelop<IotCompanyCertificateVO> addCompanyCert(@ApiParam(name = "jsonData", value = "json", defaultValue = "")
                                                           @RequestParam(value = "jsonData", required = false)String jsonData) {
        try {
            return companyService.addCompanyCert(jsonData);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
}

+ 154 - 0
app/app-iot-server/src/main/java/com/yihu/ehr/iot/controller/device/IotDeviceController.java

@ -0,0 +1,154 @@
package com.yihu.ehr.iot.controller.device;
import com.yihu.ehr.iot.controller.common.BaseController;
import com.yihu.ehr.iot.service.device.DeviceService;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.iot.common.ExistVO;
import com.yihu.jw.restmodel.iot.device.IotDeviceImportRecordVO;
import com.yihu.jw.restmodel.iot.device.IotDeviceVO;
import com.yihu.jw.rm.iot.IotRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
/**
 * @author yeshijie on 2017/12/8.
 */
@RestController
@RequestMapping(IotRequestMapping.Common.device)
@Api(tags = "设备管理相关操作", description = "设备管理相关操作")
public class IotDeviceController extends BaseController{
    @Autowired
    private DeviceService deviceService;
    @PostMapping(value = IotRequestMapping.Device.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建设备", notes = "创建设备")
    public Envelop<IotDeviceVO> create(@ApiParam(name = "json_data", value = "", defaultValue = "")
                          @RequestParam String jsonData) {
        try {
            return deviceService.create(jsonData);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.Device.api_getById)
    @ApiOperation(value = "根据code查找设备", notes = "根据code查找设备")
    public Envelop<IotDeviceVO> findByCode(@ApiParam(name = "id", value = "id")
                              @RequestParam(value = "id", required = true) String id ) {
        try {
            return deviceService.findByCode(id);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.Device.isSnExist)
    @ApiOperation(value = "sn码是否存在", notes = "sn码是否存在")
    public Envelop<ExistVO> isSnExist(@ApiParam(name = "sn", value = "sn")
                                      @RequestParam(value = "sn", required = true) String sn) {
        try {
            return deviceService.isSnExist(sn);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.Device.isSimExist)
    @ApiOperation(value = "sim卡号是否存在", notes = "sim卡号是否存在")
    public Envelop<ExistVO> isSimExist(@ApiParam(name = "sim", value = "sim")
                                           @RequestParam(value = "sim", required = true) String sim) {
        try {
            return deviceService.isSimExist(sim);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.Device.api_queryPage)
    @ApiOperation(value = "分页查找设备", notes = "分页查找设备")
    public Envelop<IotDeviceVO> findProductPageByCompanyId(@ApiParam(name = "sn", value = "SN码或SIM卡号", defaultValue = "")
                                                           @RequestParam(value = "sn", required = false) String sn,
                                                           @ApiParam(name = "hospital", value = "社区医院", defaultValue = "")
                                                           @RequestParam(value = "hospital", required = false) String hospital,
                                                           @ApiParam(name = "orderId", value = "订单id", defaultValue = "")
                                                           @RequestParam(value = "orderId", required = false) String orderId,
                                                           @ApiParam(name = "purcharseId", value = "采购id", defaultValue = "")
                                                           @RequestParam(value = "purcharseId", required = true) String purcharseId,
                                                           @ApiParam(name = "page", value = "第几页", defaultValue = "")
                                                           @RequestParam(value = "page", required = false) Integer page,
                                                           @ApiParam(name = "size", value = "每页记录数", defaultValue = "")
                                                           @RequestParam(value = "size", required = false) Integer size){
        try {
            if(page == null|| page < 0){
                page = 1;
            }
            if(size == null){
                size = 10;
            }
            return deviceService.findProductPageByCompanyId(sn,hospital,orderId,purcharseId,page,size);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.Device.isImportDevice)
    @ApiOperation(value = "是否正在导入设备数据", notes = "是否正在导入设备数据")
    public Envelop<ExistVO> isImportDevice(@ApiParam(name = "purcharseId", value = "purcharseId")
                                           @RequestParam(value = "purcharseId", required = true) String purcharseId
    ) {
        try {
            return deviceService.isImportDevice(purcharseId);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(IotRequestMapping.FileUpload.message_fail_upload, IotRequestMapping.api_iot_fail);
        }
    }
    @PostMapping(value = IotRequestMapping.Device.importDevice)
    @ApiOperation(value = "设备导入", notes = "设备导入")
    public Envelop<IotDeviceImportRecordVO> uploadStream(@ApiParam(value = "文件", required = true)
                                          @RequestParam(value = "file", required = true) MultipartFile file,
                                          @ApiParam(name = "purcharseId", value = "采购id", defaultValue = "")
                                          @RequestParam(value = "purcharseId", required = true) String purcharseId) {
        try {
            return deviceService.uploadStream(file,purcharseId);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(IotRequestMapping.FileUpload.message_fail_upload, IotRequestMapping.api_iot_fail);
        }
    }
    @GetMapping(value = IotRequestMapping.Device.queryImportRecordPage)
    @ApiOperation(value = "分页查找导入记录", notes = "分页查找导入记录")
    public Envelop<IotDeviceImportRecordVO> queryImportRecordPage(@ApiParam(name = "purcharseId", value = "采购id", defaultValue = "")
                                                           @RequestParam(value = "purcharseId", required = true) String purcharseId,
                                                                       @ApiParam(name = "page", value = "第几页", defaultValue = "")
                                                           @RequestParam(value = "page", required = false) Integer page,
                                                                       @ApiParam(name = "size", value = "每页记录数", defaultValue = "")
                                                           @RequestParam(value = "size", required = false) Integer size){
        try {
            if(page == null|| page < 0){
                page = 1;
            }
            if(size == null){
                size = 10;
            }
            return queryImportRecordPage(purcharseId,page,size);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
}

+ 121 - 0
app/app-iot-server/src/main/java/com/yihu/ehr/iot/controller/device/IotDeviceOrderController.java

@ -0,0 +1,121 @@
package com.yihu.ehr.iot.controller.device;
import com.yihu.ehr.iot.controller.common.BaseController;
import com.yihu.ehr.iot.service.device.DeviceOrderService;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.iot.device.IotDeviceOrderVO;
import com.yihu.jw.restmodel.iot.device.IotOrderPurchaseVO;
import com.yihu.jw.restmodel.iot.device.IotOrderVO;
import com.yihu.jw.rm.iot.IotRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
/**
 * @author yeshijie on 2017/12/8.
 */
@RestController
@RequestMapping(IotRequestMapping.Common.order)
@Api(tags = "设备订单管理相关操作", description = "设备订单管理相关操作")
public class IotDeviceOrderController extends BaseController {
    @Autowired
    private DeviceOrderService deviceOrderService;
    @PostMapping(value = IotRequestMapping.DeviceOrder.createOrder, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建设备订单", notes = "创建设备订单")
    public Envelop<IotOrderVO> create(@ApiParam(name = "json_data", value = "", defaultValue = "")
                          @RequestParam String jsonData) {
        try {
            return deviceOrderService.create(jsonData);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.DeviceOrder.findById)
    @ApiOperation(value = "根据id查找设备订单", notes = "根据id查找设备订单")
    public Envelop<IotDeviceOrderVO>  findByCode(@ApiParam(name = "id", value = "id")
                              @RequestParam(value = "id", required = true) String id) {
        try {
            return deviceOrderService.findByCode(id);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.DeviceOrder.findPage)
    @ApiOperation(value = "分页查找设备订单", notes = "分页查找设备订单")
    public Envelop<IotDeviceOrderVO> findPage(@ApiParam(name = "name", value = "供应商名称或负责人姓名", defaultValue = "")
                                                 @RequestParam(value = "name", required = false) String name,
                                                 @ApiParam(name = "type", value = "企业类型", defaultValue = "")
                                                 @RequestParam(value = "type", required = false) String type,
                                                 @ApiParam(name = "page", value = "第几页", defaultValue = "")
                                                 @RequestParam(value = "page", required = false) Integer page,
                                                 @ApiParam(name = "size", value = "每页记录数", defaultValue = "")
                                                 @RequestParam(value = "size", required = false) Integer size){
        try {
            if(page == null|| page < 0){
                page = 1;
            }
            if(size == null){
                size = 10;
            }
            return deviceOrderService.findPage(name,type,page,size);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.DeviceOrder.delOrder)
    @ApiOperation(value = "删除订单", notes = "删除订单")
    public Envelop<IotDeviceOrderVO> delOrder(@ApiParam(name = "id", value = "id")
                                            @RequestParam(value = "id", required = true) String id) {
        try {
            return deviceOrderService.delOrder(id);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.DeviceOrder.updOrder)
    @ApiOperation(value = "修改订单", notes = "修改订单")
    public Envelop<IotOrderVO> updOrder(@ApiParam(name = "jsonData", value = "json", defaultValue = "")
                                            @RequestParam(value = "jsonData", required = false)String jsonData) {
        try {
            return deviceOrderService.updOrder(jsonData);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.DeviceOrder.findPurcharsePage)
    @ApiOperation(value = "分页查找采购清单", notes = "分页查找采购清单")
    public Envelop<IotOrderPurchaseVO> findPurcharsePage(@ApiParam(name = "orderId", value = "订单id", defaultValue = "")
                                                     @RequestParam(value = "orderId", required = true) String orderId,
                                                         @ApiParam(name = "page", value = "第几页", defaultValue = "")
                                                     @RequestParam(value = "page", required = false) Integer page,
                                                         @ApiParam(name = "size", value = "每页记录数", defaultValue = "")
                                                     @RequestParam(value = "size", required = false) Integer size){
        try {
            if(page == null|| page < 0){
                page = 1;
            }
            if(size == null){
                size = 10;
            }
            return deviceOrderService.findPurcharsePage(orderId,page,size);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
}

+ 124 - 0
app/app-iot-server/src/main/java/com/yihu/ehr/iot/controller/product/IotProductController.java

@ -0,0 +1,124 @@
package com.yihu.ehr.iot.controller.product;
import com.yihu.ehr.iot.controller.common.BaseController;
import com.yihu.ehr.iot.service.product.ProductService;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.iot.product.IotProductBaseInfoVO;
import com.yihu.jw.restmodel.iot.product.IotProductVO;
import com.yihu.jw.rm.iot.IotRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * @author yeshijie on 2018/1/17.
 */
@RestController
@RequestMapping(IotRequestMapping.Common.product)
@Api(tags = "产品管理相关操作", description = "产品管理相关操作")
public class IotProductController extends BaseController {
    @Autowired
    private ProductService productService;
    @GetMapping(value = IotRequestMapping.Product.findProductPage)
    @ApiOperation(value = "分页查找产品", notes = "分页查找产品")
    public Envelop<IotProductBaseInfoVO> findCompanyPage(@ApiParam(name = "name", value = "注册证号或产品名称", defaultValue = "")
                                                 @RequestParam(value = "name", required = false) String name,
                                                         @ApiParam(name = "classify", value = "产品分类", defaultValue = "")
                                                 @RequestParam(value = "classify", required = false) String classify,
                                                         @ApiParam(name = "page", value = "第几页", defaultValue = "")
                                                 @RequestParam(value = "page", required = false) Integer page,
                                                         @ApiParam(name = "size", value = "每页记录数", defaultValue = "")
                                                 @RequestParam(value = "size", required = false) Integer size){
        try {
            if(page == null|| page < 0){
                page = 1;
            }
            if(size == null){
                size = 10;
            }
            return productService.findCompanyPage(name,classify,page,size);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.Product.findProductPageByCompanyId)
    @ApiOperation(value = "分页查找产品(按企业id)", notes = "分页查找产品")
    public Envelop<IotProductBaseInfoVO> findProductPageByCompanyId(@ApiParam(name = "name", value = "产品名称", defaultValue = "")
                                                         @RequestParam(value = "name", required = false) String name,
                                                         @ApiParam(name = "companyId", value = "企业id", defaultValue = "")
                                                         @RequestParam(value = "companyId", required = true) String companyId,
                                                         @ApiParam(name = "page", value = "第几页", defaultValue = "")
                                                         @RequestParam(value = "page", required = false) Integer page,
                                                         @ApiParam(name = "size", value = "每页记录数", defaultValue = "")
                                                         @RequestParam(value = "size", required = false) Integer size){
        try {
            if(page == null|| page < 0){
                page = 1;
            }
            if(size == null){
                size = 10;
            }
            return productService.findProductPageByCompanyId(name,companyId,page,size);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.Product.addProduct)
    @ApiOperation(value = "创建产品", notes = "创建产品")
    public Envelop<IotProductVO> addProduct(@ApiParam(name = "jsonData", value = "json", defaultValue = "")
                                            @RequestParam(value = "jsonData", required = false)String jsonData) {
        try {
            return productService.addProduct(jsonData);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.Product.findProductById)
    @ApiOperation(value = "根据id查找产品", notes = "根据id查找产品")
    public Envelop<IotProductVO> findByCode(@ApiParam(name = "id", value = "id")
                                            @RequestParam(value = "id", required = true) String id) {
        try {
            return productService.findByCode(id);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.Product.delProduct)
    @ApiOperation(value = "删除产品", notes = "删除产品")
    public Envelop<IotProductVO> delCompany(@ApiParam(name = "id", value = "id")
                                            @RequestParam(value = "id", required = true) String id) {
        try {
            return productService.delCompany(id);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.Product.updProduct)
    @ApiOperation(value = "修改产品信息", notes = "修改产品信息")
    public Envelop<IotProductVO> updCompany(@ApiParam(name = "jsonData", value = "json", defaultValue = "")
                                            @RequestParam(value = "jsonData", required = false)String jsonData) {
        try {
            return productService.updCompany(jsonData);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
}

+ 9 - 9
app/app-iot-server/src/main/java/com/yihu/ehr/iot/interceptor/LoginInterceptor.java

@ -14,15 +14,15 @@ public class LoginInterceptor extends HandlerInterceptorAdapter {
    protected String contextPath;
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if(request.getRequestURL().indexOf("/ambulance/search")!=-1){
            return true;
        }
        Boolean isLogin = (Boolean) request.getSession().getAttribute("isLogin");
        if (isLogin == null || !isLogin) {
            response.sendRedirect(contextPath+"/login");
            response.setStatus(-200);
            return false;
        }
//        if(request.getRequestURL().indexOf("/ambulance/search")!=-1){
//            return true;
//        }
//        Boolean isLogin = (Boolean) request.getSession().getAttribute("isLogin");
//        if (isLogin == null || !isLogin) {
//            response.sendRedirect(contextPath+"/login");
//            response.setStatus(-200);
//            return false;
//        }
        return true;
    }
}

+ 79 - 0
app/app-iot-server/src/main/java/com/yihu/ehr/iot/service/common/FileUploadService.java

@ -0,0 +1,79 @@
package com.yihu.ehr.iot.service.common;
import com.yihu.ehr.iot.constant.ServiceApi;
import com.yihu.ehr.iot.util.http.HttpHelper;
import com.yihu.ehr.iot.util.http.HttpResponse;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.iot.common.UploadVO;
import io.swagger.annotations.ApiParam;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
 * @author yeshijie on 2017/12/7.
 */
@Service
public class FileUploadService extends BaseService{
    /**
     * 文件流上传图片
     * @param file
     * @return
     */
    public Envelop<UploadVO> uploadImg(MultipartFile file) throws IOException{
        Map<String, Object> params = new HashMap<>();
        params.put("file", file);
        HttpResponse response = HttpHelper.post(iotUrl + ServiceApi.FileUpload.UploadImg, params);
        Envelop<UploadVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 文件流上传附件
     * @param file
     * @return
     * @throws Exception
     */
    public Envelop<UploadVO> uploadAttachment(MultipartFile file) throws Exception{
        Map<String, Object> params = new HashMap<>();
        params.put("file", file);
        HttpResponse response = HttpHelper.post(iotUrl + ServiceApi.FileUpload.UploadattAchment, params);
        Envelop<UploadVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 文件流上传文件
     * @param file
     * @return
     * @throws Exception
     */
    public Envelop<UploadVO> uploadStream(MultipartFile file) throws Exception {
        Map<String, Object> params = new HashMap<>();
        params.put("file", file);
        HttpResponse response = HttpHelper.post(iotUrl + ServiceApi.FileUpload.UploadStream, params);
        Envelop<UploadVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * base64上传图片
     * @param jsonData
     * @return
     * @throws Exception
     */
    public Envelop<UploadVO> uploadImages(@ApiParam(name = "jsonData", value = "头像转化后的输入流") @RequestBody String jsonData) throws Exception {
        Map<String, Object> params = new HashMap<>();
        params.put("jsonData", jsonData);
        HttpResponse response = HttpHelper.post(iotUrl + ServiceApi.FileUpload.UploadString, params);
        Envelop<UploadVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
}

+ 34 - 0
app/app-iot-server/src/main/java/com/yihu/ehr/iot/service/common/SystemDictService.java

@ -0,0 +1,34 @@
package com.yihu.ehr.iot.service.common;
import com.yihu.ehr.iot.constant.ServiceApi;
import com.yihu.ehr.iot.util.http.HttpHelper;
import com.yihu.ehr.iot.util.http.HttpResponse;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.iot.dict.IotSystemDictVO;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;
/**
 * @author yeshijie on 2018/1/16.
 */
@Service
public class SystemDictService extends BaseService{
    /**
     * 获取字典列表(不分页)
     * @param dictName
     * @return
     * @throws Exception
     */
    public Envelop<IotSystemDictVO> getList(String dictName) throws Exception {
        Map<String, Object> params = new HashMap<>();
        params.put("dictName", dictName);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.System.FindDictByCode, params);
        Envelop<IotSystemDictVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
}

+ 133 - 1
app/app-iot-server/src/main/java/com/yihu/ehr/iot/service/company/CompanyService.java

@ -1,9 +1,11 @@
package com.yihu.ehr.iot.service.company;
import com.yihu.ehr.iot.constant.ServiceApi;
import com.yihu.ehr.iot.service.common.BaseService;
import com.yihu.ehr.iot.util.http.HttpHelper;
import com.yihu.ehr.iot.util.http.HttpResponse;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.iot.company.IotCompanyCertificateVO;
import com.yihu.jw.restmodel.iot.company.IotCompanyVO;
import org.springframework.stereotype.Service;
@ -34,9 +36,139 @@ public class CompanyService extends BaseService {
        params.put("type", type);
        params.put("page", page);
        params.put("size", size);
        HttpResponse response = HttpHelper.get(iotUrl + "/oauth/validToken", params);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.Company.FindCompanyPage, params);
        Envelop<IotCompanyVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 创建企业
     * @param jsonData
     * @return
     * @throws IOException
     */
    public Envelop<IotCompanyVO> addCompany(String jsonData) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("jsonData", jsonData);
        HttpResponse response = HttpHelper.post(iotUrl + ServiceApi.Company.AddCompany, params);
        Envelop<IotCompanyVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 根据id查找企业
     * @param id
     * @return
     * @throws IOException
     */
    public Envelop<IotCompanyVO> findByCode(String id) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.Company.FindCompanyById, params);
        Envelop<IotCompanyVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 根据营业执照号查找企业
     * @param businessLicense
     * @return
     * @throws IOException
     */
    public Envelop<IotCompanyVO> findByBusinessLicense(String businessLicense) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("businessLicense", businessLicense);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.Company.FindByBusinessLicense, params);
        Envelop<IotCompanyVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 删除企业
     * @param id
     * @return
     * @throws IOException
     */
    public Envelop<IotCompanyVO> delCompany(String id) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        HttpResponse response = HttpHelper.post(iotUrl + ServiceApi.Company.DelCompany, params);
        Envelop<IotCompanyVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 修改企业信息
     * @param jsonData
     * @return
     * @throws IOException
     */
    public Envelop<IotCompanyVO> updCompany(String jsonData) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("jsonData", jsonData);
        HttpResponse response = HttpHelper.post(iotUrl + ServiceApi.Company.UpdCompany, params);
        Envelop<IotCompanyVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 分页获取企业证书
     * @param name
     * @param page
     * @param size
     * @return
     * @throws IOException
     */
    public Envelop<IotCompanyCertificateVO> findCompanyCertPage(String name,Integer page,Integer size) throws IOException{
        Map<String, Object> params = new HashMap<>();
        params.put("name", name);
        params.put("page", page);
        params.put("size", size);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.Company.FindCompanyCertPage, params);
        Envelop<IotCompanyCertificateVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 根据id查找企业证书
     * @param id
     * @return
     * @throws IOException
     */
    public Envelop<IotCompanyCertificateVO> findCompanyCertById(String id) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.Company.FindCompanyCertById, params);
        Envelop<IotCompanyCertificateVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 根据企业id查找企业证书
     * @param companyId
     * @return
     * @throws IOException
     */
    public Envelop<IotCompanyCertificateVO> findCompanyCertByCompanyId(String companyId) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("companyId", companyId);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.Company.FindCompanyCertByCompanyId, params);
        Envelop<IotCompanyCertificateVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 创建企业证书
     * @param jsonData
     * @return
     * @throws IOException
     */
    public Envelop<IotCompanyCertificateVO> addCompanyCert(String jsonData) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("jsonData", jsonData);
        HttpResponse response = HttpHelper.post(iotUrl + ServiceApi.Company.AddCompanyCert, params);
        Envelop<IotCompanyCertificateVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
}

+ 117 - 0
app/app-iot-server/src/main/java/com/yihu/ehr/iot/service/device/DeviceOrderService.java

@ -0,0 +1,117 @@
package com.yihu.ehr.iot.service.device;
import com.yihu.ehr.iot.constant.ServiceApi;
import com.yihu.ehr.iot.service.common.BaseService;
import com.yihu.ehr.iot.util.http.HttpHelper;
import com.yihu.ehr.iot.util.http.HttpResponse;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.iot.device.IotDeviceOrderVO;
import com.yihu.jw.restmodel.iot.device.IotOrderPurchaseVO;
import com.yihu.jw.restmodel.iot.device.IotOrderVO;
import org.springframework.stereotype.Service;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
 * @author yeshijie on 2017/12/8.
 */
@Service
public class DeviceOrderService extends BaseService{
    /**
     * 创建设备订单
     * @param jsonData
     * @return
     * @throws IOException
     */
    public Envelop<IotOrderVO> create(String jsonData) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("jsonData", jsonData);
        HttpResponse response = HttpHelper.post(iotUrl + ServiceApi.DeviceOrder.CreateOrder, params);
        Envelop<IotOrderVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 根据id查找设备订单
     * @param id
     * @return
     * @throws IOException
     */
    public Envelop<IotDeviceOrderVO>  findByCode(String id) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.DeviceOrder.FindById, params);
        Envelop<IotDeviceOrderVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 分页查找设备订单
     * @param name
     * @param type
     * @param page
     * @param size
     * @return
     * @throws IOException
     */
    public Envelop<IotDeviceOrderVO> findPage(String name,String type,Integer page,Integer size) throws IOException{
        Map<String, Object> params = new HashMap<>();
        params.put("name", name);
        params.put("type", type);
        params.put("page", page);
        params.put("size", size);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.DeviceOrder.FindPage, params);
        Envelop<IotDeviceOrderVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 删除订单
     * @param id
     * @return
     * @throws IOException
     */
    public Envelop<IotDeviceOrderVO> delOrder(String id) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        HttpResponse response = HttpHelper.post(iotUrl + ServiceApi.DeviceOrder.DelOrder, params);
        Envelop<IotDeviceOrderVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 修改订单
     * @param jsonData
     * @return
     * @throws IOException
     */
    public Envelop<IotOrderVO> updOrder(String jsonData) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("jsonData", jsonData);
        HttpResponse response = HttpHelper.post(iotUrl + ServiceApi.DeviceOrder.UpdOrder, params);
        Envelop<IotOrderVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 分页查找采购清单
     * @param orderId
     * @param page
     * @param size
     * @return
     * @throws IOException
     */
    public Envelop<IotOrderPurchaseVO> findPurcharsePage(String orderId,Integer page,Integer size) throws IOException{
        Map<String, Object> params = new HashMap<>();
        params.put("orderId", orderId);
        params.put("page", page);
        params.put("size", size);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.DeviceOrder.FindPurcharsePage, params);
        Envelop<IotOrderPurchaseVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
}

+ 212 - 0
app/app-iot-server/src/main/java/com/yihu/ehr/iot/service/device/DeviceService.java

@ -0,0 +1,212 @@
package com.yihu.ehr.iot.service.device;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.yihu.base.fastdfs.FastDFSHelper;
import com.yihu.ehr.iot.constant.ServiceApi;
import com.yihu.ehr.iot.service.common.BaseService;
import com.yihu.ehr.iot.util.excel.AExcelReader;
import com.yihu.ehr.iot.util.excel.reader.IotDeviceImportVOReader;
import com.yihu.ehr.iot.util.http.HttpHelper;
import com.yihu.ehr.iot.util.http.HttpResponse;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.iot.common.ExistVO;
import com.yihu.jw.restmodel.iot.device.IotDeviceImportRecordVO;
import com.yihu.jw.restmodel.iot.device.IotDeviceImportVO;
import com.yihu.jw.restmodel.iot.device.IotDeviceVO;
import com.yihu.jw.rm.iot.IotRequestMapping;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
 * @author yeshijie on 2017/12/8.
 */
@Service
public class DeviceService extends BaseService{
    @Autowired
    private FastDFSHelper fastDFSHelper;
    /**
     * 创建设备
     * @param jsonData
     * @return
     * @throws IOException
     */
    public Envelop<IotDeviceVO> create(@ApiParam(name = "json_data", value = "", defaultValue = "")
                          @RequestBody String jsonData) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("jsonData", jsonData);
        HttpResponse response = HttpHelper.post(iotUrl + ServiceApi.Device.CreateDevice, params);
        Envelop<IotDeviceVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 根据code查找设备
     * @param id
     * @return
     * @throws IOException
     */
    @GetMapping(value = IotRequestMapping.Device.api_getById)
    @ApiOperation(value = "根据code查找设备", notes = "根据code查找设备")
    public Envelop<IotDeviceVO> findByCode(String id)throws IOException{
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.Device.GetDeviceById, params);
        Envelop<IotDeviceVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * sn码是否存在
     * @param sn
     * @return
     * @throws IOException
     */
    public Envelop<ExistVO> isSnExist(String sn) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("sn", sn);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.Device.IsSnExist, params);
        Envelop<ExistVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * sim卡号是否存在
     * @param sim
     * @return
     * @throws IOException
     */
    public Envelop<ExistVO> isSimExist(String sim) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("sim", sim);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.Device.IsSimExist, params);
        Envelop<ExistVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 分页查找设备
     * @param sn
     * @param hospital
     * @param orderId
     * @param purcharseId
     * @param page
     * @param size
     * @return
     * @throws IOException
     */
    public Envelop<IotDeviceVO> findProductPageByCompanyId(String sn,String hospital,String orderId,
                String purcharseId,Integer page,Integer size) throws IOException{
        Map<String, Object> params = new HashMap<>();
        params.put("sn", sn);
        params.put("hospital", hospital);
        params.put("orderId", orderId);
        params.put("purcharseId", purcharseId);
        params.put("page", page);
        params.put("size", size);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.Device.QueryDevicePage, params);
        Envelop<IotDeviceVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 是否正在导入设备数据
     * @param purcharseId
     * @return
     */
    public Envelop<ExistVO> isImportDevice(String purcharseId) throws IOException {
        Envelop<ExistVO> envelop = objectMapper.readValue(isImporting(purcharseId),Envelop.class);
        return envelop;
    }
    /**
     * 是否正在导入设备数据
     * @param purcharseId
     * @return
     */
    public String isImporting(String purcharseId){
        Map<String, Object> params = new HashMap<>();
        params.put("purcharseId", purcharseId);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.Device.IsImportDevice, params);
        return response.getBody();
    }
    /**
     * 设备导入
     * @param file
     * @param purcharseId
     * @return
     * @throws IOException
     */
    public Envelop<IotDeviceImportRecordVO> uploadStream(MultipartFile file,String purcharseId) throws Exception {
        String res = isImporting(purcharseId);
        JSONObject json = JSON.parseObject(res);
        if(json.getInteger("status")==200){
            if(json.getJSONObject("obj").getInteger("isExist")==1){
                return Envelop.getError("已存在导入中的数据,请等待上次数据处理完后在导入");
            }
        }else {
            return Envelop.getError("查询是否在导入中失败");
        }
        //文件上传
        // 得到文件的完整名称  xxx.txt
        String fullName = file.getOriginalFilename();
        //得到文件类型
        String fileType = fullName.substring(fullName.lastIndexOf(".") + 1).toLowerCase();
        if(!"xls".equals(fileType)){
            return Envelop.getError("文件格式不正确");
        }
        String fileName = fullName.substring(0, fullName.lastIndexOf("."));
        //上传到fastdfs
        ObjectNode objectNode = fastDFSHelper.upload(file.getInputStream(), fileType, "");
        //解析excel封装对象
        AExcelReader excelReader = new IotDeviceImportVOReader();
        excelReader.read(file.getInputStream());
        List<IotDeviceImportVO> correctLs = excelReader.getCorrectLs();
        Map<String, Object> params = new HashMap<>();
        params.put("purcharseId", purcharseId);
        params.put("jsonData", JSONObject.toJSONString(correctLs));
        params.put("fileName", fileName);
        params.put("url", objectNode.get("fid").toString().replaceAll("\"", ""));
        String ret = HttpHelper.postBody(iotUrl + ServiceApi.Device.ImportDevice,JSONObject.toJSONString(params));
        Envelop<IotDeviceImportRecordVO> envelop = objectMapper.readValue(ret,Envelop.class);
//        HttpResponse response = HttpHelper.post(iotUrl + ServiceApi.Device.ImportDevice, params);
//        Envelop<IotDeviceImportRecordVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 分页查找导入记录
     * @param purcharseId
     * @param page
     * @param size
     * @return
     * @throws IOException
     */
    public Envelop<IotDeviceImportRecordVO> queryImportRecordPage(String purcharseId,Integer page,Integer size) throws IOException{
        Map<String, Object> params = new HashMap<>();
        params.put("purcharseId", purcharseId);
        params.put("page", page);
        params.put("size", size);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.Device.QueryImportRecordPage, params);
        Envelop<IotDeviceImportRecordVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
}

+ 123 - 0
app/app-iot-server/src/main/java/com/yihu/ehr/iot/service/product/ProductService.java

@ -0,0 +1,123 @@
package com.yihu.ehr.iot.service.product;
import com.yihu.ehr.iot.constant.ServiceApi;
import com.yihu.ehr.iot.service.common.BaseService;
import com.yihu.ehr.iot.util.http.HttpHelper;
import com.yihu.ehr.iot.util.http.HttpResponse;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.iot.product.IotProductBaseInfoVO;
import com.yihu.jw.restmodel.iot.product.IotProductVO;
import com.yihu.jw.rm.iot.IotRequestMapping;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.PostMapping;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
 * @author yeshijie on 2018/1/17.
 */
@Service
public class ProductService extends BaseService {
    /**
     * 分页查找产品
     * @param name
     * @param classify
     * @param page
     * @param size
     * @return
     */
    public Envelop<IotProductBaseInfoVO> findCompanyPage(String name,String classify,Integer page,Integer size) throws IOException{
        Map<String, Object> params = new HashMap<>();
        params.put("name", name);
        params.put("classify", classify);
        params.put("page", page);
        params.put("size", size);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.Product.FindProductPage, params);
        Envelop<IotProductBaseInfoVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 分页查找产品
     * @param name
     * @param companyId
     * @param page
     * @param size
     * @return
     * @throws IOException
     */
    public Envelop<IotProductBaseInfoVO> findProductPageByCompanyId(String name,String companyId,Integer page, Integer size) throws IOException{
        Map<String, Object> params = new HashMap<>();
        params.put("name", name);
        params.put("page", page);
        params.put("companyId", companyId);
        params.put("size", size);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.Product.FindProductPageByCompanyId, params);
        Envelop<IotProductBaseInfoVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 创建产品
     * @param jsonData
     * @return
     * @throws IOException
     */
    public Envelop<IotProductVO> addProduct(String jsonData) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("jsonData", jsonData);
        HttpResponse response = HttpHelper.post(iotUrl + ServiceApi.Product.AddProduct, params);
        Envelop<IotProductVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 根据id查找产品
     * @param id
     * @return
     * @throws IOException
     */
    public Envelop<IotProductVO> findByCode(String id) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        HttpResponse response = HttpHelper.get(iotUrl + ServiceApi.Product.FindProductById, params);
        Envelop<IotProductVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 删除产品
     * @param id
     * @return
     * @throws IOException
     */
    @PostMapping(value = IotRequestMapping.Product.delProduct)
    @ApiOperation(value = "删除产品", notes = "删除产品")
    public Envelop<IotProductVO> delCompany(String id) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("id", id);
        HttpResponse response = HttpHelper.post(iotUrl + ServiceApi.Product.DelProduct, params);
        Envelop<IotProductVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
    /**
     * 修改产品信息
     * @param jsonData
     * @return
     * @throws IOException
     */
    public Envelop<IotProductVO> updCompany(String jsonData) throws IOException {
        Map<String, Object> params = new HashMap<>();
        params.put("jsonData", jsonData);
        HttpResponse response = HttpHelper.post(iotUrl + ServiceApi.Product.UpdProduct, params);
        Envelop<IotProductVO> envelop = objectMapper.readValue(response.getBody(),Envelop.class);
        return envelop;
    }
}

+ 70 - 0
app/app-iot-server/src/main/java/com/yihu/ehr/iot/util/excel/AExcelReader.java

@ -0,0 +1,70 @@
package com.yihu.ehr.iot.util.excel;
import jxl.Sheet;
import jxl.Workbook;
import java.io.File;
import java.io.InputStream;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 * @author lincl
 * @version 1.0
 * @created 2016/6/18
 */
public abstract class AExcelReader {
    protected List errorLs = new ArrayList<>();
    protected List correctLs = new ArrayList<>();
    protected Map<String, Set> repeat = new HashMap<>();
    private static Pattern blankPattern = Pattern.compile("\\s*|\t|\r|\n");
    public abstract void read(Workbook rwb) throws Exception;
    public void read(File file) throws Exception {
        read(Workbook.getWorkbook(file));
    }
    public void read(InputStream is) throws Exception {
        read(Workbook.getWorkbook(is));
    }
    public static String replaceBlank(String str) {
        String dest = "";
        if (str!=null) {
            //去除字符串中的空格、回车、换行符、制表符
            Matcher m = blankPattern.matcher(str);
            dest = m.replaceAll("");
        }
        return dest;
    }
    protected String getCellCont(Sheet sheet, int row, int col){
        return sheet.getCell(col, row).getContents();
    }
    public List getErrorLs() {
        return errorLs;
    }
    public void setErrorLs(List errorLs) {
        this.errorLs = errorLs;
    }
    public List getCorrectLs() {
        return correctLs;
    }
    public void setCorrectLs(List correctLs) {
        this.correctLs = correctLs;
    }
    public Map<String, Set> getRepeat() {
        return repeat;
    }
    public void setRepeat(Map<String, Set> repeat) {
        this.repeat = repeat;
    }
}

+ 33 - 0
app/app-iot-server/src/main/java/com/yihu/ehr/iot/util/excel/reader/IotDeviceImportVOReader.java

@ -0,0 +1,33 @@
package com.yihu.ehr.iot.util.excel.reader;
import com.yihu.ehr.iot.util.excel.AExcelReader;
import com.yihu.jw.restmodel.iot.device.IotDeviceImportVO;
import jxl.Sheet;
import jxl.Workbook;
/**
 * @author yeshijie on 2018/1/23.
 */
public class IotDeviceImportVOReader extends AExcelReader {
    @Override
    public void read(Workbook rwb) throws Exception {
        try {
            Sheet sheet = rwb.getSheet(0) ;
            for (int i = 1; i < sheet.getRows(); i++) {
                IotDeviceImportVO device = new IotDeviceImportVO();
                device.setSn(getCellCont(sheet, i, 0));
                device.setHospital(getCellCont(sheet, i, 1));
                device.setSim(getCellCont(sheet, i, 2).trim());
                correctLs.add(device);
            }
        } catch (Exception e) {
            throw new RuntimeException("模板不正确,请下载新的模板,并按照示例正确填写后上传!");
        } finally {
            if (rwb != null){
                rwb.close();
            }
        }
    }
}

+ 20 - 0
app/app-iot-server/src/main/java/com/yihu/ehr/iot/util/http/HttpClientUtil.java

@ -21,7 +21,10 @@ import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;
import java.io.*;
import java.nio.charset.Charset;
@ -34,6 +37,23 @@ import java.util.Map;
 */
public class HttpClientUtil {
    /**
     * 发送post请求
     * @param url     请求地址
     * @param params  请求参数
     * @return
     */
    public static String postBody(String url, String params,Map<String,Object> header,SSLConnectionSocketFactory ssl, String user, String password) {
        RestTemplate restTemplate = new RestTemplate();
        HttpHeaders headers = new HttpHeaders();
        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
        headers.setContentType(type);
        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
        org.springframework.http.HttpEntity<String> formEntity = new org.springframework.http.HttpEntity<String>(params, headers);
        String ret = restTemplate.postForObject(url, formEntity, String.class);
        return ret;
    }
    /**************************** 私有方法 *****************************************/
    private static CloseableHttpClient getCloseableHttpClient(SSLConnectionSocketFactory ssl) {

+ 39 - 0
app/app-iot-server/src/main/java/com/yihu/ehr/iot/util/http/HttpHelper.java

@ -218,4 +218,43 @@ public class HttpHelper {
        return HttpClientUtil.request("DELETE",url,params,header,ssl,user,password);
    }
    /************************************postBody*******************************************************************/
    public static String postBody(String url)
    {
        return postBody(url, null, null);
    }
    public static String postBody(String url, String params)
    {
        return postBody(url, params, null);
    }
    public static String postBody(String url, String params, Map<String,Object> header)
    {
        if(url.startsWith("https"))
        {
            return postBody(url, params, header, defaultSSL);
        }
        else{
            //默认http不走ssl和用户密码
            return postBody(url, params, header, null, null, null);
        }
    }
    public static String postBody(String url, String params, Map<String,Object> header, Boolean isCheck)
    {
        if(isCheck)
        {
            return postBody(url, params, header, defaultSSL, defaultHttpUser, defaultHttpPassword);
        }
        else{
            return postBody(url, params, header, null, null, null);
        }
    }
    public static String postBody(String url, String params, Map<String,Object> header, SSLConnectionSocketFactory ssl)
    {
        return postBody(url, params, header, ssl, defaultHttpUser, defaultHttpPassword);
    }
    public static String postBody(String url, String params, Map<String,Object> header, SSLConnectionSocketFactory ssl, String user, String password)
    {
        return HttpClientUtil.postBody(url,params,header,ssl,user,password);
    }
}

+ 19 - 50
app/app-iot-server/src/main/resources/application.yml

@ -28,6 +28,20 @@ app:
  clientId: 3CDhsgepr4
  baseClientId: Qz2yA1MOD0  # 【物联网】应用
fast-dfs:
  tracker-server: 172.19.103.54:22122 #服务器地址
  connect-timeout: 2 #链接超时时间
  network-timeout: 30
  charset: ISO8859-1 #编码
  http:
    tracker-http-port: 80
    anti-steal-token: no
    secret-key: FastDFS1234567890
  pool: #连接池大小
    init-size: 5
    max-size: 20
    wait-time: 500
---
spring:
  profiles: dev
@ -40,14 +54,14 @@ app:
  oauth2InnerUrl: http://172.19.103.44:10260/
  oauth2OuterUrl: http://27.154.233.186:10260/  #上饶-授权外网映射
service-gateway:
  iotUrl: http://192.168.131.24:8088/
  iotUrl: http://192.168.131.24:8088/svr-iot/
  profileInnerUrl: http://172.19.103.48:10000/api/v1.0/admin
  profileOuterUrl: http://27.154.233.186:10000/api/v1.0/admin
  portalInnerUrl: http://172.19.103.48:10280/api/v1.0/portal
  portalOuterUrl: http://27.154.233.186:10280/api/v1.0/portal
fast-dfs:
  tracker-server: 172.19.103.13:22122
  public-server: http://172.19.103.52:80
  tracker-server: 172.19.103.54:22122
  public-server: http://172.19.103.54:80/
logging:
  path: /data/logger
  file: app-emergency-server
@ -69,8 +83,8 @@ service-gateway:
  portalInnerUrl: http://172.19.103.73:10280/api/v1.0/portal
  portalOuterUrl: http://27.154.233.186:10280/api/v1.0/portal
fast-dfs:
  tracker-server: 172.19.103.13:22122
  public-server: http://172.19.103.52:80
  tracker-server: 172.19.103.54:22122
  public-server: http://172.19.103.54:80/
logging:
  path: /data/logger
  file: app-emergency-server
@ -98,48 +112,3 @@ logging:
  path: /data/logger
  file: app-emergency-server
---
spring:
  profiles: prod_fz
  loginVaild: true
  redis:
    host: 192.168.135.40 # Redis server host.
    port: 6390
    password: redis!@456
app:
  oauth2InnerUrl: http://192.168.135.35:10260/
  oauth2OuterUrl: http://11.1.2.16:10260/
service-gateway:
  profileInnerUrl: http://192.168.135.31:10001/api/v1.0/admin
  profileOuterUrl: http://11.1.2.13:10000/api/v1.0/admin
  portalInnerUrl: http://192.168.135.31:10280/api/v1.0/portal
  portalOuterUrl: http://11.1.2.13:10280/api/v1.0/portal
fast-dfs:
  tracker-server: 192.168.135.42:22122
  public-server: http://192.168.135.42:22122
logging:
  path: /data/logger
  file: app-emergency-server
---
spring:
  profiles: prod_sr
  loginVaild: true
  redis:
    host: 10.176.97.5 # Redis server host.
    port: 6390
    password: q4YaQemf
app:
  oauth2InnerUrl: http://10.176.97.10:10260/
  oauth2OuterUrl: http://171.35.109.46:10260/
service-gateway:
  profileInnerUrl: http://10.176.97.10:10000/api/v1.0/admin
  profileOuterUrl: http://171.35.109.46:10000/api/v1.0/admin
  portalInnerUrl: http://10.176.97.10:10280/api/v1.0/portal
  portalOuterUrl: http://171.35.109.46:10280/api/v1.0/portal
fast-dfs:
  tracker-server: 10.176.97.5:22122
  public-server: http://10.176.97.5:8888
logging:
  path: /data/logger
  file: app-emergency-server

+ 1 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/iot/IotRequestMapping.java

@ -197,6 +197,7 @@ public class IotRequestMapping {
        public static final String isSnExist = "isSnExist";
        public static final String isSimExist = "isSimExist";
        public static final String importDevice = "importDevice";
        public static final String isImportDevice = "isImportDevice";
        public static final String queryImportRecordPage = "queryImportRecordPage";

+ 1 - 1
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/common/ExistVO.java

@ -13,7 +13,7 @@ import java.io.Serializable;
@ApiModel(description = "是否存在")
public class ExistVO implements Serializable{
    @ApiModelProperty("是否存在(1已经存在,2不存在)")
    @ApiModelProperty("是否存在(1已经存在,0不存在)")
    private Integer isExist;
    public ExistVO() {

+ 46 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/device/IotDeviceImportVO.java

@ -0,0 +1,46 @@
package com.yihu.jw.restmodel.iot.device;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
/**
 * @author yeshijie on 2018/1/23.
 */
@JsonInclude(JsonInclude.Include.ALWAYS)
@ApiModel(description = "设备导入")
public class IotDeviceImportVO implements Serializable {
    @ApiModelProperty("sn码")
    private String sn;
    @ApiModelProperty("归属社区")
    private String hospital;
    @ApiModelProperty("sim卡号")
    private String sim;
    public String getSn() {
        return sn;
    }
    public void setSn(String sn) {
        this.sn = sn;
    }
    public String getHospital() {
        return hospital;
    }
    public void setHospital(String hospital) {
        this.hospital = hospital;
    }
    public String getSim() {
        return sim;
    }
    public void setSim(String sim) {
        this.sim = sim;
    }
}

+ 2 - 1
svr/svr-iot/src/main/java/com/yihu/iot/controller/common/FileUploadController.java

@ -23,10 +23,11 @@ import java.net.URLDecoder;
import java.util.Base64;
/**
 * 文件上传不在微服务中处理
 * @author yeshijie on 2017/12/7.
 */
@RestController
@RequestMapping(IotRequestMapping.api_iot_common)
@RequestMapping(IotRequestMapping.Common.file_upload)
@Api(tags = "文件上传相关操作", description = "文件上传相关操作")
public class FileUploadController extends EnvelopRestController{

+ 1 - 1
svr/svr-iot/src/main/java/com/yihu/iot/controller/company/IotCompanyController.java

@ -131,7 +131,7 @@ public class IotCompanyController extends EnvelopRestController {
        }
    }
    @PostMapping(value = IotRequestMapping.Company.findCompanyCertPage)
    @GetMapping(value = IotRequestMapping.Company.findCompanyCertPage)
    @ApiOperation(value = "分页获取企业证书", notes = "分页获取企业证书")
    public Envelop<IotCompanyCertificateVO> findCompanyCertPage
            (@ApiParam(name = "name", value = "证书名称", defaultValue = "")

+ 31 - 38
svr/svr-iot/src/main/java/com/yihu/iot/controller/device/IotDeviceController.java

@ -1,6 +1,8 @@
package com.yihu.iot.controller.device;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.base.fastdfs.FastDFSHelper;
import com.yihu.iot.dao.device.IotDeviceImportRecordDao;
import com.yihu.iot.service.device.IotDeviceService;
@ -10,22 +12,19 @@ import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.common.EnvelopRestController;
import com.yihu.jw.restmodel.iot.common.ExistVO;
import com.yihu.jw.restmodel.iot.device.IotDeviceImportRecordVO;
import com.yihu.jw.restmodel.iot.device.IotDeviceImportVO;
import com.yihu.jw.restmodel.iot.device.IotDeviceVO;
import com.yihu.jw.rm.iot.IotRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.ArrayList;
import java.util.List;
@ -51,7 +50,7 @@ public class IotDeviceController extends EnvelopRestController{
    @PostMapping(value = IotRequestMapping.Device.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建设备", notes = "创建设备")
    public Envelop<IotDeviceVO> create(@ApiParam(name = "json_data", value = "", defaultValue = "")
                          @RequestBody String jsonData) {
                          @RequestParam String jsonData) {
        try {
            IotDeviceDO iotDevice = toEntity(jsonData, IotDeviceDO.class);
            if(StringUtils.isBlank(iotDevice.getDeviceSn())){
@ -175,45 +174,39 @@ public class IotDeviceController extends EnvelopRestController{
        }
    }
    @GetMapping(value = IotRequestMapping.Device.isImportDevice)
    @ApiOperation(value = "是否正在导入设备数据", notes = "是否正在导入设备数据")
    public Envelop<ExistVO> isImportDevice(@ApiParam(name = "purcharseId", value = "purcharseId")
                                       @RequestParam(value = "purcharseId", required = true) String purcharseId
    ) {
        try {
            IotDeviceImportRecordDO recordDO = iotDeviceImportRecordDao.findByPurchaseId(purcharseId);
            ExistVO existVO = new ExistVO(recordDO==null?0:1);
            return Envelop.getSuccess(IotRequestMapping.Device.message_success_find, existVO);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.Device.importDevice)
    @ApiOperation(value = "设备导入", notes = "设备导入")
    public Envelop<IotDeviceImportRecordVO> uploadStream(@ApiParam(value = "文件", required = true)
                                          @RequestParam(value = "file", required = true) MultipartFile file,
                                          @ApiParam(name = "purcharseId", value = "采购id", defaultValue = "")
                                          @RequestParam(value = "purcharseId", required = true) String purcharseId) {
    public Envelop<IotDeviceImportRecordVO> uploadStream(@ApiParam(value = "jsonData", required = true)
                                          @RequestBody String jsonData) {
        try {
            // 得到文件的完整名称  xxx.txt
            String fullName = file.getOriginalFilename();
            //得到文件类型
            String fileType = fullName.substring(fullName.lastIndexOf(".") + 1).toLowerCase();
            if(!"xls".equals(fileType)){
                return Envelop.getError("文件格式不正确");
            }
            JSONObject json = JSONObject.parseObject(jsonData);
            String data = json.getString("jsonData");
            String fileName = json.getString("fileName");
            String purcharseId = json.getString("purcharseId");
            String url = json.getString("url");
            IotDeviceImportRecordDO recordDO = iotDeviceImportRecordDao.findByPurchaseId(purcharseId);
            if(recordDO!=null){
                return Envelop.getError("正在导入中,请耐心等待");
            }
            String fileName = fullName.substring(0, fullName.lastIndexOf("."));
            HSSFWorkbook wb = null;
            IotDeviceImportRecordVO vo = null;
            try {
                wb = new HSSFWorkbook(file.getInputStream());
                HSSFSheet sheet = wb.getSheetAt(0);
                if(sheet==null||sheet.getLastRowNum()<2){
                    return Envelop.getError("文件内容不正确");
                }
                HSSFRow row = sheet.getRow(0);
                if(row.getLastCellNum()<3){
                    return Envelop.getError("文件内容不正确");
                }
                //上传到fastdfs
                ObjectNode objectNode = fastDFSHelper.upload(file.getInputStream(), fileType, "");
                vo = iotDeviceService.importDevice(objectNode.get("fid").toString().replaceAll("\"", ""),fileName,purcharseId,wb);
            } catch (Exception e) {
                e.printStackTrace();
                logger.error(e.getMessage());
                return Envelop.getError(IotRequestMapping.FileUpload.message_fail_upload, IotRequestMapping.api_iot_fail);
            }
            ObjectMapper objectMapper = new ObjectMapper();
            List<IotDeviceImportVO> importVOList = objectMapper.readValue(data, new TypeReference<List<IotDeviceImportVO>>() {});
            IotDeviceImportRecordVO vo = iotDeviceService.importDevice(url,fileName,purcharseId,importVOList);
            return Envelop.getSuccess(IotRequestMapping.Common.message_success_create,vo);
        } catch (Exception e) {
            e.printStackTrace();

+ 1 - 1
svr/svr-iot/src/main/java/com/yihu/iot/controller/device/IotDeviceOrderController.java

@ -37,7 +37,7 @@ public class IotDeviceOrderController extends EnvelopRestController{
    @PostMapping(value = IotRequestMapping.DeviceOrder.createOrder, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建设备订单", notes = "创建设备订单")
    public Envelop<IotOrderVO> create(@ApiParam(name = "json_data", value = "", defaultValue = "")
                          @RequestBody String jsonData) {
                          @RequestParam String jsonData) {
        try {
            IotOrderVO iotOrderVO = toEntity(jsonData, IotOrderVO.class);
            iotDeviceOrderService.create(iotOrderVO);

+ 72 - 22
svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotDeviceImportRecordService.java

@ -8,6 +8,8 @@ import com.yihu.iot.dao.device.IotDeviceImportRecordDao;
import com.yihu.jw.iot.device.IotDeviceDO;
import com.yihu.jw.iot.device.IotDeviceImportRecordDO;
import com.yihu.jw.iot.device.IotOrderPurchaseDO;
import com.yihu.jw.restmodel.iot.device.IotDeviceImportVO;
import org.apache.commons.collections.map.HashedMap;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
@ -22,6 +24,7 @@ import org.springframework.stereotype.Service;
import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * @author yeshijie on 2018/1/19.
@ -36,29 +39,74 @@ public class IotDeviceImportRecordService extends BaseJpaService<IotDeviceImport
    @Autowired
    private FastDFSHelper fastDFSHelper;
    /**
     * 创建 HSSFWorkbook
     * @return
     */
    private HSSFWorkbook createWb(){
        //创建HSSFWorkbook对象
        HSSFWorkbook wb = new HSSFWorkbook();
        //创建HSSFSheet对象
        HSSFSheet sheet = wb.createSheet("sheet0");
        //创建HSSFRow对象
        HSSFRow row0 = sheet.createRow(0);
        //创建HSSFCell对象
        HSSFCell cell0=row0.createCell(0);
        HSSFCell cell1=row0.createCell(1);
        HSSFCell cell2=row0.createCell(2);
        HSSFCell cell3=row0.createCell(3);
        //设置单元格的值
        cell0.setCellValue("sn码");
        cell1.setCellValue("归属社区");
        cell2.setCellValue("sim卡号");
        cell3.setCellValue("导入结果");
        return wb;
    }
    /**
     * 新增单元行
     * @param sheet
     * @param rowNum
     * @param vo
     * @param msg
     */
    private void addRow(HSSFSheet sheet,Integer rowNum,IotDeviceImportVO vo,String msg){
        HSSFRow row =sheet.createRow(rowNum);
        HSSFCell cell0 = row.createCell(0);
        HSSFCell cell1 = row.createCell(1);
        HSSFCell cell2 = row.createCell(2);
        HSSFCell cell3 = row.createCell(3);
        //设置单元格的值
        cell0.setCellValue(vo.getSn());
        cell1.setCellValue(vo.getHospital());
        cell2.setCellValue(vo.getSim());
        cell3.setCellValue(msg);
    }
    @Async
    public void importDevice(IotOrderPurchaseDO purchaseDO, HSSFWorkbook wb, IotDeviceImportRecordDO recordDO){
    public void importDevice(IotOrderPurchaseDO purchaseDO, List<IotDeviceImportVO> importVOList, IotDeviceImportRecordDO recordDO){
        HSSFWorkbook wb = createWb();
        HSSFSheet sheet = wb.getSheetAt(0);
        List<IotDeviceDO> deviceDOList = new ArrayList<IotDeviceDO>();
        Integer associatedNum = iotDeviceDao.countByPurchaseId(purchaseDO.getId());
        Long unAssociatedNum = purchaseDO.getPurchaseNum()-associatedNum;//未关联数量
        Integer count = 0;
        HSSFSheet sheet = wb.getSheetAt(0);
        for(int i = sheet.getFirstRowNum();i<=sheet.getLastRowNum();i++){
            HSSFRow row = sheet.getRow(i);
        Integer rowNum = 0;
        Map<String,String> snMap = new HashedMap(importVOList.size());
        for(IotDeviceImportVO iotDeviceImportVO:importVOList){
            rowNum++;
            try{
                if(i==sheet.getFirstRowNum()){
                    HSSFCell cell = row.createCell(3);
                    cell.setCellValue("导入结果");
                    continue;
                }
                String errorMsg = null;
                if(unAssociatedNum<=count){
                    errorMsg = "入库SN码数量超过采购量";
                    addRow(sheet,rowNum,iotDeviceImportVO,errorMsg);
                    continue;
                }
                String sn = getStringCellValue(row,0);
                String hos = getStringCellValue(row,1);
                String sim = getStringCellValue(row,2);
                String sn = iotDeviceImportVO.getSn();
                String hos = iotDeviceImportVO.getHospital();
                String sim = iotDeviceImportVO.getSim();
                //分割字符串--思明区莲前街道社区卫生服务中心(3502030400)
                String[] ho = hos.split("\\(");
@ -67,9 +115,15 @@ public class IotDeviceImportRecordService extends BaseJpaService<IotDeviceImport
                //验证
                if(StringUtils.isBlank(sn)){
                    errorMsg = "sn码不能为空";
                    HSSFCell cell = row.createCell(3);
                    cell.setCellValue(errorMsg);
                    addRow(sheet,rowNum,iotDeviceImportVO,errorMsg);
                    continue;
                }
                if(snMap.containsKey(sn)){
                    errorMsg = "SN码重复,并不允许新增";
                    addRow(sheet,rowNum,iotDeviceImportVO,errorMsg);
                    continue;
                }else {
                    snMap.put(sn,sn);
                }
                IotDeviceDO device = iotDeviceDao.findByDeviceSn(sn);
//                if(iotDeviceDao.findByDeviceSn(sn)!=null){
@ -80,18 +134,16 @@ public class IotDeviceImportRecordService extends BaseJpaService<IotDeviceImport
//                }
                if(StringUtils.isNotBlank(sim)&&iotDeviceDao.findByDeviceSn(sim)!=null){
                    errorMsg = "SIM卡号重复,并不允许新增";
                    HSSFCell cell = row.createCell(3);
                    cell.setCellValue(errorMsg);
                    addRow(sheet,rowNum,iotDeviceImportVO,errorMsg);
                    continue;
                }
                if(device==null){
                    device = new IotDeviceDO();
                    device.setSaasId(getCode());
                }
                device = new IotDeviceDO();
                device.setDel(1);
                device.setOrderNo(purchaseDO.getOrderNo());
                device.setProductId(purchaseDO.getProductId());
                device.setSaasId(getCode());
                device.setStatus(IotDeviceDO.DeviceStatus.normal.getValue());
                device.setDeviceSn(sn);
                device.setDeviceSource(IotDeviceDO.DeviceSource.purchaese.getValue());
@ -107,12 +159,10 @@ public class IotDeviceImportRecordService extends BaseJpaService<IotDeviceImport
                device.setSupplierName(purchaseDO.getSupplierName());
                deviceDOList.add(device);
                HSSFCell cell = row.createCell(3);
                cell.setCellValue("新增成功");
                addRow(sheet,rowNum,iotDeviceImportVO,"新增成功");
            }catch (Exception e){
                e.printStackTrace();
                HSSFCell cell = row.createCell(3);
                cell.setCellValue("新增失败:"+e.getMessage());
                addRow(sheet,rowNum,iotDeviceImportVO,"新增失败:"+e.getMessage());
            }
        }
        //保存结果

+ 3 - 3
svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotDeviceService.java

@ -10,9 +10,9 @@ import com.yihu.jw.iot.device.IotDeviceImportRecordDO;
import com.yihu.jw.iot.device.IotOrderPurchaseDO;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.iot.device.IotDeviceImportRecordVO;
import com.yihu.jw.restmodel.iot.device.IotDeviceImportVO;
import com.yihu.jw.rm.iot.IotRequestMapping;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
@ -105,7 +105,7 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
    /**
     * 设备导入
     */
    public IotDeviceImportRecordVO importDevice(String fileUrl,String fileName,String purcharseId,HSSFWorkbook wb){
    public IotDeviceImportRecordVO importDevice(String fileUrl, String fileName, String purcharseId, List<IotDeviceImportVO> importVOList){
        IotDeviceImportRecordDO recordDO = new IotDeviceImportRecordDO();
        IotOrderPurchaseDO purchaseDO = iotOrderPurchaseDao.findById(purcharseId);
        recordDO.setDel(1);
@ -120,7 +120,7 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
        IotDeviceImportRecordVO vo = convertToModel(recordDO,IotDeviceImportRecordVO.class);
        //批量导入 异步操作
        importRecordService.importDevice(purchaseDO,wb,recordDO);
        importRecordService.importDevice(purchaseDO,importVOList,recordDO);
        return vo;
    };

+ 1 - 1
web-gateway/src/main/java/com/yihu/jw/controller/iot/company/IotCompanyController.java

@ -94,7 +94,7 @@ public class IotCompanyController extends EnvelopRestController {
        return iotCompanyFeign.updCompany(jsonData);
    }
    @PostMapping(value = IotRequestMapping.Company.findCompanyCertPage)
    @GetMapping(value = IotRequestMapping.Company.findCompanyCertPage)
    @ApiOperation(value = "分页获取企业证书", notes = "分页获取企业证书")
    public Envelop<IotCompanyCertificateVO> findCompanyCertPage
            (@ApiParam(name = "name", value = "证书名称", defaultValue = "")

+ 12 - 7
web-gateway/src/main/java/com/yihu/jw/controller/iot/device/IotDeviceController.java

@ -14,7 +14,6 @@ import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
/**
 * @author yeshijie on 2017/12/8.
@ -30,7 +29,7 @@ public class IotDeviceController extends EnvelopRestController{
    @PostMapping(value = IotRequestMapping.Device.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建设备", notes = "创建设备")
    public Envelop<IotDeviceVO> create(@ApiParam(name = "json_data", value = "", defaultValue = "")
                          @RequestBody String jsonData) {
                          @RequestParam String jsonData) {
        return iotDeviceFeign.create(jsonData);
    }
@ -76,13 +75,19 @@ public class IotDeviceController extends EnvelopRestController{
        return iotDeviceFeign.findProductPageByCompanyId(sn,hospital,orderId,purcharseId,page,size);
    }
    @GetMapping(value = IotRequestMapping.Device.isImportDevice)
    @ApiOperation(value = "是否正在导入设备数据", notes = "是否正在导入设备数据")
    public Envelop<ExistVO> isImportDevice(@ApiParam(name = "purcharseId", value = "purcharseId")
                                           @RequestParam(value = "purcharseId", required = true) String purcharseId
    ) {
        return iotDeviceFeign.isImportDevice(purcharseId);
    }
    @PostMapping(value = IotRequestMapping.Device.importDevice)
    @ApiOperation(value = "设备导入", notes = "设备导入")
    public Envelop<IotDeviceImportRecordVO> uploadStream(@ApiParam(value = "文件", required = true)
                                          @RequestParam(value = "file", required = true) MultipartFile file,
                                          @ApiParam(name = "purcharseId", value = "采购id", defaultValue = "")
                                          @RequestParam(value = "purcharseId", required = true) String purcharseId) {
        return iotDeviceFeign.uploadStream(file,purcharseId);
    public Envelop<IotDeviceImportRecordVO> uploadStream(@ApiParam(value = "jsonData", required = true)
                                                         @RequestBody String jsonData) {
        return iotDeviceFeign.uploadStream(jsonData);
    }
    @GetMapping(value = IotRequestMapping.Device.queryImportRecordPage)

+ 1 - 1
web-gateway/src/main/java/com/yihu/jw/controller/iot/device/IotDeviceOrderController.java

@ -28,7 +28,7 @@ public class IotDeviceOrderController extends EnvelopRestController{
    @PostMapping(value = IotRequestMapping.DeviceOrder.createOrder, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建设备订单", notes = "创建设备订单")
    public Envelop<IotOrderVO> create(@ApiParam(name = "json_data", value = "", defaultValue = "")
                          @RequestBody String jsonData) {
                          @RequestParam String jsonData) {
        return iotDeviceOrderFeign.create(jsonData);
    }

+ 11 - 4
web-gateway/src/main/java/com/yihu/jw/feign/fallbackfactory/iot/device/IotDeviceFallbackFactory.java

@ -6,12 +6,12 @@ import com.yihu.jw.restmodel.iot.common.ExistVO;
import com.yihu.jw.restmodel.iot.device.IotDeviceImportRecordVO;
import com.yihu.jw.restmodel.iot.device.IotDeviceVO;
import feign.hystrix.FallbackFactory;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
/**
 * @author yeshijie on 2017/12/8.
@ -75,13 +75,20 @@ public class IotDeviceFallbackFactory implements FallbackFactory<IotDeviceFeign>
            }
            @Override
            public Envelop<IotDeviceImportRecordVO> uploadStream(@RequestParam(value = "file", required = true) MultipartFile file,
                                                                 @RequestParam(value = "purcharseId", required = true) String purcharseId) {
                tracer.getCurrentSpan().logEvent("设备导入失败:原因:" + e.getMessage());
            public Envelop<ExistVO> isImportDevice(@ApiParam(name = "purcharseId", value = "purcharseId")
                                                   @RequestParam(value = "purcharseId", required = true) String purcharseId) {
                tracer.getCurrentSpan().logEvent("是否正在导入设备数据失败:原因:" + e.getMessage());
                tracer.getCurrentSpan().logEvent("purcharseId:" + purcharseId);
                return null;
            }
            @Override
            public Envelop<IotDeviceImportRecordVO> uploadStream(@RequestBody String jsonData) {
                tracer.getCurrentSpan().logEvent("设备导入失败:原因:" + e.getMessage());
                tracer.getCurrentSpan().logEvent("jsonData:" + jsonData);
                return null;
            }
            @Override
            public Envelop<IotDeviceImportRecordVO> queryImportRecordPage(@RequestParam(value = "purcharseId", required = true) String purcharseId,
                                                                               @RequestParam(value = "page", required = false) Integer page,

+ 4 - 5
web-gateway/src/main/java/com/yihu/jw/feign/iot/device/IotDeviceFeign.java

@ -10,7 +10,6 @@ import com.yihu.jw.rm.iot.IotRequestMapping;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
/**
 * @author yeshijie on 2017/12/8.
@ -43,11 +42,11 @@ public interface IotDeviceFeign{
            @RequestParam(value = "page", required = false) Integer page,
            @RequestParam(value = "size", required = false) Integer size);
    @PostMapping(value = IotRequestMapping.Device.importDevice)
    public Envelop<IotDeviceImportRecordVO> uploadStream(
            @RequestParam(value = "file", required = true) MultipartFile file,
            @RequestParam(value = "purcharseId", required = true) String purcharseId);
    @GetMapping(value = IotRequestMapping.Device.isImportDevice)
    public Envelop<ExistVO> isImportDevice(@RequestParam(value = "purcharseId", required = true) String purcharseId);
    @PostMapping(value = IotRequestMapping.Device.importDevice)
    public Envelop<IotDeviceImportRecordVO> uploadStream(@RequestBody String jsonData);
    @GetMapping(value = IotRequestMapping.Device.queryImportRecordPage)
    public Envelop<IotDeviceImportRecordVO> queryImportRecordPage(