yonge 4 years ago
parent
commit
6d885ac9f1

+ 27 - 0
cms/src/main/java/com/ym/mec/cms/controller/TaskController.java

@@ -0,0 +1,27 @@
+package com.ym.mec.cms.controller;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import com.ym.mec.cms.service.SysNewsInformationService;
+import com.ym.mec.common.controller.BaseController;
+
+@RequestMapping("task")
+@RestController
+@Api(tags = "资讯服务")
+public class TaskController extends BaseController {
+
+	@Autowired
+	private SysNewsInformationService sysNewsInformationService;
+
+	@ApiOperation(value = "查询奖品组列表")
+	@GetMapping("/updateStatus")
+	public void updateStatus(){
+		
+	}
+}

+ 6 - 0
cms/src/main/java/com/ym/mec/cms/dal/dao/SysNewsInformationDao.java

@@ -25,4 +25,10 @@ public interface SysNewsInformationDao extends BaseDAO<Long, SysNewsInformation>
 	List<SysNewsInformation> queryHomePage(Map<String, Object> params);
 	
 	int queryHomeCount(Map<String, Object> params);
+	
+	/**
+	 * 查询需要更新状态的对象集合
+	 * @return
+	 */
+	List<SysNewsInformation> queryNeedUpdateStatusList();
 }

+ 25 - 0
cms/src/main/java/com/ym/mec/cms/dal/entity/SysNewsInformation.java

@@ -1,6 +1,9 @@
 package com.ym.mec.cms.dal.entity;
 
 import io.swagger.annotations.ApiModelProperty;
+
+import java.util.Date;
+
 import org.apache.commons.lang3.builder.ToStringBuilder;
 
 /**
@@ -46,6 +49,12 @@ public class SysNewsInformation {
 
 	@ApiModelProperty(value = "顺序号", required = true)
 	private Integer order;
+	
+	@ApiModelProperty(value = "上线时间", required = false)
+	private Date onlineTime;
+	
+	@ApiModelProperty(value = "下线时间", required = false)
+	private Date offlineTime;
 
 	/**  */
 	private java.util.Date createTime;
@@ -208,6 +217,22 @@ public class SysNewsInformation {
 		this.attribute2 = attribute2;
 	}
 
+	public Date getOnlineTime() {
+		return onlineTime;
+	}
+
+	public void setOnlineTime(Date onlineTime) {
+		this.onlineTime = onlineTime;
+	}
+
+	public Date getOfflineTime() {
+		return offlineTime;
+	}
+
+	public void setOfflineTime(Date offlineTime) {
+		this.offlineTime = offlineTime;
+	}
+
 	@Override
 	public String toString() {
 		return ToStringBuilder.reflectionToString(this);

+ 6 - 0
cms/src/main/java/com/ym/mec/cms/service/SysNewsInformationService.java

@@ -32,4 +32,10 @@ public interface SysNewsInformationService extends BaseService<Long, SysNewsInfo
 	 * @return
 	 */
 	Map<String, PageInfo<SysNewsInformation>> getHomeList(SysUser user, NewsInformationQueryInfo queryInfo);
+	
+	/**
+	 * 自动更新状态
+	 * @return
+	 */
+	boolean autoUpdateStatus();
 }

+ 18 - 0
cms/src/main/java/com/ym/mec/cms/service/impl/SysNewsInformationServiceImpl.java

@@ -150,4 +150,22 @@ public class SysNewsInformationServiceImpl extends BaseServiceImpl<Long, SysNews
 		return pageInfo;
 	}
 
+	@Override
+	public boolean autoUpdateStatus() {
+		List<SysNewsInformation> list = sysNewsInformationDao.queryNeedUpdateStatusList();
+		if(list != null && list.size() > 0){
+			Date now = new Date();
+			for(SysNewsInformation news : list){
+				if(news.getStatus() == NewsStatusEnum.SHOW){
+					news.setStatus(NewsStatusEnum.HIDDEN);
+				}else{
+					news.setStatus(NewsStatusEnum.SHOW);
+				}
+				news.setUpdateTime(now);
+				sysNewsInformationDao.update(news);
+			}
+		}
+		return true;
+	}
+
 }

+ 16 - 0
cms/src/main/java/com/ym/mec/cms/task/CmsTaskRemoteService.java

