提交代码

master
胡锐 3 weeks ago
parent 8a615ef604
commit 1e729f1465
  1. 1
      bweb/src/main/java/com/bweb/config/AuthConfig.java
  2. 53
      bweb/src/main/java/com/bweb/controller/CmsController.java
  3. 39
      schedule/src/main/java/com/hfkj/consumer/CmsOfflineConsumer.java
  4. 38
      schedule/src/main/java/com/hfkj/consumer/CmsOnlineConsumer.java
  5. 12
      service/src/main/java/com/hfkj/dao/CmsContentMapper.java
  6. 28
      service/src/main/java/com/hfkj/dao/CmsContentSqlProvider.java
  7. 32
      service/src/main/java/com/hfkj/entity/CmsContent.java
  8. 120
      service/src/main/java/com/hfkj/entity/CmsContentExample.java
  9. 4
      service/src/main/java/com/hfkj/mqtopic/TaskTopic.java
  10. 21
      service/src/main/java/com/hfkj/service/cms/CmsContentService.java
  11. 91
      service/src/main/java/com/hfkj/service/cms/impl/CmsContentServiceImpl.java

@ -100,6 +100,7 @@ public class AuthConfig implements WebMvcConfigurer {
.excludePathPatterns("/tuanYou/*")
.excludePathPatterns("/merchantChainBrandAccount")
.excludePathPatterns("/userSpread/*")
.excludePathPatterns("/cms/*")
;
}

