Browse Source

物联网后台系统 增加业务类型管理操作 完善平台接口信息日志操作

mengkang 5 years ago
parent
commit
e4e54b0997

+ 247 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/iot/platform/IotInterfaceLogDO.java

@ -0,0 +1,247 @@
package com.yihu.jw.entity.iot.platform;
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import org.hibernate.boot.model.relational.Namespace;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.Date;
/**接口日志
 * @author HZY
 * @vsrsion 1.0
 * Created at 2020/4/28
 */
@Entity
@Table(name = "iot_interface_log")
public class IotInterfaceLogDO extends UuidIdentityEntityWithOperator implements Serializable {
    @Column(name="company_id")
    private String companyId;//公司ID
    @Column(name="company_name")
    private String companyName;//公司名称
    @Column(name="app_id")
    private String appId;//应用ID
    @Column(name="app_name")
    private String  appName;//应用名称
    @Column(name="work_type_id")
    private String workTypeId;//业务类型ID
    @Column(name="work_type")
    private String workType;//业务类型
    @Column(name="explanation")
    private String explanation;//接口说明
    @Column(name="user_id")
    private String userId;//用户id
    @Column(name="user_name")
    private String userName;//用户名称
    @Column(name="address_ip")
    private String addressIp;//访问ip地址
    @Column(name="source")
    private String source;//请求来源 1:卫健委 2:单位 3:系统管理员
    @Column(name="head")
    private String head;//请求头
    @Column(name="request")
    private String request;//请求参数
    @Column(name="interface_name")
    private String interfaceName;//请求接口名称
    @Column(name="method")
    private String method;//方法名
    @Column(name="type")
    private int type;//请求方式 1:get请求  2:post请求
    @Column(name="url")
    private String url;//请求URL
    @Column(name="response")
    private String  response;//响应参数
    @Column(name="time")
    private Date time;//调用时间
    @Column(name="state")
    private int  state;//调用状态 1:成功   0:失败
    @Transient
    private String count;//调用次数
    @Transient
    private String failureRate;//失败率
    public String getCompanyId() {
        return companyId;
    }
    public void setCompanyId(String companyId) {
        this.companyId = companyId;
    }
    public String getCompanyName() {
        return companyName;
    }
    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }
    public String getAppId() {
        return appId;
    }
    public void setAppId(String appId) {
        this.appId = appId;
    }
    public String getAppName() {
        return appName;
    }
    public void setAppName(String appName) {
        this.appName = appName;
    }
    public String getWorkTypeId() {
        return workTypeId;
    }
    public void setWorkTypeId(String workTypeId) {
        this.workTypeId = workTypeId;
    }
    public String getUserId() {
        return userId;
    }
    public void setUserId(String userId) {
        this.userId = userId;
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getAddressIp() {
        return addressIp;
    }
    public void setAddressIp(String addressIp) {
        this.addressIp = addressIp;
    }
    public String getSource() {
        return source;
    }
    public void setSource(String source) {
        this.source = source;
    }
    public String getHead() {
        return head;
    }
    public void setHead(String head) {
        this.head = head;
    }
    public String getRequest() {
        return request;
    }
    public void setRequest(String request) {
        this.request = request;
    }
    public String getInterfaceName() {
        return interfaceName;
    }
    public void setInterfaceName(String interfaceName) {
        this.interfaceName = interfaceName;
    }
    public String getMethod() {
        return method;
    }
    public void setMethod(String method) {
        this.method = method;
    }
    public int getType() {
        return type;
    }
    public void setType(int type) {
        this.type = type;
    }
    public String getUrl() {
        return url;
    }
    public void setUrl(String url) {
        this.url = url;
    }
    public String getResponse() {
        return response;
    }
    public void setResponse(String response) {
        this.response = response;
    }
    public Date getTime() {
        return time;
    }
    public void setTime(Date time) {
        this.time = time;
    }
    public int getState() {
        return state;
    }
    public void setState(int state) {
        this.state = state;
    }
    public String getWorkType() {
        return workType;
    }
    public void setWorkType(String workType) {
        this.workType = workType;
    }
    public String getExplanation() {
        return explanation;
    }
    public void setExplanation(String explanation) {
        this.explanation = explanation;
    }
    @Transient
    public String getCount() {
        return count;
    }
    public void setCount(String count) {
        this.count = count;
    }
    @Transient
    public String getFailureRate() {
        return failureRate;
    }
    public void setFailureRate(String failureRate) {
        this.failureRate = failureRate;
    }
}