@@ -0,0 +1,16 @@
+package com.ym.mec.cms.task;
+
+import org.springframework.cloud.openfeign.FeignClient;
+import org.springframework.web.bind.annotation.GetMapping;
+
+import com.ym.mec.common.config.FeignConfiguration;
+import com.ym.mec.task.fallback.TaskRemoteServiceFallback;
+
+@FeignClient(name = "cms-server", contextId = "CmsTaskRemoteService", configuration = { FeignConfiguration.class }, fallback = TaskRemoteServiceFallback.class)
+public interface CmsTaskRemoteService {
+
+	@GetMapping(value = "task/updateStatus")
+	// 自动更新状态
+	public void updateStatusTask();
+
+}

+ 19 - 0
cms/src/main/java/com/ym/mec/cms/task/fallback/CmsTaskRemoteServiceFallback.java

@@ -0,0 +1,19 @@
+package com.ym.mec.cms.task.fallback;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.stereotype.Component;
+
+import com.ym.mec.cms.task.CmsTaskRemoteService;
+
+@Component
+public class CmsTaskRemoteServiceFallback implements CmsTaskRemoteService {
+
+	private final static Logger logger = LoggerFactory.getLogger(CmsTaskRemoteServiceFallback.class);
+
+	@Override
+	public void updateStatusTask() {
+		logger.info("更新状态的服务调用失败");
+	}
+
+}

+ 18 - 2
cms/src/main/resources/config/mybatis/SysNewsInformationMapper.xml

@@ -14,6 +14,8 @@
 		<result column="video_cover_image_" property="videoCoverImage" />
 		<result column="link_url_" property="linkUrl"/>
 		<result column="type_" property="type"/>
+		<result column="online_time_" property="onlineTime"/>
+		<result column="offline_time_" property="offlineTime"/>
 		<result column="sub_type_" property="subType"/>
 		<result column="status_" property="status" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler" />
 		<result column="create_time_" property="createTime" />
@@ -73,8 +75,8 @@
 	
 	<!-- 向数据库增加一条记录 -->
 	<insert id="insert" parameterType="com.ym.mec.cms.dal.entity.SysNewsInformation" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
