Browse Source

Merge branch 'dev' of humingfen/wlyy2.0 into dev

humingfen 5 years ago
parent
commit
eac49fb21e

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

@ -229,6 +229,7 @@ public class IotRequestMapping {
        public static final String updSim = "updSim";
        public static final String importDevice = "importDevice";
        public static final String isImportDevice = "isImportDevice";
        public static final String uploadDeviceInfo = "uploadDeviceInfo";
        public static final String queryImportRecordPage = "queryImportRecordPage";

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

@ -13,20 +13,18 @@ import java.io.Serializable;
@ApiModel(description = "设备导入")
public class IotDeviceImportVO implements Serializable {
    @ApiModelProperty("sn码")
    private String sn;
    @ApiModelProperty("设备sn码")
    private String deviceSn;
    @ApiModelProperty("归属社区")
    private String hospital;
    @ApiModelProperty("sim卡号")
    private String sim;
    public String getSn() {
        return sn;
    }
    public void setSn(String sn) {
        this.sn = sn;
    }
    @ApiModelProperty("设备名称")
    private String name;
    @ApiModelProperty("设备类型名称")
    private String categoryName;//设备类型名称
    @ApiModelProperty("厂商名称")
    private String manufacturerName;
    public String getHospital() {
        return hospital;
@ -43,4 +41,36 @@ public class IotDeviceImportVO implements Serializable {
    public void setSim(String sim) {
        this.sim = sim;
    }
    public String getDeviceSn() {
        return deviceSn;
    }
    public void setDeviceSn(String deviceSn) {
        this.deviceSn = deviceSn;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getCategoryName() {
        return categoryName;
    }
    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }
    public String getManufacturerName() {
        return manufacturerName;
    }
    public void setManufacturerName(String manufacturerName) {
        this.manufacturerName = manufacturerName;
    }
}

+ 39 - 22
svr/svr-iot/src/main/java/com/yihu/iot/controller/device/IotDeviceController.java

@ -23,7 +23,9 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
@ -160,37 +162,39 @@ public class IotDeviceController extends EnvelopRestEndpoint {
    @GetMapping(value = IotRequestMapping.Device.api_queryPage)
    @ApiOperation(value = "分页查找设备", notes = "分页查找设备")
    public MixEnvelop<IotDeviceVO, 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 = false) String purcharseId,
                                                              @ApiParam(name = "isBinding", value = "是否绑定(1已绑定,2未绑定)", defaultValue = "")
                                                           @RequestParam(value = "isBinding", required = false) Integer isBinding,
                                                                           @RequestParam(value = "sn", required = false) String sn,
                                                                           @ApiParam(name = "hospital", value = "社区医院", defaultValue = "")
                                                                           @RequestParam(value = "hospital", required = false) String hospital,
                                                                           @ApiParam(name = "hospitalName", value = "社区医院名称", defaultValue = "")
                                                                           @RequestParam(value = "hospitalName", required = false) String hospitalName,
                                                                           @ApiParam(name = "orderId", value = "订单id", defaultValue = "")
                                                                           @RequestParam(value = "orderId", required = false) String orderId,
                                                                           @ApiParam(name = "purcharseId", value = "采购id", defaultValue = "")
                                                                           @RequestParam(value = "purcharseId", required = false) String purcharseId,
                                                                           @ApiParam(name = "isBinding", value = "是否绑定(1已绑定,2未绑定)", defaultValue = "")
                                                                           @RequestParam(value = "isBinding", required = false) Integer isBinding,
                                                                           @ApiParam(name = "productId", value = "产品id")
                                                                               @RequestParam(value = "productId", required = false) String productId,
                                                                           @RequestParam(value = "productId", required = false) String productId,
                                                                           @ApiParam(name = "name", value = "设备名称")
                                                                               @RequestParam(value = "name", required = false) String name,
                                                                           @RequestParam(value = "name", required = false) String name,
                                                                           @ApiParam(name = "categoryCode", value = "设备类型标识")
                                                                               @RequestParam(value = "categoryCode", required = false) String categoryCode,
                                                                           @RequestParam(value = "categoryCode", required = false) String categoryCode,
                                                                           @ApiParam(name = "manufacturerId", value = "供应厂商id")
                                                                               @RequestParam(value = "manufacturerId", required = false) String manufacturerId,
                                                              @ApiParam(name = "page", value = "第几页", defaultValue = "")
                                                           @RequestParam(value = "page", required = false) Integer page,
                                                              @ApiParam(name = "size", value = "每页记录数", defaultValue = "")
                                                           @RequestParam(value = "size", required = false) Integer size){
                                                                           @RequestParam(value = "manufacturerId", required = false) String manufacturerId,
                                                                           @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){
            if (page == null || page < 0) {
                page = 1;
            }
            if(size == null){
            if (size == null) {
                size = 10;
            }
            if(isBinding==null){
                return iotDeviceService.queryPage(sn, hospital, orderId, purcharseId, productId, name, categoryCode, manufacturerId, page, size);
            }else {
            if (isBinding == null) {
                return iotDeviceService.queryPage(sn, hospital, hospitalName, orderId, purcharseId, productId, name, categoryCode, manufacturerId, page, size);
            } else {
                return iotDeviceService.queryPage(sn, hospital, orderId, purcharseId, isBinding, page, size);
            }
        } catch (Exception e) {
@ -275,4 +279,17 @@ public class IotDeviceController extends EnvelopRestEndpoint {
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.Device.uploadDeviceInfo)
    @ApiOperation(value = "导入设备sn码相关信息", notes = "导入设备sn码相关信息")
    public MixEnvelop<IotDeviceImportVO, IotDeviceImportVO> uploadStream(@ApiParam(value = "文件", required = true)
                                                                                     @RequestParam(value = "file", required = true) MultipartFile file,
                                                                                     HttpServletRequest request) {
        try {
            return iotDeviceService.uploadStream(file, request);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(IotRequestMapping.FileUpload.message_fail_upload, IotRequestMapping.api_iot_fail);
        }
    }
}

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

@ -1,8 +1,12 @@
package com.yihu.iot.service.device;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.iot.dao.device.*;
import com.yihu.iot.dao.product.IotProductDataTransmissionDao;
import com.yihu.iot.service.dict.IotSystemDictService;
import com.yihu.iot.util.excel.reader.IotDeviceImportVOReader;
import com.yihu.jw.entity.iot.device.*;
import com.yihu.jw.entity.iot.product.IotProductDataTransmissionDO;
import com.yihu.jw.restmodel.iot.device.IotDeviceImportRecordVO;
@ -13,6 +17,8 @@ import com.yihu.jw.restmodel.iot.product.IotProductDataTransmissionVO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.iot.IotRequestMapping;
import com.yihu.iot.util.excel.AExcelReader;
import com.yihu.iot.util.excel.reader.IotDeviceImportVOReader;
import com.yihu.mysql.query.BaseJpaService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -20,7 +26,9 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@ -199,7 +207,7 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
     * @param size
     * @return
     */
    public MixEnvelop<IotDeviceVO, IotDeviceVO> queryPage(String sn, String hospital, String orderId, String purcharseId, String productId, String name, String categoryCode, String manufacturerId, Integer page, Integer size) throws Exception{
    public MixEnvelop<IotDeviceVO, IotDeviceVO> queryPage(String sn, String hospital, String hospitalName,String orderId, String purcharseId, String productId, String name, String categoryCode, String manufacturerId, Integer page, Integer size) throws Exception{
        String filters = "del=1;";
        String semicolon = "";
        if(StringUtils.isNotBlank(orderId)){
@ -234,6 +242,10 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
            filters += semicolon +"manufacturerId="+manufacturerId;
            semicolon = ";";
        }
        if(StringUtils.isNotBlank(hospitalName)){
            filters += semicolon + "hospitalName?"+hospitalName+"";
            semicolon = ";";
        }
        String sorts = "-updateTime";
        //得到list数据
        List<IotDeviceDO> list = search(null, filters, sorts, page, size);
@ -458,4 +470,25 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
            }
        }
    }
    public MixEnvelop<IotDeviceImportVO, IotDeviceImportVO> uploadStream(MultipartFile file, HttpServletRequest request) throws Exception {
        // 得到文件的完整名称  xxx.txt
        String fullName = file.getOriginalFilename();
        //得到文件类型
        String fileType = fullName.substring(fullName.lastIndexOf(".") + 1).toLowerCase();
        if (!"xls".equals(fileType) || !"xlsx".equals(fileType)) {
            return MixEnvelop.getError("文件格式不正确");
        }
//        String fileName = fullName.substring(0, fullName.lastIndexOf("."));
        //解析excel封装对象
        AExcelReader excelReader = new IotDeviceImportVOReader();
        excelReader.read(file.getInputStream());
        List<IotDeviceImportVO> correctLs = excelReader.getCorrectLs();
        ObjectMapper objectMapper = new ObjectMapper();
        List<IotDeviceImportVO> importVOList = objectMapper.readValue(JSONObject.toJSONString(correctLs), new TypeReference<List<IotDeviceImportVO>>() {
        });
//        IotDeviceImportRecordVO vo = this.importDevice(null,fileName,null,importVOList);
        return MixEnvelop.getSuccess(IotRequestMapping.FileUpload.message_success_upload, importVOList);
    }
}

+ 70 - 0
svr/svr-iot/src/main/java/com/yihu/iot/util/excel/AExcelReader.java

@ -0,0 +1,70 @@
package com.yihu.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;
    }
}