@ -5,22 +5,27 @@ import com.github.pagehelper.PageInfo;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.DateUtil;
import com.hfkj.common.utils.RedisUtil;
import com.hfkj.common.utils.ResponseMsgUtil;
import com.hfkj.entity.CmsContent;
import com.hfkj.model.ResponseData;
import com.hfkj.mqtopic.TaskTopic;
import com.hfkj.service.cms.CmsContentService;
import com.hfkj.service.cms.impl.CmsContentServiceImpl;
import com.hfkj.sysenum.cms.CmsStatusEnum;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@ -36,8 +41,10 @@ public class CmsController {
private static Logger log = LoggerFactory.getLogger(CmsController.class);
@Resource
private CmsContentService cmsContentService;
@Resource
private RedisUtil redisUtil;
public static void main(String[] args) {
System.out.println(new Date().compareTo(new Date()));
}
@RequestMapping(value="/edit",method = RequestMethod.POST)
@ResponseBody
@ -47,9 +54,18 @@ public class CmsController {
if (body == null
|| body.getType() == null
|| StringUtils.isBlank(body.getImgUrl())
|| body.getStartTime() == null
|| body.getEndTime() == null
) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR);
}
if (body.getStartTime().compareTo(new Date()) < 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "开始时间,必须大于当前时间");
}
if (body.getEndTime().compareTo(body.getStartTime()) < 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "结束时间,必须大于开始时间");
}
CmsContent cmsContent = null;
if (body.getId() != null) {
// 查询内容
@ -68,7 +84,10 @@ public class CmsController {
cmsContent.setImgUrl(body.getImgUrl());
cmsContent.setJumpType(body.getJumpType());
cmsContent.setJumpUrl(body.getJumpUrl());
cmsContent.setStartTime(body.getStartTime());
cmsContent.setEndTime(body.getEndTime());
cmsContentService.editData(cmsContent);
return ResponseMsgUtil.success("操作成功");
} catch (Exception e) {
@ -84,19 +103,9 @@ public class CmsController {
if (body == null || body.getId() == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR);
}
// 查询内容
CmsContent cmsContent = cmsContentService.getDetail(body.getId());
if (cmsContent == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到数据");
}
if (!CmsStatusEnum.status1.getStatus().equals(cmsContent.getStatus())) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法上线,状态错误");
}
cmsContent.setStatus(CmsStatusEnum.status2.getStatus());
cmsContentService.editData(cmsContent);
// 删除缓存
redisUtil.hdel(CmsContentServiceImpl.CACHE_CMS_ONLINE, ""+cmsContent.getType());
cmsContentService.online(body.getId());
return ResponseMsgUtil.success("操作成功");
} catch (Exception e) {
@ -112,19 +121,9 @@ public class CmsController {
if (body == null || body.getId() == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR);
}
// 查询内容
CmsContent cmsContent = cmsContentService.getDetail(body.getId());
if (cmsContent == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到数据");
}
if (!CmsStatusEnum.status2.getStatus().equals(cmsContent.getStatus())) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法下线,状态错误");
}
cmsContent.setStatus(CmsStatusEnum.status3.getStatus());
cmsContentService.editData(cmsContent);
// 删除缓存
redisUtil.hdel(CmsContentServiceImpl.CACHE_CMS_ONLINE, ""+cmsContent.getType());
cmsContentService.offline(body.getId());
return ResponseMsgUtil.success("操作成功");
} catch (Exception e) {
@ -149,7 +148,7 @@ public class CmsController {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法删除,状态错误");
}
cmsContent.setStatus(CmsStatusEnum.status0.getStatus());
cmsContentService.editData(cmsContent);
cmsContentService.update(cmsContent);
return ResponseMsgUtil.success("操作成功");

@ -0,0 +1,39 @@
package com.hfkj.consumer;
import com.hfkj.entity.BsGasOilPriceTask;
import com.hfkj.entity.CmsContent;
import com.hfkj.service.cms.CmsContentService;
import com.hfkj.service.gas.BsGasOilPriceTaskService;
import com.hfkj.sysenum.cms.CmsStatusEnum;
import com.hfkj.sysenum.gas.GasTaskStatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
@Component
@Slf4j
@RocketMQMessageListener(consumerGroup = "cms-offline", topic = "task-topic",selectorExpression = "cms-offline")
public class CmsOfflineConsumer implements RocketMQListener<String> {
@Resource
private CmsContentService cmsContentService;
@Override
public void onMessage(String id) {
System.out.println("CMS内容下线id:" + id);
try {
CmsContent content = cmsContentService.getDetail(Long.parseLong(id));
if (content != null && content.getEndTime() != null && content.getStatus().equals(CmsStatusEnum.status2.getStatus())) {
if (content.getEndTime().compareTo(new Date()) <= 0) {
cmsContentService.offline(Long.parseLong(id));
}
}
} catch (Exception e) {
}
}
}

@ -0,0 +1,38 @@
package com.hfkj.consumer;
import com.hfkj.entity.BsGasOilPriceTask;
import com.hfkj.entity.CmsContent;
import com.hfkj.service.cms.CmsContentService;
import com.hfkj.service.gas.BsGasOilPriceTaskService;
import com.hfkj.sysenum.cms.CmsStatusEnum;
import com.hfkj.sysenum.gas.GasTaskStatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.Date;
@Component
@Slf4j
@RocketMQMessageListener(consumerGroup = "cms-online", topic = "task-topic",selectorExpression = "cms-online")
public class CmsOnlineConsumer implements RocketMQListener<String> {
@Resource
private CmsContentService cmsContentService;
@Override
public void onMessage(String id) {
System.out.println("CMS内容上线id:" + id);
try {
CmsContent content = cmsContentService.getDetail(Long.parseLong(id));
if (content != null && content.getStartTime() != null && content.getStatus().equals(CmsStatusEnum.status1.getStatus())) {
if (content.getStartTime().compareTo(new Date()) <= 0) {
cmsContentService.online(Long.parseLong(id));
}
}
} catch (Exception e) {
}
}
}

@ -42,11 +42,13 @@ public interface CmsContentMapper extends CmsContentMapperExt {
"insert into cms_content (`type`, `name`, ",
"img_url, jump_type, ",
"jump_url, `status`, ",
"start_time, end_time, ",
"create_time, update_time, ",
"ext_1, ext_2, ext_3)",
"values (#{type,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, ",
"#{imgUrl,jdbcType=VARCHAR}, #{jumpType,jdbcType=INTEGER}, ",
"#{jumpUrl,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, ",
"#{startTime,jdbcType=TIMESTAMP}, #{endTime,jdbcType=TIMESTAMP}, ",
"#{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP}, ",
"#{ext1,jdbcType=VARCHAR}, #{ext2,jdbcType=VARCHAR}, #{ext3,jdbcType=VARCHAR})"
})
@ -66,6 +68,8 @@ public interface CmsContentMapper extends CmsContentMapperExt {
@Result(column="jump_type", property="jumpType", jdbcType=JdbcType.INTEGER),
@Result(column="jump_url", property="jumpUrl", jdbcType=JdbcType.VARCHAR),
@Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
@Result(column="start_time", property="startTime", jdbcType=JdbcType.TIMESTAMP),
@Result(column="end_time", property="endTime", jdbcType=JdbcType.TIMESTAMP),
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
@Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
@Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR),
@ -76,8 +80,8 @@ public interface CmsContentMapper extends CmsContentMapperExt {
@Select({
"select",
"id, `type`, `name`, img_url, jump_type, jump_url, `status`, create_time, update_time, ",
"ext_1, ext_2, ext_3",
"id, `type`, `name`, img_url, jump_type, jump_url, `status`, start_time, end_time, ",
"create_time, update_time, ext_1, ext_2, ext_3",
"from cms_content",
"where id = #{id,jdbcType=BIGINT}"
})
@ -89,6 +93,8 @@ public interface CmsContentMapper extends CmsContentMapperExt {
@Result(column="jump_type", property="jumpType", jdbcType=JdbcType.INTEGER),
@Result(column="jump_url", property="jumpUrl", jdbcType=JdbcType.VARCHAR),
@Result(column="status", property="status", jdbcType=JdbcType.INTEGER),
@Result(column="start_time", property="startTime", jdbcType=JdbcType.TIMESTAMP),
@Result(column="end_time", property="endTime", jdbcType=JdbcType.TIMESTAMP),
@Result(column="create_time", property="createTime", jdbcType=JdbcType.TIMESTAMP),
@Result(column="update_time", property="updateTime", jdbcType=JdbcType.TIMESTAMP),
@Result(column="ext_1", property="ext1", jdbcType=JdbcType.VARCHAR),
@ -114,6 +120,8 @@ public interface CmsContentMapper extends CmsContentMapperExt {
"jump_type = #{jumpType,jdbcType=INTEGER},",
"jump_url = #{jumpUrl,jdbcType=VARCHAR},",
"`status` = #{status,jdbcType=INTEGER},",
"start_time = #{startTime,jdbcType=TIMESTAMP},",
"end_time = #{endTime,jdbcType=TIMESTAMP},",
"create_time = #{createTime,jdbcType=TIMESTAMP},",
"update_time = #{updateTime,jdbcType=TIMESTAMP},",
"ext_1 = #{ext1,jdbcType=VARCHAR},",

@ -52,6 +52,14 @@ public class CmsContentSqlProvider {
sql.VALUES("`status`", "#{status,jdbcType=INTEGER}");
}
if (record.getStartTime() != null) {
sql.VALUES("start_time", "#{startTime,jdbcType=TIMESTAMP}");
}
if (record.getEndTime() != null) {
sql.VALUES("end_time", "#{endTime,jdbcType=TIMESTAMP}");
}
if (record.getCreateTime() != null) {
sql.VALUES("create_time", "#{createTime,jdbcType=TIMESTAMP}");
}
@ -88,6 +96,8 @@ public class CmsContentSqlProvider {
sql.SELECT("jump_type");
sql.SELECT("jump_url");
sql.SELECT("`status`");
sql.SELECT("start_time");
sql.SELECT("end_time");
sql.SELECT("create_time");
sql.SELECT("update_time");
sql.SELECT("ext_1");
@ -138,6 +148,14 @@ public class CmsContentSqlProvider {
sql.SET("`status` = #{record.status,jdbcType=INTEGER}");
}
if (record.getStartTime() != null) {
sql.SET("start_time = #{record.startTime,jdbcType=TIMESTAMP}");
}
if (record.getEndTime() != null) {
sql.SET("end_time = #{record.endTime,jdbcType=TIMESTAMP}");
}
if (record.getCreateTime() != null) {
sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}");
}
@ -173,6 +191,8 @@ public class CmsContentSqlProvider {
sql.SET("jump_type = #{record.jumpType,jdbcType=INTEGER}");
sql.SET("jump_url = #{record.jumpUrl,jdbcType=VARCHAR}");
sql.SET("`status` = #{record.status,jdbcType=INTEGER}");
sql.SET("start_time = #{record.startTime,jdbcType=TIMESTAMP}");
sql.SET("end_time = #{record.endTime,jdbcType=TIMESTAMP}");
sql.SET("create_time = #{record.createTime,jdbcType=TIMESTAMP}");
sql.SET("update_time = #{record.updateTime,jdbcType=TIMESTAMP}");
sql.SET("ext_1 = #{record.ext1,jdbcType=VARCHAR}");
@ -212,6 +232,14 @@ public class CmsContentSqlProvider {
sql.SET("`status` = #{status,jdbcType=INTEGER}");
}
if (record.getStartTime() != null) {
sql.SET("start_time = #{startTime,jdbcType=TIMESTAMP}");
}
if (record.getEndTime() != null) {
sql.SET("end_time = #{endTime,jdbcType=TIMESTAMP}");
}
if (record.getCreateTime() != null) {
sql.SET("create_time = #{createTime,jdbcType=TIMESTAMP}");
}

@ -48,6 +48,16 @@ public class CmsContent implements Serializable {
*/
private Integer status;
/**
* 上线时间
*/
private Date startTime;
/**
* 下线时间
*/
private Date endTime;
/**
* 创建时间
*/
@ -122,6 +132,22 @@ public class CmsContent implements Serializable {
this.status = status;
}
public Date getStartTime() {
return startTime;
}
public void setStartTime(Date startTime) {
this.startTime = startTime;
}
public Date getEndTime() {
return endTime;
}
public void setEndTime(Date endTime) {
this.endTime = endTime;
}
public Date getCreateTime() {
return createTime;
}
@ -181,6 +207,8 @@ public class CmsContent implements Serializable {
&& (this.getJumpType() == null ? other.getJumpType() == null : this.getJumpType().equals(other.getJumpType()))
&& (this.getJumpUrl() == null ? other.getJumpUrl() == null : this.getJumpUrl().equals(other.getJumpUrl()))
&& (this.getStatus() == null ? other.getStatus() == null : this.getStatus().equals(other.getStatus()))
&& (this.getStartTime() == null ? other.getStartTime() == null : this.getStartTime().equals(other.getStartTime()))
&& (this.getEndTime() == null ? other.getEndTime() == null : this.getEndTime().equals(other.getEndTime()))
&& (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()))
&& (this.getUpdateTime() == null ? other.getUpdateTime() == null : this.getUpdateTime().equals(other.getUpdateTime()))
&& (this.getExt1() == null ? other.getExt1() == null : this.getExt1().equals(other.getExt1()))
@ -199,6 +227,8 @@ public class CmsContent implements Serializable {
result = prime * result + ((getJumpType() == null) ? 0 : getJumpType().hashCode());
result = prime * result + ((getJumpUrl() == null) ? 0 : getJumpUrl().hashCode());
result = prime * result + ((getStatus() == null) ? 0 : getStatus().hashCode());
result = prime * result + ((getStartTime() == null) ? 0 : getStartTime().hashCode());
result = prime * result + ((getEndTime() == null) ? 0 : getEndTime().hashCode());
result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
result = prime * result + ((getUpdateTime() == null) ? 0 : getUpdateTime().hashCode());
result = prime * result + ((getExt1() == null) ? 0 : getExt1().hashCode());
@ -220,6 +250,8 @@ public class CmsContent implements Serializable {
sb.append(", jumpType=").append(jumpType);
sb.append(", jumpUrl=").append(jumpUrl);
sb.append(", status=").append(status);
sb.append(", startTime=").append(startTime);
sb.append(", endTime=").append(endTime);
sb.append(", createTime=").append(createTime);
sb.append(", updateTime=").append(updateTime);
sb.append(", ext1=").append(ext1);

@ -575,6 +575,126 @@ public class CmsContentExample {
return (Criteria) this;
}
public Criteria andStartTimeIsNull() {
addCriterion("start_time is null");
return (Criteria) this;
}
public Criteria andStartTimeIsNotNull() {
addCriterion("start_time is not null");
return (Criteria) this;
}
public Criteria andStartTimeEqualTo(Date value) {
addCriterion("start_time =", value, "startTime");
return (Criteria) this;
}
public Criteria andStartTimeNotEqualTo(Date value) {
addCriterion("start_time <>", value, "startTime");
return (Criteria) this;
}
public Criteria andStartTimeGreaterThan(Date value) {
addCriterion("start_time >", value, "startTime");
return (Criteria) this;
}
public Criteria andStartTimeGreaterThanOrEqualTo(Date value) {
addCriterion("start_time >=", value, "startTime");
return (Criteria) this;
}
public Criteria andStartTimeLessThan(Date value) {
addCriterion("start_time <", value, "startTime");
return (Criteria) this;
}
public Criteria andStartTimeLessThanOrEqualTo(Date value) {
addCriterion("start_time <=", value, "startTime");
return (Criteria) this;
}
public Criteria andStartTimeIn(List<Date> values) {
addCriterion("start_time in", values, "startTime");
return (Criteria) this;
}
public Criteria andStartTimeNotIn(List<Date> values) {
addCriterion("start_time not in", values, "startTime");
return (Criteria) this;
}
public Criteria andStartTimeBetween(Date value1, Date value2) {
addCriterion("start_time between", value1, value2, "startTime");
return (Criteria) this;
}
public Criteria andStartTimeNotBetween(Date value1, Date value2) {
addCriterion("start_time not between", value1, value2, "startTime");
return (Criteria) this;
}
public Criteria andEndTimeIsNull() {
addCriterion("end_time is null");
return (Criteria) this;
}
public Criteria andEndTimeIsNotNull() {
addCriterion("end_time is not null");
return (Criteria) this;
}
public Criteria andEndTimeEqualTo(Date value) {
addCriterion("end_time =", value, "endTime");
return (Criteria) this;
}
public Criteria andEndTimeNotEqualTo(Date value) {
addCriterion("end_time <>", value, "endTime");
return (Criteria) this;
}
public Criteria andEndTimeGreaterThan(Date value) {
addCriterion("end_time >", value, "endTime");
return (Criteria) this;
}
public Criteria andEndTimeGreaterThanOrEqualTo(Date value) {
addCriterion("end_time >=", value, "endTime");
return (Criteria) this;
}
public Criteria andEndTimeLessThan(Date value) {
addCriterion("end_time <", value, "endTime");
return (Criteria) this;
}
public Criteria andEndTimeLessThanOrEqualTo(Date value) {
addCriterion("end_time <=", value, "endTime");
return (Criteria) this;
}
public Criteria andEndTimeIn(List<Date> values) {
addCriterion("end_time in", values, "endTime");
return (Criteria) this;
}
public Criteria andEndTimeNotIn(List<Date> values) {
addCriterion("end_time not in", values, "endTime");
return (Criteria) this;
}
public Criteria andEndTimeBetween(Date value1, Date value2) {
addCriterion("end_time between", value1, value2, "endTime");
return (Criteria) this;
}
public Criteria andEndTimeNotBetween(Date value1, Date value2) {
addCriterion("end_time not between", value1, value2, "endTime");
return (Criteria) this;
}
public Criteria andCreateTimeIsNull() {
addCriterion("create_time is null");
return (Criteria) this;

@ -12,6 +12,10 @@ public enum TaskTopic {
TASK_TOPIC("task-topic", "","任务主题"),
// 油价任务
OIL_PRICE(TASK_TOPIC.getTopic(),"oil-price", "油价任务"),
// CMS定时上线
CMS_ONLINE(TASK_TOPIC.getTopic(),"cms-online", "CMS内容定时上线"),
// CMS定时下线
CMS_OFFLINE(TASK_TOPIC.getTopic(),"cms-offline", "CMS内容定时下线"),
;
private String topic;

@ -1,6 +1,9 @@
package com.hfkj.service.cms;
import com.hfkj.entity.CmsContent;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.remoting.exception.RemotingException;
import java.util.List;
import java.util.Map;
@ -18,6 +21,24 @@ public interface CmsContentService {
*/
void editData(CmsContent data) ;
/**
* 修改
* @param data
*/
void update(CmsContent data);
/**
* 上线
* @param id
*/
void online(Long id);
/**
* 下线
* @param id
*/
void offline(Long id);
/**
* 详情
* @param id

@ -1,12 +1,26 @@
package com.hfkj.service.cms.impl;
import com.alibaba.fastjson.JSONObject;
import com.hfkj.common.exception.BaseException;
import com.hfkj.common.exception.ErrorCode;
import com.hfkj.common.exception.ErrorHelp;
import com.hfkj.common.exception.SysCode;
import com.hfkj.common.utils.DateUtil;
import com.hfkj.common.utils.RedisUtil;
import com.hfkj.dao.CmsContentMapper;
import com.hfkj.entity.CmsContent;
import com.hfkj.entity.CmsContentExample;
import com.hfkj.mqtopic.TaskTopic;
import com.hfkj.service.cms.CmsContentService;
import com.hfkj.sysenum.cms.CmsStatusEnum;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -23,6 +37,10 @@ import java.util.Map;
public class CmsContentServiceImpl implements CmsContentService {
@Resource
private CmsContentMapper cmsContentMapper;
@Resource
private RocketMQTemplate rocketMQTemplate;
@Resource
private RedisUtil redisUtil;
public final static String CACHE_CMS_ONLINE = "CACHE_CMS_ONLINE";
@Override
public void editData(CmsContent data){
@ -30,9 +48,82 @@ public class CmsContentServiceImpl implements CmsContentService {
if (data.getId() == null) {
data.setCreateTime(new Date());
cmsContentMapper.insert(data);
} else {
cmsContentMapper.updateByPrimaryKey(data);
}
try {
if (data.getStartTime() != null) {
if (DateUtil.getSecondDiff(new Date(), data.getStartTime()) >= 1) {
Message message = new Message(TaskTopic.TASK_TOPIC.getTopic(), TaskTopic.CMS_ONLINE.getTag(), data.getId().toString().getBytes());
// 定时投递,执行时间
message.setDeliverTimeMs(data.getStartTime().getTime());
SendResult sendResult = rocketMQTemplate.getProducer().send(message);
System.out.println("开始时间:"+ JSONObject.toJSONString(sendResult));
} else {
// 开始时间小于当前时间
// 上线
online(data.getId());
}
}
if (data.getEndTime() != null) {
if (DateUtil.getSecondDiff(new Date(), data.getEndTime()) >= 1) {
Message message = new Message(TaskTopic.TASK_TOPIC.getTopic(), TaskTopic.CMS_OFFLINE.getTag(), data.getId().toString().getBytes());
// 定时投递,执行时间
message.setDeliverTimeMs(data.getEndTime().getTime());
SendResult sendResult = rocketMQTemplate.getProducer().send(message);
System.out.println("结束时间:"+ JSONObject.toJSONString(sendResult));
} else {
// 下线
offline(data.getId());
}
}
} catch (BaseException e) {
throw ErrorHelp.genException(SysCode.System,ErrorCode.COMMON_ERROR, e.getErrorMsg());
} catch (Exception e) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.UNKNOW_ERROR, e.getMessage() );
}
}
@Override
public void update(CmsContent data) {
data.setUpdateTime(new Date());
cmsContentMapper.updateByPrimaryKey(data);
}
@Override
public void online(Long id) {
// 查询内容
CmsContent cmsContent = getDetail(id);
if (cmsContent == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到数据");
}
if (!CmsStatusEnum.status1.getStatus().equals(cmsContent.getStatus())) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法上线,状态错误");
}
cmsContent.setStatus(CmsStatusEnum.status2.getStatus());
update(cmsContent);
// 删除缓存
redisUtil.hdel(CmsContentServiceImpl.CACHE_CMS_ONLINE, ""+cmsContent.getType());
}
@Override
public void offline(Long id) {
// 查询内容
CmsContent cmsContent = getDetail(id);
if (cmsContent == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到数据");
}
if (!CmsStatusEnum.status2.getStatus().equals(cmsContent.getStatus())) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法下线,状态错误");
}
cmsContent.setStatus(CmsStatusEnum.status3.getStatus());
update(cmsContent);
// 删除缓存
redisUtil.hdel(CmsContentServiceImpl.CACHE_CMS_ONLINE, ""+cmsContent.getType());
}
@Override

Loading…
Cancel
Save