From fef08a3f58923504b39b95c302aa4e6ea1851ef6 Mon Sep 17 00:00:00 2001 From: wangning <164851225@qq.com> Date: Thu, 8 Mar 2018 15:35:45 +0800 Subject: [PATCH] update --- .../core/impl/ClientContractServiceImpl.java | 59 ++++++++++++++----- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/system/core/impl/ClientContractServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/system/core/impl/ClientContractServiceImpl.java index 1f5a058a0..2292ef9c5 100644 --- a/src/main/java/au/com/royalpay/payment/manage/system/core/impl/ClientContractServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/system/core/impl/ClientContractServiceImpl.java @@ -1,6 +1,5 @@ package au.com.royalpay.payment.manage.system.core.impl; -import au.com.royalpay.payment.manage.appclient.core.RetailAppService; import au.com.royalpay.payment.manage.mappers.system.ClientFilesMapper; import au.com.royalpay.payment.manage.mappers.system.ClientRateMapper; import au.com.royalpay.payment.manage.mappers.system.ClientsContractMapper; @@ -35,8 +34,6 @@ public class ClientContractServiceImpl implements ClientContractService { @Resource private ClientsContractMapper clientsContractMapper; @Resource - private RetailAppService retailAppService; - @Resource private ClientRateMapper clientRateMapper; @Override @@ -46,9 +43,15 @@ public class ClientContractServiceImpl implements ClientContractService { if (client == null) { throw new NotFoundException("merchant not found"); } + JSONObject expireInfo = getClientContractExpire(client_id); + if(expireInfo.getBoolean("rate_waring")){ + List files = clientFilesMapper.findFileByClientAndType(client_id, "source_agree_file"); + return files.get(0); + } + JSONObject contract = clientsContractMapper.findByClientId(client_id); Date now = new Date(); - if (contract == null || now.compareTo(contract.getDate("expiry_date")) > 0) { + if (contract == null || now.compareTo(contract.getDate("expiry_date")) > 0 ) { try { clientManager.getAggregateAgreeFile(client.getString("client_moniker"), null); } catch (Exception e) { @@ -59,7 +62,6 @@ public class ClientContractServiceImpl implements ClientContractService { saveContract(client_id, now); return files.get(0); } else { - JSONObject expireInfo = getClientContractExpire(client_id); List files = clientFilesMapper.findFileByClientAndType(client_id, "source_agree_file"); JSONObject file = files.get(0); if (expireInfo.getBoolean("rate_expire")) { @@ -83,13 +85,39 @@ public class ClientContractServiceImpl implements ClientContractService { } @Override + @Transactional public void confirmSourceAgreement(int client_id) { - JSONObject file = clientsContractMapper.findByClientId(client_id); - if (file == null) { + JSONObject rateExpire = getClientContractExpire(client_id); + boolean expire = rateExpire.getBoolean("rate_expire"); + boolean waring = rateExpire.getBoolean("rate_waring"); + if(!(expire && waring)){ + return; + } + JSONObject contract = clientsContractMapper.findByClientId(client_id); + if (contract == null) { throw new BadRequestException("generate contract first"); } - file.put("has_sign", 1); - clientsContractMapper.update(file); + contract.put("has_sign", 1); + clientsContractMapper.update(contract); + Date now = new Date(); + List rateInfo = clientRateMapper.minExpiryTime(client_id, null); + if(expire){ + rateInfo.forEach((p)->{ + p.remove("client_rate_id"); + p.put("create_time",now); + p.put("active_time",now); + p.put("expiry_time",DateUtils.addYears(now,1)); + }); + } + if(!expire && waring){ + rateInfo.forEach((p)->{ + p.remove("client_rate_id"); + p.put("create_time",now); + p.put("active_time",DateUtils.addYears(p.getDate("active_time"),1)); + p.put("expiry_time",DateUtils.addYears(p.getDate("expiry_time"),1)); + }); + } + } @Override @@ -109,17 +137,20 @@ public class ClientContractServiceImpl implements ClientContractService { } List rateInfo = clientRateMapper.minExpiryTime(client_id, null); JSONObject result = new JSONObject(); + if (CollectionUtils.isEmpty(rateInfo)) { + result.put("rate_expire", true); + result.put("rate_waring", true); + return result; + } result.put("rate_expire", false); result.put("rate_waring", false); Date now = new Date(); JSONObject contract = clientsContractMapper.findByClientId(client_id); - if(contract!=null && contract.getDate("expiry_date").compareTo(now)>0 && contract.getBoolean("has_sign")){ + if (contract != null && contract.getDate("expiry_date").compareTo(now) > 0 && contract.getBoolean("has_sign")) { return result; } - if (CollectionUtils.isEmpty(rateInfo)) { - return result; - } - rateInfo.forEach((p)->{ + + rateInfo.forEach((p) -> { if (now.compareTo(p.getDate("expiry_time")) > -1) { result.put("rate_expire", true); }