+ 10 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/iot/product/IotProductBaseInfoDO.java

@ -73,6 +73,8 @@ public class IotProductBaseInfoDO extends UuidIdentityEntityWithOperator impleme
    private Double purchasePrice;//进货价
    private Double purchasePrice;//进货价
    @Column(name = "retail_price")
    @Column(name = "retail_price")
    private Double retailPrice;//零售价格
    private Double retailPrice;//零售价格
    @Column(name = "category_name")
    private String categoryName;//设备类型标识
    @Column(name = "category_code")
    @Column(name = "category_code")
    private String categoryCode;//设备类型标识
    private String categoryCode;//设备类型标识
@ -307,4 +309,12 @@ public class IotProductBaseInfoDO extends UuidIdentityEntityWithOperator impleme
    public void setCategoryCode(String categoryCode) {
    public void setCategoryCode(String categoryCode) {
        this.categoryCode = categoryCode;
        this.categoryCode = categoryCode;
    }
    }
    public String getCategoryName() {
        return categoryName;
    }
    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }
}
}

+ 63 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/iot/workType/IotWorkTypeDO.java

@ -0,0 +1,63 @@
package com.yihu.jw.entity.iot.workType;
import com.yihu.jw.entity.UuidIdentityEntityWithOperator;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * @author HZY 业务类型表
 * @vsrsion 1.0
 * Created at 2020/4/29
 */
