holiday config

master
yixian 5 years ago
parent 40c158de6e
commit 041dbd1364

@ -5,7 +5,7 @@
<parent>
<groupId>au.com.royalpay.payment</groupId>
<artifactId>payment-parent</artifactId>
<version>2.1.49</version>
<version>2.2.3</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>manage</artifactId>

@ -0,0 +1,28 @@
package au.com.royalpay.payment.manage.management.sysconfig.beans;
import au.com.royalpay.payment.tools.holiday.beans.SettlementRegion;
import javax.validation.constraints.NotEmpty;
public class HolidayConfig {
@NotEmpty
private String description;
@NotEmpty
private SettlementRegion[] regions;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public SettlementRegion[] getRegions() {
return regions;
}
public void setRegions(SettlementRegion[] regions) {
this.regions = regions;
}
}

@ -1,5 +1,8 @@
package au.com.royalpay.payment.manage.management.sysconfig.core;
import au.com.royalpay.payment.manage.management.sysconfig.beans.HolidayConfig;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
/**
@ -7,7 +10,9 @@ import java.util.List;
*/
public interface ClearDateManager {
List<String> listClearingDays(String monthPattern);
List<JSONObject> listClearingDays(String monthPattern);
void configHoliday(String date, HolidayConfig config);
void setMonthClearDays(String monthPattern, List<String> days);
void removeHolidayConfig(String date);
}

