|
|
@@ -4,14 +4,209 @@ package com.uas.platform.b2c.trade.rate.task;
|
|
|
* Created by uas on 2017-08-30.
|
|
|
*/
|
|
|
|
|
|
+import com.uas.platform.b2c.common.account.dao.EnterpriseDao;
|
|
|
+import com.uas.platform.b2c.common.account.dao.UserDao;
|
|
|
+import com.uas.platform.b2c.common.account.model.Enterprise;
|
|
|
+import com.uas.platform.b2c.common.account.model.User;
|
|
|
+import com.uas.platform.b2c.core.config.SysConf;
|
|
|
+import com.uas.platform.b2c.core.support.SystemSession;
|
|
|
+import com.uas.platform.b2c.core.support.log.UsageBufferedLogger;
|
|
|
+import com.uas.platform.b2c.core.utils.FastjsonUtils;
|
|
|
+import com.uas.platform.b2c.trade.order.dao.OrderDao;
|
|
|
+import com.uas.platform.b2c.trade.order.model.Order;
|
|
|
+import com.uas.platform.b2c.trade.order.model.StatusHistory;
|
|
|
+import com.uas.platform.b2c.trade.order.service.OrderService;
|
|
|
+import com.uas.platform.b2c.trade.presale.dao.TradeBasicPropertiesDao;
|
|
|
+import com.uas.platform.b2c.trade.rate.service.RateService;
|
|
|
+import com.uas.platform.core.exception.IllegalOperatorException;
|
|
|
+import com.uas.platform.core.logging.BufferedLoggerManager;
|
|
|
+import com.uas.platform.core.model.Status;
|
|
|
+import com.uas.platform.core.model.Type;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.util.CollectionUtils;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 评价的一些自动任务
|
|
|
*
|
|
|
* @author wangdy
|
|
|
- * @version 2017-08-81 8:59:06 创建文件
|
|
|
+ * @version 2017-08-31 8:59:06 创建文件
|
|
|
*/
|
|
|
@Component("RateTask")
|
|
|
public class RateTask {
|
|
|
+
|
|
|
+ private final OrderDao orderDao;
|
|
|
+
|
|
|
+ private final OrderService orderService;
|
|
|
+
|
|
|
+ private final TradeBasicPropertiesDao tradeBasicPropertiesDao;
|
|
|
+
|
|
|
+ private final UserDao userDao;
|
|
|
+
|
|
|
+ private final SysConf sysConf;
|
|
|
+
|
|
|
+ private final EnterpriseDao enterpriseDao;
|
|
|
+
|
|
|
+ private final RateService rateService;
|
|
|
+
|
|
|
+
|
|
|
+ private static final UsageBufferedLogger logger = BufferedLoggerManager.getLogger(UsageBufferedLogger.class);
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public RateTask(OrderDao orderDao, OrderService orderService, TradeBasicPropertiesDao tradeBasicPropertiesDao, UserDao userDao, SysConf sysConf, EnterpriseDao enterpriseDao, RateService rateService) {
|
|
|
+ this.orderDao = orderDao;
|
|
|
+ this.orderService = orderService;
|
|
|
+ this.tradeBasicPropertiesDao = tradeBasicPropertiesDao;
|
|
|
+ this.userDao = userDao;
|
|
|
+ this.sysConf = sysConf;
|
|
|
+ this.enterpriseDao = enterpriseDao;
|
|
|
+ this.rateService = rateService;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 对超过初评时间的订单,自动初评
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public void autoRate() {
|
|
|
+ try {
|
|
|
+ User user = null;
|
|
|
+ List<User> userUUs = userDao.findUserByUserUU(sysConf.getAdminUU());
|
|
|
+ if(CollectionUtils.isEmpty(userUUs)) {
|
|
|
+ throw new IllegalOperatorException("根据配置文件的adminUU 找不到对应的个人信息");
|
|
|
+ }
|
|
|
+ user = userUUs.get(0);
|
|
|
+ Enterprise enterprise = enterpriseDao.findByUu(sysConf.getEnUU());
|
|
|
+ user.setEnterprise(enterprise);
|
|
|
+ SystemSession.setUser(user);
|
|
|
+ String infoByType = tradeBasicPropertiesDao.findInfoByType(Type.B2C_AUTO_RECEVIED_TIME.value());
|
|
|
+ if(StringUtils.isEmpty(infoByType)) {
|
|
|
+ throw new IllegalOperatorException("买家自动初评时间为空,不能继续操作");
|
|
|
+ }
|
|
|
+ Integer automaticReceipt = null;
|
|
|
+ try {
|
|
|
+ automaticReceipt = Integer.valueOf(infoByType);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ //先写在代码上,20个工作日自动好评
|
|
|
+ automaticReceipt = 20;
|
|
|
+
|
|
|
+ List<Order> orderList = orderService.findByStatus(Status.COMPLETED.value());
|
|
|
+ String ids = "-";
|
|
|
+ for (Order order : orderList) {
|
|
|
+ List<StatusHistory> statusHistories = FastjsonUtils.fromJsonArray(order.getStatushistory(), StatusHistory.class);
|
|
|
+ for (int i = statusHistories.size() - 1; i > 0 ; i--) {
|
|
|
+ StatusHistory statusHistory = statusHistories.get(i);
|
|
|
+ if(statusHistory.getStatus().intValue() == Status.COMPLETED.value()) {
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ Date date = new Date();
|
|
|
+ calendar.setTime(date);
|
|
|
+ calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - automaticReceipt);
|
|
|
+ Date time = calendar.getTime();
|
|
|
+ time.setHours(0);
|
|
|
+ time.setMinutes(0);
|
|
|
+ time.setSeconds(0);
|
|
|
+ Date shipTime = statusHistory.getTime();
|
|
|
+ shipTime.setHours(0);
|
|
|
+ shipTime.setMinutes(0);
|
|
|
+ shipTime.setSeconds(0);
|
|
|
+ if(compareTimeIsGigger24Hours(time, shipTime)) {
|
|
|
+ ids = ids + order.getId() + "-";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if(ids.length() > 1) {
|
|
|
+ ids = ids.substring(1, ids.length() - 1);
|
|
|
+ rateService.autosavebuyerRate(ids);
|
|
|
+ }
|
|
|
+ logger.log("自动初评", "买家自动初评订单:" + ids);
|
|
|
+ }catch (Exception e) {
|
|
|
+ } finally {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 对超过追评时间的订单,自动初评
|
|
|
+ */
|
|
|
+ @Transactional
|
|
|
+ public void autoAfterRate() {
|
|
|
+ try {
|
|
|
+ User user = null;
|
|
|
+ List<User> userUUs = userDao.findUserByUserUU(sysConf.getAdminUU());
|
|
|
+ if(CollectionUtils.isEmpty(userUUs)) {
|
|
|
+ throw new IllegalOperatorException("根据配置文件的adminUU 找不到对应的个人信息");
|
|
|
+ }
|
|
|
+ user = userUUs.get(0);
|
|
|
+ Enterprise enterprise = enterpriseDao.findByUu(sysConf.getEnUU());
|
|
|
+ user.setEnterprise(enterprise);
|
|
|
+ SystemSession.setUser(user);
|
|
|
+ String infoByType = tradeBasicPropertiesDao.findInfoByType(Type.B2C_AUTO_RECEVIED_TIME.value());
|
|
|
+ if(StringUtils.isEmpty(infoByType)) {
|
|
|
+ throw new IllegalOperatorException("买家自动追评时间为空,不能继续操作");
|
|
|
+ }
|
|
|
+ Integer automaticReceipt = null;
|
|
|
+ try {
|
|
|
+ automaticReceipt = Integer.valueOf(infoByType);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+// //先写在代码上,180个工作日自动追评价
|
|
|
+ automaticReceipt = 180;
|
|
|
+ List<Order> orderList = orderService.findByStatus(Status.COMPLETED.value());
|
|
|
+ String ids = "-";
|
|
|
+ for (Order order : orderList) {
|
|
|
+ List<StatusHistory> statusHistories = FastjsonUtils.fromJsonArray(order.getStatushistory(), StatusHistory.class);
|
|
|
+ for (int i = statusHistories.size() - 1; i > 0 ; i--) {
|
|
|
+ StatusHistory statusHistory = statusHistories.get(i);
|
|
|
+ if(statusHistory.getStatus().intValue() == Status.COMPLETED.value()) {
|
|
|
+ Calendar calendar = Calendar.getInstance();
|
|
|
+ Date date = new Date();
|
|
|
+ calendar.setTime(date);
|
|
|
+ calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - automaticReceipt);
|
|
|
+ Date time = calendar.getTime();
|
|
|
+ time.setHours(0);
|
|
|
+ time.setMinutes(0);
|
|
|
+ time.setSeconds(0);
|
|
|
+ Date shipTime = statusHistory.getTime();
|
|
|
+ shipTime.setHours(0);
|
|
|
+ shipTime.setMinutes(0);
|
|
|
+ shipTime.setSeconds(0);
|
|
|
+ if(compareTimeIsGigger24Hours(time, shipTime)) {
|
|
|
+ ids = ids + order.getId() + "-";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(ids.length() > 1) {
|
|
|
+ ids = ids.substring(1, ids.length() - 1);
|
|
|
+ rateService.autosaveAfterbuyerRate(ids);
|
|
|
+ }
|
|
|
+ logger.log("自动追评", "买家自动追加评价:" + ids);
|
|
|
+ }catch (Exception e) {
|
|
|
+ } finally {
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 比较日期的大小(只比较年、月、日),,相隔的时间是否超过24小时
|
|
|
+ * @param date1
|
|
|
+ * @param date2
|
|
|
+ * @return date1 - date2 > 0 return true else false
|
|
|
+ */
|
|
|
+ private boolean compareTimeIsGigger24Hours (Date date1, Date date2) {
|
|
|
+ long mills = date1.getTime() - date2.getTime();
|
|
|
+ if(mills > 0) {
|
|
|
+ return true;
|
|
|
+ }else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|