parent
a3e5a4beb7
commit
cc960e5103
@ -0,0 +1,118 @@
|
||||
package au.com.royalpay.payment.manage.merchants.beans;
|
||||
|
||||
import au.com.royalpay.payment.core.exceptions.ParamInvalidException;
|
||||
import au.com.royalpay.payment.tools.merchants.beans.BalanceGroup;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* Create by yixian at 2018-01-07 22:25
|
||||
*/
|
||||
public class SettleDetail {
|
||||
private Integer hour;
|
||||
@JSONField(name = "rule_type")
|
||||
@Pattern(regexp = "^(DAY_OF_MONTH)|(DAY_OF_WEEK)$", message = "Invalid Rule Type")
|
||||
@NotNull(message = "error.payment.valid.param_missing")
|
||||
private String rule_type;
|
||||
|
||||
private String rule;
|
||||
private boolean manual;
|
||||
private boolean everyday;
|
||||
private BigDecimal min = BigDecimal.ZERO;
|
||||
private int max_settle_days;
|
||||
|
||||
private String group= BalanceGroup.RPAY_SVC_CARD.toString();
|
||||
|
||||
public String ruleToCron() {
|
||||
if (everyday) {
|
||||
return "* * ?";
|
||||
}
|
||||
if (!manual && rule_type == null) {
|
||||
throw new ParamInvalidException("rule_type", "error.payment.valid.param_missing");
|
||||
}
|
||||
if (rule_type != null) {
|
||||
switch (rule_type) {
|
||||
case "DAY_OF_MONTH":
|
||||
return rule + " * ?";
|
||||
case "DAY_OF_WEEK":
|
||||
return "? * " + rule;
|
||||
default:
|
||||
throw new ParamInvalidException("rule_type", "Invalid Rule Type");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Integer getHour() {
|
||||
return hour;
|
||||
}
|
||||
|
||||
public SettleDetail setHour(Integer hour) {
|
||||
this.hour = hour;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getRule_type() {
|
||||
return rule_type;
|
||||
}
|
||||
|
||||
public SettleDetail setRule_type(String rule_type) {
|
||||
this.rule_type = rule_type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getRule() {
|
||||
return rule;
|
||||
}
|
||||
|
||||
public SettleDetail setRule(String rule) {
|
||||
this.rule = rule;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BigDecimal getMin() {
|
||||
return min;
|
||||
}
|
||||
|
||||
public SettleDetail setMin(BigDecimal min) {
|
||||
this.min = min;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isManual() {
|
||||
return manual;
|
||||
}
|
||||
|
||||
public SettleDetail setManual(boolean manual) {
|
||||
this.manual = manual;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isEveryday() {
|
||||
return everyday;
|
||||
}
|
||||
|
||||
public SettleDetail setEveryday(boolean everyday) {
|
||||
this.everyday = everyday;
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getMax_settle_days() {
|
||||
return max_settle_days;
|
||||
}
|
||||
|
||||
public void setMax_settle_days(int max_settle_days) {
|
||||
this.max_settle_days = max_settle_days;
|
||||
}
|
||||
|
||||
public String getGroup() {
|
||||
return group;
|
||||
}
|
||||
|
||||
public void setGroup(String group) {
|
||||
this.group = group;
|
||||
}
|
||||
}
|
@ -0,0 +1,134 @@
|
||||
package au.com.royalpay.payment.manage.merchants.core.impls;
|
||||
|
||||
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
|
||||
import au.com.royalpay.payment.manage.merchants.beans.SettleDetail;
|
||||
import au.com.royalpay.payment.manage.merchants.core.ClientInfoCacheSupport;
|
||||
import au.com.royalpay.payment.manage.merchants.core.ClientManager;
|
||||
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
|
||||
import au.com.royalpay.payment.tools.utils.CurrencyAmountUtils;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cronutils.model.Cron;
|
||||
import com.cronutils.model.CronType;
|
||||
import com.cronutils.model.definition.CronDefinition;
|
||||
import com.cronutils.model.definition.CronDefinitionBuilder;
|
||||
import com.cronutils.model.field.CronFieldName;
|
||||
import com.cronutils.parser.CronParser;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 分渠道清算服务
|
||||
*/
|
||||
@Component
|
||||
public class ClientChannelSettlement {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(getClass());
|
||||
|
||||
@Autowired
|
||||
private ClientManager clientManager;
|
||||
|
||||
@Resource
|
||||
private ClientMapper clientMapper;
|
||||
|
||||
// @Autowired
|
||||
// private ClientManagerApplication application;
|
||||
|
||||
@Resource
|
||||
private ClientInfoCacheSupport clientInfoCacheSupport;
|
||||
|
||||
|
||||
public JSONObject getClientChannelSettleConfig(String clientMoniker, JSONObject manager, String group) {
|
||||
JSONObject client = clientManager.getClientInfoByMoniker(clientMoniker);
|
||||
JSONObject card = this.getGroup(client, group);
|
||||
if (card == null) {
|
||||
return null;
|
||||
}
|
||||
String settleRule = card.getString("date_rule");
|
||||
String minSettle = card.getString("min_settle");
|
||||
JSONObject config = new JSONObject();
|
||||
config.put("max_settle_days", card.getInteger("max_settle_days"));
|
||||
config.put("min", new BigDecimal(minSettle).toPlainString());
|
||||
if ("* * ?".equals(settleRule)) {
|
||||
config.put("everyday", true);
|
||||
} else {
|
||||
config.put("everyday", false);
|
||||
CronDefinition cronDefinition =
|
||||
CronDefinitionBuilder.instanceDefinitionFor(CronType.QUARTZ);
|
||||
CronParser parser = new CronParser(cronDefinition);
|
||||
Cron cron = parser.parse("0 0 0 " + settleRule);
|
||||
if (settleRule.startsWith("? * ")) {
|
||||
String dayOfWeek = cron.retrieve(CronFieldName.DAY_OF_WEEK).getExpression().asString();
|
||||
logger.info("DAY_OF_WEEK CRON => " + dayOfWeek);
|
||||
config.put("rule_type", "DAY_OF_WEEK");
|
||||
config.put("days", dayOfWeek.split(","));
|
||||
}
|
||||
if (settleRule.endsWith(" * ?")) {
|
||||
String dayOfMon = cron.retrieve(CronFieldName.DAY_OF_MONTH).getExpression().asString();
|
||||
logger.info("DAY_OF_WEEK CRON => " + dayOfMon);
|
||||
config.put("rule_type", "DAY_OF_MONTH");
|
||||
config.put("days", dayOfMon.split(","));
|
||||
}
|
||||
}
|
||||
logger.info("=====>getClientChannelSettleConfig:{}",config.toJSONString());
|
||||
return config;
|
||||
}
|
||||
|
||||
public void configClientChannelSettleDetails(JSONObject manager, String clientMoniker, SettleDetail detail) {
|
||||
JSONObject client = clientManager.getClientInfoByMoniker(clientMoniker);
|
||||
JSONArray ruleExt = client.getJSONArray("settle_rule_ext");
|
||||
if (ruleExt == null) {
|
||||
ruleExt = new JSONArray();
|
||||
JSONObject object = new JSONObject();
|
||||
this.setSettleRuleExt(detail, object);
|
||||
ruleExt.add(object);
|
||||
} else {
|
||||
JSONObject card = this.getGroup(client, detail.getGroup());
|
||||
if (card == null) {
|
||||
JSONObject object = new JSONObject();
|
||||
this.setSettleRuleExt(detail, object);
|
||||
ruleExt.add(object);
|
||||
} else {
|
||||
ruleExt.remove(card);
|
||||
this.setSettleRuleExt(detail, card);
|
||||
ruleExt.add(card);
|
||||
}
|
||||
}
|
||||
|
||||
JSONObject update = new JSONObject();
|
||||
update.put("client_id", client.getIntValue("client_id"));
|
||||
logger.info("SETTLE RULE EXT => " + ruleExt.toString());
|
||||
update.put("settle_rule_ext", ruleExt.toString());
|
||||
clientMapper.update(update);
|
||||
|
||||
clientInfoCacheSupport.clearClientCache(client.getIntValue("client_id"));
|
||||
}
|
||||
|
||||
private void setSettleRuleExt(SettleDetail detail, JSONObject object) {
|
||||
object.put("date_rule", detail.ruleToCron());
|
||||
object.put("min_settle", CurrencyAmountUtils.scale(detail.getMin(), PlatformEnvironment.getEnv().getForeignCurrency()));
|
||||
object.put("group", detail.getGroup());
|
||||
// object.put("max_settle_days", detail.getMax_settle_days()); //max_settle_days 在rp中去掉
|
||||
}
|
||||
|
||||
private JSONObject getGroup(JSONObject client, String group) {
|
||||
JSONArray ruleExt = client.getJSONArray("settle_rule_ext");
|
||||
if (ruleExt == null) {
|
||||
return null;
|
||||
}
|
||||
for (Object o : ruleExt) {
|
||||
JSONObject item = (JSONObject) o;
|
||||
if (group.equalsIgnoreCase(item.getString("group"))) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package au.com.royalpay.payment.manage.merchants.web;
|
||||
|
||||
import au.com.royalpay.payment.manage.merchants.beans.SettleDetail;
|
||||
import au.com.royalpay.payment.manage.merchants.core.impls.ClientChannelSettlement;
|
||||
import au.com.royalpay.payment.manage.permission.manager.ManagerMapping;
|
||||
import au.com.royalpay.payment.tools.CommonConsts;
|
||||
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* 分渠道清算规则配置资源
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/sys/partners/{clientMoniker}/channel_settle_config")
|
||||
public class PartnerChannelSettlementController {
|
||||
|
||||
@Autowired
|
||||
private ClientChannelSettlement channelSettlement;
|
||||
|
||||
/**
|
||||
* 结算规则配置详情
|
||||
*
|
||||
* @param clientMoniker
|
||||
* @param manager
|
||||
* @return
|
||||
*/
|
||||
@ManagerMapping(method = RequestMethod.GET)
|
||||
public JSONObject getClientChannelSettleConfig(@PathVariable String clientMoniker, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager, @RequestParam(value = "group") String group) {
|
||||
return channelSettlement.getClientChannelSettleConfig(clientMoniker, manager, group);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 设置结算规则配置
|
||||
*
|
||||
* @param clientMoniker
|
||||
* @param settleDetail
|
||||
* @param manager
|
||||
*/
|
||||
@ManagerMapping(method = RequestMethod.PUT, role = {ManagerRole.ADMIN, ManagerRole.OPERATOR, ManagerRole.FINANCIAL_STAFF})
|
||||
public void configClientChannelSettleDetails(@PathVariable String clientMoniker, @RequestBody SettleDetail settleDetail, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) {
|
||||
channelSettlement.configClientChannelSettleDetails(manager, clientMoniker, settleDetail);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
<div class="modal-header">
|
||||
<h4>Choose Settle Day</h4>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="alert alert-warning" ng-if="formData.chosenDay>28">Settle may not execute when the month do not have this day</div>
|
||||
<div class="date-box">
|
||||
<button class="day btn btn-default" style="padding: 0" ng-repeat="day in availableDays" ng-disabled="chosenDays.indexOf(day)>=0"
|
||||
ng-click="formData.chosenDay = day" ng-class="{'active':formData.chosenDay == day}" ng-bind="day"></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn btn-danger" ng-click="$dismiss()">Cancel</button>
|
||||
<button class="btn btn-success" ng-disabled="!formData.chosenDay" ng-click="choose()">Choose</button>
|
||||
</div>
|
Loading…
Reference in new issue