master
kira 6 years ago
parent 5a0d041f9c
commit 3307ce25b7

@ -0,0 +1,9 @@
package au.com.royalpay.payment.manage.dev.core;
/**
* @author kira
* @date 2018/8/2
*/
public interface ManualService {
void clientPostpone();
}

@ -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<JSONObject> expiryClient = clientRateMapper.getAllExpiry(now);
if (CollectionUtils.isEmpty(expiryClient)) {
return;
}
Map<Integer, JSONObject> 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<JSONObject> adminAccounts = clientAccountMapper.listAdminAccounts(client_id);
List<JSONObject> 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");
}
}

@ -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();
}
}
Loading…
Cancel
Save