-		INSERT INTO sys_news_information (id_,title_,content_,cover_image_,video_cover_image_,type_,sub_type_,status_,create_time_,update_time_,link_url_,href_target_,order_,del_flag_,memo_,tenant_id_,attribute1_,attribute2_)
-		VALUES(#{id},#{title},#{content},#{coverImage},#{videoCoverImage},#{type},#{subType},#{status, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},now(),now(),#{linkUrl},#{hrefTarget},#{order},0,#{memo},#{tenantId},#{attribute1},#{attribute2})
+		INSERT INTO sys_news_information (id_,title_,content_,cover_image_,video_cover_image_,type_,online_time_,offline_time_,sub_type_,status_,create_time_,update_time_,link_url_,href_target_,order_,del_flag_,memo_,tenant_id_,attribute1_,attribute2_)
+		VALUES(#{id},#{title},#{content},#{coverImage},#{videoCoverImage},#{type},#{onlineTime},#{offlineTime},#{subType},#{status, typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},now(),now(),#{linkUrl},#{hrefTarget},#{order},0,#{memo},#{tenantId},#{attribute1},#{attribute2})
 	</insert>
 	
 	<!-- 根据主键查询一条记录 -->
@@ -105,6 +107,12 @@
 			<if test="type != null">
 				type_ = #{type},
 			</if>
+			<if test="onlineTime != null">
+				online_time_ = #{onlineTime},
+			</if>
+			<if test="offlineTime != null">
+				offline_time_ = #{offlineTime},
+			</if>
 			<if test="subType != null">
 				sub_type_ = #{subType},
 			</if>
@@ -236,4 +244,12 @@
 			</choose>
 		</if>
 	</select>
+	
+	<select id="queryNeedUpdateStatusList" resultMap="SysNewsInformation" >
+		SELECT * FROM sys_news_information WHERE del_flag_ = 0 and (
+		(online_time_ is not null and now() between online_time_ and offline_time_ and status_ = 0) 
+		or (offline_time_ is not null and offline_time_ &lt;= now() and status_ = 1)
+		or (online_time_ is not null and online_time_ &gt;= now() and status_ = 1)
+		)
+	</select>
 </mapper>

+ 24 - 0
mec-biz/src/main/resources/config/mybatis/LuckDrawGroupMapper.xml

@@ -22,6 +22,10 @@
     where id_ = #{id,jdbcType=INTEGER}
   </select>
   
+  <select id="findAll" resultMap="BaseResultMap" parameterType="map" >
+    select * from luck_draw_group
+  </select>
+  
   <delete id="delete" parameterType="java.lang.Integer" >
     delete from luck_draw_group
     where id_ = #{id,jdbcType=INTEGER}
@@ -60,4 +64,24 @@
     </set>
     where id_ = #{id,jdbcType=INTEGER}
   </update>
+
+	<select id="queryCount" parameterType="map" resultType="int">
+		select count(*) from luck_draw_group
+		<where>
+			<if test="search != null">
+				and name_ like concat('%',#{search},'%')
+			</if>
+		</where>
+	</select>
+
+	<select id="queryPage" parameterType="map" resultMap="BaseResultMap">
+		select * from luck_draw_group
+		<where>
+			<if test="search != null">
+				and name_ like concat('%',#{search},'%')
+			</if>
+		</where>
+		<include refid="global.orderby" />
+		<include refid="global.limit" />
+	</select>
 </mapper>

+ 1 - 1
mec-biz/src/main/resources/config/mybatis/LuckDrawLogMapper.xml

@@ -89,7 +89,7 @@
 		where id_ = #{id,jdbcType=BIGINT}
 	</update>
 
-	<select id="findCount" parameterType="map" resultType="int">
+	<select id="queryCount" parameterType="map" resultType="int">
 		select count(*)
 		from (luck_draw_log l left join luck_draw_prize d on
 		l.prize_id_ = d.id_) left join sys_user u on u.id_=l.user_id_

+ 1 - 1
mec-biz/src/main/resources/config/mybatis/LuckDrawPrizeMapper.xml

@@ -95,7 +95,7 @@
 		where id_ = #{id,jdbcType=INTEGER}
 	</update>
 
-	<select id="findCount" parameterType="map" resultType="int">
+	<select id="queryCount" parameterType="map" resultType="int">
 		select count(*) from luck_draw_prize
 		<include refid="queryCondition" />
 	</select>

+ 5 - 0
mec-task/pom.xml

@@ -64,6 +64,11 @@
         	<groupId>com.ym</groupId>
         	<artifactId>mec-auth-api</artifactId>
         </dependency>
+        
+        <dependency>
+        	<groupId>com.ym</groupId>
+        	<artifactId>cms</artifactId>
+        </dependency>
 		
 	</dependencies>
 	

+ 20 - 0
mec-task/src/main/java/com/ym/mec/task/jobs/CmsUpdateStatusTask.java

@@ -0,0 +1,20 @@
+package com.ym.mec.task.jobs;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import com.ym.mec.cms.task.CmsTaskRemoteService;
+import com.ym.mec.task.core.BaseTask;
+import com.ym.mec.task.core.TaskException;
+
+@Service
+public class CmsUpdateStatusTask extends BaseTask {
+
+	@Autowired
+	private CmsTaskRemoteService cmsTaskRemoteService;
+
+	@Override
+	public void execute() throws TaskException {
+		cmsTaskRemoteService.updateStatusTask();
+	}
+}

+ 13 - 0
mec-web/src/main/java/com/ym/mec/web/controller/LuckDrawController.java

@@ -4,6 +4,8 @@ import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.MediaType;
@@ -21,6 +23,7 @@ import com.ym.mec.biz.service.LuckDrawLogService;
 import com.ym.mec.biz.service.LuckDrawPrizeService;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.page.QueryInfo;
+import com.ym.mec.util.collection.MapUtil;
 
 @Api(tags = "抽奖")
 @RestController
@@ -36,6 +39,16 @@ public class LuckDrawController extends BaseController {
 	private LuckDrawLogService luckDrawLogService;
 	
 	@ApiOperation(value = "查询奖品组列表")
+	@GetMapping(value = "luckDrawGroup/findAll", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
+	@PreAuthorize("@pcs.hasPermissions('luckDrawGroup/list')")
+	public Object luckDrawGroupFindAll(QueryInfo queryInfo) {
+		Map<String, Object> params = new HashMap<String, Object>();
+		MapUtil.populateMap(params, queryInfo);
+		
+		return succeed(luckDrawGroupService.findAll(params));
+	}
+	
+	@ApiOperation(value = "查询所有奖品组")
 	@GetMapping(value = "luckDrawGroup/list", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
 	@PreAuthorize("@pcs.hasPermissions('luckDrawGroup/list')")
 	public Object luckDrawGroupList(QueryInfo queryInfo) {

+ 6 - 0
pom.xml

@@ -61,6 +61,12 @@
 
 			<dependency>
 				<groupId>com.ym</groupId>
+				<artifactId>cms</artifactId>
+				<version>1.0</version>
+			</dependency>
+
+			<dependency>
+				<groupId>com.ym</groupId>
 				<artifactId>mec-auth-api</artifactId>
 				<version>1.0</version>
 			</dependency>