Quellcode durchsuchen

Merge branch 'dev' of http://192.168.1.220:10080/Amoy2/wlyy2.0 into dev

ysj vor 5 Jahren
Ursprung
Commit
b4794bddce

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

@ -0,0 +1,246 @@
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;
    }
}

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

@ -161,6 +161,7 @@ public class BaseRequestMapping {
        public static final String CHECK_MOBILE = "/check_mobile";
        public static final String findUserBaseInfo = "/findUserBaseInfo";
        public static final String resetPwd = "/resetPwd";
        public static final String updatePwd = "/updatePwd";
        public static final String queryOne = "/queryOne";
        public static final String orgTreeInfo = "/orgTreeInfo";
        public static final String userInfoList = "/userInfoList";

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

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

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

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

+ 12 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/user/UserEndpoint.java

@ -11,6 +11,7 @@ import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.BaseRequestMapping;
import com.yihu.jw.rm.hospital.BaseHospitalRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -235,4 +236,15 @@ public class UserEndpoint extends EnvelopRestEndpoint {
        }
        return success(jsonObject.getString("msg"));
    }
    
    @PostMapping(value = BaseRequestMapping.User.updatePwd)
    @ApiOperation(value = "修账号密码")
    public Envelop updatePwd(@ApiParam(name = "id", value = "用户ID")
                                  @RequestParam(value = "id", required = true)String id,
                                  @ApiParam(name = "pw", value = "密码")
                                  @RequestParam(value = "pw", required = true)String pw,
                                  @ApiParam(name = "orgPw", value = "原密码")
                                  @RequestParam(value = "orgPw", required = true)String orgPw)throws Exception{
        return success(userService.updatePwd(id,pw,orgPw));
    }
}

+ 102 - 4
svr/svr-base/src/main/java/com/yihu/jw/base/service/user/UserService.java

