Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
K
klck
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
位宇华
klck
Commits
0dfa1e45
Commit
0dfa1e45
authored
May 22, 2024
by
刘_震
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
工资-后端接口代码的实现
parent
085f8824
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
139 additions
and
2 deletions
+139
-2
ruoyi-wages/src/main/java/com/ruoyi/system/controller/WagesCalculateConversionController.java
...system/controller/WagesCalculateConversionController.java
+2
-1
ruoyi-wages/src/main/java/com/ruoyi/system/mapper/WagesCalculateConversionMapper.java
...m/ruoyi/system/mapper/WagesCalculateConversionMapper.java
+12
-0
ruoyi-wages/src/main/java/com/ruoyi/system/service/impl/WagesCalculateConversionServiceImpl.java
...tem/service/impl/WagesCalculateConversionServiceImpl.java
+114
-1
ruoyi-wages/src/main/resources/mapper/system/WagesCalculateConversionMapper.xml
...esources/mapper/system/WagesCalculateConversionMapper.xml
+11
-0
No files found.
ruoyi-wages/src/main/java/com/ruoyi/system/controller/WagesCalculateConversionController.java
View file @
0dfa1e45
...
@@ -3,6 +3,7 @@ package com.ruoyi.system.controller;
...
@@ -3,6 +3,7 @@ package com.ruoyi.system.controller;
import
com.ruoyi.common.core.domain.AjaxResult
;
import
com.ruoyi.common.core.domain.AjaxResult
;
import
com.ruoyi.system.model.wages.dto.WagesFormulaListDto
;
import
com.ruoyi.system.model.wages.dto.WagesFormulaListDto
;
import
com.ruoyi.system.service.WagesCalculateConversionService
;
import
com.ruoyi.system.service.WagesCalculateConversionService
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.RestController
;
...
@@ -21,7 +22,7 @@ public class WagesCalculateConversionController {
...
@@ -21,7 +22,7 @@ public class WagesCalculateConversionController {
* 唐山矿转换表
* 唐山矿转换表
*/
*/
@RequestMapping
(
"/surface"
)
@RequestMapping
(
"/surface"
)
public
AjaxResult
conversionSurface
(
@RequestParam
(
""
)
WagesFormulaListDto
wagesFormulaListDto
)
{
public
AjaxResult
conversionSurface
(
@RequestBody
WagesFormulaListDto
wagesFormulaListDto
)
{
return
new
AjaxResult
(
200
,
"成功"
,
wagesCalculateConversionService
.
conversionSurface
(
wagesFormulaListDto
));
return
new
AjaxResult
(
200
,
"成功"
,
wagesCalculateConversionService
.
conversionSurface
(
wagesFormulaListDto
));
}
}
}
}
ruoyi-wages/src/main/java/com/ruoyi/system/mapper/WagesCalculateConversionMapper.java
0 → 100644
View file @
0dfa1e45
package
com.ruoyi.system.mapper
;
import
java.util.List
;
/**
* @author haiwe
* @date 2024/5/22
*/
public
interface
WagesCalculateConversionMapper
{
List
<
Object
>
select
(
String
year
);
}
ruoyi-wages/src/main/java/com/ruoyi/system/service/impl/WagesCalculateConversionServiceImpl.java
View file @
0dfa1e45
package
com.ruoyi.system.service.impl
;
package
com.ruoyi.system.service.impl
;
import
cn.hutool.core.util.ReUtil
;
import
com.ruoyi.system.mapper.WagesCalculateConversionMapper
;
import
com.ruoyi.system.model.wages.dto.WagesFormulaDto
;
import
com.ruoyi.system.model.wages.dto.WagesFormulaListDto
;
import
com.ruoyi.system.model.wages.dto.WagesFormulaListDto
;
import
com.ruoyi.system.model.wages.vo.WagesFormulaListVo
;
import
com.ruoyi.system.model.wages.vo.WagesFormulaVo
;
import
com.ruoyi.system.service.WagesCalculateConversionService
;
import
com.ruoyi.system.service.WagesCalculateConversionService
;
import
lombok.RequiredArgsConstructor
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
/**
* 2024/5/21
* 2024/5/21
*/
*/
@Service
@Service
@RequiredArgsConstructor
public
class
WagesCalculateConversionServiceImpl
implements
WagesCalculateConversionService
{
public
class
WagesCalculateConversionServiceImpl
implements
WagesCalculateConversionService
{
private
final
WagesCalculateConversionMapper
wagesCalculateConversionMapper
;
@Override
@Override
public
Object
conversionSurface
(
WagesFormulaListDto
wagesFormulaListDto
)
{
public
Object
conversionSurface
(
WagesFormulaListDto
wagesFormulaListDto
)
{
return
null
;
WagesFormulaListVo
listVo
=
new
WagesFormulaListVo
();
List
<
WagesFormulaVo
>
wagesFormulaVoList
=
new
ArrayList
<>();
List
<
WagesFormulaDto
>
wagesFormulaDtoList
=
wagesFormulaListDto
.
getWagesFormulaDtoList
();
//获取传过来的值(date - 格式为:xxxx-MM)
String
date
=
wagesFormulaListDto
.
getDate
();
String
[]
parts
=
date
.
split
(
"-"
);
String
year
=
parts
[
0
];
//根据时间去数据库中查询,得到每一条的list集合
List
<
Object
>
wagesList
=
wagesCalculateConversionMapper
.
select
(
year
);
Object
dep
=
wagesList
.
get
(
3
);
double
result
=
calculateFormula
(
wagesList
,
wagesFormulaDtoList
);
// 设置部门信息
listVo
.
setDep
(
String
.
valueOf
(
dep
));
// 构建WagesFormulaVo对象并添加到列表中
for
(
WagesFormulaDto
wagesFormulaDto
:
wagesFormulaDtoList
)
{
WagesFormulaVo
formulaVo
=
new
WagesFormulaVo
();
formulaVo
.
setLabel
(
wagesFormulaDto
.
getLabel
());
formulaVo
.
setC
(
wagesFormulaDto
.
getC
());
formulaVo
.
setValue
(
String
.
valueOf
(
result
));
wagesFormulaVoList
.
add
(
formulaVo
);
}
return
listVo
;
}
private
double
calculateFormula
(
List
<
Object
>
wagesList
,
List
<
WagesFormulaDto
>
wagesFormulaDtoList
)
{
double
result
=
0.0
;
for
(
WagesFormulaDto
wagesFormulaDto
:
wagesFormulaDtoList
)
{
String
value
=
wagesFormulaDto
.
getValue
();
String
formula
=
extractOperands
(
value
);
double
operand
=
evaluateExpression
(
wagesList
,
formula
);
result
+=
operand
;
}
return
result
;
}
private
double
evaluateExpression
(
List
<
Object
>
wagesList
,
String
formula
)
{
String
[]
tokens
=
formula
.
split
(
" "
);
double
result
=
Double
.
parseDouble
(
tokens
[
0
]);
for
(
int
i
=
1
;
i
<
tokens
.
length
-
1
;
i
+=
2
)
{
String
operator
=
tokens
[
i
];
double
operand
=
Double
.
parseDouble
(
tokens
[
i
+
1
]);
switch
(
operator
)
{
case
"+"
:
result
+=
operand
;
break
;
case
"-"
:
result
-=
operand
;
break
;
case
"*"
:
result
*=
operand
;
break
;
case
"/"
:
result
/=
operand
;
break
;
default
:
break
;
}
}
return
result
;
}
private
String
extractOperands
(
String
value
)
{
List
<
String
>
operands
=
new
ArrayList
<>();
StringBuilder
currentOperand
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
value
.
length
();
i
++)
{
char
c
=
value
.
charAt
(
i
);
if
(
Character
.
isDigit
(
c
)
||
c
==
'.'
)
{
currentOperand
.
append
(
c
);
}
else
if
(
isOperator
(
c
))
{
String
operand
=
currentOperand
.
toString
().
trim
();
if
(!
operand
.
isEmpty
())
{
operands
.
add
(
operand
);
}
currentOperand
=
new
StringBuilder
();
operands
.
add
(
String
.
valueOf
(
c
));
}
}
String
lastOperand
=
currentOperand
.
toString
().
trim
();
if
(!
lastOperand
.
isEmpty
())
{
operands
.
add
(
lastOperand
);
}
String
result
=
String
.
join
(
" "
,
operands
);
return
result
;
}
private
boolean
isOperator
(
char
c
)
{
return
c
==
'+'
||
c
==
'-'
||
c
==
'*'
||
c
==
'/'
;
}
}
}
}
ruoyi-wages/src/main/resources/mapper/system/WagesCalculateConversionMapper.xml
0 → 100644
View file @
0dfa1e45
<?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=
"com.ruoyi.system.mapper.WagesCalculateConversionMapper"
>
<select
id=
"select"
resultType=
"java.lang.Object"
parameterType=
"java.lang.String"
>
select * from wages_details_original_data where year = #{year}
</select>
</mapper>
\ No newline at end of file
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