Browse Source

物联网相关

yeshijie 7 years ago
parent
commit
1aeffd7fd4
27 changed files with 1076 additions and 417 deletions
  1. 98 0
      common/common-entity/src/main/java/com/yihu/jw/iot/device/IotDeviceImportRecordDO.java
  2. 30 12
      common/common-entity/src/main/java/com/yihu/jw/iot/device/IotDeviceOrderDO.java
  3. 31 10
      common/common-entity/src/main/java/com/yihu/jw/iot/device/IotOrderPurchaseDO.java
  4. 15 0
      common/common-request-mapping/src/main/java/com/yihu/jw/rm/iot/IotRequestMapping.java
  5. 33 0
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/common/ExistVO.java
  6. 78 0
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/device/IotDeviceImportRecordVO.java
  7. 13 11
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/device/IotDeviceOrderVO.java
  8. 40 1
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/device/IotOrderPurchaseVO.java
  9. 39 0
      common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/device/IotOrderVO.java
  10. 5 0
      svr/svr-iot/pom.xml
  11. 1 1
      svr/svr-iot/src/main/java/com/yihu/iot/controller/common/FileUploadController.java
  12. 26 18
      svr/svr-iot/src/main/java/com/yihu/iot/controller/company/IotCompanyController.java
  13. 208 50
      svr/svr-iot/src/main/java/com/yihu/iot/controller/device/IotDeviceController.java
  14. 100 52
      svr/svr-iot/src/main/java/com/yihu/iot/controller/device/IotDeviceOrderController.java
  15. 6 4
      svr/svr-iot/src/main/java/com/yihu/iot/controller/device/IotDeviceQualityInspectionPlanController.java
  16. 13 9
      svr/svr-iot/src/main/java/com/yihu/iot/controller/product/IotProductController.java
  17. 14 3
      svr/svr-iot/src/main/java/com/yihu/iot/dao/device/IotDeviceDao.java
  18. 17 0
      svr/svr-iot/src/main/java/com/yihu/iot/dao/device/IotDeviceImportRecordDao.java
  19. 13 4
      svr/svr-iot/src/main/java/com/yihu/iot/service/company/IotCompanyService.java
  20. 0 15
      svr/svr-iot/src/main/java/com/yihu/iot/service/company/IotCompanyTypeService.java
  21. 225 9
      svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotDeviceOrderService.java
  22. 71 0
      svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotDeviceService.java
  23. 0 115
      web-gateway/src/main/java/com/yihu/jw/controller/iot/supplier/IotDeviceSupplierController.java
  24. 0 5
      web-gateway/src/main/java/com/yihu/jw/feign/fallbackfactory/iot/data_input/DataStandardConvertFeignFallbackFactory.java
  25. 0 50
      web-gateway/src/main/java/com/yihu/jw/feign/fallbackfactory/iot/supplier/IotDeviceSupplierFeignFallbackFactory.java
  26. 0 2
      web-gateway/src/main/java/com/yihu/jw/feign/iot/data_input/DataInputFeign.java
  27. 0 46
      web-gateway/src/main/java/com/yihu/jw/feign/iot/supplier/IotDeviceSupplierFeign.java

+ 98 - 0
common/common-entity/src/main/java/com/yihu/jw/iot/device/IotDeviceImportRecordDO.java

@ -0,0 +1,98 @@
package com.yihu.jw.iot.device;
import com.yihu.jw.IdEntityWithOperation;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * 设备批量导入历史记录
 * @author yeshijie on 2018/1/18.
 */
@Entity
@Table(name = "iot_device_import_record")
public class IotDeviceImportRecordDO extends IdEntityWithOperation implements Serializable {
    @Column(name = "saas_id")
    private String saasId;//
    @Column(name = "file_name")
    private String fileName;//导入文件名
    @Column(name = "file_url")
    private String fileUrl;//导入文件连接
    @Column(name = "result_url")
    private String resultUrl;//导入结果连接
    @Column(name = "order_id")
    private String orderId;//订单id
    @Column(name = "purchase_id")
    private String purchaseId;//采购id
    @Column(name = "status")
    private String status;//导入状态(1进行中,2已完成)
    @Column(name = "del")
    private Integer del;//删除标志
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    public String getFileName() {
        return fileName;
    }
    public void setFileName(String fileName) {
        this.fileName = fileName;
    }
    public String getFileUrl() {
        return fileUrl;
    }
    public void setFileUrl(String fileUrl) {
        this.fileUrl = fileUrl;
    }
    public String getResultUrl() {
        return resultUrl;
    }
    public void setResultUrl(String resultUrl) {
        this.resultUrl = resultUrl;
    }
    public String getOrderId() {
        return orderId;
    }
    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }
    public String getPurchaseId() {
        return purchaseId;
    }
    public void setPurchaseId(String purchaseId) {
        this.purchaseId = purchaseId;
    }
    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
    public Integer getDel() {
        return del;
    }
    public void setDel(Integer del) {
        this.del = del;
    }
}

+ 30 - 12
common/common-entity/src/main/java/com/yihu/jw/iot/device/IotDeviceOrderDO.java

@ -23,7 +23,7 @@ public class IotDeviceOrderDO extends IdEntityWithOperation implements Serializa
    private String orderNo;//订单编号
    @Column(name = "order_status")
    private String orderStatus;//订单状态
    private String orderStatus;//订单状态(1新增、2已采购、3已入库)
    @Column(name = "purchase_time")
    private Date purchaseTime;//采购时间
@ -52,9 +52,6 @@ public class IotDeviceOrderDO extends IdEntityWithOperation implements Serializa
    @Column(name = "supplier_name")
    private String supplierName;//供应商名称
    @Column(name = "supplier_type")
    private String supplierType;//供应商类型
    @Column(name = "supplier_leader")
    private String supplierLeader;//供应商负责人
@ -70,6 +67,35 @@ public class IotDeviceOrderDO extends IdEntityWithOperation implements Serializa
    @Column(name = "del")
    private Integer del;//删除标志
    public enum DeviceOrderStatus {
        create("新增", "1"),
        purchased("已采购", "2"),
        storaged("已入库", "3");
        private String name;
        private String value;
        DeviceOrderStatus(String name, String value) {
            this.name = name;
            this.value = value;
        }
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public String getValue() {
            return value;
        }
        public void setValue(String value) {
            this.value = value;
        }
    }
    public String getSaasId() {
        return saasId;
    }
@ -166,14 +192,6 @@ public class IotDeviceOrderDO extends IdEntityWithOperation implements Serializa
        this.supplierName = supplierName;
    }
    public String getSupplierType() {
        return supplierType;
    }
    public void setSupplierType(String supplierType) {
        this.supplierType = supplierType;
    }
    public String getSupplierLeader() {
        return supplierLeader;
    }

+ 31 - 10
common/common-entity/src/main/java/com/yihu/jw/iot/device/IotOrderPurchaseDO.java

@ -6,7 +6,6 @@ import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.Date;
/**
 * 采购清单表
@ -49,12 +48,18 @@ public class IotOrderPurchaseDO extends IdEntityWithOperation implements Seriali
    @Column(name = "purchase_num")
    private Long purchaseNum;//采购数量
    @Column(name = "next_quality_time")
    private Date nextQualityTime;//'下次质检时间'
//    @Column(name = "next_quality_time")
//    private Date nextQualityTime;//'下次质检时间'
    @Column(name = "quality_status")
    private String qualityStatus;//'质检状态'
    @Column(name = "maintenance_unit_id")
    private String maintenanceUnitId;//维护单位Id
    @Column(name = "maintenance_unit_name")
    private String maintenanceUnitName;//维护单位名称
    @Column(name = "del")
    private Integer del;//删除标志
@ -146,13 +151,13 @@ public class IotOrderPurchaseDO extends IdEntityWithOperation implements Seriali
        this.purchaseNum = purchaseNum;
    }
    public Date getNextQualityTime() {
        return nextQualityTime;
    }
    public void setNextQualityTime(Date nextQualityTime) {
        this.nextQualityTime = nextQualityTime;
    }
//    public Date getNextQualityTime() {
//        return nextQualityTime;
//    }
//
//    public void setNextQualityTime(Date nextQualityTime) {
//        this.nextQualityTime = nextQualityTime;
//    }
    public String getQualityStatus() {
        return qualityStatus;
@ -169,4 +174,20 @@ public class IotOrderPurchaseDO extends IdEntityWithOperation implements Seriali
    public void setDel(Integer del) {
        this.del = del;
    }
    public String getMaintenanceUnitId() {
        return maintenanceUnitId;
    }
    public void setMaintenanceUnitId(String maintenanceUnitId) {
        this.maintenanceUnitId = maintenanceUnitId;
    }
    public String getMaintenanceUnitName() {
        return maintenanceUnitName;
    }
    public void setMaintenanceUnitName(String maintenanceUnitName) {
        this.maintenanceUnitName = maintenanceUnitName;
    }
}

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

@ -16,6 +16,8 @@ public class IotRequestMapping {
        public static final String system_dict = api_iot_common + "/systemDict";
        public static final String file_upload = api_iot_common + "/fileUpload";
        public static final String product = api_iot_common + "/product";
        public static final String order = api_iot_common + "/order";
        public static final String device = api_iot_common + "/device";
        public static final String message_success_update = "update success";
@ -191,6 +193,12 @@ public class IotRequestMapping {
        public static final String api_queryPage = "queryDevicePage";
        public static final String api_getList = "getDeviceList";
        public static final String isSnExist = "isSnExist";
        public static final String isSimExist = "isSimExist";
        public static final String importDevice = "importDevice";
        public static final String queryImportRecordPage = "queryImportRecordPage";
        public static final String message_success_update = "device update success";
        public static final String message_success_delete = "device delete success";
        public static final String message_success_find = "device find success";
@ -210,6 +218,13 @@ public class IotRequestMapping {
     * 设备订单模块常量
     */
    public static class DeviceOrder{
        public static final String findPage = "findPage";
        public static final String findById = "findById";
        public static final String delOrder = "delOrder";
        public static final String updOrder = "updOrder";
        public static final String findPurcharsePage = "findPurcharsePage";
        public static final String api_create = "deviceOrder";
        public static final String api_delete = "deviceOrder";
        public static final String api_getById = "getDeviceOrderById";

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

@ -0,0 +1,33 @@
package com.yihu.jw.restmodel.iot.common;
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/18.
 */
@JsonInclude(JsonInclude.Include.ALWAYS)
@ApiModel(description = "是否存在")
public class ExistVO implements Serializable{
    @ApiModelProperty("是否存在(1已经存在,2不存在)")
    private Integer isExist;
    public ExistVO() {
    }
    public ExistVO(Integer isExist) {
        this.isExist = isExist;
    }
    public Integer getIsExist() {
        return isExist;
    }
    public void setIsExist(Integer isExist) {
        this.isExist = isExist;
    }
}

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

@ -0,0 +1,78 @@
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/18.
 */
@JsonInclude(JsonInclude.Include.ALWAYS)
@ApiModel(description = "设备批量导入历史记录")
public class IotDeviceImportRecordVO implements Serializable {
    @ApiModelProperty("导入文件名")
    private String fileName;
    @ApiModelProperty("导入文件连接")
    private String fileUrl;
    @ApiModelProperty("导入结果连接")
    private String resultUrl;
    @ApiModelProperty("订单id")
    private String orderId;
    @ApiModelProperty("采购id")
    private String purchaseId;
    @ApiModelProperty("导入状态(1进行中,2已完成)")
    private String status;
    public String getFileName() {
        return fileName;
    }
    public void setFileName(String fileName) {
        this.fileName = fileName;
    }
    public String getFileUrl() {
        return fileUrl;
    }
    public void setFileUrl(String fileUrl) {
        this.fileUrl = fileUrl;
    }
    public String getResultUrl() {
        return resultUrl;
    }
    public void setResultUrl(String resultUrl) {
        this.resultUrl = resultUrl;
    }
    public String getOrderId() {
        return orderId;
    }
    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }
    public String getPurchaseId() {
        return purchaseId;
    }
    public void setPurchaseId(String purchaseId) {
        this.purchaseId = purchaseId;
    }
    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
}

+ 13 - 11
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/device/IotDeviceOrderVO.java

@ -3,11 +3,13 @@ package com.yihu.jw.restmodel.iot.device;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.yihu.jw.restmodel.iot.common.BaseVO;
import com.yihu.jw.restmodel.iot.company.IotCompanyTypeVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
/**
 * 设备订单表
@ -40,8 +42,6 @@ public class IotDeviceOrderVO extends BaseVO implements Serializable{
    private String supplierId;
    @ApiModelProperty("供应商名称")
    private String supplierName;
    @ApiModelProperty("供应商类型")
    private String supplierType;
    @ApiModelProperty("供应商负责人")
    private String supplierLeader;
    @ApiModelProperty("供应商负责人联系方式")
@ -49,6 +49,9 @@ public class IotDeviceOrderVO extends BaseVO implements Serializable{
    @ApiModelProperty("订单说明")
    private String instruction;
    @ApiModelProperty("类型")
    private List<IotCompanyTypeVO> typeList;
    public String getOrderNo() {
        return orderNo;
    }
@ -137,14 +140,6 @@ public class IotDeviceOrderVO extends BaseVO implements Serializable{
        this.supplierName = supplierName;
    }
    public String getSupplierType() {
        return supplierType;
    }
    public void setSupplierType(String supplierType) {
        this.supplierType = supplierType;
    }
    public String getSupplierLeader() {
        return supplierLeader;
    }
@ -168,5 +163,12 @@ public class IotDeviceOrderVO extends BaseVO implements Serializable{
    public void setInstruction(String instruction) {
        this.instruction = instruction;
    }
    
    public List<IotCompanyTypeVO> getTypeList() {
        return typeList;
    }
    public void setTypeList(List<IotCompanyTypeVO> typeList) {
        this.typeList = typeList;
    }
}

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

@ -38,6 +38,14 @@ public class IotOrderPurchaseVO extends BaseVO implements Serializable{
    private Date nextQualityTime;
    @ApiModelProperty("质检状态")
    private String qualityStatus;
    @ApiModelProperty("维护单位Id")
    private String maintenanceUnitId;
    @ApiModelProperty("维护单位名称")
    private String maintenanceUnitName;
    @ApiModelProperty("已关联数量")
    private Long associatedNum;
    @ApiModelProperty("未关联数量")
    private Long unAssociatedNum;
    public String getOrderId() {
        return orderId;
@ -118,5 +126,36 @@ public class IotOrderPurchaseVO extends BaseVO implements Serializable{
    public void setQualityStatus(String qualityStatus) {
        this.qualityStatus = qualityStatus;
    }
    
    public String getMaintenanceUnitId() {
        return maintenanceUnitId;
    }
    public void setMaintenanceUnitId(String maintenanceUnitId) {
        this.maintenanceUnitId = maintenanceUnitId;
    }
    public String getMaintenanceUnitName() {
        return maintenanceUnitName;
    }
    public void setMaintenanceUnitName(String maintenanceUnitName) {
        this.maintenanceUnitName = maintenanceUnitName;
    }
    public Long getAssociatedNum() {
        return associatedNum;
    }
    public void setAssociatedNum(Long associatedNum) {
        this.associatedNum = associatedNum;
    }
    public Long getUnAssociatedNum() {
        return unAssociatedNum;
    }
    public void setUnAssociatedNum(Long unAssociatedNum) {
        this.unAssociatedNum = unAssociatedNum;
    }
}

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

@ -0,0 +1,39 @@
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;
import java.util.List;
/**
 * @author yeshijie on 2018/1/18.
 */
@JsonInclude(JsonInclude.Include.ALWAYS)
@ApiModel(value = "设备订单", description = "设备订单")
public class IotOrderVO implements Serializable{
    @ApiModelProperty("设备订单")
    private IotDeviceOrderVO iotDeviceOrderVO;
    @ApiModelProperty("采购清单")
    private List<IotOrderPurchaseVO> purchaseVOList;
    public IotDeviceOrderVO getIotDeviceOrderVO() {
        return iotDeviceOrderVO;
    }
    public void setIotDeviceOrderVO(IotDeviceOrderVO iotDeviceOrderVO) {
        this.iotDeviceOrderVO = iotDeviceOrderVO;
    }
    public List<IotOrderPurchaseVO> getPurchaseVOList() {
        return purchaseVOList;
    }
    public void setPurchaseVOList(List<IotOrderPurchaseVO> purchaseVOList) {
        this.purchaseVOList = purchaseVOList;
    }
}

+ 5 - 0
svr/svr-iot/pom.xml