@Entity
@Table(name = "iot_work_type")
public class IotWorkTypeDO extends UuidIdentityEntityWithOperator implements Serializable {
    @Column(name = "saas_id")
    private String saasId;
    @Column(name = "name")
    private String name;//业务类型名称
    @Column(name = "explanation")
    private String explanation;//说明
    @Column(name = "del")
    private String del;//删除标识: 1:删除  0:不删除
    public String getSaasId() {
        return saasId;
    }
    public void setSaasId(String saasId) {
        this.saasId = saasId;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getExplanation() {
        return explanation;
    }
    public void setExplanation(String explanation) {
        this.explanation = explanation;
    }
    public String getDel() {
        return del;
    }
    public void setDel(String del) {
        this.del = del;
    }
}

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

@ -23,6 +23,7 @@ public class IotRequestMapping {
        public static final String wlyy = api_iot_common + "/wlyy";
        public static final String wlyy = api_iot_common + "/wlyy";
        public static final String figereLabel = api_iot_common + "/figereLabel";
        public static final String figereLabel = api_iot_common + "/figereLabel";
        public static final String platform = api_iot_common + "/platform";
        public static final String platform = api_iot_common + "/platform";
        public static final String workType = api_iot_common + "/workType";
        public static final String hospital = api_iot_common + "/hospital";
        public static final String hospital = api_iot_common + "/hospital";
@ -288,20 +289,38 @@ public class IotRequestMapping {
    }
    }
    /**
    /**
     * 居民标签信息模块常量
     * 平台接口信息模块常量
     */
     */
    public static class  Platform{
    public static class  Platform{
        public static final String addInterface ="addInterface";
        public static final String addInterface ="addInterface";
        public static final String editInterface ="editInterface";
        public static final String editInterface ="editInterface";
        public static final String findInterfaceById ="findInterfaceById";
        public static final String findInterfaceById ="findInterfaceById";
        public static final String findAll ="findAll";
        public static final String findAll ="findAll";
        public static final String findAllLog ="findAllLog";
        public static final String conditionQueryPage ="conditionQueryPage";
        public static final String conditionQueryPage ="conditionQueryPage";
        public static final String delete ="delete";
        public static final String dataConsumption ="dataConsumption";
        public static final String message_success_add = "add success";
        public static final String message_success_add = "add success";
        public static final String message_success_edit = "edit success";
        public static final String message_success_edit = "edit success";
        public static final String message_success_find = "find success";
        public static final String message_success_find = "find success";
        public static final String message_success_delete = "delete success";
    }
    }
    /**
     * 业务类型信息模块常量
     */
    public static class WorkType{
        public static final  String addType="addType";
        public static final  String editType="editType";
        public static final  String deleteType="deleteType";
        public static final  String findType="findType";
        public static final String message_success_add = "workType add success";
        public static final String message_success_edit = "workType edit success";
        public static final String message_success_delete = "workType delete success";
        public static final String message_success_find = "workType find success";
    }
    /**
    /**
     * 单位模块常量
     * 单位模块常量

+ 121 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/iot/platform/IotInterfaceLogVO.java

@ -0,0 +1,121 @@
package com.yihu.jw.restmodel.iot.platform;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.yihu.jw.restmodel.iot.common.BaseVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.io.Serializable;
import java.util.Date;
/**
 * @author 接口日志表
 * @vsrsion 1.0
 * Created at 2020/4/29
 */
@JsonInclude(JsonInclude.Include.ALWAYS)
@ApiModel(value = "接口日志表", description = "接口日志表")
public class IotInterfaceLogVO extends BaseVO implements Serializable {
    @ApiModelProperty("请求接口名称")
    private String interfaceName;//
    @ApiModelProperty("方法名")
    private String method;//方法名
    @ApiModelProperty("业务类型")
    private String workType;//业务类型
    @ApiModelProperty("接口说明")
    private String explanation;//接口说明
    @ApiModelProperty("访问ip地址")
    private String addressIp;//访问ip地址
    @ApiModelProperty("调用状态 1:成功   0:失败")
    private int  state;//调用状态 1:成功   0:失败
    @ApiModelProperty("调用时间")
    private Date time;//调用时间
    @ApiModelProperty("应用名称")
    private String  appName;//应用名称
    @ApiModelProperty("调用次数")
    private String count;//调用次数
    @ApiModelProperty("失败率")
    private String failureRate;//失败率
    public String getInterfaceName() {
        return interfaceName;
    }
    public void setInterfaceName(String interfaceName) {
        this.interfaceName = interfaceName;
    }
    public String getMethod() {
        return method;
    }
    public void setMethod(String method) {
        this.method = method;
    }
    public String getWorkType() {
        return workType;
    }
    public void setWorkType(String workType) {
        this.workType = workType;
    }
    public String getExplanation() {
        return explanation;
    }
    public void setExplanation(String explanation) {
        this.explanation = explanation;
    }
    public String getAddressIp() {
        return addressIp;
    }
    public void setAddressIp(String addressIp) {
        this.addressIp = addressIp;
    }
    public int getState() {
        return state;
    }
    public void setState(int state) {
        this.state = state;
    }
    public Date getTime() {
        return time;
    }
    public void setTime(Date time) {
        this.time = time;
    }
    public String getAppName() {
        return appName;
    }
    public void setAppName(String appName) {
        this.appName = appName;
    }
    public String getCount() {
        return count;
    }
    public void setCount(String count) {
        this.count = count;
    }
    public String getFailureRate() {
        return failureRate;
    }
    public void setFailureRate(String failureRate) {
        this.failureRate = failureRate;
    }
}

+ 74 - 8
svr/svr-iot/src/main/java/com/yihu/iot/controller/platform/IotInterfaceController.java

@ -1,9 +1,9 @@
package com.yihu.iot.controller.platform;
package com.yihu.iot.controller.platform;
import com.alibaba.fastjson.JSONObject;
import com.yihu.iot.service.platform.IotInterfaceLogService;
import com.yihu.iot.service.platform.IotShareInterfaceService;
import com.yihu.iot.service.platform.IotShareInterfaceService;
import com.yihu.jw.entity.iot.platform.IotShareInterfaceDO;
import com.yihu.jw.entity.iot.platform.IotShareInterfaceDO;
import com.yihu.jw.restmodel.iot.company.IotCompanyVO;
import com.yihu.jw.restmodel.iot.platform.IotInterfaceLogVO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.iot.IotRequestMapping;
import com.yihu.jw.rm.iot.IotRequestMapping;
@ -11,12 +11,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import org.springframework.web.bind.annotation.*;
/**
/**
 * @author HZY
 * @author HZY
@ -31,6 +26,10 @@ public class IotInterfaceController extends EnvelopRestEndpoint {
    @Autowired
    @Autowired
    private IotShareInterfaceService iotShareInterfaceService;
    private IotShareInterfaceService iotShareInterfaceService;
    @Autowired
    private IotInterfaceLogService iotInterfaceLogService;
    @PostMapping(value = IotRequestMapping.Platform.addInterface)
    @PostMapping(value = IotRequestMapping.Platform.addInterface)
    @ApiOperation(value = "新增共享接口",notes = "新增共享接口")
    @ApiOperation(value = "新增共享接口",notes = "新增共享接口")
    public MixEnvelop<IotShareInterfaceDO,IotShareInterfaceDO> addInterface(@ApiParam(name = "JSON",value = "接口JSON串") @RequestParam(value = "JSON",required = true)String json){
    public MixEnvelop<IotShareInterfaceDO,IotShareInterfaceDO> addInterface(@ApiParam(name = "JSON",value = "接口JSON串") @RequestParam(value = "JSON",required = true)String json){
@ -97,6 +96,24 @@ public class IotInterfaceController extends EnvelopRestEndpoint {
    }
    }
    @GetMapping(value = IotRequestMapping.Platform.delete)
    @ApiOperation(value = "根据ID删除共享接口",notes = "根据ID删除共享接口")
    public MixEnvelop<IotShareInterfaceDO,IotShareInterfaceDO> deleteById(@ApiParam(name = "id", value = "ID", defaultValue = "")
                                                                       @RequestParam(value = "id", required = false) String id){
        try {
            iotShareInterfaceService.deleteById(id);
            return MixEnvelop.getSuccess(IotRequestMapping.Platform.message_success_delete);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.Platform.conditionQueryPage)
    @PostMapping(value = IotRequestMapping.Platform.conditionQueryPage)
    @ApiOperation(value = "条件查询分页",notes = "条件查询分页")
    @ApiOperation(value = "条件查询分页",notes = "条件查询分页")
    public MixEnvelop<IotShareInterfaceDO,IotShareInterfaceDO> conditionQueryPage(@ApiParam(name = "type", value = "业务类型", defaultValue = "")
    public MixEnvelop<IotShareInterfaceDO,IotShareInterfaceDO> conditionQueryPage(@ApiParam(name = "type", value = "业务类型", defaultValue = "")
@ -123,4 +140,53 @@ public class IotInterfaceController extends EnvelopRestEndpoint {
    }
    }
    @GetMapping(value = IotRequestMapping.Platform.findAllLog)
    @ApiOperation(value = "分页查询所有接口日志信息",notes = "分页查询所有接口日志信息")
    public MixEnvelop<IotInterfaceLogVO,IotInterfaceLogVO> findAllLog(@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 iotInterfaceLogService.findAll(page,size);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.Platform.dataConsumption)
    @ApiOperation(value = "接口数据消费分页查询",notes = "接口数据消费分页查询")
    public MixEnvelop<IotInterfaceLogVO,IotInterfaceLogVO> dataConsumption(@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 iotInterfaceLogService.dataConsumption(page,size);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
}
}

+ 88 - 0
svr/svr-iot/src/main/java/com/yihu/iot/controller/workType/IotWorkTypeController.java

@ -0,0 +1,88 @@
package com.yihu.iot.controller.workType;
import com.yihu.iot.service.workType.IotWorkTypeService;
import com.yihu.jw.entity.iot.workType.IotWorkTypeDO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.iot.IotRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2020/4/29
 */
@RestController
@RequestMapping(IotRequestMapping.Common.workType)
@Api(tags = "业务类型管理相关操作", description = "业务类型管理相关操作")
public class IotWorkTypeController extends EnvelopRestEndpoint {
    @Autowired
    private IotWorkTypeService iotWorkTypeService;
    @PostMapping(value = IotRequestMapping.WorkType.addType)
    @ApiOperation(value = "添加业务类型",notes = "添加业务类型")
    public MixEnvelop<IotWorkTypeDO,IotWorkTypeDO> addType(@ApiParam(name = "JSON",value = "JSON串")
                                                           @RequestParam(value = "JSON",required = true)String json){
        try {
            iotWorkTypeService.addType(json);
            return MixEnvelop.getSuccess(IotRequestMapping.WorkType.message_success_add);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @PostMapping(value = IotRequestMapping.WorkType.editType)
    @ApiOperation(value = "编辑业务类型",notes = "编辑业务类型")
    public MixEnvelop<IotWorkTypeDO,IotWorkTypeDO> editType(@ApiParam(name = "JSON",value = "JSON串")
                                                            @RequestParam(value = "JSON",required = true)String json){
        try {
            iotWorkTypeService.editType(json);
            return MixEnvelop.getSuccess(IotRequestMapping.WorkType.message_success_edit);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.WorkType.deleteType)
    @ApiOperation(value = "根据ID删除业务类型",notes = "根据ID删除业务类型")
    public MixEnvelop<IotWorkTypeDO,IotWorkTypeDO> deleteType(@ApiParam(name = "id",value = "ID")
                                                              @RequestParam(value = "id",required = true)String id){
        try {
            iotWorkTypeService.deleteType(id);
            return MixEnvelop.getSuccess(IotRequestMapping.WorkType.message_success_delete);
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
    @GetMapping(value = IotRequestMapping.WorkType.findType)
    @ApiOperation(value = "根据ID查找业务类型",notes = "根据ID查找业务类型")
    public MixEnvelop<IotWorkTypeDO,IotWorkTypeDO> findType(@ApiParam(name = "id",value = "ID")
                                                            @RequestParam(value = "id",required = true)String id){
        try {
            return MixEnvelop.getSuccess(IotRequestMapping.WorkType.message_success_find, iotWorkTypeService.findType(id));
        } catch (Exception e) {
            e.printStackTrace();
            return MixEnvelop.getError(e.getMessage());
        }
    }
}

+ 13 - 0
svr/svr-iot/src/main/java/com/yihu/iot/dao/platform/IotInterfaceLogDao.java

@ -0,0 +1,13 @@
package com.yihu.iot.dao.platform;
import com.yihu.jw.entity.iot.platform.IotInterfaceLogDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2020/4/28
 */
public interface IotInterfaceLogDao extends PagingAndSortingRepository<IotInterfaceLogDO,String>, JpaSpecificationExecutor<IotInterfaceLogDO> {
}

+ 3 - 0
svr/svr-iot/src/main/java/com/yihu/iot/dao/platform/IotShareInterfaceDao.java

@ -2,6 +2,7 @@ package com.yihu.iot.dao.platform;
import com.yihu.jw.entity.iot.platform.IotShareInterfaceDO;
import com.yihu.jw.entity.iot.platform.IotShareInterfaceDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
/**
@ -11,4 +12,6 @@ import org.springframework.data.repository.PagingAndSortingRepository;
 */
 */
public interface IotShareInterfaceDao extends PagingAndSortingRepository<IotShareInterfaceDO,String>, JpaSpecificationExecutor<IotShareInterfaceDO> {
public interface IotShareInterfaceDao extends PagingAndSortingRepository<IotShareInterfaceDO,String>, JpaSpecificationExecutor<IotShareInterfaceDO> {
    @Query("from IotShareInterfaceDO w where w.id =?1 and w.del=0")
    IotShareInterfaceDO findById(String id);
}
}

+ 19 - 0
svr/svr-iot/src/main/java/com/yihu/iot/dao/workType/IotWorkTypeDao.java

@ -0,0 +1,19 @@
package com.yihu.iot.dao.workType;
import com.yihu.jw.entity.iot.platform.IotInterfaceLogDO;
import com.yihu.jw.entity.iot.workType.IotWorkTypeDO;
import org.springframework.data.jpa.mapping.JpaPersistentEntity;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2020/4/29
 */
public interface IotWorkTypeDao extends PagingAndSortingRepository<IotWorkTypeDO,String>, JpaSpecificationExecutor<IotWorkTypeDO> {
    @Query("from IotWorkTypeDO w where w.id=?1 and w.del=0")
    IotWorkTypeDO findById(String id);
}

+ 131 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/platform/IotInterfaceLogService.java

@ -0,0 +1,131 @@
package com.yihu.iot.service.platform;
import com.sun.org.apache.bcel.internal.generic.NEW;
import com.yihu.iot.dao.platform.IotInterfaceLogDao;
import com.yihu.iot.service.useragent.UserAgent;
import com.yihu.jw.entity.iot.company.IotCompanyDO;
import com.yihu.jw.entity.iot.platform.IotInterfaceLogDO;
import com.yihu.jw.restmodel.iot.platform.IotInterfaceLogVO;
import com.yihu.jw.restmodel.web.MixEnvelop;
import com.yihu.jw.rm.iot.IotRequestMapping;
import com.yihu.mysql.query.BaseJpaService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
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 javax.swing.plaf.PanelUI;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2020/4/28
 */
@Service
public class IotInterfaceLogService extends BaseJpaService<IotInterfaceLogDO,IotInterfaceLogDao> {
    private static final Logger logger = LoggerFactory.getLogger(IotInterfaceLogService.class);
    @Autowired
    private IotInterfaceLogDao iotInterfaceLogDao;
    @Autowired
    private UserAgent userAgent;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 分页查询日志信息
     * @param page
     * @param size
     * @return
     * @throws ParseException
     */
    public MixEnvelop<IotInterfaceLogVO,IotInterfaceLogVO> findAll(Integer page, Integer size) throws ParseException {
        String sql = "select * from iot_interface_log where 1=1;";
        String sorts = "-updateTime";//按更新时间降序
//        List<IotInterfaceLogDO> list = search(null, filters, sorts, page, size);
        List<IotInterfaceLogDO> list = jdbcTemplate.query(sql,new BeanPropertyRowMapper(IotInterfaceLogDO.class));
        ArrayList<IotInterfaceLogVO> resultList = new ArrayList<>();
        list.forEach(one->{
            IotInterfaceLogVO target = new IotInterfaceLogVO();
            BeanUtils.copyProperties(one,target);
            resultList.add(target);
        });
        long count =list.size();
        return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Platform.message_success_find,resultList,page, size,count);
    }
    /**
     * 分页查询接口调用信息
     * @param page
     * @param size
     * @return
     */
    public MixEnvelop<IotInterfaceLogVO,IotInterfaceLogVO> dataConsumption(Integer page,Integer size){
        String sqlTotal="SELECT COUNT(id) num,app_name,interface_name,work_type FROM iot_interface_log GROUP BY app_name,interface_name;";
        String sql="SELECT COUNT(id) num,app_name,interface_name,work_type FROM iot_interface_log  WHERE state=0 GROUP BY app_name,interface_name;";
        List<IotInterfaceLogVO> list = new ArrayList<>();
        List<Map<String, Object>> total = jdbcTemplate.queryForList(sqlTotal);
        List<Map<String, Object>> failCount = jdbcTemplate.queryForList(sql);
        total.forEach(one->{
            IotInterfaceLogVO iotInterfaceLogVO = new IotInterfaceLogVO();
            iotInterfaceLogVO.setAppName(one.get("app_name").toString());
            iotInterfaceLogVO.setInterfaceName(one.get("interface_name").toString());
            iotInterfaceLogVO.setWorkType(one.get("work_type").toString());
            iotInterfaceLogVO.setCount(one.get("num").toString());
            list.add(iotInterfaceLogVO);
        });
        Long totalCount = (long) list.size();
        if (failCount==null){
            list.forEach(one->{
                one.setFailureRate("0.00");
            });
            return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Platform.message_success_find,list,page, size,totalCount);
        }
        list.forEach(iotInterfaceLogVO->{
            failCount.forEach(one->{
                if(iotInterfaceLogVO.getAppName().equalsIgnoreCase(one.get("app_name").toString())
                        && iotInterfaceLogVO.getInterfaceName().equalsIgnoreCase(one.get("interface_name").toString()) ){
                    String num = one.get("num").toString();
                    Double value = Double.valueOf(num);
                    String count = iotInterfaceLogVO.getCount();
                    Double all = Double.valueOf(count);
                    DecimalFormat df=new DecimalFormat("0.00");//设置保留位数
                    String format = df.format(value / all);
                    iotInterfaceLogVO.setFailureRate(format);
                }
            });
        });
        return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Platform.message_success_find,list,page, size,totalCount);
    }
}

+ 13 - 3
svr/svr-iot/src/main/java/com/yihu/iot/service/platform/IotShareInterfaceService.java

@ -69,9 +69,9 @@ public class IotShareInterfaceService extends BaseJpaService<IotShareInterfaceDO
     * @param id
     * @param id
     * @return
     * @return
     */
     */
    public IotShareInterfaceDO findInterfaceById(String id) throws ParseException {
    public IotShareInterfaceDO findInterfaceById(String id) {
        IotShareInterfaceDO iotShareInterfaceDO = iotShareInterfaceDao.findOne(id);
        IotShareInterfaceDO iotShareInterfaceDO = iotShareInterfaceDao.findById(id);
        return iotShareInterfaceDO;
        return iotShareInterfaceDO;
    }
    }
@ -95,7 +95,7 @@ public class IotShareInterfaceService extends BaseJpaService<IotShareInterfaceDO
    }
    }
    /**
    /**
     * 分页查询所有
     * 条件分页查询所有
     * @param page
     * @param page
     * @param size
     * @param size
     * @param type
     * @param type
@ -125,4 +125,14 @@ public class IotShareInterfaceService extends BaseJpaService<IotShareInterfaceDO
        return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Company.message_success_find_functions,list, page, size,count);
        return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Company.message_success_find_functions,list, page, size,count);
    }
    }
    /**
     * 根据ID删除共享接口
     * @param id
     * @return
     */
    public void deleteById(String id) {
        IotShareInterfaceDO shareInterfaceDO = iotShareInterfaceDao.findById(id);
        shareInterfaceDO.setDel("1");
        iotShareInterfaceDao.save(shareInterfaceDO);
    }
}
}

