Browse Source

修改店铺自动完成处置任务

huxz 8 years ago
parent
commit
f7d4fa2ce0

+ 11 - 2
src/main/java/com/uas/platform/b2c/prod/store/service/impl/StoreViolationsServiceImpl.java

@@ -93,7 +93,10 @@ public class StoreViolationsServiceImpl implements StoreViolationsService {
 			if (days != null && days > 0) {
 				Calendar calendar = Calendar.getInstance();
 				calendar.setTime(violations.getCreateTime());
-				calendar.add(Calendar.DAY_OF_MONTH, days);
+				// calendar.add(Calendar.DAY_OF_MONTH, days);
+
+				// TODO huxz 暂时固定处置结束时间
+				calendar.add(Calendar.MINUTE, 10);
 
 				violations.setDisposeEndTime(calendar.getTime());
 			} else {
@@ -296,7 +299,7 @@ public class StoreViolationsServiceImpl implements StoreViolationsService {
 	}
 
 	@Override
-	@Transactional
+	@Transactional(rollbackFor = Exception.class)
 	public void autoFinishViolationsWhenDisposeTimeIsInvalid() {
 		Date date = new Date();
 		List<StoreViolations> violationsList = violationsDao.findByDisposeEndTimeLessThanAndCurrent(date, true);
@@ -310,6 +313,12 @@ public class StoreViolationsServiceImpl implements StoreViolationsService {
 					continue;
 				}
 
+				// 如果用户发起申述但没有审核或者管理员审核成功,则不进行自动任务
+				if (ViolationsStatus.COMPLAINT == violations.getStatus() || ViolationsStatus.SUCCESS == violations.getStatus()) {
+					continue;
+				}
+
+				violations.setRestore(true);
 				violations.setStatus(ViolationsStatus.DONE);
 				violations.setCurrent(false);
 				violations.setUpdateTime(new Date());

+ 14 - 2
src/main/java/com/uas/platform/b2c/prod/store/task/ViolationsAutoFinish.java

@@ -1,6 +1,7 @@
 package com.uas.platform.b2c.prod.store.task;
 
 import com.uas.platform.b2c.prod.store.service.StoreViolationsService;
+import org.apache.log4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.scheduling.annotation.EnableAsync;
@@ -8,9 +9,12 @@ import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
 
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
 /**
  * 店铺违规处置自动结束定时任务
- * 每天0:0:0执行任务
+ * 每天0:0:0执行任务[cron: '0 0 0 1/1 * ?']
  *
  * @author huxz
  * @version 2017-08-14 14:59:56 创建文件
@@ -22,15 +26,23 @@ public class ViolationsAutoFinish {
 
 	private final StoreViolationsService violationsService;
 
+	private final Logger logger = Logger.getLogger(getClass());
+
 	@Autowired
 	public ViolationsAutoFinish(StoreViolationsService violationsService) {
 		this.violationsService = violationsService;
+		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+		logger.info(String.format("%s 店铺违规处置自动完成任务实例化", dateFormat.format(new Date())));
 	}
 
 	@Async
-	@Scheduled(cron = "0 0 0 1/1 * ?")
+	@Scheduled(cron = "0 */1 * * * ?")
 	public void execute() {
 		try {
+			Date startTime = new Date();
+			SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+			logger.info(String.format("%s 店铺违规处置自动完成任务开始", dateFormat.format(startTime)));
+
 			violationsService.autoFinishViolationsWhenDisposeTimeIsInvalid();
 		} catch (Exception e) {
 			e.printStackTrace();