@ -136,6 +136,11 @@
            <artifactId>commons-lang3</artifactId>
            <version>3.3.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.15-beta1</version>
        </dependency>
    </dependencies>
    <build>
        <finalName>svr-iot</finalName>

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

@ -35,7 +35,7 @@ public class FileUploadController extends EnvelopRestController{
    @Value("${fastDFS.fastdfs_file_url}")
    private String fastdfs_file_url;
    @PostMapping(value = IotRequestMapping.FileUpload.api_upload_stream)
    @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){

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

@ -2,7 +2,6 @@ package com.yihu.iot.controller.company;
import com.yihu.iot.service.company.IotCompanyCertificateService;
import com.yihu.iot.service.company.IotCompanyService;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.iot.company.IotCompanyCertificateDO;
import com.yihu.jw.iot.company.IotCompanyDO;
import com.yihu.jw.restmodel.common.Envelop;
@ -59,6 +58,7 @@ public class IotCompanyController extends EnvelopRestController {
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
@ -70,12 +70,12 @@ public class IotCompanyController extends EnvelopRestController {
        try {
            IotCompanyDO iotCompany = toEntity(jsonData, IotCompanyDO.class);
            return Envelop.getSuccess(IotRequestMapping.Company.message_success_create, iotCompanyService.create(iotCompany));
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        } 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")
@ -84,8 +84,9 @@ public class IotCompanyController extends EnvelopRestController {
            IotCompanyDO iotCompanyDO = iotCompanyService.findById(id);
            IotCompanyVO vo = iotCompanyService.convertToModelVO(iotCompanyDO);
            return Envelop.getSuccess(IotRequestMapping.Company.message_success_find, vo);
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
@ -97,8 +98,9 @@ public class IotCompanyController extends EnvelopRestController {
            IotCompanyDO iotCompanyDO = iotCompanyService.findByBusinessLicense(businessLicense);
            IotCompanyVO vo = iotCompanyService.convertToModelVO(iotCompanyDO);
            return Envelop.getSuccess(IotRequestMapping.Company.message_success_find, vo);
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
@ -109,8 +111,9 @@ public class IotCompanyController extends EnvelopRestController {
        try {
            iotCompanyService.delCompany(id);
            return Envelop.getSuccess(IotRequestMapping.Company.message_success_find);
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
@ -122,8 +125,9 @@ public class IotCompanyController extends EnvelopRestController {
            IotCompanyDO iotCompany = toEntity(jsonData, IotCompanyDO.class);
            iotCompanyService.updCompany(iotCompany);
            return Envelop.getSuccess(IotRequestMapping.Company.message_success_find);
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
@ -145,6 +149,7 @@ public class IotCompanyController extends EnvelopRestController {
            }
            return iotCompanyCertificateService.queryPage(page,size,name);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
@ -157,8 +162,9 @@ public class IotCompanyController extends EnvelopRestController {
            IotCompanyCertificateDO iotCompanyCertificateDO = iotCompanyCertificateService.findById(id);
            IotCompanyCertificateVO vo = convertToModel(iotCompanyCertificateDO,IotCompanyCertificateVO.class);
            return Envelop.getSuccess(IotRequestMapping.Common.message_success_find, vo);
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
@ -170,8 +176,9 @@ public class IotCompanyController extends EnvelopRestController {
            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 (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
@ -182,8 +189,9 @@ public class IotCompanyController extends EnvelopRestController {
        try {
            IotCompanyCertificateDO iotCompanyCertificate = toEntity(jsonData, IotCompanyCertificateDO.class);
            return Envelop.getSuccess(IotRequestMapping.Common.message_success_create, iotCompanyCertificateService.create(iotCompanyCertificate));
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }

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

@ -1,99 +1,257 @@
package com.yihu.iot.controller.device;
import com.yihu.base.fastdfs.FastDFSHelper;
import com.yihu.iot.dao.device.IotDeviceImportRecordDao;
import com.yihu.iot.service.device.IotDeviceService;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.iot.device.IotDeviceDO;
import com.yihu.jw.iot.device.IotDeviceImportRecordDO;
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.common.UploadVO;
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.apache.commons.lang.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
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 javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
 * @author yeshijie on 2017/12/8.
 */
@RestController
@RequestMapping(IotRequestMapping.api_iot_common)
@RequestMapping(IotRequestMapping.Common.device)
@Api(tags = "设备管理相关操作", description = "设备管理相关操作")
public class IotDeviceController extends EnvelopRestController{
    private Logger logger = LoggerFactory.getLogger(IotDeviceController.class);
    @Autowired
    private IotDeviceService iotDeviceService;
    @Autowired
    private FastDFSHelper fastDFSHelper;
    @Value("${fastDFS.fastdfs_file_url}")
    private String fastdfs_file_url;
    @Autowired
    private IotDeviceImportRecordDao iotDeviceImportRecordDao;
    @PostMapping(value = IotRequestMapping.Device.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建设备", notes = "创建设备")
    public Envelop create(@ApiParam(name = "json_data", value = "", defaultValue = "")
    public Envelop<IotDeviceVO> create(@ApiParam(name = "json_data", value = "", defaultValue = "")
                          @RequestBody String jsonData) {
        try {
            IotDeviceDO iotDevice = toEntity(jsonData, IotDeviceDO.class);
            return Envelop.getSuccess(IotRequestMapping.Device.message_success_create, iotDeviceService.create(iotDevice));
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
            if(StringUtils.isBlank(iotDevice.getDeviceSn())){
                return Envelop.getError("sn码不能为空");
            }
            if(iotDeviceService.findByDeviceSn(iotDevice.getDeviceSn())!=null){
                return Envelop.getError("SN码重复,并不允许新增");
            }
            if(StringUtils.isNotBlank(iotDevice.getSimNo())&&iotDeviceService.findByDeviceSn(iotDevice.getSimNo())!=null){
                return Envelop.getError("SIM卡号重复,并不允许新增");
            }
            iotDeviceService.create(iotDevice);
            return Envelop.getSuccess(IotRequestMapping.Device.message_success_create);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.Device.api_getById)
    @ApiOperation(value = "根据code查找设备", notes = "根据code查找设备")
    public Envelop findByCode(@ApiParam(name = "id", value = "id")
    public Envelop<IotDeviceVO> findByCode(@ApiParam(name = "id", value = "id")
                              @RequestParam(value = "id", required = true) String id
    ) {
        try {
            return Envelop.getSuccess(IotRequestMapping.Device.message_success_find, iotDeviceService.findById(id));
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
            IotDeviceDO iotDeviceDO = iotDeviceService.findById(id);
            IotDeviceVO iotDeviceVO = convertToModel(iotDeviceDO,IotDeviceVO.class);
            return Envelop.getSuccess(IotRequestMapping.Device.message_success_find, iotDeviceVO);
        } 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 {
            IotDeviceDO iotDeviceDO = iotDeviceService.findByDeviceSn(sn);
            ExistVO existVO = new ExistVO(iotDeviceDO==null?0:1);
            return Envelop.getSuccess(IotRequestMapping.Device.message_success_find, existVO);
        } 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 {
            IotDeviceDO iotDeviceDO = iotDeviceService.findBySimNo(sim);
            ExistVO existVO = new ExistVO(iotDeviceDO==null?0:1);
            return Envelop.getSuccess(IotRequestMapping.Device.message_success_find, existVO);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @RequestMapping(value = IotRequestMapping.Device.api_queryPage, method = RequestMethod.GET)
    @ApiOperation(value = "分页获取设备")
    public Envelop queryPage(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段(id,supplierName,type,contactsName,contactsMobile)", defaultValue = "")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件(supplierName?中 g1;contactsName?中 g1)")
            @RequestParam(value = "filters", required = false,defaultValue = "") String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "-createTime")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) Integer size,
            @ApiParam(name = "page", value = "页码", defaultValue = "1")
            @RequestParam(value = "page", required = false) Integer page,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        //得到list数据
        List<IotDeviceDO> list = iotDeviceService.search(fields, filters, sorts, page, size);
        //获取总数
        long count=iotDeviceService.getCount(filters);
        //封装头信息
        pagedResponse(request, response, count, page, size);
        //封装返回格式
        List<IotDeviceDO> iotDevices = convertToModels(list, new ArrayList<>(list.size()), IotDeviceDO.class, fields);
    @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;
            }
            String filters = "";
            String semicolon = "";
            if(StringUtils.isNotBlank(orderId)){
                filters += semicolon +"orderId="+orderId;
                semicolon = ";";
            }
            if(StringUtils.isNotBlank(purcharseId)){
                filters += semicolon +"purcharseId="+purcharseId;
                semicolon = ";";
            }
            if(StringUtils.isNotBlank(hospital)){
                filters += semicolon +"hospital="+hospital;
                semicolon = ";";
            }
            if(StringUtils.isNotBlank(sn)){
                filters = "deviceSn?"+sn+" g1;simNo?"+sn+" g1";
                semicolon = ";";
            }
            if(StringUtils.isBlank(filters)){
                filters+= semicolon + "del=1";
            }
            String sorts = "-updateTime";
            //得到list数据
            List<IotDeviceDO> list = iotDeviceService.search(null, filters, sorts, page, size);
            //获取总数
            long count = iotDeviceService.getCount(filters);
            //DO转VO
            List<IotDeviceVO> iotDeviceVOList = convertToModels(list,new ArrayList<>(list.size()),IotDeviceVO.class);
        return Envelop.getSuccessListWithPage(IotRequestMapping.Device.message_success_find_functions,iotDevices, page, size,count);
            return Envelop.getSuccessListWithPage(IotRequestMapping.Company.message_success_find_functions,iotDeviceVOList, page, size,count);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.Device.importDevice)
    @ApiOperation(value = "设备导入", notes = "设备导入")
    public Envelop<UploadVO> 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 {
            // 得到文件的完整名称  xxx.txt
            String fullName = file.getOriginalFilename();
            //得到文件类型
            String fileType = fullName.substring(fullName.lastIndexOf(".") + 1).toLowerCase();
            if(!"xls".equals(fileType)){
                return Envelop.getError("文件格式不正确");
            }
            IotDeviceImportRecordDO recordDO = iotDeviceImportRecordDao.findByPurchaseId(purcharseId);
            if(recordDO!=null){
                return Envelop.getError("正在导入中,请耐心等待");
            }
            String fileName = fullName.substring(0, fullName.lastIndexOf("."));
            HSSFWorkbook wb = null;
            try {
                wb = new HSSFWorkbook(file.getInputStream());
                // logger.debug(wb.getNumberOfSheets());
                HSSFSheet sheet = wb.getSheetAt(0);
                logger.debug("sheet name = "+wb.getSheetName(0));
                for(int i = sheet.getFirstRowNum();i<=sheet.getLastRowNum();i++){
                    HSSFRow row = sheet.getRow(i);
                    Iterator cells = row.cellIterator();
                    while(cells.hasNext()){
                        HSSFCell cell = (HSSFCell) cells.next();
                        logger.debug(cell.getStringCellValue());
                    }
                }
                logger.debug("last row = "+sheet.getLastRowNum());
    @GetMapping(value = IotRequestMapping.Device.api_getList)
    @ApiOperation(value = "获取设备列表(不分页)")
    public Envelop getList(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段(id,supplierName,type,contactsName,contactsMobile)", defaultValue = "")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "-createTime")
            @RequestParam(value = "sorts", required = false) String sorts) throws Exception {
        //得到list数据
        List<IotDeviceDO> list = iotDeviceService.search(fields,filters,sorts);
        //封装返回格式
        List<IotDeviceDO> iotDevices = convertToModels(list, new ArrayList<>(list.size()), IotDeviceDO.class, fields);
        return Envelop.getSuccessList(IotRequestMapping.Device.message_success_find_functions,iotDevices);
//                return wb.getNumberOfSheets();
//            return sheet.getFirstRowNum();
            } catch (Exception e) {
                e.printStackTrace();
                logger.error(e.getMessage());
            }
            //上传到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);
        }
    }
    @GetMapping(value = IotRequestMapping.Device.queryImportRecordPage)
    @ApiOperation(value = "分页查找导入记录", notes = "分页查找导入记录")
    public Envelop<IotDeviceImportRecordVO> findProductPageByCompanyId(@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 iotDeviceService.queryImportRecordPage(page,size,purcharseId);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
}

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

@ -1,21 +1,25 @@
package com.yihu.iot.controller.device;
import com.yihu.iot.service.company.IotCompanyService;
import com.yihu.iot.service.device.IotDeviceOrderService;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.iot.company.IotCompanyTypeDO;
import com.yihu.jw.iot.device.IotDeviceOrderDO;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.common.EnvelopRestController;
import com.yihu.jw.restmodel.iot.company.IotCompanyTypeVO;
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.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;
@ -23,78 +27,122 @@ import java.util.List;
 * @author yeshijie on 2017/12/8.
 */
@RestController
@RequestMapping(IotRequestMapping.api_iot_common)
@RequestMapping(IotRequestMapping.Common.order)
@Api(tags = "设备订单管理相关操作", description = "设备订单管理相关操作")
public class IotDeviceOrderController extends EnvelopRestController{
    @Autowired
    private IotDeviceOrderService iotDeviceOrderService;
    @Autowired
    private IotCompanyService iotCompanyService;
    @PostMapping(value = IotRequestMapping.DeviceOrder.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建设备订单", notes = "创建设备订单")
    public Envelop<IotDeviceOrderVO> create(@ApiParam(name = "json_data", value = "", defaultValue = "")
    public Envelop<IotOrderVO> create(@ApiParam(name = "json_data", value = "", defaultValue = "")
                          @RequestBody String jsonData) {
        try {
            IotDeviceOrderDO iotDeviceOrder = toEntity(jsonData, IotDeviceOrderDO.class);
            iotDeviceOrderService.create(iotDeviceOrder);
            IotOrderVO iotOrderVO = toEntity(jsonData, IotOrderVO.class);
            iotDeviceOrderService.create(iotOrderVO);
            return Envelop.getSuccess(IotRequestMapping.DeviceOrder.message_success_create);
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.DeviceOrder.api_getById)
    @ApiOperation(value = "根据code查找设备订单", notes = "根据code查找设备订单")
    public Envelop<IotDeviceOrderDO>  findByCode(@ApiParam(name = "id", value = "id")
    @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 Envelop.getSuccess(IotRequestMapping.DeviceOrder.message_success_find, iotDeviceOrderService.findById(id));
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
            IotDeviceOrderDO iotDeviceOrderDO = iotDeviceOrderService.findById(id);
            IotDeviceOrderVO deviceOrderVO = convertToModel(iotDeviceOrderDO,IotDeviceOrderVO.class);
            //获取企业类型
            List<IotCompanyTypeDO> companyTypeDOList = iotCompanyService.findTypeByCompanyId(deviceOrderVO.getSupplierId());
            List<IotCompanyTypeVO> companyTypeVOList = convertToModels(companyTypeDOList,new ArrayList<>(companyTypeDOList.size()),IotCompanyTypeVO.class);
            deviceOrderVO.setTypeList(companyTypeVOList);
            return Envelop.getSuccess(IotRequestMapping.DeviceOrder.message_success_find,deviceOrderVO);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @RequestMapping(value = IotRequestMapping.DeviceOrder.api_queryPage, method = RequestMethod.GET)
    @ApiOperation(value = "分页获取设备订单")
    public Envelop<IotDeviceOrderDO>  queryPage(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段(id,supplierName,type,contactsName,contactsMobile)", defaultValue = "")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件(supplierName?中 g1;contactsName?中 g1)")
            @RequestParam(value = "filters", required = false,defaultValue = "") String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "-createTime")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) Integer size,
            @ApiParam(name = "page", value = "页码", defaultValue = "1")
            @RequestParam(value = "page", required = false) Integer page,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        //得到list数据
        List<IotDeviceOrderDO> list = iotDeviceOrderService.search(fields, filters, sorts, page, size);
        //获取总数
        long count=iotDeviceOrderService.getCount(filters);
        //封装头信息
        pagedResponse(request, response, count, page, size);
        //封装返回格式
        List<IotDeviceOrderDO> iotDeviceOrders = convertToModels(list, new ArrayList<>(list.size()), IotDeviceOrderDO.class, fields);
    @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;
            }
            if(StringUtils.isBlank(type)){
                return iotDeviceOrderService.queryPage(page,size,name);
            }else {
                return iotDeviceOrderService.queryPage(page,size,name,type);
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
        return Envelop.getSuccessListWithPage(IotRequestMapping.DeviceOrder.message_success_find_functions,iotDeviceOrders, page, size,count);
    @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 {
            iotDeviceOrderService.delOrder(id);
            return Envelop.getSuccess(IotRequestMapping.DeviceOrder.message_success_find);
        } 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 {
            IotOrderVO iotOrderVO = toEntity(jsonData, IotOrderVO.class);
            iotDeviceOrderService.updOrder(iotOrderVO);
            return Envelop.getSuccess(IotRequestMapping.DeviceOrder.message_success_find);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.DeviceOrder.api_getList)
    @ApiOperation(value = "获取设备订单列表(不分页)")
    public Envelop<IotDeviceOrderDO>  getList(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段(id,supplierName,type,contactsName,contactsMobile)", defaultValue = "")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "-createTime")
            @RequestParam(value = "sorts", required = false) String sorts) throws Exception {
        //得到list数据
        List<IotDeviceOrderDO> list = iotDeviceOrderService.search(fields,filters,sorts);
        //封装返回格式
        List<IotDeviceOrderDO> iotDeviceOrders = convertToModels(list, new ArrayList<>(list.size()), IotDeviceOrderDO.class, fields);
        return Envelop.getSuccessList(IotRequestMapping.DeviceOrder.message_success_find_functions,iotDeviceOrders);
    @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 iotDeviceOrderService.queryPurcharsePage(page,size,orderId,"1");
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
}

+ 6 - 4
svr/svr-iot/src/main/java/com/yihu/iot/controller/device/IotDeviceQualityInspectionPlanController.java

@ -35,8 +35,9 @@ public class IotDeviceQualityInspectionPlanController extends EnvelopRestControl
        try {
            IotDeviceQualityInspectionPlanDO iotDeviceQualityInspectionPlan = toEntity(jsonData, IotDeviceQualityInspectionPlanDO.class);
            return Envelop.getSuccess(IotRequestMapping.DeviceQualityInspectionPlan.message_success_create, iotDeviceQualityInspectionPlanService.create(iotDeviceQualityInspectionPlan));
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
@ -47,8 +48,9 @@ public class IotDeviceQualityInspectionPlanController extends EnvelopRestControl
    ) {
        try {
            return Envelop.getSuccess(IotRequestMapping.DeviceQualityInspectionPlan.message_success_find, iotDeviceQualityInspectionPlanService.findById(id));
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }

+ 13 - 9
svr/svr-iot/src/main/java/com/yihu/iot/controller/product/IotProductController.java

@ -1,7 +1,6 @@
package com.yihu.iot.controller.product;
import com.yihu.iot.service.product.IotProductBaseInfoService;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.iot.product.IotProductBaseInfoDO;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.common.EnvelopRestController;
@ -71,6 +70,7 @@ public class IotProductController extends EnvelopRestController {
            return Envelop.getSuccessListWithPage(IotRequestMapping.Company.message_success_find_functions,iotCompanyVOList, page, size,count);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
@ -108,6 +108,7 @@ public class IotProductController extends EnvelopRestController {
            return Envelop.getSuccessListWithPage(IotRequestMapping.Company.message_success_find_functions,iotCompanyVOList, page, size,count);
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
@ -120,8 +121,9 @@ public class IotProductController extends EnvelopRestController {
            IotProductVO iotProductVO = toEntity(jsonData, IotProductVO.class);
            iotProductBaseInfoService.addProduct(iotProductVO);
            return Envelop.getSuccess(IotRequestMapping.Common.message_success_create);
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
@ -133,8 +135,8 @@ public class IotProductController extends EnvelopRestController {
        try {
            IotProductVO vo = iotProductBaseInfoService.findProductById(id);
            return Envelop.getSuccess(IotRequestMapping.Common.message_success_find, vo);
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        } catch (Exception e) {
            return Envelop.getError(e.getMessage());
        }
    }
@ -145,8 +147,9 @@ public class IotProductController extends EnvelopRestController {
        try {
            iotProductBaseInfoService.delProduct(id);
            return Envelop.getSuccess(IotRequestMapping.Common.message_success_find);
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }
@ -158,8 +161,9 @@ public class IotProductController extends EnvelopRestController {
            IotProductVO iotProductVO = toEntity(jsonData, IotProductVO.class);
            iotProductBaseInfoService.updProduct(iotProductVO);
            return Envelop.getSuccess(IotRequestMapping.Common.message_success_find);
        } catch (ApiException e) {
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        } catch (Exception e) {
            e.printStackTrace();
            return Envelop.getError(e.getMessage());
        }
    }

+ 14 - 3
svr/svr-iot/src/main/java/com/yihu/iot/dao/device/IotDeviceDao.java

@ -5,17 +5,28 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * @author yeshijie on 2017/12/1.
 */
public interface IotDeviceDao extends PagingAndSortingRepository<IotDeviceDO, String>, JpaSpecificationExecutor<IotDeviceDO> {
    @Query("from IotDeviceDO w where w.id =?1")
    @Query("from IotDeviceDO w where w.id =?1 and w.del=1")
    IotDeviceDO findById(String id);
    @Query("select count(*) from IotDeviceDO w where w.deviceSn =?1")
    @Query("select count(*) from IotDeviceDO w where w.deviceSn =?1 and w.del=1")
    int countByDeviceSn(String deviceSn);
    @Query("from IotDeviceDO w where w.deviceSn =?1")
    @Query("select count(*) from IotDeviceDO w where w.purchaseId =?1 and w.del=1")
    int countByPurchaseId(String purchaseId);
    @Query("from IotDeviceDO w where w.deviceSn =?1 and w.del=1")
    IotDeviceDO findByDeviceSn(String deviceSn);
    @Query("from IotDeviceDO w where w.simNo =?1 and w.del=1")
    IotDeviceDO findBySimNo(String simNo);
    @Query("from IotDeviceDO w where w.purchaseId =?1 and w.del=1")
    List<IotDeviceDO> findListByPurchaseId(String purchaseId);
}

+ 17 - 0
svr/svr-iot/src/main/java/com/yihu/iot/dao/device/IotDeviceImportRecordDao.java

@ -0,0 +1,17 @@
package com.yihu.iot.dao.device;
import com.yihu.jw.iot.device.IotDeviceDO;
import com.yihu.jw.iot.device.IotDeviceImportRecordDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * @author yeshijie on 2018/1/18.
 */
public interface IotDeviceImportRecordDao extends PagingAndSortingRepository<IotDeviceImportRecordDO, String>,
        JpaSpecificationExecutor<IotDeviceImportRecordDO> {
    @Query("from IotDeviceImportRecordDO w where w.purchaseId =?1 and w.status='1' and w.del=1")
    IotDeviceImportRecordDO findByPurchaseId(String purchaseId);
}

+ 13 - 4
svr/svr-iot/src/main/java/com/yihu/iot/service/company/IotCompanyService.java

@ -115,8 +115,8 @@ public class IotCompanyService extends BaseJpaService<IotCompanyDO,IotCompanyDao
     * @return
     */
    public Envelop<IotCompanyVO> queryPage(Integer page, Integer size, String status, String name, String type){
        StringBuffer sql = new StringBuffer("SELECT DISTINCT c.* from iot_company c ,iot_company_type t WHERE del=1 ");
        StringBuffer sqlCount = new StringBuffer("SELECT COUNT(DISTINCT c.id) count from iot_company c ,iot_company_type t WHERE del=1 ");
        StringBuffer sql = new StringBuffer("SELECT DISTINCT c.* from iot_company c ,iot_company_type t WHERE c.del=1 ");
        StringBuffer sqlCount = new StringBuffer("SELECT COUNT(DISTINCT c.id) count from iot_company c ,iot_company_type t WHERE c.del=1 ");
        List<Object> args = new ArrayList<>();
        if(StringUtils.isNotBlank(status)){
            sql.append(" and c.status=? ");
@ -124,8 +124,8 @@ public class IotCompanyService extends BaseJpaService<IotCompanyDO,IotCompanyDao
            args.add(status);
        }
        if(StringUtils.isNotBlank(name)){
            sql.append(" and (c.name like ? or c.contactsName like ?)");
            sqlCount.append(" and (c.name like '").append(name).append("' or c.contactsName like '").append(name).append("')");
            sql.append(" and (c.name like ? or c.contacts_name like ?)");
            sqlCount.append(" and (c.name like '").append(name).append("' or c.contacts_name like '").append(name).append("')");
            args.add(name);
            args.add(name);
        }
@ -215,6 +215,15 @@ public class IotCompanyService extends BaseJpaService<IotCompanyDO,IotCompanyDao
        company.setTypeList(list);
    }
    /**
     * 查找企业类型
     * @param companyId
     * @return
     */
    public List<IotCompanyTypeDO> findTypeByCompanyId(String companyId){
        return iotCompanyTypeDao.findByCompanyId(companyId);
    }
    /**
     * 删除
     * @param id

+ 0 - 15
svr/svr-iot/src/main/java/com/yihu/iot/service/company/IotCompanyTypeService.java

@ -1,15 +0,0 @@
package com.yihu.iot.service.company;
import com.yihu.base.mysql.query.BaseJpaService;
import com.yihu.iot.dao.company.IotCompanyTypeDao;
import com.yihu.jw.iot.company.IotCompanyTypeDO;
import org.springframework.stereotype.Service;
/**
 * @author yeshijie on 2018/1/16.
 */
@Service
public class IotCompanyTypeService extends BaseJpaService<IotCompanyTypeDO,IotCompanyTypeDao> {
}

+ 225 - 9
svr/svr-iot/src/main/java/com/yihu/iot/service/device/IotDeviceOrderService.java

@ -1,14 +1,31 @@
package com.yihu.iot.service.device;
import com.yihu.base.mysql.query.BaseJpaService;
import com.yihu.iot.dao.company.IotCompanyTypeDao;
import com.yihu.iot.dao.device.IotDeviceDao;
import com.yihu.iot.dao.device.IotDeviceOrderDao;
import com.yihu.iot.dao.device.IotOrderPurchaseDao;
import com.yihu.jw.iot.company.IotCompanyTypeDO;
import com.yihu.jw.iot.device.IotDeviceOrderDO;
import com.yihu.jw.iot.device.IotOrderPurchaseDO;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.iot.company.IotCompanyTypeVO;
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 com.yihu.jw.util.date.DateUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
 * @author yeshijie on 2017/12/8.
@ -18,28 +35,227 @@ public class IotDeviceOrderService extends BaseJpaService<IotDeviceOrderDO,IotDe
    @Autowired
    private IotDeviceOrderDao iotDeviceOrderDao;
    @Autowired
    private IotOrderPurchaseDao iotOrderPurchaseDao;
    @Autowired
    private IotCompanyTypeDao iotCompanyTypeDao;
    @Autowired
    private JdbcTemplate jdbcTempalte;
    @Autowired
    private IotDeviceDao iotDeviceDao;
    /**
     * 新增
     * @param iotDeviceOrder
     * @param iotOrderVO
     * @return
     */
    public IotDeviceOrderDO create(IotDeviceOrderDO iotDeviceOrder) {
    public IotDeviceOrderDO create(IotOrderVO iotOrderVO) {
        IotDeviceOrderVO iotDeviceOrderVO = iotOrderVO.getIotDeviceOrderVO();
        List<IotOrderPurchaseVO> iotOrderPurchaseVOList = iotOrderVO.getPurchaseVOList();
        IotDeviceOrderDO iotDeviceOrderDO = convertToModel(iotDeviceOrderVO,IotDeviceOrderDO.class);
        List<IotOrderPurchaseDO> orderPurchaseDOList =
                convertToModels(iotOrderPurchaseVOList,new ArrayList<>(iotOrderPurchaseVOList.size()),IotOrderPurchaseDO.class);
        String time = DateUtil.dateToStr(new Date(),DateUtil.YYYYMMDD);
        List<IotDeviceOrderDO> doList = iotDeviceOrderDao.findByYmd(time);
        iotDeviceOrder.setOrderNo(String.format("",doList.size()));
        iotDeviceOrder.setSaasId(getCode());
        iotDeviceOrder.setDel(1);
        iotDeviceOrder.setYmd(time);
        return iotDeviceOrderDao.save(iotDeviceOrder);
        String orderNo = String.format("%05d",doList.size());
        iotDeviceOrderDO.setOrderNo(orderNo);
        iotDeviceOrderDO.setOrderStatus(IotDeviceOrderDO.DeviceOrderStatus.create.getValue());
        iotDeviceOrderDO.setSaasId(getCode());
        iotDeviceOrderDO.setDel(1);
        iotDeviceOrderDO.setYmd(time);
        iotDeviceOrderDao.save(iotDeviceOrderDO);
        String orderId = iotDeviceOrderDO.getId();
        //采购清单
        orderPurchaseDOList.forEach(purchase->{
            purchase.setDel(1);
            purchase.setOrderId(orderId);
            purchase.setOrderNo(orderNo);
            purchase.setSaasId(getCode());
        });
        iotOrderPurchaseDao.save(orderPurchaseDOList);
        return iotDeviceOrderDO;
    }
    /**
     * 按id查找
     * @param id
     * @return
     */
    public IotDeviceOrderDO findById(String id) {
        return iotDeviceOrderDao.findById(id);
    }
    public static void main(String[] args) {
        System.out.println(String.format("%05d", 5));
    /**
     * 删除
     * @param id
     */
    public void delOrder(String id){
        IotDeviceOrderDO order = iotDeviceOrderDao.findById(id);
        order.setDel(0);
        iotDeviceOrderDao.save(order);
    }
    /**
     * 修改订单
     * @param iotOrderVO
     */
    public void updOrder(IotOrderVO iotOrderVO){
        IotDeviceOrderVO iotDeviceOrderVO = iotOrderVO.getIotDeviceOrderVO();
        List<IotOrderPurchaseVO> iotOrderPurchaseVOList = iotOrderVO.getPurchaseVOList();
        IotDeviceOrderDO iotDeviceOrderDO = convertToModel(iotDeviceOrderVO,IotDeviceOrderDO.class);
        List<IotOrderPurchaseDO> orderPurchaseDOList =
                convertToModels(iotOrderPurchaseVOList,new ArrayList<>(iotOrderPurchaseVOList.size()),IotOrderPurchaseDO.class);
        IotDeviceOrderDO iotDeviceOrderDOOld = iotDeviceOrderDao.findById(iotDeviceOrderDO.getId());
        iotDeviceOrderDO.setOrderNo(iotDeviceOrderDOOld.getOrderNo());
        iotDeviceOrderDO.setOrderStatus(iotDeviceOrderDOOld.getOrderStatus());
        iotDeviceOrderDO.setSaasId(iotDeviceOrderDOOld.getSaasId());
        iotDeviceOrderDO.setDel(1);
        iotDeviceOrderDO.setYmd(iotDeviceOrderDOOld.getYmd());
        iotDeviceOrderDao.save(iotDeviceOrderDO);
        //采购清单
        orderPurchaseDOList.forEach(purchase->{
            IotOrderPurchaseDO purchaseDOOld = iotOrderPurchaseDao.findById(purchase.getId());
            purchase.setDel(1);
            purchase.setOrderId(purchaseDOOld.getOrderId());
            purchase.setOrderNo(purchaseDOOld.getOrderNo());
            purchase.setSaasId(purchaseDOOld.getSaasId());
        });
        iotOrderPurchaseDao.save(orderPurchaseDOList);
    }
    /**
     * 分页查找
     * @param page
     * @param size
     * @param name
     * @return
     * @throws ParseException
     */
    public Envelop<IotDeviceOrderVO> queryPage(Integer page, Integer size, String name) throws ParseException {
        String filters = "";
        String semicolon = "";
        if(StringUtils.isNotBlank(name)){
            filters = "supplierName?"+name+" g1;purchaserName?"+name+" g1";
            semicolon = ";";
        }
        if(StringUtils.isBlank(filters)){
            filters+= semicolon + "del=1";
        }
        String sorts = "-updateTime";
        //得到list数据
        List<IotDeviceOrderDO> list = search(null, filters, sorts, page, size);
        //获取总数
        long count = getCount(filters);
        //DO转VO
        List<IotDeviceOrderVO> iotDeviceOrderVOList = convertToModels(list,new ArrayList<>(list.size()),IotDeviceOrderVO.class);
        iotDeviceOrderVOList.forEach(one->{
            findType(one);
        });
        return Envelop.getSuccessListWithPage(IotRequestMapping.Common.message_success_find_functions,iotDeviceOrderVOList, page, size,count);
    }
    /**
     * 添加类型
     * @param deviceOrderVO
     */
    public void findType(IotDeviceOrderVO deviceOrderVO){
        //查找类型
        List<IotCompanyTypeDO> companyTypes = iotCompanyTypeDao.findByCompanyId(deviceOrderVO.getSupplierId());
        List<IotCompanyTypeVO> list = new ArrayList<>(8);
        if(companyTypes.size()>0){
            companyTypes.forEach(one->{
                IotCompanyTypeVO vo = new IotCompanyTypeVO();
                vo.setType(one.getType());
                vo.setTypeName(one.getTypeName());
                list.add(vo);
            });
        }
        deviceOrderVO.setTypeList(list);
    }
    /**
     * 按类型分页查找
     * @param page
     * @param size
     * @param name
     * @param type
     * @return
     */
    public Envelop<IotDeviceOrderVO> queryPage(Integer page, Integer size, String name, String type){
        StringBuffer sql = new StringBuffer("SELECT DISTINCT c.* from iot_device_order c ,iot_company_type t WHERE c.del=1 ");
        StringBuffer sqlCount = new StringBuffer("SELECT COUNT(DISTINCT c.id) count from iot_device_order c ,iot_company_type t WHERE c.del=1 ");
        List<Object> args = new ArrayList<>();
        if(StringUtils.isNotBlank(name)){
            sql.append(" and (c.supplier_name like ? or c.purchaser_name like ?)");
            sqlCount.append(" and (c.supplier_name like '").append(name).append("' or c.purchaser_name like '").append(name).append("')");
            args.add(name);
            args.add(name);
        }
        if(StringUtils.isNotBlank(type)){
            sql.append(" and t.type=? ");
            sqlCount.append(" and t.type='").append(type).append("' ");
            args.add(type);
        }
        sql.append("order by c.update_time desc limit ").append((page-1)*size).append(",").append(size);
        List<IotDeviceOrderDO> list = jdbcTempalte.query(sql.toString(),args.toArray(),new BeanPropertyRowMapper(IotDeviceOrderDO.class));
        List<Map<String,Object>> countList = jdbcTempalte.queryForList(sqlCount.toString());
        long count = Long.valueOf(countList.get(0).get("count").toString());
        //DO转VO
        List<IotDeviceOrderVO> iotDeviceOrderVOList = convertToModels(list,new ArrayList<>(list.size()),IotDeviceOrderVO.class);
        iotDeviceOrderVOList.forEach(one->{
            findType(one);
        });
        return Envelop.getSuccessListWithPage(IotRequestMapping.Common.message_success_find_functions,iotDeviceOrderVOList, page, size,count);
    }
    /**
     * 按类型分页查找
     * @param page
     * @param size
     * @param orderId
     * @param type (1返回已关联数量,2不返回已关联数量)
     * @return
     */
    public Envelop<IotOrderPurchaseVO> queryPurcharsePage(Integer page, Integer size, String orderId, String type){
        StringBuffer sql = new StringBuffer("SELECT c.* from iot_order_purchase c  WHERE c.del=1 ");
        StringBuffer sqlCount = new StringBuffer("SELECT COUNT(c.id) count from iot_order_purchase c WHERE c.del=1 ");
        List<Object> args = new ArrayList<>();
        if(StringUtils.isNotBlank(orderId)){
            sql.append(" and c.order_id=? ");
            sqlCount.append(" and c.order_id='").append(orderId).append("' ");
            args.add(orderId);
        }
        sql.append("order by c.update_time desc limit ").append((page-1)*size).append(",").append(size);
        List<IotOrderPurchaseDO> list = jdbcTempalte.query(sql.toString(),args.toArray(),new BeanPropertyRowMapper(IotOrderPurchaseDO.class));
        List<Map<String,Object>> countList = jdbcTempalte.queryForList(sqlCount.toString());
        long count = Long.valueOf(countList.get(0).get("count").toString());
        //DO转VO
        List<IotOrderPurchaseVO> iotOrderPurchaseVOList = convertToModels(list,new ArrayList<>(list.size()),IotOrderPurchaseVO.class);
        if("1".equals(type)){
            iotOrderPurchaseVOList.forEach(purchase->{
                //计算已关联设备数量
                Integer num = iotDeviceDao.countByPurchaseId(purchase.getId());
                Long unNum = (purchase.getPurchaseNum()-num)>0? (purchase.getPurchaseNum()-num):0;
                purchase.setAssociatedNum(Long.valueOf(num));
                purchase.setUnAssociatedNum(unNum);
            });
        }
        return Envelop.getSuccessListWithPage(IotRequestMapping.Common.message_success_find_functions,iotOrderPurchaseVOList, page, size,count);
    }
}

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

@ -1,13 +1,25 @@
package com.yihu.iot.service.device;
import com.yihu.base.fastdfs.FastDFSHelper;
import com.yihu.base.mysql.query.BaseJpaService;
import com.yihu.iot.dao.device.IotDeviceDao;
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.restmodel.common.Envelop;
import com.yihu.jw.restmodel.iot.device.IotDeviceImportRecordVO;
import com.yihu.jw.rm.iot.IotRequestMapping;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * @author yeshijie on 2017/12/8.
@ -17,6 +29,14 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
    @Autowired
    private IotDeviceDao iotDeviceDao;
    @Autowired
    private FastDFSHelper fastDFSHelper;
    @Value("${fastDFS.fastdfs_file_url}")
    private String fastdfs_file_url;
    @Autowired
    private IotDeviceImportRecordDao iotDeviceImportRecordDao;
    @Autowired
    private JdbcTemplate jdbcTempalte;
    /**
     * 新增
@ -26,13 +46,28 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
    public IotDeviceDO create(IotDeviceDO iotDevice) {
        iotDevice.setSaasId(getCode());
        iotDevice.setDel(1);
        return iotDeviceDao.save(iotDevice);
    }
    /**
     * 按id查找
     * @param id
     * @return
     */
    public IotDeviceDO findById(String id) {
        return iotDeviceDao.findById(id);
    }
    /**
     * 按sim卡号查找
     * @param simNo
     * @return
     */
    public IotDeviceDO findBySimNo(String simNo) {
        return iotDeviceDao.findBySimNo(simNo);
    }
    /**
     * 设备注册及绑定
     * @param iotDeviceDO
@ -59,4 +94,40 @@ public class IotDeviceService extends BaseJpaService<IotDeviceDO,IotDeviceDao> {
    public IotDeviceDO findByDeviceSn(String deviceSn) {
        return iotDeviceDao.findByDeviceSn(deviceSn);
    }
    /**
     * 设备导入
     */
    public void importDevice(){
    };
    /**
     * 分页查找导入记录
     * @param page
     * @param size
     * @param purcharseId
     * @return
     */
    public Envelop<IotDeviceImportRecordVO> queryImportRecordPage(Integer page, Integer size, String purcharseId){
        StringBuffer sql = new StringBuffer("SELECT c.* from iot_device_import_record c  WHERE c.del=1 ");
        StringBuffer sqlCount = new StringBuffer("SELECT COUNT(c.id) count from iot_device_import_record c WHERE c.del=1 ");
        List<Object> args = new ArrayList<>();
        if(StringUtils.isNotBlank(purcharseId)){
            sql.append(" and c.purcharse_id=? ");
            sqlCount.append(" and c.purcharse_id='").append(purcharseId).append("' ");
            args.add(purcharseId);
        }
        sql.append("order by c.update_time desc limit ").append((page-1)*size).append(",").append(size);
        List<IotDeviceImportRecordDO> list = jdbcTempalte.query(sql.toString(),args.toArray(),new BeanPropertyRowMapper(IotDeviceImportRecordDO.class));
        List<Map<String,Object>> countList = jdbcTempalte.queryForList(sqlCount.toString());
        long count = Long.valueOf(countList.get(0).get("count").toString());
        //DO转VO
        List<IotDeviceImportRecordVO> importRecordVOList = convertToModels(list,new ArrayList<>(list.size()),IotDeviceImportRecordVO.class);
        return Envelop.getSuccessListWithPage(IotRequestMapping.Common.message_success_find_functions,importRecordVOList, page, size,count);
    }
}

+ 0 - 115
web-gateway/src/main/java/com/yihu/jw/controller/iot/supplier/IotDeviceSupplierController.java

@ -1,115 +0,0 @@
package com.yihu.jw.controller.iot.supplier;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.yihu.jw.commnon.iot.SupplierContants;
import com.yihu.jw.feign.iot.supplier.IotDeviceSupplierFeign;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.common.EnvelopRestController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.sleuth.Tracer;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
/**
 * @author yeshijie on 2017/12/5.
 */
@RestController
@RequestMapping(SupplierContants.DeviceSupplier.api_common)
@Api(value = "供应商相关操作", description = "供应商相关操作")
public class IotDeviceSupplierController extends EnvelopRestController{
    private Logger logger = LoggerFactory.getLogger(IotDeviceSupplierController.class);
    @Autowired
    private IotDeviceSupplierFeign iotDeviceSupplierFeign;
    @Autowired
    private Tracer tracer;
    @PostMapping(value = SupplierContants.DeviceSupplier.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建供应商", notes = "创建供应商")
    @HystrixCommand(commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
            @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
    public Envelop create(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestBody String jsonData) {
        return iotDeviceSupplierFeign.create(jsonData);
    }
    @PutMapping(value = SupplierContants.DeviceSupplier.api_update, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改供应商", notes = "修改供应商")
    @HystrixCommand(commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
            @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
    public Envelop update(
            @ApiParam(name = "json_data", value = "", defaultValue = "")
            @RequestBody String jsonData) {
        return iotDeviceSupplierFeign.update(jsonData);
    }
    @DeleteMapping(value =SupplierContants.DeviceSupplier.api_delete)
    @ApiOperation(value = "删除供应商", notes = "删除供应商")
    @HystrixCommand(commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
            @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
    public Envelop delete(
            @ApiParam(name = "code", value = "code")
            @RequestParam(value = "code", required = true) String code) {
        return iotDeviceSupplierFeign.delete(code);
    }
    @GetMapping(value =SupplierContants.DeviceSupplier.api_getByCode)
    @ApiOperation(value = "根据code查找供应商", notes = "根据code查找供应商")
    @HystrixCommand(commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
            @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
    public Envelop findByCode(
            @ApiParam(name = "code", value = "code")
            @RequestParam(value = "code", required = true) String code
    ) {
        return iotDeviceSupplierFeign.findByCode(code);
    }
    @RequestMapping(value = SupplierContants.DeviceSupplier.api_queryPage, method = RequestMethod.GET)
    @ApiOperation(value = "分页获取供应商")
    @HystrixCommand(commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
            @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
    public Envelop queryPage(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "id,code,parentCode,saasId,name,price,posterPic,remark,type,status")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+createTime")
            @RequestParam(value = "sorts", required = false) String sorts,
            @ApiParam(name = "size", value = "分页大小", defaultValue = "15")
            @RequestParam(value = "size", required = false) int size,
            @ApiParam(name = "page", value = "页码", defaultValue = "1")
            @RequestParam(value = "page", required = false) int page) throws Exception {
        return iotDeviceSupplierFeign.queryPage(fields,filters,sorts,size,page);
    }
    @GetMapping(value =SupplierContants.DeviceSupplier.api_getList)
    @ApiOperation(value = "获取供应商列表(不分页)")
    @HystrixCommand(commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "-1"),//超时时间
            @HystrixProperty(name = "execution.timeout.enabled", value = "false") })
    public Envelop getList(
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段", defaultValue = "id,code,parentCode,saasId,name,price,posterPic,remark,type,status")
            @RequestParam(value = "fields", required = false) String fields,
            @ApiParam(name = "filters", value = "过滤器,为空检索所有条件")
            @RequestParam(value = "filters", required = false) String filters,
            @ApiParam(name = "sorts", value = "排序,规则参见说明文档", defaultValue = "+createTime")
            @RequestParam(value = "sorts", required = false) String sorts) throws Exception {
        return iotDeviceSupplierFeign.getList(fields,filters,sorts);
    }
}

+ 0 - 5
web-gateway/src/main/java/com/yihu/jw/feign/fallbackfactory/iot/data_input/DataStandardConvertFeignFallbackFactory.java

@ -1,16 +1,11 @@
package com.yihu.jw.feign.fallbackfactory.iot.data_input;
import com.yihu.jw.exception.business.JiWeiException;
import com.yihu.jw.feign.iot.data_input.DataInputFeign;
import com.yihu.jw.feign.iot.data_input.DataStandardConvertFeign;
import com.yihu.jw.feign.iot.supplier.IotDeviceSupplierFeign;
import com.yihu.jw.restmodel.common.Envelop;
import feign.hystrix.FallbackFactory;
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;
@Component
public class DataStandardConvertFeignFallbackFactory implements FallbackFactory<DataStandardConvertFeign> {

+ 0 - 50
web-gateway/src/main/java/com/yihu/jw/feign/fallbackfactory/iot/supplier/IotDeviceSupplierFeignFallbackFactory.java

@ -1,50 +0,0 @@
package com.yihu.jw.feign.fallbackfactory.iot.supplier;
import com.yihu.jw.feign.iot.supplier.IotDeviceSupplierFeign;
import com.yihu.jw.restmodel.common.Envelop;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
/**
 * @author yeshijie on 2017/12/5.
 */
@Component
public class IotDeviceSupplierFeignFallbackFactory implements FallbackFactory<IotDeviceSupplierFeign> {
    @Override
    public IotDeviceSupplierFeign create(Throwable throwable) {
        return new IotDeviceSupplierFeign() {
            @Override
            public Envelop create(@RequestBody String jsonData) {
                return null;
            }
            @Override
            public Envelop update(@RequestBody String jsonData) {
                return null;
            }
            @Override
            public Envelop delete(@RequestParam(value = "code") String code) {
                return null;
            }
            @Override
            public Envelop findByCode(@RequestParam(value = "code") String code) {
                return null;
            }
            @Override
            public Envelop queryPage(@RequestParam(value = "fields", required = false) String fields, @RequestParam(value = "filters", required = false) String filters, @RequestParam(value = "sorts", required = false) String sorts, @RequestParam(value = "size", required = false) int size, @RequestParam(value = "page", required = false) int page) {
                return null;
            }
            @Override
            public Envelop getList(@RequestParam(value = "fields", required = false) String fields, @RequestParam(value = "filters", required = false) String filters, @RequestParam(value = "sorts", required = false) String sorts) {
                return null;
            }
        };
    }
}

+ 0 - 2
web-gateway/src/main/java/com/yihu/jw/feign/iot/data_input/DataInputFeign.java

@ -1,11 +1,9 @@
package com.yihu.jw.feign.iot.data_input;
import com.yihu.jw.feign.fallbackfactory.iot.data_input.DataInputFeignFallbackFactory;
import com.yihu.jw.feign.fallbackfactory.iot.supplier.IotDeviceSupplierFeignFallbackFactory;
import com.yihu.jw.restmodel.CommonContants;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.rm.iot.DataRequestMapping;
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.PostMapping;

+ 0 - 46
web-gateway/src/main/java/com/yihu/jw/feign/iot/supplier/IotDeviceSupplierFeign.java

@ -1,46 +0,0 @@
package com.yihu.jw.feign.iot.supplier;
import com.yihu.jw.feign.fallbackfactory.iot.supplier.IotDeviceSupplierFeignFallbackFactory;
import com.yihu.jw.restmodel.CommonContants;
import com.yihu.jw.restmodel.common.Envelop;
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.*;
/**
 * @author yeshijie on 2017/12/5.
 */
@FeignClient(
        name = CommonContants.svr_iot // name值是eurika的实例名字
        ,fallbackFactory  = IotDeviceSupplierFeignFallbackFactory.class
)
@RequestMapping(IotRequestMapping.api_iot_common)
public interface IotDeviceSupplierFeign {
    @PostMapping(value = IotRequestMapping.DeviceSupplier.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    Envelop create(@RequestBody String jsonData);
    @PutMapping(value = IotRequestMapping.DeviceSupplier.api_update, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    Envelop update(@RequestBody String jsonData);
    @DeleteMapping(value = IotRequestMapping.DeviceSupplier.api_delete)
    Envelop delete( @RequestParam(value = "id") String id);
    @RequestMapping(value= IotRequestMapping.DeviceSupplier.api_getById,method = RequestMethod.GET)
    Envelop findByCode( @RequestParam(value = "id" ) String id);
    @RequestMapping(value = IotRequestMapping.DeviceSupplier.api_queryPage, method = RequestMethod.GET)
    Envelop queryPage(
            @RequestParam(value = "fields", required = false) String fields,
            @RequestParam(value = "filters", required = false) String filters,
            @RequestParam(value = "sorts", required = false) String sorts,
            @RequestParam(value = "size", required = false) int size,
            @RequestParam(value = "page", required = false) int page);
    @GetMapping(value = IotRequestMapping.DeviceSupplier.api_getList)
    Envelop getList(
            @RequestParam(value = "fields", required = false) String fields,
            @RequestParam(value = "filters", required = false) String filters,
            @RequestParam(value = "sorts", required = false) String sorts);
}