From 3307ce25b76155b10316e492f2cb81fceb079c42 Mon Sep 17 00:00:00 2001 From: kira <164851225@qq.com> Date: Thu, 2 Aug 2018 10:42:12 +0800 Subject: [PATCH] fixbug --- .../manage/dev/core/ManualService.java | 9 ++ .../dev/core/impl/ManualServiceimpl.java | 95 +++++++++++++++++++ .../manage/dev/web/ManualController.java | 26 +++++ 3 files changed, 130 insertions(+) create mode 100644 src/main/java/au/com/royalpay/payment/manage/dev/core/ManualService.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/dev/core/impl/ManualServiceimpl.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/dev/web/ManualController.java diff --git a/src/main/java/au/com/royalpay/payment/manage/dev/core/ManualService.java b/src/main/java/au/com/royalpay/payment/manage/dev/core/ManualService.java new file mode 100644 index 000000000..cc083f972 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/dev/core/ManualService.java @@ -0,0 +1,9 @@ +package au.com.royalpay.payment.manage.dev.core; + +/** + * @author kira + * @date 2018/8/2 + */ +public interface ManualService { + void clientPostpone(); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/dev/core/impl/ManualServiceimpl.java b/src/main/java/au/com/royalpay/payment/manage/dev/core/impl/ManualServiceimpl.java new file mode 100644 index 000000000..6218b5be9 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/dev/core/impl/ManualServiceimpl.java @@ -0,0 +1,95 @@ +package au.com.royalpay.payment.manage.dev.core.impl; + +import au.com.royalpay.payment.manage.dev.core.ManualService; +import au.com.royalpay.payment.manage.mappers.system.ClientAccountMapper; +import au.com.royalpay.payment.manage.mappers.system.ClientRateMapper; +import au.com.royalpay.payment.manage.merchants.core.ClientModifySupport; +import au.com.royalpay.payment.manage.merchants.entity.impls.SwitchPermissionModify; +import au.com.royalpay.payment.manage.task.PostponeClientTask; +import au.com.royalpay.payment.tools.scheduler.SynchronizedScheduler; + +import com.alibaba.fastjson.JSONObject; + +import org.apache.commons.lang3.time.DateFormatUtils; +import org.apache.commons.lang3.time.DateUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; + +/** + * @author kira + * @date 2018/8/2 + */ +@Service +public class ManualServiceimpl implements ManualService { + + Logger logger = LoggerFactory.getLogger(PostponeClientTask.class); + @Resource + private ClientRateMapper clientRateMapper; + @Resource + private ClientAccountMapper clientAccountMapper; + @Resource + private SynchronizedScheduler synchronizedScheduler; + @Resource + private ClientModifySupport clientModifySupport; + + @Override + public void clientPostpone() { + logger.info("start doing client postpone"); + synchronizedScheduler.executeProcess("manage_task:postPoneClient", 120_000, () -> { + Date now = new Date(); + Date tomorrow = DateUtils.addDays(now, 1); + Date yearTomorrow = DateUtils.addYears(tomorrow, 1); + String expireDate = DateFormatUtils.format(yearTomorrow, "yyyy-MM-dd"); + List expiryClient = clientRateMapper.getAllExpiry(now); + + if (CollectionUtils.isEmpty(expiryClient)) { + return; + } + Map expiryClients = new HashMap<>(); + expiryClient.forEach(p -> { + expiryClients.put(p.getInteger("client_id"), p); + }); + expiryClients.values().forEach(p -> { + int client_id = p.getIntValue("client_id"); + List adminAccounts = clientAccountMapper.listAdminAccounts(client_id); + List clientRates = clientRateMapper.maxChannelExpiryTime(client_id, null); + JSONObject wechatRate = clientRateMapper.latestChannelCleanDays("Wechat", p.getIntValue("client_id")); + int cleanDays = 1; + if (wechatRate.getInteger("clean_days") != null) { + cleanDays = wechatRate.getIntValue("clean_days"); + } else { + cleanDays = wechatRate.getIntValue("c_clean_days"); + } + int finalCleanDays = cleanDays; + clientRates.forEach(o -> { + JSONObject record = clientRateMapper.latestExpiryConfig(client_id, o.getString("rate_name")); + record.remove("client_rate_id"); + record.put("active_time", now); + record.put("manager_id", 0); + record.put("expiry_time", yearTomorrow); + record.put("create_time", now); + record.put("update_time", now); + record.put("clean_days", finalCleanDays); + record.put("manager_name", "System"); + record.put("remark", "费率到期系统自动延期1年"); + clientRateMapper.saveRate(record); + + }); + if(p.getBooleanValue("tax_in_surcharge")){ + clientModifySupport.processClientConfigModify(new SwitchPermissionModify(null,p.getString("client_moniker"),"tax_in_surcharge",false)); + } + }); + }); + logger.info("end doing client postpone"); + + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/dev/web/ManualController.java b/src/main/java/au/com/royalpay/payment/manage/dev/web/ManualController.java new file mode 100644 index 000000000..32892a63f --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/dev/web/ManualController.java @@ -0,0 +1,26 @@ +package au.com.royalpay.payment.manage.dev.web; + +import au.com.royalpay.payment.manage.dev.core.ManualService; +import au.com.royalpay.payment.manage.permission.manager.ManagerMapping; +import au.com.royalpay.payment.tools.permission.enums.ManagerRole; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.annotation.Resource; + +/** + * Created by yixian on 2017-01-25. + */ +@RestController +@ManagerMapping(role = ManagerRole.DEVELOPER,value = "/dev/manual") +public class ManualController { + @Resource + private ManualService manualService; + + @RequestMapping(method = RequestMethod.GET,value = "/client/postpone") + public void clientPostpone(){ + manualService.clientPostpone(); + } +}