+ 1 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/product/IotProductBaseInfoService.java

@ -174,6 +174,7 @@ public class IotProductBaseInfoService extends BaseJpaService<IotProductBaseInfo
        baseInfoDOOld.setUnit(baseInfoDO.getUnit());
        baseInfoDOOld.setUnit(baseInfoDO.getUnit());
        baseInfoDOOld.setPurchasePrice(baseInfoDO.getPurchasePrice());
        baseInfoDOOld.setPurchasePrice(baseInfoDO.getPurchasePrice());
        baseInfoDOOld.setRetailPrice(baseInfoDO.getRetailPrice());
        baseInfoDOOld.setRetailPrice(baseInfoDO.getRetailPrice());
        baseInfoDOOld.setCategoryName(baseInfoDO.getCategoryName());
        baseInfoDOOld.setCategoryCode(baseInfoDO.getCategoryCode());
        baseInfoDOOld.setCategoryCode(baseInfoDO.getCategoryCode());
        baseInfoDOOld.setSaasId(getCode());
        baseInfoDOOld.setSaasId(getCode());
        baseInfoDOOld.setId(baseInfoDO.getId());
        baseInfoDOOld.setId(baseInfoDO.getId());

+ 73 - 0
svr/svr-iot/src/main/java/com/yihu/iot/service/workType/IotWorkTypeService.java