@ -1,5 +1,6 @@
package com.yihu.jw.base.service.user;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
@ -17,11 +18,15 @@ import com.yihu.jw.entity.base.org.BaseOrgUserDO;
import com.yihu.jw.entity.base.role.RoleDO;
import com.yihu.jw.entity.base.saas.SaasDO;
import com.yihu.jw.entity.base.user.UserDO;
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
import com.yihu.jw.hospital.dict.WlyyHospitalSysDictDao;
import com.yihu.jw.util.date.DateUtil;
import com.yihu.mysql.query.BaseJpaService;
import com.yihu.utils.security.MD5;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
@ -61,9 +66,15 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
    @Autowired
    private BaseOrgSaasService baseOrgSaasService;
    
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Value("${configDefault.saasId}")
    private String defaultSaasId;
    
    @Autowired
    private WlyyHospitalSysDictDao wlyyHospitalSysDictDao;
    public UserDO registerWithIdcard(UserDO userDO) {
@ -214,9 +225,44 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
                    }
            }
        }
    
    
        //密码过期
        userinfo.put("authPw",findDoctorPwlimitDate(id));
        return userinfo;
    }
    
    public com.alibaba.fastjson.JSONObject findDoctorPwlimitDate(String user){
        String key = "base:authPw:iser:" + user;
        String authPw = redisTemplate.opsForValue().get(key);
        com.alibaba.fastjson.JSONObject valueJson = null;
        if(org.apache.commons.lang3.StringUtils.isNotBlank(authPw)){
            
            WlyyHospitalSysDictDO wlyyHospitalSysDictDO = wlyyHospitalSysDictDao.findById("pwOverDue");
            String code[] = wlyyHospitalSysDictDO.getDictCode().split(",");
            Integer maxDateInt = Integer.parseInt(code[0]);
            Integer remainDateInt = Integer.parseInt(code[1]);
            
            valueJson = JSON.parseObject(authPw);
            Long updateTimeLong = valueJson.getLong("updateTime");
            Date updateTime = new Date();
            updateTime.setTime(updateTimeLong);
            Date maxDate = DateUtil.getPreDays(updateTime,maxDateInt);
            
            Long betweenDate = (maxDate.getTime() - new Date().getTime())/(60*60*24*1000);
            valueJson.put("betweenDate",betweenDate);
            if(betweenDate<remainDateInt){
                valueJson.put("remaind",true);
            }else {
                valueJson.put("remaind",false);
            }
        }else {
            valueJson = new com.alibaba.fastjson.JSONObject();
            valueJson.put("isChanged",false);
        }
        return valueJson;
    }
    /**
@ -427,6 +473,58 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
        return result;
    }
    /**
     * 用户修改密码
     * @param userId
     * @return
     */
    public JSONObject updatePwd(String userId,String pwd,String oldpwd){
        JSONObject result = new JSONObject();
        UserDO user = userDao.findOne(userId);
        if(null == user){
            result.put("response", ConstantUtils.FAIL);
            result.put("msg","user not exist for id : " + userId);
            return result;
        }
    
        String orgPwMd5 = MD5.md5Hex(oldpwd + "{" + user.getSalt() + "}");
        if(!orgPwMd5.equals(user.getPassword())){
            result.put("response", ConstantUtils.FAIL);
            result.put("msg","旧密码不正确!");
            return result;
        }
        if(StringUtils.isEmpty(pwd)){
            result.put("response", ConstantUtils.FAIL);
            result.put("msg","新密码不能为空!");
            return result;
        }
        user.setSalt(randomString(5));
        user.setEnabled(true);
        user.setLocked(false);
        user.setLoginFailureCount(0);
        user.setPassword(MD5.md5Hex(pwd + "{" + user.getSalt() + "}"));
        userDao.save(user);
        result.put("response",ConstantUtils.SUCCESS);
        result.put("msg", "修改成功");
    
        //设置用户密码过期时间
        saveUserPwlimitDate(userId);
        
        return result;
    }
    
    public boolean saveUserPwlimitDate(String user){
        String key = "base:authPw:user:" + user;
        com.alibaba.fastjson.JSONObject valueJson = new com.alibaba.fastjson.JSONObject();
        valueJson.put("updateTime",new Date().getTime());
        valueJson.put("isChanged",true);
        redisTemplate.opsForValue().set(key,valueJson.toJSONString());
        return true;
    }
    
    /**
     * 用户重置密码
     * @param userId
@ -444,26 +542,26 @@ public class UserService extends BaseJpaService<UserDO, UserDao> {
        String idcard = user.getIdcard();
        String mobile = user.getMobile();
        String password = null;
        
        if(!StringUtils.isEmpty(password)&&idcard.length()>10){
            password = idcard.substring(idcard.length()-6,idcard.length());
        }else if(!StringUtils.isEmpty(mobile)&&mobile.length()>=11){
            password = mobile.substring(mobile.length()-6,mobile.length());
        }
        
        if(StringUtils.isEmpty(password)){
            result.put("response", ConstantUtils.FAIL);
            result.put("msg","idcard or moblie not exist : " + userId);
            return result;
        }
        
        user.setSalt(randomString(5));
        user.setEnabled(true);
        user.setLocked(false);
        user.setLoginFailureCount(0);
        user.setPassword(MD5.md5Hex(password + "{" + user.getSalt() + "}"));
        userDao.save(user);
        
        result.put("response",ConstantUtils.SUCCESS);
        result.put("msg", password);
        return result;

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

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

+ 1 - 10
svr/svr-iot/src/main/java/com/yihu/iot/controller/platform/IotInterfaceController.java

@ -1,9 +1,8 @@
package com.yihu.iot.controller.platform;
import com.alibaba.fastjson.JSONObject;
import com.yihu.iot.service.company.IotCompanyService;
import com.yihu.iot.service.platform.IotCompanyAppInterfaceService;
import com.yihu.iot.service.log.IotInterfaceLogService;
import com.yihu.iot.service.platform.IotInterfaceLogService;
import com.yihu.iot.service.platform.IotShareInterfaceService;
import com.yihu.jw.entity.iot.company.IotCompanyDO;
import com.yihu.jw.entity.iot.platform.IotCompanyAppInterfaceDO;
@ -17,16 +16,8 @@ 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.poi.ss.formula.functions.T;
import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
/**

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

@ -0,0 +1,14 @@
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> {
}

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

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

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

@ -0,0 +1,255 @@
package com.yihu.iot.service.platform;
import com.alibaba.fastjson.JSONObject;
import com.yihu.iot.dao.company.IotCompanyAppDao;
import com.yihu.iot.dao.platform.IotInterfaceLogDao;
import com.yihu.iot.dao.workType.IotWorkTypeDao;
import com.yihu.iot.service.useragent.UserAgent;
import com.yihu.jw.entity.iot.company.IotCompanyAppDO;
import com.yihu.jw.entity.iot.platform.IotInterfaceLogDO;
import com.yihu.jw.entity.iot.workType.IotWorkTypeDO;
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.apache.commons.lang.StringUtils;
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.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.*;
/**
 * @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;
    @Autowired
    private IotCompanyAppDao iotCompanyAppDao;
    @Autowired
    private IotWorkTypeDao iotWorkTypeDao;
    /**
     * 分页查询日志信息
     * @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);*/
        String sql ="SELECT  COALESCE(c.fali,0),b.count,b.app_name,b.interface_name,b.work_type FROM " +
                "                                        (SELECT COUNT(id) fali,app_name,interface_name FROM iot_interface_log  WHERE state=0 GROUP BY app_name,interface_name) c " +
                                                         "RIGHT JOIN (SELECT count(id) count,app_name,interface_name,work_type FROM iot_interface_log " +
                                                         " GROUP BY app_name,interface_name) b ON c.app_name=b.app_name AND c.interface_name=b.interface_name;";
        List<Map<String, Object>> listSql = jdbcTemplate.queryForList(sql);
        List<IotInterfaceLogVO> list = new ArrayList<>();
        listSql.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("count").toString());
            iotInterfaceLogVO.setFailureRate(Float.toString(Float.parseFloat(one.get("COALESCE(c.fali,0)").toString())/Float.parseFloat(one.get("count").toString())));
            list.add(iotInterfaceLogVO);
        });
        long totalCount=listSql.size();
        return MixEnvelop.getSuccessListWithPage(IotRequestMapping.Platform.message_success_find,list,page, size,totalCount);
    }
    /**
     * 保存接口调用日志
     * @param appId 应用ID
     * @param params 入参
     * @param response 出参
     * @param request
     * @param state 调用状态
     * @param interfaceName 接口名称
     * @param method 方法名
     * @param workTypeId 业务类型
     * @param time 调用时间
     */
    public void saveLog(String appId, String params, String response, HttpServletRequest request,Integer state,String  interfaceName,String method,String workTypeId,Date time){
        IotInterfaceLogDO interfaceLogDO = new IotInterfaceLogDO();
        //设置应用与公司
        IotCompanyAppDO appDO = iotCompanyAppDao.findById(appId);
        interfaceLogDO.setAppId(appId);
        interfaceLogDO.setAppName(appDO.getName());
        interfaceLogDO.setCompanyId(appDO.getCompanyId());
        interfaceLogDO.setCompanyName(appDO.getCompanyName());
        //设置业务类型
        IotWorkTypeDO work = iotWorkTypeDao.findById(workTypeId);
        interfaceLogDO.setWorkType(work.getName());
        interfaceLogDO.setExplanation(work.getExplanation());
        interfaceLogDO.setWorkTypeId(workTypeId);
        //设置用户名称与ID
        if(StringUtils.isBlank(userAgent.getUID())){
            interfaceLogDO.setUserId("system");
            interfaceLogDO.setUserName("system");
        }else{
            interfaceLogDO.setUserId(userAgent.getUID());
            interfaceLogDO.setUserId(userAgent.getUNAME());
        }
        interfaceLogDO.setAddressIp(getIpAddress(request));
        interfaceLogDO.setUrl(request.getRequestURL().toString());
        HashMap<String, String> headMap = new HashMap<>(16);
        Enumeration<String> headerNames = request.getHeaderNames();
        while (headerNames.hasMoreElements()){
            String name = headerNames.nextElement();
            String value = request.getHeader(name);
            headMap.put(name,value);
        }
        String headJson = JSONObject.toJSONString(headMap);
        interfaceLogDO.setHead(headJson);
        interfaceLogDO.setRequest(params);
        interfaceLogDO.setResponse(response);
        interfaceLogDO.setState(state);
        interfaceLogDO.setInterfaceName(interfaceName);
        interfaceLogDO.setMethod(method);
        interfaceLogDO.setTime(time);
        iotInterfaceLogDao.save(interfaceLogDO);
    }
    /**
     * 获取用户真实IP地址,不使用request.getRemoteAddr();的原因是有可能用户使用了代理软件方式避免真实IP地址。
     * 可是,如果通过了多级反向代理的话,X-Forwarded-For的值并不止一个,而是一串IP值,究竟哪个才是真正的用户端的真实IP呢?
     * 答案是取X-Forwarded-For中第一个非unknown的有效IP字符串
     * @param request
     * @return
     */
    private String getIpAddress(HttpServletRequest request) {
        String ip = request.getHeader("x-forwarded-for");
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("WL-Proxy-Client-IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_CLIENT_IP");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getHeader("HTTP_X_FORWARDED_FOR");
        }
        if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
            ip = request.getRemoteAddr();
            if("127.0.0.1".equals(ip)||"0:0:0:0:0:0:0:1".equals(ip)){
                //根据网卡取本机配置的IP
                InetAddress inet=null;
                try {
                    inet = InetAddress.getLocalHost();
                } catch (UnknownHostException e) {
                    e.printStackTrace();
                }
                ip= inet.getHostAddress();
            }
        }
        return ip;
    }
}

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

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

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

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

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

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