From 257f3c2572ed81ea3d8bfd79666c7fc638c35596 Mon Sep 17 00:00:00 2001 From: yixian Date: Tue, 14 Jul 2020 00:25:54 +1000 Subject: [PATCH] manual settle --- .../clearing/beans/PriorityModifyLog.java | 76 ++++++++++++ .../clearing/core/PriorityListManager.java | 16 +++ .../core/impl/MonikerStringUtils.java | 51 ++++++++ .../core/impl/PriorityListManagerImpl.java | 109 ++++++++++++++++++ .../core/impl/SettleTaskServiceImpl.java | 40 +------ .../clearing/web/SettleTasksController.java | 32 ++++- .../mappers/system/SysSettlePlanMapper.java | 6 +- src/main/ui/static/analysis/settle_tasks.js | 51 +++++++- .../templates/settle_tasks_index.html | 10 +- .../settle_tasks_priority_history.html | 21 ++++ .../templates/settle_tasks_prioritylist.html | 58 ++++++++++ .../analysis/templates/settlement_detail.html | 1 + 12 files changed, 425 insertions(+), 46 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/management/clearing/beans/PriorityModifyLog.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/management/clearing/core/PriorityListManager.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/MonikerStringUtils.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/PriorityListManagerImpl.java create mode 100644 src/main/ui/static/analysis/templates/settle_tasks_priority_history.html create mode 100644 src/main/ui/static/analysis/templates/settle_tasks_prioritylist.html diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/beans/PriorityModifyLog.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/beans/PriorityModifyLog.java new file mode 100644 index 000000000..eef0c9336 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/beans/PriorityModifyLog.java @@ -0,0 +1,76 @@ +package au.com.royalpay.payment.manage.management.clearing.beans; + +import com.alibaba.fastjson.PropertyNamingStrategy; +import com.alibaba.fastjson.annotation.JSONType; +import com.fasterxml.jackson.annotation.JsonFormat; +import org.springframework.data.mongodb.core.mapping.Document; + +import java.util.Date; + +@Document(collection = "settle_priority_modify") +@JSONType(naming = PropertyNamingStrategy.SnakeCase) +public class PriorityModifyLog { + public static final String OP_ADD = "ADD"; + public static final String OP_REMOVE = "REMOVE"; + private long id; + private String clientMoniker; + private String operation; + private String operatorId; + private String operatorName; + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+10") + private Date createTime; + + public long getId() { + return id; + } + + public PriorityModifyLog setId(long id) { + this.id = id; + return this; + } + + public String getClientMoniker() { + return clientMoniker; + } + + public PriorityModifyLog setClientMoniker(String clientMoniker) { + this.clientMoniker = clientMoniker; + return this; + } + + public String getOperation() { + return operation; + } + + public PriorityModifyLog setOperation(String operation) { + this.operation = operation; + return this; + } + + public String getOperatorId() { + return operatorId; + } + + public PriorityModifyLog setOperatorId(String operatorId) { + this.operatorId = operatorId; + return this; + } + + public String getOperatorName() { + return operatorName; + } + + public PriorityModifyLog setOperatorName(String operatorName) { + this.operatorName = operatorName; + return this; + } + + public Date getCreateTime() { + return createTime; + } + + public PriorityModifyLog setCreateTime(Date createTime) { + this.createTime = createTime; + return this; + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/PriorityListManager.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/PriorityListManager.java new file mode 100644 index 000000000..f9dac7ecf --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/PriorityListManager.java @@ -0,0 +1,16 @@ +package au.com.royalpay.payment.manage.management.clearing.core; + +import au.com.royalpay.payment.manage.management.clearing.beans.PriorityModifyLog; +import com.alibaba.fastjson.JSONObject; + +import java.util.List; + +public interface PriorityListManager { + List listPriorityMerchants(); + + void setMerchantPriority(String clientMoniker, JSONObject manager); + + void removePriorityMerchant(String clientMoniker, JSONObject manager); + + List getMerchantsModifyHistory(); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/MonikerStringUtils.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/MonikerStringUtils.java new file mode 100644 index 000000000..f3e07037c --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/MonikerStringUtils.java @@ -0,0 +1,51 @@ +package au.com.royalpay.payment.manage.management.clearing.core.impl; + +import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.StringUtils; + +import java.util.Arrays; +import java.util.stream.Stream; + +public class MonikerStringUtils { + private MonikerStringUtils() { + } + + public static String formatStringArray(String str) { + str = str.replace(",", ","); + str = str.replace(" ", ","); + str = str.replace("\r\n", ","); + str = str.replace("\n", ","); + str = str.replace("\r", ","); + String nStr = str.replace(",,", ","); + while (!nStr.equals(str)) { + str = nStr; + nStr = str.replace(",,", ","); + } + str = nStr; + if (str.endsWith(",")) { + str = StringUtils.substring(str, 0, -1); + } + if (str.startsWith(",")) { + str = StringUtils.substring(str, 1); + } + return str; + } + + public static Stream splitStringArray(String str) { + return Arrays.stream(formatStringArray(str).split(",")); + } + + public static JSONObject getSimplifiedClientsInfo(MerchantInfoProvider mchInfoProvider, String moniker) { + JSONObject info = mchInfoProvider.getClientInfoByMoniker(moniker); + if (info == null) { + return null; + } + JSONObject simple = new JSONObject(); + simple.put("client_moniker", info.getString("client_moniker")); + simple.put("company_name", info.getString("company_name")); + simple.put("clean_days", info.getIntValue("clean_days")); + simple.put("bd_user_name", info.getString("bd_user_name")); + return simple; + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/PriorityListManagerImpl.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/PriorityListManagerImpl.java new file mode 100644 index 000000000..ac1af20d2 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/PriorityListManagerImpl.java @@ -0,0 +1,109 @@ +package au.com.royalpay.payment.manage.management.clearing.core.impl; + +import au.com.royalpay.payment.manage.management.clearing.beans.PriorityModifyLog; +import au.com.royalpay.payment.manage.management.clearing.core.PriorityListManager; +import au.com.royalpay.payment.manage.mappers.system.SysSettlePlanMapper; +import au.com.royalpay.payment.tools.exceptions.NotFoundException; +import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider; +import au.com.royalpay.payment.tools.utils.id.IdUtil; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.lang3.time.DateUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.data.domain.Sort; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.stereotype.Service; + +import java.util.Date; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +@Service +public class PriorityListManagerImpl implements PriorityListManager { + private static final String PRIORITY_ID = "id1_priority"; + private static final String COLLECTION_NAME = "settle_priority_modify"; + public static final String KEY_WHITELIST_CLIENTS = "whitelist_clients"; + private final Logger logger = LoggerFactory.getLogger(getClass()); + private final MerchantInfoProvider mchInfoProvider; + private final MongoTemplate mongoTemplate; + private final SysSettlePlanMapper planMapper; + + public PriorityListManagerImpl(MerchantInfoProvider mchInfoProvider, MongoTemplate mongoTemplate, SysSettlePlanMapper planMapper) { + this.mchInfoProvider = mchInfoProvider; + this.mongoTemplate = mongoTemplate; + this.planMapper = planMapper; + } + + @Override + public List listPriorityMerchants() { + JSONObject detail = planMapper.findPlanDetail(PRIORITY_ID); + return MonikerStringUtils.splitStringArray(detail.getString(KEY_WHITELIST_CLIENTS)) + .map(moniker -> MonikerStringUtils.getSimplifiedClientsInfo(mchInfoProvider, moniker)) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + } + + @Override + public void setMerchantPriority(String clientMoniker, JSONObject manager) { + JSONObject client = mchInfoProvider.getClientInfoByMoniker(clientMoniker); + if (client == null) { + throw new NotFoundException("Client " + clientMoniker + " not found"); + } + JSONObject detail = planMapper.findPlanDetail(PRIORITY_ID); + String clientMonikers = detail.getString(KEY_WHITELIST_CLIENTS); + List monikerList = MonikerStringUtils.splitStringArray(clientMonikers).collect(Collectors.toList()); + if (monikerList.stream().anyMatch(moniker -> moniker.equalsIgnoreCase(clientMoniker))) { + logger.debug("{} exists,ignore", clientMoniker); + return; + } + monikerList.add(clientMoniker.toUpperCase()); + planMapper.setWhitelistClients(PRIORITY_ID, String.join(",", monikerList)); + try { + PriorityModifyLog log = new PriorityModifyLog() + .setId(IdUtil.getId()) + .setClientMoniker(clientMoniker) + .setOperation(PriorityModifyLog.OP_ADD) + .setOperatorId(manager.getString("manager_id")) + .setOperatorName(manager.getString("display_name")) + .setCreateTime(new Date()); + mongoTemplate.insert(log); + } catch (Exception ignore) { + } + } + + @Override + public void removePriorityMerchant(String clientMoniker, JSONObject manager) { + JSONObject detail = planMapper.findPlanDetail(PRIORITY_ID); + String clientMonikers = detail.getString(KEY_WHITELIST_CLIENTS); + List monikerList = MonikerStringUtils.splitStringArray(clientMonikers).collect(Collectors.toList()); + if (!monikerList.removeIf(moniker -> moniker.equalsIgnoreCase(clientMoniker))) { + logger.debug("{} not exists,ignore", clientMoniker); + return; + } + planMapper.setWhitelistClients(PRIORITY_ID, String.join(",", monikerList)); + try { + PriorityModifyLog log = new PriorityModifyLog() + .setId(IdUtil.getId()) + .setClientMoniker(clientMoniker) + .setOperation(PriorityModifyLog.OP_REMOVE) + .setOperatorId(manager.getString("manager_id")) + .setOperatorName(manager.getString("display_name")) + .setCreateTime(new Date()); + mongoTemplate.insert(log); + } catch (Exception ignore) { + } + } + + @Override + public List getMerchantsModifyHistory() { + Date twoMonthAgo = DateUtils.addMonths(new Date(), -2); + Query query = new Query() + .limit(20) + .with(Sort.by(Sort.Direction.DESC, "createTime")) + .addCriteria(Criteria.where("createTime").gt(twoMonthAgo)); + return mongoTemplate.find(query, PriorityModifyLog.class); + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/SettleTaskServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/SettleTaskServiceImpl.java index 1a9db80b0..7cd333bc2 100644 --- a/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/SettleTaskServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/core/impl/SettleTaskServiceImpl.java @@ -21,8 +21,6 @@ import org.springframework.web.util.UriComponentsBuilder; import java.net.URI; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -75,20 +73,9 @@ public class SettleTaskServiceImpl implements SettleTasksService { @Override public List listMerchantsInfo(String mchMonikers) { - List monikers = new ArrayList<>(Arrays.asList(formatStringArray(mchMonikers).split(","))); - return monikers.parallelStream().map(this::getSimplifiedClientsInfo).filter(Objects::nonNull).collect(Collectors.toList()); - } - - private JSONObject getSimplifiedClientsInfo(String moniker) { - JSONObject info = mchInfoProvider.getClientInfoByMoniker(moniker); - if (info == null) { - return null; - } - JSONObject simple = new JSONObject(); - simple.put("client_moniker", info.getString("client_moniker")); - simple.put("clean_days", info.getIntValue("clean_days")); - simple.put("bd_user_name", info.getString("bd_user_name")); - return simple; + List monikers = MonikerStringUtils.splitStringArray(mchMonikers).collect(Collectors.toList()); + return monikers.parallelStream().map(moniker -> MonikerStringUtils.getSimplifiedClientsInfo(mchInfoProvider, moniker)) + .filter(Objects::nonNull).collect(Collectors.toList()); } @Override @@ -110,24 +97,5 @@ public class SettleTaskServiceImpl implements SettleTasksService { } } - public static String formatStringArray(String str) { - str = str.replace(",", ","); - str = str.replace(" ", ","); - str = str.replace("\r\n", ","); - str = str.replace("\n", ","); - str = str.replace("\r", ","); - String nStr = str.replace(",,", ","); - while (!nStr.equals(str)) { - str = nStr; - nStr = str.replace(",,", ","); - } - str = nStr; - if (str.endsWith(",")) { - str = StringUtils.substring(str, 0, -1); - } - if (str.startsWith(",")) { - str = StringUtils.substring(str, 1); - } - return str; - } + } diff --git a/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/SettleTasksController.java b/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/SettleTasksController.java index 3f68a3286..f015e4000 100644 --- a/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/SettleTasksController.java +++ b/src/main/java/au/com/royalpay/payment/manage/management/clearing/web/SettleTasksController.java @@ -1,13 +1,13 @@ package au.com.royalpay.payment.manage.management.clearing.web; +import au.com.royalpay.payment.manage.management.clearing.beans.PriorityModifyLog; +import au.com.royalpay.payment.manage.management.clearing.core.PriorityListManager; import au.com.royalpay.payment.manage.management.clearing.core.SettleTasksService; 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.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import java.util.List; @@ -15,9 +15,11 @@ import java.util.List; @ManagerMapping(value = "/sys/settle_tasks", role = {ManagerRole.FINANCIAL_STAFF, ManagerRole.DEVELOPER}) public class SettleTasksController { private SettleTasksService svc; + private PriorityListManager priorityListManager; - public SettleTasksController(SettleTasksService svc) { + public SettleTasksController(SettleTasksService svc, PriorityListManager priorityListManager) { this.svc = svc; + this.priorityListManager = priorityListManager; } @GetMapping("/plans") @@ -40,4 +42,24 @@ public class SettleTasksController { svc.submitTasks(tasks); return getProcessingStatus(); } + + @GetMapping("/priority_merchants") + public List listPriorityMerchants() { + return priorityListManager.listPriorityMerchants(); + } + + @PutMapping("/priority_merchants/{clientMoniker}") + public void setMerchantPriority(@PathVariable String clientMoniker, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { + priorityListManager.setMerchantPriority(clientMoniker, manager); + } + + @DeleteMapping("/priority_merchants/{clientMoniker}") + public void removePriorityMerchant(@PathVariable String clientMoniker, @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { + priorityListManager.removePriorityMerchant(clientMoniker, manager); + } + + @GetMapping("/priority_merchants_modify_history") + public List getMerchantsModifyHistory() { + return priorityListManager.getMerchantsModifyHistory(); + } } diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/system/SysSettlePlanMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/system/SysSettlePlanMapper.java index 2f5219da5..89e011bd1 100644 --- a/src/main/java/au/com/royalpay/payment/manage/mappers/system/SysSettlePlanMapper.java +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/system/SysSettlePlanMapper.java @@ -5,6 +5,7 @@ import com.yixsoft.support.mybatis.autosql.annotations.AdvanceSelect; import com.yixsoft.support.mybatis.autosql.annotations.AutoMapper; import com.yixsoft.support.mybatis.autosql.annotations.AutoSql; import com.yixsoft.support.mybatis.autosql.annotations.SqlType; +import org.apache.ibatis.annotations.Param; import java.util.List; @@ -14,7 +15,8 @@ public interface SysSettlePlanMapper { List listPlans(); @AutoSql(SqlType.SELECT) - JSONObject findPlanDetail(String planId); - + JSONObject findPlanDetail(@Param("plan_id") String planId); + @AutoSql(SqlType.UPDATE) + void setWhitelistClients(@Param("plan_id") String planId, @Param("whitelist_clients") String clientMonikers); } diff --git a/src/main/ui/static/analysis/settle_tasks.js b/src/main/ui/static/analysis/settle_tasks.js index d7c3b753a..2f60f29ce 100644 --- a/src/main/ui/static/analysis/settle_tasks.js +++ b/src/main/ui/static/analysis/settle_tasks.js @@ -7,11 +7,15 @@ define(['angular', 'uiBootstrap', 'uiRouter'], function (angular) { url: '/settle_tasks', templateUrl: '/static/analysis/templates/settle_tasks_index.html', controller: 'settleTasksRootCtrl' + }).state('settle_tasks.priority_list', { + url: '/priority_list', + templateUrl: '/static/analysis/templates/settle_tasks_prioritylist.html', + controller: 'settleTasksPriorityListManageCtrl' }) }]); - app.controller('settleTasksRootCtrl', ['$scope', '$http', '$interval', '$q', '$uibModal', 'commonDialog', - function ($scope, $http, $interval, $q, $uibModal, commonDialog) { + app.controller('settleTasksRootCtrl', ['$scope', '$http', '$interval', '$filter', '$q', '$uibModal', '$state', 'commonDialog', + function ($scope, $http, $interval, $filter, $q, $uibModal, $state, commonDialog) { let ctrl = this; $scope.loadPlans = function () { $http.get('/sys/settle_tasks/plans').then(function (res) { @@ -21,6 +25,9 @@ define(['angular', 'uiBootstrap', 'uiRouter'], function (angular) { } }) }; + $scope.redirectToSettleLogs = function () { + $state.go('clearingLogs.settlementDetail', {date: $filter('date')(new Date(), 'yyyy-MM-dd')}) + } $scope.checkProgressStatus = function () { let defer = $q.defer(); $http.get('/sys/settle_tasks/curent_progress').then(function (res) { @@ -146,6 +153,46 @@ define(['angular', 'uiBootstrap', 'uiRouter'], function (angular) { $scope.$close($scope.merchantsInfo) } }]); + + app.controller('settleTasksPriorityListManageCtrl', ['$scope', '$http', 'commonDialog', function ($scope, $http, commonDialog) { + $scope.filters = {}; + $scope.input = {} + $scope.loadPriorities = function () { + $http.get('/sys/settle_tasks/priority_merchants').then(function (res) { + $scope.clients = res.data; + }) + }; + $scope.addPriorityClient = function () { + if (!$scope.input.moniker) { + return; + } + $http.put('/sys/settle_tasks/priority_merchants/' + $scope.input.moniker).then(function () { + $scope.loadPriorities(); + }, function (res) { + commonDialog.alert({type: 'error', title: 'Error', content: res.data.message}) + }) + }; + $scope.dropPriorityClient = function (client) { + $http['delete']('/sys/settle_tasks/priority_merchants/' + client.client_moniker).then(function () { + $scope.loadPriorities(); + }, function (res) { + commonDialog.alert({type: 'error', title: 'Error', content: res.data.message}) + }) + }; + $scope.listHistory = function () { + $uibModal.open({ + templateUrl: '/static/analysis/templates/settle_tasks_priority_history.html', + controller: ['$scope', 'history', function (scope, history) { + scope.logs = history.data; + }], + resolve: { + history: ['$http', function (http) { + return http.get('/sys/settle_tasks/priority_merchants_modify_history') + }] + } + }) + } + }]) app.controller('newSettleTaskDialogCtrl', ['$scope', '$filter', 'plans', function ($scope, $filter, plans) { $scope.plans = plans; $scope.task = { diff --git a/src/main/ui/static/analysis/templates/settle_tasks_index.html b/src/main/ui/static/analysis/templates/settle_tasks_index.html index c5f4d7db2..df0344df2 100644 --- a/src/main/ui/static/analysis/templates/settle_tasks_index.html +++ b/src/main/ui/static/analysis/templates/settle_tasks_index.html @@ -1,4 +1,4 @@ -
+

Settle Tasks

+
+
Toolbox
+
+ + +
+
Tasks Prepare diff --git a/src/main/ui/static/analysis/templates/settle_tasks_priority_history.html b/src/main/ui/static/analysis/templates/settle_tasks_priority_history.html new file mode 100644 index 000000000..87ae8b723 --- /dev/null +++ b/src/main/ui/static/analysis/templates/settle_tasks_priority_history.html @@ -0,0 +1,21 @@ + + \ No newline at end of file diff --git a/src/main/ui/static/analysis/templates/settle_tasks_prioritylist.html b/src/main/ui/static/analysis/templates/settle_tasks_prioritylist.html new file mode 100644 index 000000000..76d20b887 --- /dev/null +++ b/src/main/ui/static/analysis/templates/settle_tasks_prioritylist.html @@ -0,0 +1,58 @@ +
+

Priority List

+ +
+
+
+
+
+ +
+ +
+
+ +
+
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + +
Client MonikerMerchant NameBD NameClean DaysOperation
+ +
+
+
+
\ No newline at end of file diff --git a/src/main/ui/static/analysis/templates/settlement_detail.html b/src/main/ui/static/analysis/templates/settlement_detail.html index a0ee513c2..578944cbb 100644 --- a/src/main/ui/static/analysis/templates/settlement_detail.html +++ b/src/main/ui/static/analysis/templates/settlement_detail.html @@ -43,6 +43,7 @@ + Settle Tasks