@ -1,18 +1,19 @@
package au.com.royalpay.payment.manage.management.sysconfig.core.impls;
import au.com.royalpay.payment.manage.management.sysconfig.beans.HolidayConfig;
import au.com.royalpay.payment.manage.management.sysconfig.core.ClearDateManager;
import au.com.royalpay.payment.manage.mappers.system.CalendarMapper;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.manage.mappers.system.HolidayDAO;
import au.com.royalpay.payment.manage.mappers.system.HolidayMapper;
import au.com.royalpay.payment.tools.holiday.beans.HolidayDefinition;
import au.com.royalpay.payment.tools.holiday.beans.SettlementRegion;
import com.alibaba.fastjson.JSONObject;
import org.joda.time.DateTime;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* Created by yixian on 2017-01-06.
@ -20,38 +21,37 @@ import java.util.List;
@Service
public class ClearDateManagerImpl implements ClearDateManager {
@Resource
private CalendarMapper calendarMapper;
private DateFormat monthFormat = new SimpleDateFormat("yyyyMM");
private DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
private HolidayMapper holidayMapper;
@Override
public List<String> listClearingDays(String monthPattern) {
try {
Date month = monthFormat.parse(monthPattern);
List<Date> dates = calendarMapper.listClearingDates(month);
List<String> dateStrings = new ArrayList<>();
for (Date dt : dates) {
dateStrings.add(dateFormat.format(dt));
}
return dateStrings;
} catch (ParseException e) {
throw new BadRequestException("error.payment.valid.invalid_date_format");
}
public List<JSONObject> listClearingDays(String monthPattern) {
List<HolidayDAO> dates = holidayMapper.listMonthly(monthPattern);
List<HolidayDefinition> definitions = dates.stream().map(HolidayDAO::toHolidayDefine).collect(Collectors.toList());
return definitions.stream().map(this::serializeHolidayDef).collect(Collectors.toList());
}
private JSONObject serializeHolidayDef(HolidayDefinition def) {
JSONObject holiday = new JSONObject();
holiday.put("holiday", new DateTime(def.getHoliday()).toString("yyyy/MM/dd"));
holiday.put("description", def.getDescription());
holiday.put("regions", def.getRegions());
return holiday;
}
@Override
@Transactional
public void setMonthClearDays(String monthPattern, List<String> days) {
try {
Date month = monthFormat.parse(monthPattern);
calendarMapper.resetClearDaysInMonth(month);
List<Date> dates = new ArrayList<>();
for (String day:days){
dates.add(dateFormat.parse(day));
}
calendarMapper.setClearingDays(dates);
} catch (ParseException e) {
throw new BadRequestException("error.payment.valid.invalid_date_format");
public void configHoliday(String date, HolidayConfig config) {
HolidayDAO dao = holidayMapper.findDefine(date);
if (dao == null) {
HolidayDefinition define = new HolidayDefinition(0, new DateTime(date).toDate(), config.getDescription(), config.getRegions());
holidayMapper.saveHoliday(new HolidayDAO(define));
} else {
holidayMapper.updateHolidayDescription(config.getDescription(),
Arrays.stream(config.getRegions()).map(SettlementRegion::toString).collect(Collectors.joining(",")), dao.getHolidayId());
}
}
@Override
public void removeHolidayConfig(String date) {
holidayMapper.deleteHoliday(date);
}
}

@ -1,19 +1,20 @@
package au.com.royalpay.payment.manage.management.sysconfig.web;
import au.com.royalpay.payment.manage.management.sysconfig.beans.HolidayConfig;
import au.com.royalpay.payment.manage.management.sysconfig.core.ClearDateManager;
import au.com.royalpay.payment.manage.management.sysconfig.core.SysPaymentConfig;
import au.com.royalpay.payment.manage.permission.manager.ManagerMapping;
import au.com.royalpay.payment.tools.CommonConsts;
import au.com.royalpay.payment.tools.env.SysConfigManager;
import au.com.royalpay.payment.tools.http.HttpUtils;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
import com.alibaba.fastjson.JSONObject;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;
/**
* Created by yixian on 2017-01-06.
@ -39,13 +40,19 @@ public class SysConfigController {
}
@ManagerMapping(value = "/clear_days/months/{monthPattern}", method = RequestMethod.GET, role = {ManagerRole.ADMIN, ManagerRole.FINANCIAL_STAFF, ManagerRole.OPERATOR})
public List<String> listClearDays(@PathVariable String monthPattern) {
public List<JSONObject> listClearDays(@PathVariable String monthPattern) {
return clearDateManager.listClearingDays(monthPattern);
}
@ManagerMapping(value = "/clear_days/months/{monthPattern}", method = RequestMethod.PUT, role = {ManagerRole.ADMIN, ManagerRole.FINANCIAL_STAFF, ManagerRole.OPERATOR})
public void updateMonthClearDays(@PathVariable String monthPattern, @RequestBody List<String> days) {
clearDateManager.setMonthClearDays(monthPattern, days);
@ManagerMapping(value = "/holidays/{date}", method = RequestMethod.PUT, role = {ManagerRole.ADMIN, ManagerRole.FINANCIAL_STAFF})
public void configHoliday(@PathVariable String date, @RequestBody @Valid HolidayConfig config, Errors errors) {
HttpUtils.handleValidErrors(errors);
clearDateManager.configHoliday(date, config);
}
@ManagerMapping(value = "/holidays/{date}", method = RequestMethod.DELETE)
public void deleteHoliday(@PathVariable String date) {
clearDateManager.removeHolidayConfig(date);
}
@ManagerMapping(value = "/payment/config", method = RequestMethod.GET, role = {ManagerRole.ADMIN, ManagerRole.FINANCIAL_STAFF, ManagerRole.OPERATOR})

@ -0,0 +1,61 @@
package au.com.royalpay.payment.manage.mappers.system;
import au.com.royalpay.payment.tools.holiday.beans.HolidayDefinition;
import au.com.royalpay.payment.tools.holiday.beans.SettlementRegion;
import org.joda.time.DateTime;
import java.util.Arrays;
import java.util.stream.Collectors;
public class HolidayDAO {
private int holidayId;
private String holiday;
private String description;
private String regions;
public HolidayDAO() {
}
public HolidayDAO(HolidayDefinition define) {
holiday = new DateTime(define.getHoliday()).toString("yyyy-MM-dd");
description = define.getDescription();
regions = Arrays.stream(define.getRegions()).map(SettlementRegion::toString).collect(Collectors.joining(","));
}
public HolidayDefinition toHolidayDefine() {
return new HolidayDefinition(holidayId, DateTime.parse(holiday).toDate(), description,
Arrays.stream(regions.split(",")).map(SettlementRegion::valueOf).toArray(SettlementRegion[]::new));
}
public int getHolidayId() {
return holidayId;
}
public void setHolidayId(int holidayId) {
this.holidayId = holidayId;
}
public String getHoliday() {
return holiday;
}
public void setHoliday(String holiday) {
this.holiday = holiday;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getRegions() {
return regions;
}
public void setRegions(String regions) {
this.regions = regions;
}
}

@ -0,0 +1,26 @@
package au.com.royalpay.payment.manage.mappers.system;
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 org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator;
import java.util.List;
@AutoMapper(tablename = "sys_holidays", pkName = "holiday_id", keyGenerator = Jdbc3KeyGenerator.class)
public interface HolidayMapper {
@AutoSql(SqlType.INSERT)
void saveHoliday(HolidayDAO dao);
List<HolidayDAO> listMonthly(@Param("month") String monthPattern);
@AutoSql(SqlType.DELETE)
void deleteHoliday(@Param("holiday") String holiday);
@AutoSql(SqlType.SELECT)
HolidayDAO findDefine(@Param("holiday") String holiday);
@AutoSql(SqlType.UPDATE)
void updateHolidayDescription(@Param("description") String description, @Param("regions") String regions, @Param("holiday_id") int holidayId);
}

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="au.com.royalpay.payment.manage.mappers.system.HolidayMapper">
<select id="listMonthly" resultType="au.com.royalpay.payment.manage.mappers.system.HolidayDAO">
select * from sys_holidays where holiday like concat(#{month},'-%')
order by holiday
</select>
</mapper>

@ -456,41 +456,72 @@ define(['angular', 'decimal', 'uiBootstrap', 'uiRouter', 'angularEcharts'], func
}
}]);
app.controller('settleDateConfigCtrl', ['$scope', '$http', '$filter', 'commonDialog', function ($scope, $http, $filter, commonDialog) {
app.controller('settleDateConfigCtrl', ['$scope', '$http', '$filter', '$uibModal', 'commonDialog', function ($scope, $http, $filter, $uibModal, commonDialog) {
$scope.loadMonthPlan = function (mon) {
$http.get('/sysconfig/clear_days/months/' + $filter('date')(mon, 'yyyyMM')).then(function (resp) {
$http.get('/sysconfig/clear_days/months/' + $filter('date')(mon, 'yyyy-MM')).then(function (resp) {
$scope.activeDates = resp.data;
});
$scope.currentMonth = mon;
};
$scope.triggerDate = function (date) {
if (date.getFullYear() != $scope.currentMonth.getFullYear() || date.getMonth() != $scope.currentMonth.getMonth()) {
return;
$scope.configHoliday = function (date) {
let holiday = $scope.getHoliday(date);
if (holiday == null) {
holiday = {'holiday': date, regions: []}
}
var str = $filter('date')(date, 'yyyy/MM/dd');
var idx = $scope.activeDates.indexOf(str);
if (idx < 0) {
$scope.activeDates.push(str);
} else {
$scope.activeDates.splice(idx, 1);
}
};
$scope.isDateOn = function (date) {
if ($scope.activeDates != null) {
return $scope.activeDates.indexOf($filter('date')(date, 'yyyy/MM/dd')) >= 0
} else {
return false;
}
};
$scope.submitMonthPlan = function () {
$http.put('/sysconfig/clear_days/months/' + $filter('date')($scope.currentMonth, 'yyyyMM'), $scope.activeDates).then(function () {
$scope.loadMonthPlan($scope.currentMonth);
commonDialog.alert({title: 'Success', content: 'Modified plan successful', type: 'success'})
}, function (resp) {
commonDialog.alert({title: 'Error', content: resp.data.message, type: 'error'})
$uibModal.open({
templateUrl: '/static/analysis/templates/dialog_holiday_config.html',
controller: ['$scope', 'holiday', function (scope, holiday) {
scope.holiday = angular.copy(holiday);
scope.regionActive = function (region) {
return scope.holiday.regions.indexOf(region) >= 0
};
scope.toggleRegion = function (region) {
let index = scope.holiday.regions.indexOf(region);
if (index >= 0) {
scope.holiday.regions.splice(index, 1);
} else {
scope.holiday.regions.push(region)
}
};
scope.commitHoliday = function () {
scope.$close({operation: 'modify', holiday: scope.holiday})
}
scope.deleteHoliday = function () {
scope.$close({operation: 'delete', holiday: scope.holiday.holiday.replace('/', '-')})
}
}],
resolve: {
holiday: function () {
return holiday;
}
}
}).result.then(function (operation) {
if (operation.operation === 'modify') {
$http.put('/sysconfig/clear_days/holidays/' + (operation.holiday.holiday.replace('/', '-')), operation.holiday).then(function () {
$scope.loadMonthPlan($scope.currentMonth);
commonDialog.alert({title: 'Success', content: 'Modified Holiday successful', type: 'success'})
}, function (resp) {
commonDialog.alert({title: 'Error', content: resp.data.message, type: 'error'})
})
} else if (operation.operation === 'delete') {
$http['delete']('/sysconfig/clear_days/holidays/' + operation.holiday).then(function () {
$scope.loadMonthPlan($scope.currentMonth);
}, function (resp) {
commonDialog.alert({title: 'Error', content: resp.data.message, type: 'error'})
})
}
})
};
$scope.getHoliday = function (date) {
let dateStr = $filter('date')(date, 'yyyy/MM/dd');
for (let holiday of $scope.activeDates) {
if (holiday.holiday === dateStr) {
return holiday;
}
}
return null;
};
}]);
app.controller('settlementSendCheckCodeCtrl', ['$scope', '$http', '$rootScope', '$stateParams', 'settleLogs', function ($scope, $http, $rootScope, $stateParams, settleLogs) {
$scope.settleLogs = settleLogs.map(log => {

@ -0,0 +1,38 @@
<div class="modal-header">Holiday Config: {{holiday.holiday}}</div>
<div class="modal-body">
<div class="row">
<div class="col-md-12">
<div class="form-group">
<input title="Description" placeholder="Description" ng-model="holiday.description">
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<ul class="list-group">
<li class="list-group-item disabled">Affected Regions</li>
<li class="list-group-item" ng-class="{'active':regionActive('CN_MAINLAND')}"
ng-click="toggleRegion('CN_MAINLAND')">CN MainLand
</li>
<li class="list-group-item" ng-class="{'active':regionActive('CN_HONGKONG')}"
ng-click="toggleRegion('CN_HONGKONG')">CN Hongkong
</li>
<li class="list-group-item" ng-class="{'active':regionActive('AU_VIC')}"
ng-click="toggleRegion('AU_VIC')">AU VIC
</li>
<li class="list-group-item" ng-class="{'active':regionActive('AU_NSW')}"
ng-click="toggleRegion('AU_NSW')">AU NSW
</li>
</ul>
</div>
</div>
</div>
<div class="modal-footer">
<div class="btn-group">
<button ng-click="commitHoliday()" type="button" class="btn btn-primary">Commit</button>
<button ng-click="deleteHoliday()" type="button" class="btn btn-danger" ng-if="holiday.holiday_id">Delete
</button>
<button ng-click="$dismiss()" type="button" class="btn btn-warning">Cancel</button>
</div>
</div>

@ -11,8 +11,14 @@
<div class="row">
<div class="col-xs-12">
<div royal-calendar month-change="loadMonthPlan($month)">
<div class="rc-full" style="font-size: 40px" ng-click="triggerDate(day)">
<i class="fa fa-check-circle text-green" ng-if="isDateOn(day)"></i>
<div class="rc-full" style="color: green" ng-click="configHoliday(day)">
<dl ng-init="holiday=getHoliday(day)" ng-if="holiday!=null">
<dt ng-bind="holiday.description"></dt>
<dd>
<span class="label label-success" ng-repeat="region in holiday.regions"
ng-bind="region"></span>
</dd>
</dl>
</div>
</div>
</div>

Loading…
Cancel
Save