@ -1,10 +1,28 @@
package jnpf.service.impl ;
import cn.hutool.json.JSONUtil ;
import com.alibaba.fastjson.JSONArray ;
import jnpf.base.ActionResult ;
import jnpf.engine.controller.FlowBeforeController ;
import jnpf.engine.model.flowbefore.FlowBeforeInfoVO ;
import jnpf.engine.model.flowbefore.FlowTaskOperatorRecordModel ;
import jnpf.engine.model.flowengine.FlowModel ;
import jnpf.entity.* ;
import jnpf.exception.WorkFlowException ;
import jnpf.mapper.CwpaymentreceiptMapper ;
import jnpf.mapper.PaymentApplicationMapper ;
import jnpf.model.cwpaymentreceipt.PaymentdocMessage ;
import jnpf.permission.entity.OrganizeEntity ;
import jnpf.permission.service.OrganizeService ;
import jnpf.permission.service.UserService ;
import jnpf.service.* ;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl ;
import jnpf.model.paymentapplication.* ;
import java.io.BufferedOutputStream ;
import java.io.ByteArrayOutputStream ;
import java.io.IOException ;
import java.io.UnsupportedEncodingException ;
import java.math.BigDecimal ;
import cn.hutool.core.util.ObjectUtil ;
import jnpf.permission.model.authorize.AuthorizeConditionModel ;
@ -14,10 +32,13 @@ import jnpf.database.model.superQuery.ConditionJsonModel;
import jnpf.database.model.superQuery.SuperQueryConditionModel ;
import java.lang.reflect.Field ;
import com.baomidou.mybatisplus.annotation.TableField ;
import java.net.URLEncoder ;
import java.util.regex.Pattern ;
import jnpf.model.QueryModel ;
import java.util.stream.Collectors ;
import jnpf.base.model.ColumnDataModel ;
import jnpf.util.context.SpringContext ;
import org.springframework.stereotype.Service ;
import com.baomidou.mybatisplus.core.metadata.IPage ;
import jnpf.database.model.superQuery.SuperJsonModel ;
@ -30,6 +51,9 @@ import jnpf.util.*;
import java.util.* ;
import jnpf.base.UserInfo ;
import jnpf.permission.entity.UserEntity ;
import javax.servlet.http.HttpServletResponse ;
/ * *
*
* PaymentApplication
@ -45,6 +69,14 @@ public class PaymentApplicationServiceImpl extends ServiceImpl<PaymentApplicatio
@Autowired
private UserProvider userProvider ;
@Autowired
private CwpaymentreceiptMapper cwpaymentreceiptMapper ;
@Autowired
private OrganizeService organizeService ;
@Autowired
private UserService userService ;
@Autowired
private SubjectbasicService subjectbasicService ;
@Autowired
private PaymentapplicationsettlementService paymentapplicationsettlementService ;
@ -185,6 +217,12 @@ public class PaymentApplicationServiceImpl extends ServiceImpl<PaymentApplicatio
}
}
if ( isPc ) {
if ( ObjectUtil . isNotEmpty ( paymentApplicationPagination . getApplyWeight ( ) ) ) {
paymentApplicationNum + + ;
paymentApplicationQueryWrapper . lambda ( ) . eq ( PaymentApplicationEntity : : getApplyWeight , new BigDecimal ( paymentApplicationPagination . getApplyWeight ( ) ) ) ;
}
if ( ObjectUtil . isNotEmpty ( paymentApplicationPagination . getCode ( ) ) ) {
paymentApplicationNum + + ;
@ -288,6 +326,9 @@ public class PaymentApplicationServiceImpl extends ServiceImpl<PaymentApplicatio
if ( "0" . equals ( dataType ) ) {
if ( ( total > 0 & & AllIdList . size ( ) > 0 ) | | total = = 0 ) {
if ( ObjectUtil . isNotEmpty ( paymentApplicationPagination . getCreatorUserName ( ) ) ) {
paymentApplicationQueryWrapper . inSql ( "f_creator_user_id" , "SELECT f_id from base_user where f_real_name like '%" + paymentApplicationPagination . getCreatorUserName ( ) + "%'" ) ;
}
Page < PaymentApplicationEntity > page = new Page < > ( paymentApplicationPagination . getCurrentPage ( ) , paymentApplicationPagination . getPageSize ( ) ) ;
IPage < PaymentApplicationEntity > userIPage = this . page ( page , paymentApplicationQueryWrapper ) ;
return paymentApplicationPagination . setData ( userIPage . getRecords ( ) , userIPage . getTotal ( ) ) ;
@ -420,4 +461,138 @@ public class PaymentApplicationServiceImpl extends ServiceImpl<PaymentApplicatio
}
}
}
@Override
public void getPaymentDocPdf ( String id ) throws IOException {
List < Map < String , Object > > paymentDocNodeInfo = cwpaymentreceiptMapper . getPaymentDocNodeInfo ( id ) ;
String stringtime = null ;
if ( paymentDocNodeInfo ! = null & & paymentDocNodeInfo . size ( ) > 0 ) {
System . out . println ( paymentDocNodeInfo . get ( 0 ) . get ( "handleTime" ) ) ;
stringtime = paymentDocNodeInfo . get ( 0 ) . get ( "handleTime" ) . toString ( ) ;
}
PaymentdocMessage paymentdocMessage = new PaymentdocMessage ( ) ;
PaymentApplicationEntity paymentApplicationEntity = this . getById ( id ) ;
SubjectbasicEntity subjectbasicEntity = subjectbasicService . getById ( paymentApplicationEntity . getSubjectId ( ) ) ;
UserEntity userEntity = userService . getInfo ( paymentApplicationEntity . getCreatorUserId ( ) ) ;
paymentdocMessage . setRealName ( userEntity . getRealName ( ) ) ;
paymentdocMessage . setMobilePhone ( userEntity . getAccount ( ) ) ;
paymentdocMessage . setNowTime ( new SimpleDateFormat ( "yyyy-MM-dd HH:mm:ss" ) . format ( paymentApplicationEntity . getCreatorTime ( ) ) ) ;
OrganizeEntity companyEntity = organizeService . getById ( paymentApplicationEntity . getCompanyId ( ) ) ;
if ( companyEntity = = null ) {
companyEntity = new OrganizeEntity ( ) ;
}
paymentdocMessage . setCustomerName ( companyEntity . getFullName ( ) + "请示" ) ;
paymentdocMessage . setDocumentNo ( paymentApplicationEntity . getCode ( ) ) ;
paymentdocMessage . setSupplierName ( paymentApplicationEntity . getPayee ( ) ) ;
paymentdocMessage . setRamout ( paymentApplicationEntity . getApplyAmount ( ) . toString ( ) ) ;
paymentdocMessage . setPaymentAmout ( "" ) ;
paymentdocMessage . setCollectionAccout ( subjectbasicEntity . getBankAccount ( ) ) ;
paymentdocMessage . setColletionBank ( subjectbasicEntity . getBankBranchName ( ) ) ;
paymentdocMessage . setRemark ( paymentApplicationEntity . getRemark ( ) ) ;
paymentdocMessage . setEnclosure ( paymentApplicationEntity . getAnnex ( ) ) ;
paymentdocMessage . setPayType ( "货款" ) ;
OrganizeEntity departmentEntity = organizeService . getById ( paymentApplicationEntity . getDepartmentId ( ) ) ;
if ( departmentEntity = = null ) {
departmentEntity = new OrganizeEntity ( ) ;
}
paymentdocMessage . setFullName ( companyEntity . getFullName ( ) + "/" + departmentEntity . getFullName ( ) ) ;
StringBuilder payEnclosureStr = new StringBuilder ( ) ;
if ( paymentdocMessage . getEnclosure ( ) ! = null ) { //附件不为空
String enclosure = paymentdocMessage . getEnclosure ( ) ;
JSONArray jsonToJsonArray = JsonUtil . getJsonToJsonArray ( enclosure ) ;
for ( int i = 0 ; i < jsonToJsonArray . size ( ) ; i + + ) {
Map o = ( Map ) jsonToJsonArray . get ( i ) ;
Object name = o . get ( "name" ) ;
if ( i = = 0 ) {
payEnclosureStr . append ( name ) ;
} else {
payEnclosureStr . append ( "<br/>" + name ) ;
}
}
paymentdocMessage . setEnclosure ( payEnclosureStr . toString ( ) ) ;
}
// StringUtil.indexOf()
// String templateFilePath = configValueUtil.getTemplateFilePath() +"paymentDocPdf//";
Map < String , Object > map = JsonUtil . stringToMap ( JSONUtil . toJsonStr ( paymentdocMessage ) ) ;
map . put ( "substring" , companyEntity . getFullName ( ) ) ;
map . put ( "substring1" , departmentEntity . getFullName ( ) ) ;
// map.put("reportList",paymentDocNodeInfo);
FlowBeforeController bean = SpringContext . getBean ( FlowBeforeController . class ) ;
ActionResult info = null ;
try {
info = bean . info ( id , new FlowModel ( ) ) ;
} catch ( WorkFlowException e ) {
throw new RuntimeException ( e ) ;
}
FlowBeforeInfoVO data = ( FlowBeforeInfoVO ) info . getData ( ) ;
List < FlowTaskOperatorRecordModel > recordList = data . getFlowTaskOperatorRecordList ( ) ;
List < Map < String , Object > > maps = new ArrayList < > ( ) ;
for ( int i = 0 ; i < recordList . size ( ) ; i + + ) {
Map < String , Object > map1 = new HashMap < String , Object > ( ) ;
FlowTaskOperatorRecordModel model = recordList . get ( i ) ;
Map < String , Object > map2 = paymentDocNodeInfo . get ( i ) ;
map1 . put ( "realName" , model . getUserName ( ) ) ;
map1 . put ( "nodeName" , model . getNodeName ( ) ) ;
map1 . put ( "handleOpinion" , model . getHandleOpinion ( ) ) ;
map1 . put ( "handleTime" , DateUtil . daFormat ( model . getHandleTime ( ) ) ) ;
map1 . put ( "node" , map2 . get ( "node" ) ) ;
maps . add ( map1 ) ;
}
ArrayList < Map < String , Object > > maps1 = new ArrayList < Map < String , Object > > ( ) ;
int num = 6 ;
if ( maps . size ( ) > num ) {
for ( int i = 0 ; i < maps . size ( ) ; i + + ) {
Map < String , Object > map1 = maps . get ( i ) ;
if ( i > = num ) {
maps1 . add ( map1 ) ;
}
}
while ( maps . size ( ) > num ) {
maps . remove ( num ) ;
}
}
map . put ( "reportList" , maps ) ;
map . put ( "reportList1" , maps1 ) ;
byte [ ] bytes = null ;
ByteArrayOutputStream out = null ;
ExportPdf exportPdf = new ExportPdf ( ) ;
// word模板
try {
out = exportPdf . createPdf ( map , "paymentDoc.ftl" , "/templates/export" ) ;
bytes = out . toByteArray ( ) ;
out . close ( ) ;
} catch ( Exception e ) {
throw new RuntimeException ( e ) ;
}
String fileName = paymentdocMessage . getCustomerName ( ) = = null ? companyEntity . getFullName ( ) + "请示.pdf" : companyEntity . getFullName ( ) + "请示(" + paymentdocMessage . getCustomerName ( ) + ").pdf" ;
HttpServletResponse response = ServletUtil . getResponse ( ) ;
response . reset ( ) ;
String excelTitle = fileName ;
String filen = null ;
try {
filen = URLEncoder . encode ( excelTitle , "UTF-8" ) . replaceAll ( "\\+" , "%20" ) ;
} catch ( UnsupportedEncodingException e ) {
throw new RuntimeException ( e ) ;
}
// 设置response的Header
response . setHeader ( "Content-disposition" , "attachment;filename*=utf-8''" + filen ) ;
response . setContentType ( "application/x-download;charset=utf-8" ) ;
BufferedOutputStream toClient = null ;
try {
toClient = new BufferedOutputStream ( response . getOutputStream ( ) ) ;
toClient . write ( out . toByteArray ( ) ) ;
toClient . flush ( ) ;
toClient . close ( ) ;
} catch ( IOException e ) {
throw new RuntimeException ( e ) ;
}
log . warn ( "pdf文件生成成功! " ) ;
}
}