| @@ -1,7 +1,6 @@ | |||||
| package com.iformall; | package com.iformall; | ||||
| import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; | import com.ulisesbocchio.jasyptspringboot.annotation.EnableEncryptableProperties; | ||||
| import org.rocketmq.starter.annotation.EnableRocketMQ; | |||||
| import org.springframework.beans.factory.annotation.Value; | import org.springframework.beans.factory.annotation.Value; | ||||
| import org.springframework.boot.SpringApplication; | import org.springframework.boot.SpringApplication; | ||||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | import org.springframework.boot.autoconfigure.SpringBootApplication; | ||||
| @@ -19,7 +18,6 @@ import tk.mybatis.spring.annotation.MapperScan; | |||||
| @EnableSwagger2 | @EnableSwagger2 | ||||
| @EnableEncryptableProperties | @EnableEncryptableProperties | ||||
| @EnableAsync | @EnableAsync | ||||
| @EnableRocketMQ | |||||
| public class UserApplication { | public class UserApplication { | ||||
| @Value("${fm.exception}") | @Value("${fm.exception}") | ||||
| @@ -53,15 +53,16 @@ spring: | |||||
| auth: true | auth: true | ||||
| starttls: | starttls: | ||||
| enable: true | enable: true | ||||
| rocketmq: | |||||
| nameServer: 127.0.0.1:9876 | |||||
| producer: | |||||
| retry-times-when-send-async-failed: 0 | |||||
| send-msg-timeout: 300000 | |||||
| compress-msg-body-over-howmuch: 4096 | |||||
| max-message-size: 4194304 | |||||
| retry-another-broker-when-not-store-ok: false | |||||
| retry-times-when-send-failed: 2 | |||||
| #rocketmq: | |||||
| # name-server: 127.0.0.1:9876 | |||||
| # producer: | |||||
| # retry-times-when-send-async-failed: 0 | |||||
| # send-msg-timeout: 300000 | |||||
| # compress-msg-body-over-howmuch: 4096 | |||||
| # max-message-size: 4194304 | |||||
| # retry-another-broker-when-not-store-ok: false | |||||
| # retry-times-when-send-failed: 2 | |||||
| aws: | aws: | ||||
| clientRegion: cn-northwest-1 | clientRegion: cn-northwest-1 | ||||
| @@ -92,4 +93,7 @@ logging: | |||||
| level: | level: | ||||
| tk.mybatis: debug | tk.mybatis: debug | ||||
| com.iformall: debug | com.iformall: debug | ||||
| path: ./logs/admin | |||||
| path: ./logs/admin | |||||
| #rocketMQ | |||||
| rocketmq.name-server: 127.0.0.1:9876 | |||||
| @@ -0,0 +1,300 @@ | |||||
| package com.iformall.domain.po; | |||||
| import javax.persistence.Id; | |||||
| import javax.persistence.Table; | |||||
| import javax.persistence.Transient; | |||||
| import java.io.Serializable; | |||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| @Table(name = "wx_msg_record") | |||||
| public class WxMsgRecord implements Serializable { | |||||
| private static final long serialVersionUID = 18957895653478L; | |||||
| @Id | |||||
| protected Long id; | |||||
| @Transient | |||||
| protected List<Long> ids; | |||||
| @Transient | |||||
| protected String sortColumns; | |||||
| public Long getId() { | |||||
| return id; | |||||
| } | |||||
| public void setId(Long id) { | |||||
| this.id = id; | |||||
| } | |||||
| public String getSortColumns() { | |||||
| return sortColumns; | |||||
| } | |||||
| public List<Long> getIds() { | |||||
| return ids; | |||||
| } | |||||
| public void setIds(List<Long> ids) { | |||||
| this.ids = ids; | |||||
| } | |||||
| //uuid | |||||
| private String uuid; | |||||
| //租户id | |||||
| private String tenantId; | |||||
| //域1sys 2a端 3c端 4b端 | |||||
| private String group; | |||||
| //type | |||||
| private Integer type; | |||||
| //msg | |||||
| private String msg; | |||||
| //发送时间 | |||||
| private String sendTime; | |||||
| //model_id | |||||
| private Long modelId; | |||||
| //from,手机号邮件地址等 | |||||
| private String from; | |||||
| //发送人id | |||||
| private Long fromUserId; | |||||
| //发送人姓名 | |||||
| private String fromUserName; | |||||
| //接收人,手机号邮件地址等 | |||||
| private String to; | |||||
| //接收人用户id | |||||
| private Long toUserId; | |||||
| //接收人姓名 | |||||
| private String toUserName; | |||||
| //消费结果 | |||||
| private Integer status; | |||||
| //消费结果信息 | |||||
| private String statusMessage; | |||||
| //签名 | |||||
| private String signature; | |||||
| //模板类型 | |||||
| private Integer modelType; | |||||
| //动态内容(map结构的json数据) | |||||
| private String dynamicContent; | |||||
| private Date createtime; | |||||
| private Date updatetime; | |||||
| public String getDynamicContent() { | |||||
| return dynamicContent; | |||||
| } | |||||
| public void setDynamicContent(String dynamicContent) { | |||||
| this.dynamicContent = dynamicContent; | |||||
| } | |||||
| public Integer getModelType() { | |||||
| return modelType; | |||||
| } | |||||
| public void setModelType(Integer modelType) { | |||||
| this.modelType = modelType; | |||||
| } | |||||
| public String getSignature() { | |||||
| return signature; | |||||
| } | |||||
| public void setSignature(String signature) { | |||||
| this.signature = signature; | |||||
| } | |||||
| public String getUuid() { | |||||
| return uuid; | |||||
| } | |||||
| public void setUuid(String uuid) { | |||||
| this.uuid = uuid; | |||||
| } | |||||
| public String getTenantId() { | |||||
| return tenantId; | |||||
| } | |||||
| public void setTenantId(String tenantId) { | |||||
| this.tenantId = tenantId; | |||||
| } | |||||
| public String getGroup() { | |||||
| return group; | |||||
| } | |||||
| public void setGroup(String group) { | |||||
| this.group = group; | |||||
| } | |||||
| public Integer getType() { | |||||
| return type; | |||||
| } | |||||
| public void setType(Integer type) { | |||||
| this.type = type; | |||||
| } | |||||
| public String getMsg() { | |||||
| return msg; | |||||
| } | |||||
| public void setMsg(String msg) { | |||||
| this.msg = msg; | |||||
| } | |||||
| public String getSendTime() { | |||||
| return sendTime; | |||||
| } | |||||
| public void setSendTime(String sendTime) { | |||||
| this.sendTime = sendTime; | |||||
| } | |||||
| public Long getModelId() { | |||||
| return modelId; | |||||
| } | |||||
| public void setModelId(Long modelId) { | |||||
| this.modelId = modelId; | |||||
| } | |||||
| public String getFrom() { | |||||
| return from; | |||||
| } | |||||
| public void setFrom(String from) { | |||||
| this.from = from; | |||||
| } | |||||
| public Long getFromUserId() { | |||||
| return fromUserId; | |||||
| } | |||||
| public void setFromUserId(Long fromUserId) { | |||||
| this.fromUserId = fromUserId; | |||||
| } | |||||
| public String getFromUserName() { | |||||
| return fromUserName; | |||||
| } | |||||
| public void setFromUserName(String fromUserName) { | |||||
| this.fromUserName = fromUserName; | |||||
| } | |||||
| public String getTo() { | |||||
| return to; | |||||
| } | |||||
| public void setTo(String to) { | |||||
| this.to = to; | |||||
| } | |||||
| public Long getToUserId() { | |||||
| return toUserId; | |||||
| } | |||||
| public void setToUserId(Long toUserId) { | |||||
| this.toUserId = toUserId; | |||||
| } | |||||
| public String getToUserName() { | |||||
| return toUserName; | |||||
| } | |||||
| public void setToUserName(String toUserName) { | |||||
| this.toUserName = toUserName; | |||||
| } | |||||
| public Integer getStatus() { | |||||
| return status; | |||||
| } | |||||
| public void setStatus(Integer status) { | |||||
| this.status = status; | |||||
| } | |||||
| public String getStatusMessage() { | |||||
| return statusMessage; | |||||
| } | |||||
| public void setStatusMessage(String statusMessage) { | |||||
| this.statusMessage = statusMessage; | |||||
| } | |||||
| public Date getCreatetime() { | |||||
| return createtime; | |||||
| } | |||||
| public void setCreatetime(Date createtime) { | |||||
| this.createtime = createtime; | |||||
| } | |||||
| public Date getUpdatetime() { | |||||
| return updatetime; | |||||
| } | |||||
| public void setUpdatetime(Date updatetime) { | |||||
| this.updatetime = updatetime; | |||||
| } | |||||
| public static enum Field | |||||
| { | |||||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | |||||
| ,TenantId_ASC("`tenantId` ASC"),TenantId_DESC("`tenantId` DESC") | |||||
| ,Name_ASC("`name` ASC"),Name_DESC("`name` DESC") | |||||
| ,Available_ASC("`available` ASC"),Available_DESC("`available` DESC") | |||||
| ,Description_ASC("`description` ASC"),Description_DESC("`description` DESC") | |||||
| ; | |||||
| private String value; | |||||
| Field(String value){ | |||||
| this.value = value; | |||||
| } | |||||
| public String getValue() { | |||||
| return value; | |||||
| } | |||||
| public void setCol(String value) { | |||||
| this.value = value; | |||||
| } | |||||
| @Override | |||||
| public String toString() { | |||||
| return this.getValue(); | |||||
| } | |||||
| } | |||||
| public void setSortColumns(WxMsgRecord.Field... fields) | |||||
| { | |||||
| if (fields == null || fields.length == 0) { | |||||
| return; | |||||
| } | |||||
| for (int k = 0; k < fields.length; k++) { | |||||
| if (fields[k] == null) { | |||||
| return; | |||||
| } | |||||
| } | |||||
| StringBuilder sb = new StringBuilder(fields[0].toString()); | |||||
| for (int k = 1; k < fields.length; k++) { | |||||
| sb.append(","); | |||||
| sb.append(fields[k].toString()); | |||||
| } | |||||
| } | |||||
| public void setSortColumns(String sortColumns) | |||||
| { | |||||
| if (sortColumns == null || "".equals(sortColumns.trim())) { | |||||
| return; | |||||
| } | |||||
| if (sortColumns.contains(",")) { | |||||
| String[] cols = sortColumns.split(","); | |||||
| List<Field> fList = new java.util.ArrayList(); | |||||
| for (int k = 0; k < cols.length; k++) { | |||||
| fList.add(Field.valueOf(cols[k])); | |||||
| } | |||||
| this.setSortColumns(fList.toArray(new Field[fList.size()])); | |||||
| } else { | |||||
| this.setSortColumns(Field.valueOf(sortColumns)); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,37 @@ | |||||
| package com.iformall.enums; | |||||
| /** | |||||
| * Created by luozukai | |||||
| */ | |||||
| public enum EnumMsgRecordStatus { | |||||
| DEFAULT(0, "默认"), | |||||
| SEND_SUCC(1, "发送成功"), | |||||
| CONSUME_SUCC(2, "消费成功"), | |||||
| CONSUME_FAIL(3, "消费失败"), | |||||
| ; | |||||
| public static EnumMsgRecordStatus getEnum(Integer code) { | |||||
| for (EnumMsgRecordStatus value : values()) { | |||||
| if (value.getCode().equals(code)) { | |||||
| return value; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private Integer code; | |||||
| private String message; | |||||
| EnumMsgRecordStatus(Integer code, String message) { | |||||
| this.code = code; | |||||
| this.message = message; | |||||
| } | |||||
| public Integer getCode() { | |||||
| return code; | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,17 @@ | |||||
| package com.iformall.mapper; | |||||
| import com.iformall.common.CommonMapper; | |||||
| import com.iformall.domain.po.MallRole; | |||||
| import com.iformall.domain.po.WxMsgRecord; | |||||
| import org.apache.ibatis.annotations.Param; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| public interface WxMsgRecordMapper extends CommonMapper<WxMsgRecord, String> { | |||||
| void update(WxMsgRecord record); | |||||
| } | |||||
| @@ -1,5 +1,9 @@ | |||||
| package com.iformall.mq; | package com.iformall.mq; | ||||
| import com.alibaba.druid.support.json.JSONUtils; | |||||
| import com.iformall.domain.po.WxMsgRecord; | |||||
| import com.iformall.enums.EnumMsgRecordStatus; | |||||
| import com.iformall.mapper.WxMsgRecordMapper; | |||||
| import lombok.extern.slf4j.Slf4j; | import lombok.extern.slf4j.Slf4j; | ||||
| import org.apache.rocketmq.client.producer.DefaultMQProducer; | import org.apache.rocketmq.client.producer.DefaultMQProducer; | ||||
| import org.apache.rocketmq.client.producer.SendCallback; | import org.apache.rocketmq.client.producer.SendCallback; | ||||
| @@ -8,10 +12,11 @@ import org.apache.rocketmq.common.message.Message; | |||||
| import org.apache.rocketmq.remoting.common.RemotingHelper; | import org.apache.rocketmq.remoting.common.RemotingHelper; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.beans.factory.annotation.Value; | import org.springframework.beans.factory.annotation.Value; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import javax.annotation.PostConstruct; | import javax.annotation.PostConstruct; | ||||
| import java.util.UUID; | |||||
| /** | /** | ||||
| * @Auther: luozukai | * @Auther: luozukai | ||||
| @@ -25,6 +30,8 @@ public class MqProducer { | |||||
| private static final DefaultMQProducer producer = new DefaultMQProducer("DefaultProducer"); | private static final DefaultMQProducer producer = new DefaultMQProducer("DefaultProducer"); | ||||
| @Value("${spring.rocketmq.nameServer}") | @Value("${spring.rocketmq.nameServer}") | ||||
| private String namesrvAddr; | private String namesrvAddr; | ||||
| @Autowired | |||||
| private WxMsgRecordMapper wxMsgRecordMapper; | |||||
| @PostConstruct | @PostConstruct | ||||
| public void start(){ | public void start(){ | ||||
| @@ -39,23 +46,30 @@ public class MqProducer { | |||||
| } | } | ||||
| } | } | ||||
| public void sendMessage(String data, String topic, String tags, String keys) throws Throwable{ | |||||
| public void sendMessage(WxMsgRecord data, String topic, String tags, String keys) throws Throwable{ | |||||
| try { | try { | ||||
| byte[] messageBody = data.getBytes(RemotingHelper.DEFAULT_CHARSET); | |||||
| data.setUuid(UUID.randomUUID().toString()); | |||||
| wxMsgRecordMapper.insert(data); | |||||
| byte[] messageBody = JSONUtils.toJSONString(data).getBytes(RemotingHelper.DEFAULT_CHARSET); | |||||
| Message mqMsg = new Message(topic, tags, keys, messageBody); | Message mqMsg = new Message(topic, tags, keys, messageBody); | ||||
| producer.send(mqMsg, new SendCallback() { | producer.send(mqMsg, new SendCallback() { | ||||
| @Override | @Override | ||||
| public void onSuccess(SendResult sendResult) { | public void onSuccess(SendResult sendResult) { | ||||
| log.info("Message Producer: Send Message Success {}", sendResult); | log.info("Message Producer: Send Message Success {}", sendResult); | ||||
| data.setStatus(EnumMsgRecordStatus.SEND_SUCC.getCode()); | |||||
| wxMsgRecordMapper.update(data); | |||||
| } | } | ||||
| @Override | @Override | ||||
| public void onException(Throwable throwable) { | public void onException(Throwable throwable) { | ||||
| log.error("Message Producer: Send Message Error ", throwable); | |||||
| log.error("Message Producer: Send Message Error (onException)", throwable); | |||||
| } | } | ||||
| }); | }); | ||||
| } catch (Throwable e) { | } catch (Throwable e) { | ||||
| e.printStackTrace(); | e.printStackTrace(); | ||||
| log.error("Message Producer: Send Message Error (sendMessage)", e); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,12 @@ | |||||
| package com.iformall.service; | |||||
| import com.iformall.domain.po.WxMsgRecord; | |||||
| public interface MsgSendService { | |||||
| void send(WxMsgRecord record); | |||||
| } | |||||
| @@ -0,0 +1,18 @@ | |||||
| package com.iformall.service.impl; | |||||
| import com.iformall.domain.po.WxMsgRecord; | |||||
| import com.iformall.service.MsgSendService; | |||||
| import org.springframework.stereotype.Service; | |||||
| /** | |||||
| * @author luozukai | |||||
| * 短信发送实现 | |||||
| */ | |||||
| @Service | |||||
| public class SendSmsServiceImpl implements MsgSendService { | |||||
| @Override | |||||
| public void send(WxMsgRecord record) { | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,65 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
| <mapper namespace="com.iformall.mapper.MallRoleMapper"> | |||||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.MallRole"> | |||||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||||
| <result column="name" jdbcType="VARCHAR" property="name" /> | |||||
| <result column="available" jdbcType="VARCHAR" property="available" /> | |||||
| <result column="description" jdbcType="VARCHAR" property="description" /> | |||||
| </resultMap> | |||||
| <sql id="allColumns"> | |||||
| `id`,`tenant_id`,`name`,`available`,`description` | |||||
| </sql> | |||||
| <sql id="dynamicWhereConditions"> | |||||
| where 1 = 1 | |||||
| <if test=" null != id "> | |||||
| and `id` = #{id} | |||||
| </if> | |||||
| <if test=" null != tenantId "> | |||||
| and `tenant_id` = #{tenantId} | |||||
| </if> | |||||
| <if test=" null != name and '' != name "> | |||||
| and `name` like concat('%', #{name},'%') | |||||
| </if> | |||||
| <if test=" null != available "> | |||||
| and `available` like concat('%', #{available},'%') | |||||
| </if> | |||||
| <if test=" null != description "> | |||||
| and `description` like concat('%', #{description},'%') | |||||
| </if> | |||||
| <if test=" null != ids "> | |||||
| and id in | |||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||||
| #{idItem} | |||||
| </foreach> | |||||
| </if> | |||||
| <if test=" null != sortColumns"> order by ${sortColumns} </if> | |||||
| </sql> | |||||
| <select id="findList" parameterType="com.iformall.domain.po.MallRole" resultMap="BaseResultMap"> | |||||
| select <include refid="allColumns" /> from mall_role | |||||
| <include refid="dynamicWhereConditions" /> | |||||
| </select> | |||||
| <select id="countByName" resultType="java.lang.Integer" parameterType="java.util.HashMap"> | |||||
| select count(1) from mall_role where name=#{name} | |||||
| <if test="id!=null"> and id !=#{id}</if> | |||||
| </select> | |||||
| </mapper> | |||||
| @@ -0,0 +1,63 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
| <mapper namespace="com.iformall.mapper.WxMsgRecordMapper"> | |||||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxMsgRecord"> | |||||
| <id column="id" property="id" /> | |||||
| <result column="tenant_id" property="tenantId" /> | |||||
| <result column="group" property="group" /> | |||||
| <result column="type" property="type" /> | |||||
| <result column="msg" property="msg" /> | |||||
| <result column="send_time" property="sendTime" /> | |||||
| <result column="model_id" property="modelId" /> | |||||
| <result column="from" property="from" /> | |||||
| <result column="from_user_id" property="fromUserId" /> | |||||
| <result column="from_user_name" property="fromUserName" /> | |||||
| <result column="to" property="to" /> | |||||
| <result column="to_user_id" property="toUserId" /> | |||||
| <result column="to_user_name" property="toUserName" /> | |||||
| <result column="status" property="status" /> | |||||
| <result column="status_message" property="statusMessage" /> | |||||
| <result column="createtime" property="createtime" /> | |||||
| <result column="updatetime" property="updatetime" /> | |||||
| <result column="uuid" property="uuid" /> | |||||
| <result column="signature" property="signature" /> | |||||
| <result column="model_type" property="modelType" /> | |||||
| <result column="dynamic_content" property="dynamicContent" /> | |||||
| </resultMap> | |||||
| <sql id="allColumns"> | |||||
| `id`,`tenant_id`,`group`,`type`,`msg` ,send_time,model_id,from,from_user_id,from_user_name,to,to_user_id,to_user_name | |||||
| ,status,status_message,createtime,updatetime,uuid,signature,model_type,dynamic_content | |||||
| </sql> | |||||
| <sql id="dynamicWhereConditions"> | |||||
| where 1 = 1 | |||||
| <if test=" null != id "> | |||||
| and `id` = #{id} | |||||
| </if> | |||||
| <if test=" null != tenantId "> | |||||
| and `tenant_id` = #{tenantId} | |||||
| </if> | |||||
| <if test=" null != ids "> | |||||
| and id in | |||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||||
| #{idItem} | |||||
| </foreach> | |||||
| </if> | |||||
| <if test=" null != sortColumns"> order by ${sortColumns} </if> | |||||
| </sql> | |||||
| <update id="update" parameterType="com.iformall.domain.po.WxMsgRecord"> | |||||
| update wx_msg_record set updatetime = now() | |||||
| <if test=" null != status ">,status = #{status}</if> | |||||
| <if test=" null != message ">,message = #{message}</if> | |||||
| where uuid = #{uuid} | |||||
| </update> | |||||
| </mapper> | |||||
| @@ -121,9 +121,9 @@ | |||||
| <!-- rocketmq --> | <!-- rocketmq --> | ||||
| <dependency> | <dependency> | ||||
| <groupId>org.rocketmq.spring.boot</groupId> | |||||
| <groupId>org.apache.rocketmq</groupId> | |||||
| <artifactId>rocketmq-spring-boot-starter</artifactId> | <artifactId>rocketmq-spring-boot-starter</artifactId> | ||||
| <version>1.0.0.RELEASE</version> | |||||
| <version>2.0.1</version> | |||||
| </dependency> | </dependency> | ||||
| <dependency> | <dependency> | ||||
| <groupId>org.apache.rocketmq</groupId> | <groupId>org.apache.rocketmq</groupId> | ||||