Commit a4570217 by fz

1.去除无用的import依赖倒入

2.新增消息订阅的方法枚举
3.新增消息订阅的service,mapper,实现逻辑
1 parent cf2301bb
package cn.com.glsx.openplatform.enums;
import cn.com.glsx.openplatform.exception.BusinessException;
/**
* <p>Description:
* <p>Project: open-platform-admin
*
* @author wbh
* @date 2020-12-16
*/
public enum MessageMethodEnum {
ADD(1, "增加"),
UPDATE(2, "修改"),
DELETE(3, "删除");
private final Integer code;
private final String msg;
MessageMethodEnum(Integer code, String msg) {
this.code = code;
this.msg = msg;
}
public Integer getCode() {
return code;
}
public String getMsg() {
return msg;
}
public BusinessException exception() {
return new BusinessException(this.code, this.msg);
}
}
package cn.com.glsx.openplatform.model; package cn.com.glsx.openplatform.model;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.io.Serializable; import java.io.Serializable;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import com.fasterxml.jackson.annotation.JsonFormat;
/** /**
* <p>Description: * <p>Description:
......
package cn.com.glsx.openplatform.model;
import cn.com.glsx.framework.core.beans.BaseModel;
import lombok.Data;
import javax.persistence.Column;
import javax.persistence.Table;
/**
* <p>Description:
* <p>Project: shop
*
* @author wbh
* @date 2020-12-15
*/
/**
* 设备管理表
*/
@Data
@Table(name = "t_platform_sub_message")
public class PlatformSubMessage extends BaseModel{
/**
* 消息类型ID
*/
@Column(name = "msg_id")
private Integer msgID;
/**
* 设备类型ID
*/
@Column(name = "device_type")
private Integer deviceType;
/**
* 推送地址
*/
@Column(name = "push_url")
private String pushUrl;
}
...@@ -38,7 +38,17 @@ public interface OpenApiService { ...@@ -38,7 +38,17 @@ public interface OpenApiService {
* @param page * @param page
* @param start_time * @param start_time
* @param end_time * @param end_time
* @return 结果集
*/
Map<String, Object> getDeviceList(int appid, Page page, Date start_time, Date end_time);
/**
* 消息订阅
* @param msgID 消息类型ID
* @param deviceType 设备类型
* @param method
* @param pushUrl
* @return * @return
*/ */
Map<String, Object> getDeviceList(Integer appid, Page page, Date start_time, Date end_time); Map<String, Object> subscribeMessage(int msgID,int deviceType,int method,String pushUrl);
} }
package cn.com.glsx.openplatform.util; package cn.com.glsx.openplatform.util;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import cn.com.glsx.openplatform.config.FdfsProperty; import cn.com.glsx.openplatform.config.FdfsProperty;
import com.github.tobato.fastdfs.domain.fdfs.StorePath; import com.github.tobato.fastdfs.domain.fdfs.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient; import com.github.tobato.fastdfs.service.FastFileStorageClient;
...@@ -14,6 +11,10 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -14,6 +11,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
/** /**
* <p>Description: FastDFS 文件操作工具类 * <p>Description: FastDFS 文件操作工具类
* <p>Project: shop * <p>Project: shop
......
package cn.com.glsx.openplatform.util; package cn.com.glsx.openplatform.util;
import org.springframework.stereotype.Component;
import org.springframework.util.Base64Utils;
import javax.crypto.Cipher; import javax.crypto.Cipher;
import java.security.KeyFactory; import java.security.*;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.interfaces.RSAPrivateKey; import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey; import java.security.interfaces.RSAPublicKey;
import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec; import java.security.spec.X509EncodedKeySpec;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.springframework.stereotype.Component;
import org.springframework.util.Base64Utils;
/** /**
......
package cn.com.glsx.openplatform.vo;
import lombok.Data;
import java.io.Serializable;
/**
* <p>Description:
* <p>Project: shop
*
* @author fengzhi
* @date 2020-12-23
*/
/**
* 设备
*/
@Data
public class OpenDeviceVo implements Serializable {
private Integer id;
/**
* 设备号
*/
private String sn;
/**
* 客户名称
*/
private String username;
/**
* 手机号
*/
private String mobile;
}
...@@ -7,7 +7,6 @@ import org.apache.ibatis.annotations.Param; ...@@ -7,7 +7,6 @@ import org.apache.ibatis.annotations.Param;
import org.oreframework.datasource.mybatis.mapper.OreMapper; import org.oreframework.datasource.mybatis.mapper.OreMapper;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* <p>Description: * <p>Description:
......
...@@ -2,10 +2,11 @@ package cn.com.glsx.openplatform.mapper; ...@@ -2,10 +2,11 @@ package cn.com.glsx.openplatform.mapper;
import cn.com.glsx.openplatform.model.PlatformDevice; import cn.com.glsx.openplatform.model.PlatformDevice;
import cn.com.glsx.openplatform.vo.DeviceVo; import cn.com.glsx.openplatform.vo.DeviceVo;
import com.github.pagehelper.Page; import cn.com.glsx.openplatform.vo.OpenDeviceVo;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import org.oreframework.datasource.mybatis.mapper.OreMapper; import org.oreframework.datasource.mybatis.mapper.OreMapper;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -34,7 +35,9 @@ public interface PlatformDeviceMapper extends OreMapper<PlatformDevice> { ...@@ -34,7 +35,9 @@ public interface PlatformDeviceMapper extends OreMapper<PlatformDevice> {
List<Map<String, Object>> getDeviceActivationStatistic(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("customerName") String customerName); List<Map<String, Object>> getDeviceActivationStatistic(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("customerName") String customerName);
List<Map<String, Object>> getDeviceByTimeRangeAndCustID(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("customerID") String customerID); List<OpenDeviceVo> getDeviceByTimeRangeAndCustID(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("customerID") Integer customerID);
int getCountDeviceByTimeRangeAndCustID(@Param("startTime") Date startTime, @Param("endTime") Date endTime, @Param("customerID") Integer customerID);
int getDeviceCountByCustomerId(@Param("customerId") int customerId, @Param("deviceTypeStr") String deviceTypeStr); int getDeviceCountByCustomerId(@Param("customerId") int customerId, @Param("deviceTypeStr") String deviceTypeStr);
......
package cn.com.glsx.openplatform.mapper;
import cn.com.glsx.openplatform.model.PlatformSubMessage;
import org.apache.ibatis.annotations.Mapper;
import org.oreframework.datasource.mybatis.mapper.OreMapper;
/**
* <p>Description:
* <p>Project: shop
*
* @author wbh
* @date 2020-12-15
*/
@Mapper
public interface PlatformMessageMapper extends OreMapper<PlatformSubMessage> {
}
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.openplatform.service; package cn.com.glsx.openplatform.service;
import cn.com.glsx.openplatform.enums.MessageMethodEnum;
import cn.com.glsx.openplatform.mapper.PlatformCustomerMapper; import cn.com.glsx.openplatform.mapper.PlatformCustomerMapper;
import cn.com.glsx.openplatform.mapper.PlatformDeviceMapper; import cn.com.glsx.openplatform.mapper.PlatformDeviceMapper;
import cn.com.glsx.openplatform.mapper.PlatformMessageMapper;
import cn.com.glsx.openplatform.mapper.PlatformUserMapper; import cn.com.glsx.openplatform.mapper.PlatformUserMapper;
import cn.com.glsx.openplatform.model.PlatformCustomer; import cn.com.glsx.openplatform.model.PlatformCustomer;
import cn.com.glsx.openplatform.model.PlatformSubMessage;
import cn.com.glsx.openplatform.vo.OpenDeviceVo;
import cn.hutool.db.Page; import cn.hutool.db.Page;
import com.alibaba.dubbo.config.annotation.Service; import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
...@@ -31,6 +36,10 @@ public class OpenApiServiceImpl implements OpenApiService { ...@@ -31,6 +36,10 @@ public class OpenApiServiceImpl implements OpenApiService {
@Resource @Resource
private PlatformCustomerMapper customerMapper; private PlatformCustomerMapper customerMapper;
@Resource
private PlatformMessageMapper messageMapper;
/** /**
* 获取商户下的数据概况信息 * 获取商户下的数据概况信息
* *
...@@ -117,11 +126,75 @@ public class OpenApiServiceImpl implements OpenApiService { ...@@ -117,11 +126,75 @@ public class OpenApiServiceImpl implements OpenApiService {
} }
@Override @Override
public Map<String, Object> getDeviceList(Integer appid, Page page, Date start_time, Date end_time) { public Map<String, Object> subscribeMessage(int msgID, int deviceType, int method, String pushUrl) {
log.info("rpc==subscribeMessage开始===msgID:" + msgID + ",deviceType:" + deviceType + ",method:" + method + ",pushUrl:" + pushUrl);
//封装返回数据
Map<String, Object> res = new HashMap<>();
try {
//查询msgID是否存在
Example example = new Example(PlatformSubMessage.class);
example.createCriteria().andEqualTo("msg_id",msgID);
PlatformSubMessage message = messageMapper.selectOneByExample(example);
//新增
if(MessageMethodEnum.ADD.getCode()==method){
if(null != message){
//msgID存在,返回失败信息
res.put("success",false);
res.put("msg","新增失败,msgID存在");
return res;
}else {
//新增订阅消息
message = new PlatformSubMessage();
message.setMsgID(msgID);
message.setPushUrl(pushUrl);
message.setDeviceType(deviceType);
messageMapper.insert(message);
}
}
//更新
if(MessageMethodEnum.UPDATE.getCode()==method){
if(null != message){
//msgID存在,更新数据
message.setPushUrl(pushUrl);
message.setDeviceType(deviceType);
messageMapper.updateByPrimaryKey(message);
}else {
//不存在,新增数据
message = new PlatformSubMessage();
message.setMsgID(msgID);
message.setPushUrl(pushUrl);
message.setDeviceType(deviceType);
messageMapper.insert(message);
}
}
//删除
if(MessageMethodEnum.DELETE.getCode()==method){
if(null != message){
//msgID存在,逻辑删除数据
message.setDeletedFlag("1");
messageMapper.updateByPrimaryKey(message);
}
}
//执行成功
res.put("success",true);
}catch (Exception e){
res.put("success",false);
res.put("msg",e.getMessage());
return res;
}
log.info("rpc==subscribeMessage结果==" + res);
return res;
}
@Override
public Map<String, Object> getDeviceList(int appid, Page page, Date start_time, Date end_time) {
log.info("rpc==getDeviceList开始==appid:" + appid, "==page:" + page + "==start_time:" + start_time, "==end_time:" + start_time); log.info("rpc==getDeviceList开始==appid:" + appid, "==page:" + page + "==start_time:" + start_time, "==end_time:" + start_time);
//分页查询 //分页查询
PageHelper.startPage(page.getPageNumber(), page.getPageSize(), true); PageHelper.startPage(page.getPageNumber(), page.getPageSize(), true);
List<Map<String, Object>> deviceList = deviceMapper.getDeviceByTimeRangeAndCustID(start_time, end_time, appid + ""); List<OpenDeviceVo> deviceList = deviceMapper.getDeviceByTimeRangeAndCustID(start_time, end_time, appid);
//分页结果 //分页结果
PageInfo pageInfo = new PageInfo<>(deviceList); PageInfo pageInfo = new PageInfo<>(deviceList);
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
<result column="update_by" jdbcType="INTEGER" property="updateBy"/> <result column="update_by" jdbcType="INTEGER" property="updateBy"/>
<result column="remark" jdbcType="VARCHAR" property="remark"/> <result column="remark" jdbcType="VARCHAR" property="remark"/>
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
<!--@mbg.generated--> <!--@mbg.generated-->
id, device_sn, device_type, customer_id, activat_time, `status`, create_time, update_time, id, device_sn, device_type, customer_id, activat_time, `status`, create_time, update_time,
...@@ -127,12 +128,21 @@ ...@@ -127,12 +128,21 @@
</if> </if>
</select> </select>
<select id="getDeviceByTimeRangeAndCustID" resultType="java.util.Map"> <select id="getDeviceByTimeRangeAndCustID" resultType="cn.com.glsx.openplatform.vo.OpenDeviceVo">
select tpd.device_sn as sn,tpu.nickname as username,tpu.contact_number as mobile from t_platform_device tpd inner join t_platform_user tpu select tpd.device_sn as sn,tpu.nickname as username,tpu.contact_number as mobile from t_platform_device tpd inner join t_platform_user tpu
on tpd.user_id = tpu.id on tpd.user_id = tpu.id
where tpd.activat_time >= #{startTime,jdbcType=TIMESTAMP} where tpd.activat_time >= #{startTime,jdbcType=TIMESTAMP}
and tpd.activat_time &lt; #{endTime,jdbcType=TIMESTAMP} and tpd.activat_time &lt; #{endTime,jdbcType=TIMESTAMP}
and tpd.customer_id = #{customerID} and tpd.customer_id = #{customerID,jdbcType=INTEGER}
order by tpd.activat_time desc
</select>
<select id="getCountDeviceByTimeRangeAndCustID" resultType="java.lang.Integer">
select count(1) from t_platform_device tpd inner join t_platform_user tpu
on tpd.user_id = tpu.id
where tpd.activat_time >= #{startTime,jdbcType=TIMESTAMP}
and tpd.activat_time &lt; #{endTime,jdbcType=TIMESTAMP}
and tpd.customer_id = #{customerID,jdbcType=INTEGER}
order by tpd.activat_time desc order by tpd.activat_time desc
</select> </select>
</mapper> </mapper>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!