@ -0,0 +1,73 @@
package com.yihu.iot.service.workType;
import com.alibaba.fastjson.JSONObject;
import com.yihu.iot.dao.workType.IotWorkTypeDao;
import com.yihu.jw.entity.iot.workType.IotWorkTypeDO;
import com.yihu.mysql.query.BaseJpaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/**
 * @author HZY
 * @vsrsion 1.0
 * Created at 2020/4/29
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class IotWorkTypeService extends BaseJpaService<IotWorkTypeDO, IotWorkTypeDao> {
    
    @Autowired
    private IotWorkTypeDao iotWorkTypeDao;
    /**
     * 增加业务类型
     * @param json
     */
    public void addType(String json) {
        IotWorkTypeDO iotWorkTypeDO = JSONObject.parseObject(json, IotWorkTypeDO.class);
        iotWorkTypeDO.setDel("0");
        iotWorkTypeDao.save(iotWorkTypeDO);
    }
    /**
     * 编辑业务类型
     * @param json
     */
    public void editType(String json) {
        IotWorkTypeDO newType = JSONObject.parseObject(json, IotWorkTypeDO.class);
        IotWorkTypeDO old = iotWorkTypeDao.findOne(newType.getId());
        old.setName(newType.getName());
        old.setExplanation(newType.getExplanation());
        old.setDel("0");
        old.setId(old.getId());
        iotWorkTypeDao.save(old);
    }
    /**
     * 根据ID删除业务类型
     * @param id
     */
    public void deleteType(String id) {
        IotWorkTypeDO type = iotWorkTypeDao.findOne(id);
        if(type.getDel().equalsIgnoreCase("1")){
            throw new RuntimeException("改类型已删除,请勿重复操作");
        }
        type.setDel("1");
        iotWorkTypeDao.save(type);
    }
    /**
     * 根据ID查找业务类型
     * @param id
     */
    public IotWorkTypeDO findType(String id) {
        IotWorkTypeDO type = iotWorkTypeDao.findById(id);
        if(type==null){
            throw  new RuntimeException("无该类型");
        }
        return type;
    }
}