+ 35 - 0
svr/svr-iot/src/main/java/com/yihu/iot/util/excel/reader/IotDeviceImportVOReader.java

@ -0,0 +1,35 @@
package com.yihu.iot.util.excel.reader;
import com.yihu.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.setName(getCellCont(sheet, i, 0));
                device.setCategoryName(getCellCont(sheet, i, 1));
                device.setDeviceSn(getCellCont(sheet, i, 2));
                device.setManufacturerName(getCellCont(sheet, i, 3));
                device.setSim(getCellCont(sheet, i, 4).trim());
                correctLs.add(device);
            }
        } catch (Exception e) {
            throw new RuntimeException("模板不正确,请下载新的模板,并按照示例正确填写后上传!");
        } finally {
            if (rwb != null){
                rwb.close();
            }
        }
    }
}

+ 2 - 2
svr/svr-iot/src/main/resources/application.yml

@ -124,9 +124,9 @@ spring:
    password: ssgg@jkzl2019
  elasticsearch:
    cluster-name: jkzl #默认即为elasticsearch  集群名
    cluster-nodes: 172.19.103.45:9300,172.19.103.68:9300 #配置es节点信息,逗号分隔,如果没有指定,则启动ClientNode
    cluster-nodes: 172.26.0.112:9300,172.26.0.112:9300 #配置es节点信息,逗号分隔,如果没有指定,则启动ClientNode
    jest:
      uris: http://172.19.103.45:9200,http://172.19.103.68:9200
      uris: http://172.26.0.112:9200,http://172.26.0.112:9200
  wlyy:
    url: http://ehr.yihu.com/wlyy/
fast-dfs: