@ -14,14 +14,35 @@ import au.com.royalpay.payment.manage.appclient.beans.AppClientBean;
import au.com.royalpay.payment.manage.mappers.financial.FinancialBDConfigMapper ;
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper ;
import au.com.royalpay.payment.manage.mappers.redpack.ActClientInvitationCodeMapper ;
import au.com.royalpay.payment.manage.mappers.system.* ;
import au.com.royalpay.payment.manage.merchants.beans.* ;
import au.com.royalpay.payment.manage.mappers.system.ClientAccountMapper ;
import au.com.royalpay.payment.manage.mappers.system.ClientApplyMapper ;
import au.com.royalpay.payment.manage.mappers.system.ClientAuditProcessMapper ;
import au.com.royalpay.payment.manage.mappers.system.ClientBDMapper ;
import au.com.royalpay.payment.manage.mappers.system.ClientBankAccountMapper ;
import au.com.royalpay.payment.manage.mappers.system.ClientDeviceMapper ;
import au.com.royalpay.payment.manage.mappers.system.ClientFilesMapper ;
import au.com.royalpay.payment.manage.mappers.system.ClientMapper ;
import au.com.royalpay.payment.manage.mappers.system.ClientRateMapper ;
import au.com.royalpay.payment.manage.mappers.system.ClientsContractMapper ;
import au.com.royalpay.payment.manage.mappers.system.CommoditiesMapper ;
import au.com.royalpay.payment.manage.mappers.system.ManagerMapper ;
import au.com.royalpay.payment.manage.mappers.system.OrgMapper ;
import au.com.royalpay.payment.manage.mappers.system.SysWxMerchantApplyMapper ;
import au.com.royalpay.payment.manage.merchants.beans.ActivityPosterBuilder ;
import au.com.royalpay.payment.manage.merchants.beans.BankAccountInfo ;
import au.com.royalpay.payment.manage.merchants.beans.ClientAuthFilesInfo ;
import au.com.royalpay.payment.manage.merchants.beans.ClientRateConfig ;
import au.com.royalpay.payment.manage.merchants.beans.ClientRegisterInfo ;
import au.com.royalpay.payment.manage.merchants.beans.NewAccountBean ;
import au.com.royalpay.payment.manage.merchants.beans.PartnerQuery ;
import au.com.royalpay.payment.manage.merchants.beans.SubMerchantIdApply ;
import au.com.royalpay.payment.manage.merchants.core.ClientComplyValidator ;
import au.com.royalpay.payment.manage.merchants.core.ClientManager ;
import au.com.royalpay.payment.manage.notice.core.MailService ;
import au.com.royalpay.payment.manage.signin.beans.TodoNotice ;
import au.com.royalpay.payment.manage.signin.core.ManagerTodoNoticeProvider ;
import au.com.royalpay.payment.manage.signin.core.SignInAccountService ;
import au.com.royalpay.payment.manage.system.core.ClientContractService ;
import au.com.royalpay.payment.manage.tradelog.beans.TradeLogQuery ;
import au.com.royalpay.payment.tools.connections.attachment.core.AttachmentClient ;
import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApi ;
@ -29,6 +50,7 @@ import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApiProvider;
import au.com.royalpay.payment.tools.connections.mpsupport.beans.TemplateMessage ;
import au.com.royalpay.payment.tools.connections.mpsupport.exceptions.WechatException ;
import au.com.royalpay.payment.tools.env.PlatformEnvironment ;
import au.com.royalpay.payment.tools.env.RequestEnvironment ;
import au.com.royalpay.payment.tools.env.SysConfigManager ;
import au.com.royalpay.payment.tools.exceptions.BadRequestException ;
import au.com.royalpay.payment.tools.exceptions.ForbiddenException ;
@ -43,17 +65,23 @@ import au.com.royalpay.payment.tools.merchants.qrboard.QRBoard;
import au.com.royalpay.payment.tools.merchants.qrboard.QRBoardProvider ;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole ;
import au.com.royalpay.payment.tools.permission.enums.PartnerRole ;
import au.com.royalpay.payment.tools.utils.* ;
import au.com.royalpay.payment.tools.utils.ImageUtils ;
import au.com.royalpay.payment.tools.utils.PageListUtils ;
import au.com.royalpay.payment.tools.utils.PasswordUtils ;
import au.com.royalpay.payment.tools.utils.PdfUtils ;
import au.com.royalpay.payment.tools.utils.QRCodeUtils ;
import au.com.royalpay.payment.tools.utils.TimeZoneUtils ;
import au.com.royalpay.payment.tools.websocket.notify.PartnerPageEvent ;
import cn.yixblog.platform.http.HttpRequestGenerator ;
import cn.yixblog.platform.http.HttpRequestResult ;
import com.alibaba.fastjson.JSON ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONObject ;
import com.github.miemiedev.mybatis.paginator.domain.Order ;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds ;
import com.github.miemiedev.mybatis.paginator.domain.PageList ;
import org.apache.commons.io.IOUtils ;
import org.apache.commons.lang3.ArrayUtils ;
import org.apache.commons.lang3.RandomStringUtils ;
import org.apache.commons.lang3.StringUtils ;
import org.apache.commons.lang3.time.DateFormatUtils ;
@ -66,32 +94,46 @@ import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable ;
import org.springframework.context.ApplicationEventPublisher ;
import org.springframework.context.ApplicationEventPublisherAware ;
import org.springframework.context.MessageSource ;
import org.springframework.data.redis.core.StringRedisTemplate ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.ui.Model ;
import org.springframework.util.Assert ;
import org.springframework.util.CollectionUtils ;
import org.springframework.web.bind.annotation.RequestMethod ;
import org.thymeleaf.context.Context ;
import org.thymeleaf.spring4.SpringTemplateEngine ;
import javax.annotation.Resource ;
import javax.imageio.ImageIO ;
import javax.servlet.ServletOutputStream ;
import javax.servlet.http.HttpServletResponse ;
import java.awt.* ;
import java.awt.image.BufferedImage ;
import java.io.* ;
import java.io.ByteArrayInputStream ;
import java.io.ByteArrayOutputStream ;
import java.io.File ;
import java.io.IOException ;
import java.io.InputStream ;
import java.io.OutputStream ;
import java.math.BigDecimal ;
import java.net.URISyntaxException ;
import java.net.URL ;
import java.util.* ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.Date ;
import java.util.List ;
import java.util.Objects ;
import java.util.concurrent.TimeUnit ;
import java.util.stream.Collectors ;
import java.util.zip.ZipEntry ;
import java.util.zip.ZipOutputStream ;
import javax.annotation.Resource ;
import javax.imageio.ImageIO ;
import javax.servlet.ServletOutputStream ;
import javax.servlet.http.HttpServletResponse ;
import cn.yixblog.platform.http.HttpRequestGenerator ;
import cn.yixblog.platform.http.HttpRequestResult ;
import static au.com.royalpay.payment.manage.permission.utils.OrgCheckUtils.checkOrgPermission ;
/ * *
@ -168,6 +210,13 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
@Resource
private FinancialBDConfigMapper financialBDConfigMapper ;
@Resource
private ClientsContractMapper clientsContractMapper ;
@Resource
private ClientContractService clientContractService ;
@Resource
private MessageSource messageSource ;
private static final String SOURCE_AGREE_FILE = "source_agree_file" ;
private static final String CLIENT_BANK_FILE = "client_bank_file" ;
private static final String CLIENT_ID_FILE = "client_id_file" ;
@ -1820,7 +1869,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
ByteArrayOutputStream bos = pdu . templetPdfBos ( file ) ;
stream = new ByteArrayInputStream ( bos . toByteArray ( ) ) ;
JSONObject fileRes = attachmentClient . uploadFile ( stream , clientMoniker + "_agreement.pdf" , false ) ;
importAgreeFile ( clientMoniker , manager , fileRes . getString ( "url" ) );
importAgreeFile ( clientMoniker , manager , fileRes . getString ( "url" ) ,false );
} catch ( Exception e ) {
logger . error ( "合同制作出现问题:" , e ) ;
} finally {
@ -1830,7 +1879,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
@Override
@Transactional
public void getAggregateAgreeFile ( String clientMoniker , JSONObject manager ) throws Exception {
public void getAggregateAgreeFile ( String clientMoniker , JSONObject manager ,boolean renewal ) throws Exception {
JSONObject client = getClientInfoByMoniker ( clientMoniker ) ;
if ( client = = null ) {
throw new InvalidShortIdException ( ) ;
@ -1848,37 +1897,26 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
client . put ( "company_name_acn" , client . getString ( "company_name" ) + " (ABN " + client . getString ( "abn" ) + ")" ) ;
}
JSONObject weChatRate = merchantInfoProvider . clientCurrentRat e( client . getIntValue ( "client_id" ) , new Date ( ) , "Wechat" ) ;
if ( weChatRate = = null ) {
List< JSONObject > clientRate = clientRateMapper . minExpiryTim e( client . getIntValue ( "client_id" ) , null ) ;
if ( CollectionUtils. isEmpty ( clientRate ) ) {
throw new BadRequestException ( "The Partner's Rate is not config!" ) ;
}
client . put ( "wechat_rate" , weChatRate . getBigDecimal ( "rate_value" ) . setScale ( 2 , BigDecimal . ROUND_DOWN ) ) ;
client . put ( "clean" , "T+" + weChatRate . getString ( "clean_days" ) ) ;
client . put ( "clean_days" , weChatRate . getString ( "clean_days" ) ) ;
try {
JSONObject alipayRate = merchantInfoProvider . clientCurrentRate ( client . getIntValue ( "client_id" ) , new Date ( ) , "Alipay" ) ;
if ( alipayRate ! = null ) {
client . put ( "alipay_rate" , alipayRate . getBigDecimal ( "rate_value" ) . setScale ( 2 , BigDecimal . ROUND_DOWN ) ) ;
}
JSONObject bestPayRate = merchantInfoProvider . clientCurrentRate ( client . getIntValue ( "client_id" ) , new Date ( ) , "Bestpay" ) ;
if ( bestPayRate ! = null ) {
client . put ( "bestpay_rate" , bestPayRate . getBigDecimal ( "rate_value" ) . setScale ( 2 , BigDecimal . ROUND_DOWN ) ) ;
}
JSONObject jdRate = merchantInfoProvider . clientCurrentRate ( client . getIntValue ( "client_id" ) , new Date ( ) , "jd" ) ;
if ( jdRate ! = null ) {
client . put ( "jd_rate" , jdRate . getBigDecimal ( "rate_value" ) . setScale ( 2 , BigDecimal . ROUND_DOWN ) ) ;
}
JSONObject alipayOnlineRate = merchantInfoProvider . clientCurrentRate ( client . getIntValue ( "client_id" ) , new Date ( ) , "AlipayOnline" ) ;
if ( alipayOnlineRate ! = null ) {
client . put ( "alipay_online_rate" , alipayOnlineRate . getBigDecimal ( "rate_value" ) . setScale ( 2 , BigDecimal . ROUND_DOWN ) ) ;
}
} catch ( Exception ignored ) {
// do nothing
}
clientRate . forEach ( ( p ) - > {
String rate_name = p . getString ( "rate_name" ) ;
if ( "Wechat" . equals ( rate_name ) ) {
client . put ( "wechat_rate" , p . getBigDecimal ( "rate_value" ) . setScale ( 2 , BigDecimal . ROUND_DOWN ) ) ;
client . put ( "clean" , "T+" + p . getString ( "clean_days" ) ) ;
client . put ( "clean_days" , p . getString ( "clean_days" ) ) ;
} else if ( "Alipay" . equals ( rate_name ) ) {
client . put ( "alipay_rate" , p . getBigDecimal ( "rate_value" ) . setScale ( 2 , BigDecimal . ROUND_DOWN ) ) ;
} else if ( "Bestpay" . equals ( rate_name ) ) {
client . put ( "bestpay_rate" , p . getBigDecimal ( "rate_value" ) . setScale ( 2 , BigDecimal . ROUND_DOWN ) ) ;
} else if ( "jd" . equals ( rate_name ) ) {
client . put ( "jd_rate" , p . getBigDecimal ( "rate_value" ) . setScale ( 2 , BigDecimal . ROUND_DOWN ) ) ;
} else if ( "AlipayOnline" . equals ( rate_name ) ) {
client . put ( "alipay_online_rate" , p . getBigDecimal ( "rate_value" ) . setScale ( 2 , BigDecimal . ROUND_DOWN ) ) ;
}
} ) ;
JSONObject account = getBankAccountByClientId ( client . getIntValue ( "client_id" ) ) ;
if ( account = = null | | account . size ( ) < = 0 ) {
@ -1897,9 +1935,9 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
File file = new File ( clientMoniker + "_agreement.pdf" ) ;
ByteArrayOutputStream bos = pdu . templetPdfBos ( file ) ;
InputStream stream = new ByteArrayInputStream ( bos . toByteArray ( ) ) ;
JSONObject fileRes = attachmentClient . uploadFile ( stream , clientMoniker + "_ agreement.pdf", false ) ;
JSONObject fileRes = attachmentClient . uploadFile ( stream , clientMoniker + "_ " + System . currentTimeMillis ( ) + "_ agreement.pdf", false ) ;
if ( fileRes ! = null ) {
importAgreeFile ( clientMoniker , manager , fileRes . getString ( "url" ) );
importAgreeFile ( clientMoniker , manager , fileRes . getString ( "url" ) ,renewal );
}
stream . close ( ) ;
} catch ( Exception e ) {
@ -1985,31 +2023,45 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
@Override
@Transactional
public void importAgreeFile ( String clientMoniker , JSONObject manager , String sourceFile ) {
public void importAgreeFile ( String clientMoniker , JSONObject manager , String sourceFile ,boolean renewal ) {
JSONObject client = getClientInfoByMoniker ( clientMoniker ) ;
if ( client = = null ) {
throw new InvalidShortIdException ( ) ;
}
if ( sourceFile ! = null ) {
JSONObject existFile = clientFilesMapper . findFileByClientAndType ( client . getIntValue ( "client_id" ) , SOURCE_AGREE_FILE ) ;
List < JSONObject > existFiles = clientFilesMapper . findFileByClientAndType ( client . getIntValue ( "client_id" ) , SOURCE_AGREE_FILE ) ;
JSONObject existFile = null ;
if ( ! CollectionUtils . isEmpty ( existFiles ) ) {
existFile = existFiles . get ( 0 ) ;
}
Date now = new Date ( ) ;
JSONObject file = new JSONObject ( ) ;
file . put ( "file_name" , SOURCE_AGREE_FILE ) ;
file . put ( "file_value" , sourceFile ) ;
file . put ( "client_id" , client . getIntValue ( "client_id" ) ) ;
file . put ( "last_update_date" , new Date ( ) ) ;
file . put ( "last_update_date" , now ) ;
if ( manager = = null ) {
file . put ( "last_update_by" , "System Import" ) ;
} else {
file . put ( "last_update_by" , manager . getString ( "display_name" ) ) ;
if ( existFile = = null | | existFile . isEmpty ( ) ) {
}
JSONObject contract = clientsContractMapper . findByClientId ( client . getIntValue ( "client_id" ) ) ;
if ( contract = = null | | now . compareTo ( contract . getDate ( "expiry_date" ) ) > 0 | | existFile = = null | | existFile . isEmpty ( ) ) {
clientFilesMapper . save ( file ) ;
} else {
file . put ( "file_id" , existFile . getString ( "file_id" ) ) ;
clientFilesMapper . update ( file ) ;
}
if ( ! renewal ) {
client . put ( "open_status" , 2 ) ;
clientMapper . update ( client ) ;
}
if ( manager ! = null ) {
saveClientAuditProcess ( client . getIntValue ( "client_id" ) , 1 , 2 , "Compliance合同制作中" , manager ) ;
}
}
}
@Override
public void completeAgree ( String clientMoniker , JSONObject manager ) {
@ -2017,8 +2069,8 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
if ( client = = null ) {
throw new InvalidShortIdException ( ) ;
}
JSONObject existFiles = clientFilesMapper . findFileByClientAndType ( client . getIntValue ( "client_id" ) , SOURCE_AGREE_FILE ) ;
if ( existFiles = = null | | existFiles . isEmpty ( ) ) {
List< JSONObject> existFiles = clientFilesMapper . findFileByClientAndType ( client . getIntValue ( "client_id" ) , SOURCE_AGREE_FILE ) ;
if ( CollectionUtils. isEmpty ( existFiles ) ) {
throw new BadRequestException ( "The Agree File is not Complete!" ) ;
}
client . put ( "open_status" , 3 ) ;
@ -2077,7 +2129,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
}
checkOrgPermission ( manager , client ) ;
if ( StringUtils . isNotBlank ( master_merchant ) ) {
// throw new NotFoundException("Invalid Input");
// throw new NotFoundException("Invalid Input");
JSONObject master_client = getClientInfoByMoniker ( master_merchant ) ;
if ( master_client = = null ) {
throw new InvalidShortIdException ( ) ;
@ -2296,7 +2348,12 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
public void updateSysClientFiles ( JSONObject manager , int clientId , String fileType , String fileValue ) {
if ( fileValue ! = null ) {
JSONObject existFile = clientFilesMapper . findFileByClientAndType ( clientId , fileType ) ;
List < JSONObject > existFiles = clientFilesMapper . findFileByClientAndType ( clientId , fileType ) ;
JSONObject existFile = null ;
if ( ! CollectionUtils . isEmpty ( existFiles ) ) {
existFile = existFiles . get ( 0 ) ;
}
JSONObject fileJson = new JSONObject ( ) ;
fileJson . put ( "client_id" , clientId ) ;
fileJson . put ( "last_update_date" , new Date ( ) ) ;
@ -2984,7 +3041,8 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
throw new InvalidShortIdException ( ) ;
}
checkOrgPermission ( manager , client ) ;
List < JSONObject > applices = sysWxMerchantApplyMapper . listWxMerchantApplices ( client . getInteger ( "client_id" ) , new PageBounds ( Order . formString ( "create_time.desc" ) ) ) ;
List < JSONObject > applices = sysWxMerchantApplyMapper . listWxMerchantApplices ( client . getInteger ( "client_id" ) ,
new PageBounds ( Order . formString ( "create_time.desc" ) ) ) ;
if ( ! applices . isEmpty ( ) ) {
return applices ;
} else {
@ -3061,4 +3119,46 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
@CacheEvict ( value = ":all_sub_merchant_id_applices:" , key = "#clientMoniker" )
public void clearCacheSubMerchantIdApplices ( String clientMoniker ) {
}
@Override
public JSONObject getCheckClientInfo ( int client_id , String account_id ) {
JSONObject result = clientContractService . getClientContractExpire ( client_id ) ;
JSONObject account = clientAccountMapper . findById ( account_id ) ;
boolean expire = result . getBoolean ( "rate_expire" ) ;
boolean waring = result . getBoolean ( "rate_waring" ) ;
if ( PartnerRole . getRole ( account . getIntValue ( "role" ) ) = = PartnerRole . CASHIER ) {
result . put ( "is_ordinary" , true ) ;
if ( ! expire & & waring ) {
String [ ] key = { result . getString ( "expire_days" ) } ;
result . put ( "contract_info" , editContractOrdinaryWaring ( key , messageSource . getMessage ( "sys.contract.ordinary.waring" , null , RequestEnvironment . getLocale ( ) ) ) ) ;
}
if ( expire ) {
result . put ( "contract_info" , messageSource . getMessage ( "sys.contract.ordinary.info" , null , RequestEnvironment . getLocale ( ) ) ) ;
}
return result ;
} else {
result . put ( "is_ordinary" , false ) ;
if ( ! expire & & waring ) {
String [ ] key = { result . getString ( "expire_days" ) } ;
result . put ( "contract_info" , editContractOrdinaryWaring ( key , messageSource . getMessage ( "sys.contract.waring" , null , RequestEnvironment . getLocale ( ) ) ) ) ;
}
if ( expire ) {
result . put ( "contract_info" , messageSource . getMessage ( "sys.contract.info" , null , RequestEnvironment . getLocale ( ) ) ) ;
}
JSONObject file = clientContractService . getOrGenerateSourceAgreement ( account . getIntValue ( "client_id" ) , "pc" ) ;
result . put ( "file_url" , file . getString ( "file_value" ) ) ;
return result ;
}
}
private String editContractOrdinaryWaring ( String [ ] key , String sourceStr ) {
if ( StringUtils . isEmpty ( sourceStr ) | | ArrayUtils . isEmpty ( key ) ) {
return "" ;
}
for ( int i = 0 ; i < key . length ; i + + ) {
sourceStr = sourceStr . replace ( "{" + i + "}" , key [ i ] ) ;
}
return sourceStr ;
}
}