Browse Source

添加库存设备sn码导入接口

humingfen 4 years ago
parent
commit
cdb8065e5f

+ 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;
    }
}

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

@ -282,7 +282,7 @@ public class IotDeviceController extends EnvelopRestEndpoint {
    @PostMapping(value = IotRequestMapping.Device.uploadDeviceInfo)
    @ApiOperation(value = "导入设备sn码相关信息", notes = "导入设备sn码相关信息")
    public MixEnvelop<IotDeviceImportRecordVO, IotDeviceImportRecordVO> uploadStream(@ApiParam(value = "文件", required = true)
    public MixEnvelop<IotDeviceImportVO, IotDeviceImportVO> uploadStream(@ApiParam(value = "文件", required = true)
                                                                                     @RequestParam(value = "file", required = true) MultipartFile file,
                                                                                     HttpServletRequest request) {
        try {

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

@ -471,23 +471,24 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
        }
    }
    public MixEnvelop<IotDeviceImportRecordVO,IotDeviceImportRecordVO> uploadStream(MultipartFile file, HttpServletRequest request) throws Exception{
    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)){
        if (!"xls".equals(fileType) || !"xlsx".equals(fileType)) {
            return MixEnvelop.getError("文件格式不正确");
        }
        String fileName = fullName.substring(0, fullName.lastIndexOf("."));
//        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.Common.message_success_create,vo);
        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);
    }
}

+ 5 - 3
svr/svr-iot/src/main/java/com/yihu/iot/util/excel/reader/IotDeviceImportVOReader.java

@ -16,9 +16,11 @@ public class IotDeviceImportVOReader extends AExcelReader {
            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());
                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);
            }