Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
T
traffic-front
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangxiaoming
traffic-front
Commits
ec296129
Commit
ec296129
authored
Aug 30, 2018
by
neo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[dev] fixed pctparsed formula to reference cell data
parent
b8b6f78b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
118 additions
and
0 deletions
+118
-0
CellDataMapper.java
...rc/main/java/pwc/taxtech/atms/vat/dao/CellDataMapper.java
+21
-0
ReportGeneratorImpl.java
...wc/taxtech/atms/vat/service/impl/ReportGeneratorImpl.java
+97
-0
No files found.
atms-api/src/main/java/pwc/taxtech/atms/vat/dao/CellDataMapper.java
View file @
ec296129
package
pwc
.
taxtech
.
atms
.
vat
.
dao
;
import
java.util.List
;
import
java.util.Set
;
import
org.apache.ibatis.annotations.Mapper
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Select
;
import
org.apache.ibatis.session.RowBounds
;
import
pwc.taxtech.atms.MyVatMapper
;
import
pwc.taxtech.atms.vat.entity.CellData
;
import
pwc.taxtech.atms.vat.entity.CellDataExample
;
import
pwc.taxtech.atms.vat.service.impl.ReportGeneratorImpl
;
@Mapper
public
interface
CellDataMapper
extends
MyVatMapper
{
...
...
@@ -105,4 +109,20 @@ public interface CellDataMapper extends MyVatMapper {
* @mbg.generated
*/
int
updateByPrimaryKey
(
CellData
record
);
@Select
(
"<script>"
+
"SELECT "
+
" r.period, c.cell_template_id, data "
+
"FROM "
+
" cell_data c, "
+
" report r "
+
"WHERE "
+
" c.report_id = r.id AND "
+
" "
+
" <foreach item=\"item\" index=\"index\" collection=\"list\""
+
" open=\"(\" separator=\"OR\" close=\")\">"
+
" ( r.period=#{item.period} and c.cell_template_id=#{item.cellTemplateId} )"
+
" </foreach>"
+
"</script>"
)
List
<
ReportGeneratorImpl
.
PCTEntity
>
queryByPCTs
(
Set
<
ReportGeneratorImpl
.
PCTEntity
>
parameter
);
}
\ No newline at end of file
atms-api/src/main/java/pwc/taxtech/atms/vat/service/impl/ReportGeneratorImpl.java
View file @
ec296129
package
pwc
.
taxtech
.
atms
.
vat
.
service
.
impl
;
import
com.google.common.collect.Lists
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.poi.openxml4j.exceptions.InvalidFormatException
;
import
org.apache.poi.ss.formula.functions.FreeRefFunction
;
...
...
@@ -36,11 +37,14 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.HashMap
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.Set
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.stream.Collectors
;
...
...
@@ -482,6 +486,7 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen
List
<
PeriodCellTemplateConfigExtendDto
>
periodCellTemplateConfigExtendDtos
=
periodCellTemplateConfigMapper
.
getPeriodCellTemplateConfigExtendDtos
(
templateIDList
,
period
);
fixedPCTParsedFormula
(
periodCellTemplateConfigExtendDtos
);
List
<
CellCalcInfoDto
>
cellCalcInfoDtos
=
new
ArrayList
<>();
periodCellTemplateConfigExtendDtos
.
stream
().
collect
(
Collectors
.
groupingBy
(
a
->
new
CellTemplateConfigGroupDto
(
a
.
getColumnIndex
(),
a
.
getRowIndex
()
...
...
@@ -513,6 +518,74 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen
return
cellCalcInfoDtos
;
}
private
void
fixedPCTParsedFormula
(
List
<
PeriodCellTemplateConfigExtendDto
>
periodCellTemplateConfigExtendDtos
)
{
Map
<
String
,
List
<
PCTEntity
>>
formulaMapToPCT
=
new
HashMap
<>();
Map
<
PeriodCellTemplateConfig
,
List
<
String
>>
configMapToPCTs
=
new
HashMap
<>();
Set
<
PCTEntity
>
parameter
=
new
HashSet
<>();
periodCellTemplateConfigExtendDtos
.
forEach
(
p
->
{
String
formula
=
p
.
getPeriodCellTemplateConfig
().
getFormula
();
String
parsedFormula
=
p
.
getPeriodCellTemplateConfig
().
getParsedFormula
();
if
(
formula
.
contains
(
"BB("
))
{
logger
.
debug
(
"period cell template config contains bb formula {}"
,
formula
);
if
(
parsedFormula
.
contains
(
"PCT("
))
{
List
<
String
>
parsedPCTs
=
new
ArrayList
<>();
byte
[]
parsedFormulaBytes
=
parsedFormula
.
getBytes
();
Integer
begin
=
null
;
for
(
int
i
=
0
;
i
<
parsedFormulaBytes
.
length
-
3
;
i
++)
{
if
(
parsedFormulaBytes
[
i
]
==
'P'
&&
parsedFormulaBytes
[
i
+
1
]
==
'C'
&&
parsedFormulaBytes
[
i
+
2
]
==
'T'
&&
parsedFormulaBytes
[
i
+
3
]
==
'('
)
{
begin
=
i
;
}
else
if
(
parsedFormulaBytes
[
i
]
==
')'
&&
begin
!=
null
)
{
parsedPCTs
.
add
(
new
String
(
Arrays
.
copyOfRange
(
parsedFormulaBytes
,
begin
,
i
+
1
)));
begin
=
null
;
}
}
if
(!
parsedPCTs
.
isEmpty
())
{
configMapToPCTs
.
put
(
p
.
getPeriodCellTemplateConfig
(),
parsedPCTs
);
}
parsedPCTs
.
stream
().
forEach
(
m
->
{
String
periodCPT
=
m
.
substring
(
m
.
indexOf
(
"("
)
+
1
,
m
.
indexOf
(
")"
));
if
(
periodCPT
.
contains
(
","
))
{
formulaMapToPCT
.
put
(
m
,
Arrays
.
asList
(
periodCPT
.
split
(
","
)).
stream
().
map
(
n
->
new
PCTEntity
(
n
))
.
collect
(
Collectors
.
toList
()));
}
else
{
formulaMapToPCT
.
put
(
m
,
Lists
.
newArrayList
(
new
PCTEntity
(
periodCPT
)));
}
parameter
.
addAll
(
formulaMapToPCT
.
get
(
m
));
});
}
else
{
logger
.
warn
(
"bb formula parsedformula must contains PCT but not found {}"
,
parsedFormula
);
}
}
});
if
(!
parameter
.
isEmpty
())
{
List
<
PCTEntity
>
pctResults
=
cellDataMapper
.
queryByPCTs
(
parameter
);
Map
<
PCTEntity
,
BigDecimal
>
pctCache
=
new
HashMap
<>();
pctResults
.
forEach
(
m
->
{
pctCache
.
put
(
m
,
m
.
data
);
});
configMapToPCTs
.
forEach
((
k
,
v
)
->
{
String
passedFormula
=
k
.
getParsedFormula
();
v
.
forEach
(
pctStr
->
{
List
<
PCTEntity
>
entities
=
formulaMapToPCT
.
get
(
pctStr
);
BigDecimal
result
=
new
BigDecimal
(
"0"
);
for
(
PCTEntity
entity
:
entities
)
{
result
=
result
.
add
(
pctCache
.
get
(
entity
));
}
passedFormula
.
replaceAll
(
pctStr
,
result
.
toString
());
});
k
.
setParsedFormula
(
passedFormula
);
});
}
}
private
String
convertListToString
(
List
<
String
>
list
)
{
StringBuilder
stringBuilder
=
new
StringBuilder
();
list
.
forEach
(
s
->
{
...
...
@@ -526,4 +599,28 @@ public class ReportGeneratorImpl extends VatAbstractService implements ReportGen
}
return
stringBuilder
.
toString
();
}
public
static
class
PCTEntity
{
Integer
period
;
Long
cellTemplateId
;
BigDecimal
data
;
public
PCTEntity
(
String
pctStr
)
{
String
[]
pct
=
pctStr
.
split
(
":"
);
this
.
period
=
Integer
.
parseInt
(
pct
[
0
]);
this
.
cellTemplateId
=
Long
.
parseLong
(
pct
[
1
]);
}
@Override
public
int
hashCode
()
{
return
(
period
+
""
+
cellTemplateId
).
hashCode
();
}
@Override
public
boolean
equals
(
Object
obj
)
{
PCTEntity
target
=
(
PCTEntity
)
obj
;
return
period
.
intValue
()
==
target
.
period
.
intValue
()
&&
cellTemplateId
.
longValue
()
==
target
.
cellTemplateId
.
longValue
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment