Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
JSH ERP
Commits
f4ef5aa0
Commit
f4ef5aa0
authored
Apr 07, 2021
by
季圣华
Browse files
vue版本上线
parent
76a0033a
Changes
242
Hide whitespace changes
Inline
Side-by-side
Too many changes to show.
To preserve performance only
20 of 242+
files are displayed.
Plain diff
Email patch
jshERP-boot/src/main/java/com/jsh/erp/service/accountHead/AccountHeadResource.java
0 → 100644
View file @
f4ef5aa0
package
com.jsh.erp.service.accountHead
;
import
com.jsh.erp.service.ResourceInfo
;
import
java.lang.annotation.*
;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo
(
value
=
"accountHead"
)
@Inherited
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
AccountHeadResource
{
}
jshERP-boot/src/main/java/com/jsh/erp/service/accountHead/AccountHeadService.java
0 → 100644
View file @
f4ef5aa0
package
com.jsh.erp.service.accountHead
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.constants.BusinessConstants
;
import
com.jsh.erp.datasource.entities.AccountHead
;
import
com.jsh.erp.datasource.entities.AccountHeadExample
;
import
com.jsh.erp.datasource.entities.AccountHeadVo4ListEx
;
import
com.jsh.erp.datasource.entities.User
;
import
com.jsh.erp.datasource.mappers.AccountHeadMapper
;
import
com.jsh.erp.datasource.mappers.AccountHeadMapperEx
;
import
com.jsh.erp.datasource.mappers.AccountItemMapperEx
;
import
com.jsh.erp.exception.JshException
;
import
com.jsh.erp.service.accountItem.AccountItemService
;
import
com.jsh.erp.service.log.LogService
;
import
com.jsh.erp.service.orgaUserRel.OrgaUserRelService
;
import
com.jsh.erp.service.user.UserService
;
import
com.jsh.erp.utils.StringUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.math.BigDecimal
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
static
com
.
jsh
.
erp
.
utils
.
Tools
.
getCenternTime
;
@Service
public
class
AccountHeadService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
AccountHeadService
.
class
);
@Resource
private
AccountHeadMapper
accountHeadMapper
;
@Resource
private
AccountHeadMapperEx
accountHeadMapperEx
;
@Resource
private
OrgaUserRelService
orgaUserRelService
;
@Resource
private
AccountItemService
accountItemService
;
@Resource
private
UserService
userService
;
@Resource
private
LogService
logService
;
@Resource
private
AccountItemMapperEx
accountItemMapperEx
;
public
AccountHead
getAccountHead
(
long
id
)
throws
Exception
{
AccountHead
result
=
null
;
try
{
result
=
accountHeadMapper
.
selectByPrimaryKey
(
id
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
public
List
<
AccountHead
>
getAccountHeadListByIds
(
String
ids
)
throws
Exception
{
List
<
Long
>
idList
=
StringUtil
.
strToLongList
(
ids
);
List
<
AccountHead
>
list
=
new
ArrayList
<>();
try
{
AccountHeadExample
example
=
new
AccountHeadExample
();
example
.
createCriteria
().
andIdIn
(
idList
);
list
=
accountHeadMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
List
<
AccountHead
>
getAccountHead
()
throws
Exception
{
AccountHeadExample
example
=
new
AccountHeadExample
();
List
<
AccountHead
>
list
=
null
;
try
{
list
=
accountHeadMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
List
<
AccountHeadVo4ListEx
>
select
(
String
type
,
String
roleType
,
String
billNo
,
String
beginTime
,
String
endTime
,
int
offset
,
int
rows
)
throws
Exception
{
List
<
AccountHeadVo4ListEx
>
resList
=
new
ArrayList
<
AccountHeadVo4ListEx
>();
List
<
AccountHeadVo4ListEx
>
list
=
null
;
try
{
String
[]
creatorArray
=
getCreatorArray
(
roleType
);
list
=
accountHeadMapperEx
.
selectByConditionAccountHead
(
type
,
creatorArray
,
billNo
,
beginTime
,
endTime
,
offset
,
rows
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
if
(
null
!=
list
)
{
for
(
AccountHeadVo4ListEx
ah
:
list
)
{
if
(
ah
.
getChangeAmount
()
!=
null
)
{
ah
.
setChangeAmount
(
ah
.
getChangeAmount
().
abs
());
}
if
(
ah
.
getTotalPrice
()
!=
null
)
{
ah
.
setTotalPrice
(
ah
.
getTotalPrice
().
abs
());
}
ah
.
setBillTimeStr
(
getCenternTime
(
ah
.
getBillTime
()));
resList
.
add
(
ah
);
}
}
return
resList
;
}
public
Long
countAccountHead
(
String
type
,
String
roleType
,
String
billNo
,
String
beginTime
,
String
endTime
)
throws
Exception
{
Long
result
=
null
;
try
{
String
[]
creatorArray
=
getCreatorArray
(
roleType
);
result
=
accountHeadMapperEx
.
countsByAccountHead
(
type
,
creatorArray
,
billNo
,
beginTime
,
endTime
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
/**
* 根据角色类型获取操作员数组
* @param roleType
* @return
* @throws Exception
*/
private
String
[]
getCreatorArray
(
String
roleType
)
throws
Exception
{
String
creator
=
""
;
User
user
=
userService
.
getCurrentUser
();
if
(
BusinessConstants
.
ROLE_TYPE_PRIVATE
.
equals
(
roleType
))
{
creator
=
user
.
getId
().
toString
();
}
else
if
(
BusinessConstants
.
ROLE_TYPE_THIS_ORG
.
equals
(
roleType
))
{
creator
=
orgaUserRelService
.
getUserIdListByUserId
(
user
.
getId
());
}
String
[]
creatorArray
=
null
;
if
(
StringUtil
.
isNotEmpty
(
creator
)){
creatorArray
=
creator
.
split
(
","
);
}
return
creatorArray
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
insertAccountHead
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
AccountHead
accountHead
=
JSONObject
.
parseObject
(
obj
.
toJSONString
(),
AccountHead
.
class
);
int
result
=
0
;
try
{
User
userInfo
=
userService
.
getCurrentUser
();
accountHead
.
setCreator
(
userInfo
==
null
?
null
:
userInfo
.
getId
());
result
=
accountHeadMapper
.
insertSelective
(
accountHead
);
logService
.
insertLog
(
"财务"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_ADD
).
append
(
accountHead
.
getBillNo
()).
toString
(),
request
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
updateAccountHead
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
AccountHead
accountHead
=
JSONObject
.
parseObject
(
obj
.
toJSONString
(),
AccountHead
.
class
);
int
result
=
0
;
try
{
result
=
accountHeadMapper
.
updateByPrimaryKeySelective
(
accountHead
);
logService
.
insertLog
(
"财务"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_EDIT
).
append
(
accountHead
.
getBillNo
()).
toString
(),
request
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
deleteAccountHead
(
Long
id
,
HttpServletRequest
request
)
throws
Exception
{
return
batchDeleteAccountHeadByIds
(
id
.
toString
());
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchDeleteAccountHead
(
String
ids
,
HttpServletRequest
request
)
throws
Exception
{
return
batchDeleteAccountHeadByIds
(
ids
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchDeleteAccountHeadByIds
(
String
ids
)
throws
Exception
{
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
BusinessConstants
.
LOG_OPERATION_TYPE_DELETE
);
List
<
AccountHead
>
list
=
getAccountHeadListByIds
(
ids
);
for
(
AccountHead
accountHead:
list
){
sb
.
append
(
"["
).
append
(
accountHead
.
getBillNo
()).
append
(
"]"
);
}
logService
.
insertLog
(
"财务"
,
sb
.
toString
(),
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
());
User
userInfo
=
userService
.
getCurrentUser
();
String
[]
idArray
=
ids
.
split
(
","
);
int
result
=
0
;
try
{
//删除主表
result
=
accountItemMapperEx
.
batchDeleteAccountItemByHeadIds
(
new
Date
(),
userInfo
==
null
?
null
:
userInfo
.
getId
(),
idArray
);
//删除子表
result
=
accountHeadMapperEx
.
batchDeleteAccountHeadByIds
(
new
Date
(),
userInfo
==
null
?
null
:
userInfo
.
getId
(),
idArray
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
public
int
checkIsNameExist
(
Long
id
,
String
name
)
throws
Exception
{
AccountHeadExample
example
=
new
AccountHeadExample
();
example
.
createCriteria
().
andIdNotEqualTo
(
id
).
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
AccountHead
>
list
=
null
;
try
{
list
=
accountHeadMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
==
null
?
0
:
list
.
size
();
}
public
void
addAccountHeadAndDetail
(
String
beanJson
,
String
rows
,
HttpServletRequest
request
)
throws
Exception
{
AccountHead
accountHead
=
JSONObject
.
parseObject
(
beanJson
,
AccountHead
.
class
);
User
userInfo
=
userService
.
getCurrentUser
();
accountHead
.
setCreator
(
userInfo
==
null
?
null
:
userInfo
.
getId
());
accountHeadMapper
.
insertSelective
(
accountHead
);
//根据单据编号查询单据id
AccountHeadExample
dhExample
=
new
AccountHeadExample
();
dhExample
.
createCriteria
().
andBillNoEqualTo
(
accountHead
.
getBillNo
()).
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
AccountHead
>
list
=
accountHeadMapper
.
selectByExample
(
dhExample
);
if
(
list
!=
null
)
{
Long
headId
=
list
.
get
(
0
).
getId
();
String
type
=
list
.
get
(
0
).
getType
();
/**处理单据子表信息*/
accountItemService
.
saveDetials
(
rows
,
headId
,
type
,
request
);
}
logService
.
insertLog
(
"财务单据"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_ADD
).
append
(
accountHead
.
getBillNo
()).
toString
(),
request
);
}
public
void
updateAccountHeadAndDetail
(
String
beanJson
,
String
rows
,
HttpServletRequest
request
)
throws
Exception
{
AccountHead
accountHead
=
JSONObject
.
parseObject
(
beanJson
,
AccountHead
.
class
);
accountHeadMapper
.
updateByPrimaryKeySelective
(
accountHead
);
//根据单据编号查询单据id
AccountHeadExample
dhExample
=
new
AccountHeadExample
();
dhExample
.
createCriteria
().
andBillNoEqualTo
(
accountHead
.
getBillNo
()).
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
AccountHead
>
list
=
accountHeadMapper
.
selectByExample
(
dhExample
);
if
(
list
!=
null
)
{
Long
headId
=
list
.
get
(
0
).
getId
();
String
type
=
list
.
get
(
0
).
getType
();
/**处理单据子表信息*/
accountItemService
.
saveDetials
(
rows
,
headId
,
type
,
request
);
}
logService
.
insertLog
(
"财务单据"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_EDIT
).
append
(
accountHead
.
getBillNo
()).
toString
(),
request
);
}
public
BigDecimal
findAllMoney
(
Integer
supplierId
,
String
type
,
String
mode
,
String
endTime
)
{
String
modeName
=
""
;
if
(
mode
.
equals
(
"实际"
))
{
modeName
=
"change_amount"
;
}
else
if
(
mode
.
equals
(
"合计"
))
{
modeName
=
"total_price"
;
}
BigDecimal
result
=
null
;
try
{
result
=
accountHeadMapperEx
.
findAllMoney
(
supplierId
,
type
,
modeName
,
endTime
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
/**
* 统计总金额
* @param getS
* @param type
* @param mode 合计或者金额
* @param endTime
* @return
*/
public
BigDecimal
allMoney
(
String
getS
,
String
type
,
String
mode
,
String
endTime
)
{
BigDecimal
allMoney
=
BigDecimal
.
ZERO
;
try
{
Integer
supplierId
=
Integer
.
valueOf
(
getS
);
BigDecimal
sum
=
findAllMoney
(
supplierId
,
type
,
mode
,
endTime
);
if
(
sum
!=
null
)
{
allMoney
=
sum
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
//返回正数,如果负数也转为正数
if
((
allMoney
.
compareTo
(
BigDecimal
.
ZERO
))==-
1
)
{
allMoney
=
allMoney
.
abs
();
}
return
allMoney
;
}
/**
* 查询单位的累计应收和累计应付,收预付款不计入此处
* @param supplierId
* @param endTime
* @param supType
* @return
*/
public
BigDecimal
findTotalPay
(
Integer
supplierId
,
String
endTime
,
String
supType
)
{
BigDecimal
sum
=
BigDecimal
.
ZERO
;
String
getS
=
supplierId
.
toString
();
int
i
=
1
;
if
((
"customer"
).
equals
(
supType
))
{
//客户
i
=
1
;
}
else
if
((
"vendor"
).
equals
(
supType
))
{
//供应商
i
=
-
1
;
}
//收付款部分
sum
=
sum
.
add
((
allMoney
(
getS
,
"付款"
,
"合计"
,
endTime
).
add
(
allMoney
(
getS
,
"付款"
,
"实际"
,
endTime
))).
multiply
(
new
BigDecimal
(
i
)));
sum
=
sum
.
subtract
((
allMoney
(
getS
,
"收款"
,
"合计"
,
endTime
).
add
(
allMoney
(
getS
,
"收款"
,
"实际"
,
endTime
))).
multiply
(
new
BigDecimal
(
i
)));
sum
=
sum
.
add
((
allMoney
(
getS
,
"收入"
,
"合计"
,
endTime
).
subtract
(
allMoney
(
getS
,
"收入"
,
"实际"
,
endTime
))).
multiply
(
new
BigDecimal
(
i
)));
sum
=
sum
.
subtract
((
allMoney
(
getS
,
"支出"
,
"合计"
,
endTime
).
subtract
(
allMoney
(
getS
,
"支出"
,
"实际"
,
endTime
))).
multiply
(
new
BigDecimal
(
i
)));
return
sum
;
}
public
List
<
AccountHeadVo4ListEx
>
getDetailByNumber
(
String
billNo
)
throws
Exception
{
List
<
AccountHeadVo4ListEx
>
resList
=
new
ArrayList
<
AccountHeadVo4ListEx
>();
List
<
AccountHeadVo4ListEx
>
list
=
null
;
try
{
list
=
accountHeadMapperEx
.
getDetailByNumber
(
billNo
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
if
(
null
!=
list
)
{
for
(
AccountHeadVo4ListEx
ah
:
list
)
{
if
(
ah
.
getChangeAmount
()
!=
null
)
{
ah
.
setChangeAmount
(
ah
.
getChangeAmount
().
abs
());
}
if
(
ah
.
getTotalPrice
()
!=
null
)
{
ah
.
setTotalPrice
(
ah
.
getTotalPrice
().
abs
());
}
ah
.
setBillTimeStr
(
getCenternTime
(
ah
.
getBillTime
()));
resList
.
add
(
ah
);
}
}
return
resList
;
}
}
jshERP-boot/src/main/java/com/jsh/erp/service/accountItem/AccountItemComponent.java
0 → 100644
View file @
f4ef5aa0
package
com.jsh.erp.service.accountItem
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.service.ICommonQuery
;
import
com.jsh.erp.utils.Constants
;
import
com.jsh.erp.utils.QueryUtils
;
import
com.jsh.erp.utils.StringUtil
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.List
;
import
java.util.Map
;
@Service
(
value
=
"accountItem_component"
)
@AccountItemResource
public
class
AccountItemComponent
implements
ICommonQuery
{
@Resource
private
AccountItemService
accountItemService
;
@Override
public
Object
selectOne
(
Long
id
)
throws
Exception
{
return
accountItemService
.
getAccountItem
(
id
);
}
@Override
public
List
<?>
select
(
Map
<
String
,
String
>
map
)
throws
Exception
{
return
getAccountItemList
(
map
);
}
private
List
<?>
getAccountItemList
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
search
=
map
.
get
(
Constants
.
SEARCH
);
String
name
=
StringUtil
.
getInfo
(
search
,
"name"
);
Integer
type
=
StringUtil
.
parseInteger
(
StringUtil
.
getInfo
(
search
,
"type"
));
String
remark
=
StringUtil
.
getInfo
(
search
,
"remark"
);
String
order
=
QueryUtils
.
order
(
map
);
return
accountItemService
.
select
(
name
,
type
,
remark
,
QueryUtils
.
offset
(
map
),
QueryUtils
.
rows
(
map
));
}
@Override
public
Long
counts
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
search
=
map
.
get
(
Constants
.
SEARCH
);
String
name
=
StringUtil
.
getInfo
(
search
,
"name"
);
Integer
type
=
StringUtil
.
parseInteger
(
StringUtil
.
getInfo
(
search
,
"type"
));
String
remark
=
StringUtil
.
getInfo
(
search
,
"remark"
);
return
accountItemService
.
countAccountItem
(
name
,
type
,
remark
);
}
@Override
public
int
insert
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
return
accountItemService
.
insertAccountItem
(
obj
,
request
);
}
@Override
public
int
update
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
return
accountItemService
.
updateAccountItem
(
obj
,
request
);
}
@Override
public
int
delete
(
Long
id
,
HttpServletRequest
request
)
throws
Exception
{
return
accountItemService
.
deleteAccountItem
(
id
,
request
);
}
@Override
public
int
deleteBatch
(
String
ids
,
HttpServletRequest
request
)
throws
Exception
{
return
accountItemService
.
batchDeleteAccountItem
(
ids
,
request
);
}
@Override
public
int
checkIsNameExist
(
Long
id
,
String
name
)
throws
Exception
{
return
accountItemService
.
checkIsNameExist
(
id
,
name
);
}
}
jshERP-boot/src/main/java/com/jsh/erp/service/accountItem/AccountItemResource.java
0 → 100644
View file @
f4ef5aa0
package
com.jsh.erp.service.accountItem
;
import
com.jsh.erp.service.ResourceInfo
;
import
java.lang.annotation.*
;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo
(
value
=
"accountItem"
)
@Inherited
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
AccountItemResource
{
}
jshERP-boot/src/main/java/com/jsh/erp/service/accountItem/AccountItemService.java
0 → 100644
View file @
f4ef5aa0
package
com.jsh.erp.service.accountItem
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.constants.BusinessConstants
;
import
com.jsh.erp.datasource.entities.AccountItem
;
import
com.jsh.erp.datasource.entities.AccountItemExample
;
import
com.jsh.erp.datasource.entities.User
;
import
com.jsh.erp.datasource.mappers.AccountItemMapper
;
import
com.jsh.erp.datasource.mappers.AccountItemMapperEx
;
import
com.jsh.erp.datasource.vo.AccountItemVo4List
;
import
com.jsh.erp.exception.JshException
;
import
com.jsh.erp.service.log.LogService
;
import
com.jsh.erp.service.user.UserService
;
import
com.jsh.erp.utils.StringUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.math.BigDecimal
;
import
java.util.Date
;
import
java.util.List
;
@Service
public
class
AccountItemService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
AccountItemService
.
class
);
@Resource
private
AccountItemMapper
accountItemMapper
;
@Resource
private
AccountItemMapperEx
accountItemMapperEx
;
@Resource
private
LogService
logService
;
@Resource
private
UserService
userService
;
public
AccountItem
getAccountItem
(
long
id
)
throws
Exception
{
AccountItem
result
=
null
;
try
{
result
=
accountItemMapper
.
selectByPrimaryKey
(
id
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
public
List
<
AccountItem
>
getAccountItem
()
throws
Exception
{
AccountItemExample
example
=
new
AccountItemExample
();
example
.
createCriteria
().
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
AccountItem
>
list
=
null
;
try
{
list
=
accountItemMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
List
<
AccountItem
>
select
(
String
name
,
Integer
type
,
String
remark
,
int
offset
,
int
rows
)
throws
Exception
{
List
<
AccountItem
>
list
=
null
;
try
{
list
=
accountItemMapperEx
.
selectByConditionAccountItem
(
name
,
type
,
remark
,
offset
,
rows
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
Long
countAccountItem
(
String
name
,
Integer
type
,
String
remark
)
throws
Exception
{
Long
result
=
null
;
try
{
result
=
accountItemMapperEx
.
countsByAccountItem
(
name
,
type
,
remark
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
insertAccountItem
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
AccountItem
accountItem
=
JSONObject
.
parseObject
(
obj
.
toJSONString
(),
AccountItem
.
class
);
int
result
=
0
;
try
{
result
=
accountItemMapper
.
insertSelective
(
accountItem
);
logService
.
insertLog
(
"财务明细"
,
BusinessConstants
.
LOG_OPERATION_TYPE_ADD
,
request
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
updateAccountItem
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
AccountItem
accountItem
=
JSONObject
.
parseObject
(
obj
.
toJSONString
(),
AccountItem
.
class
);
int
result
=
0
;
try
{
result
=
accountItemMapper
.
updateByPrimaryKeySelective
(
accountItem
);
logService
.
insertLog
(
"财务明细"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_EDIT
).
append
(
accountItem
.
getId
()).
toString
(),
request
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
deleteAccountItem
(
Long
id
,
HttpServletRequest
request
)
throws
Exception
{
int
result
=
0
;
try
{
result
=
accountItemMapper
.
deleteByPrimaryKey
(
id
);
logService
.
insertLog
(
"财务明细"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_DELETE
).
append
(
id
).
toString
(),
request
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchDeleteAccountItem
(
String
ids
,
HttpServletRequest
request
)
throws
Exception
{
List
<
Long
>
idList
=
StringUtil
.
strToLongList
(
ids
);
AccountItemExample
example
=
new
AccountItemExample
();
example
.
createCriteria
().
andIdIn
(
idList
);
int
result
=
0
;
try
{
result
=
accountItemMapper
.
deleteByExample
(
example
);
logService
.
insertLog
(
"财务明细"
,
"批量删除,id集:"
+
ids
,
request
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
public
int
checkIsNameExist
(
Long
id
,
String
name
)
throws
Exception
{
AccountItemExample
example
=
new
AccountItemExample
();
example
.
createCriteria
().
andIdNotEqualTo
(
id
).
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
AccountItem
>
list
=
null
;
try
{
list
=
accountItemMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
==
null
?
0
:
list
.
size
();
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
insertAccountItemWithObj
(
AccountItem
accountItem
)
throws
Exception
{
int
result
=
0
;
try
{
result
=
accountItemMapper
.
insertSelective
(
accountItem
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
updateAccountItemWithObj
(
AccountItem
accountItem
)
throws
Exception
{
int
result
=
0
;
try
{
result
=
accountItemMapper
.
updateByPrimaryKeySelective
(
accountItem
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
public
List
<
AccountItemVo4List
>
getDetailList
(
Long
headerId
)
{
List
<
AccountItemVo4List
>
list
=
null
;
try
{
list
=
accountItemMapperEx
.
getDetailList
(
headerId
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
void
saveDetials
(
String
rows
,
Long
headerId
,
String
type
,
HttpServletRequest
request
)
throws
Exception
{
//删除单据的明细
deleteAccountItemHeadId
(
headerId
);
JSONArray
rowArr
=
JSONArray
.
parseArray
(
rows
);
if
(
null
!=
rowArr
)
{
for
(
int
i
=
0
;
i
<
rowArr
.
size
();
i
++)
{
AccountItem
accountItem
=
new
AccountItem
();
JSONObject
tempInsertedJson
=
JSONObject
.
parseObject
(
rowArr
.
getString
(
i
));
accountItem
.
setHeaderId
(
headerId
);
if
(
tempInsertedJson
.
get
(
"accountId"
)
!=
null
&&
!
tempInsertedJson
.
get
(
"accountId"
).
equals
(
""
))
{
accountItem
.
setAccountId
(
tempInsertedJson
.
getLong
(
"accountId"
));
}
if
(
tempInsertedJson
.
get
(
"inOutItemId"
)
!=
null
&&
!
tempInsertedJson
.
get
(
"inOutItemId"
).
equals
(
""
))
{
accountItem
.
setInOutItemId
(
tempInsertedJson
.
getLong
(
"inOutItemId"
));
}
if
(
tempInsertedJson
.
get
(
"eachAmount"
)
!=
null
&&
!
tempInsertedJson
.
get
(
"eachAmount"
).
equals
(
""
))
{
BigDecimal
eachAmount
=
tempInsertedJson
.
getBigDecimal
(
"eachAmount"
);
if
(
type
.
equals
(
"付款"
))
{
eachAmount
=
BigDecimal
.
ZERO
.
subtract
(
eachAmount
);
}
accountItem
.
setEachAmount
(
eachAmount
);
}
else
{
accountItem
.
setEachAmount
(
BigDecimal
.
ZERO
);
}
accountItem
.
setRemark
(
tempInsertedJson
.
getString
(
"remark"
));
this
.
insertAccountItemWithObj
(
accountItem
);
}
}
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
void
deleteAccountItemHeadId
(
Long
headerId
)
throws
Exception
{
AccountItemExample
example
=
new
AccountItemExample
();
example
.
createCriteria
().
andHeaderIdEqualTo
(
headerId
);
try
{
accountItemMapper
.
deleteByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchDeleteAccountItemByIds
(
String
ids
)
throws
Exception
{
logService
.
insertLog
(
"财务明细"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_DELETE
).
append
(
ids
).
toString
(),
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
());
User
userInfo
=
userService
.
getCurrentUser
();
String
[]
idArray
=
ids
.
split
(
","
);
int
result
=
0
;
try
{
result
=
accountItemMapperEx
.
batchDeleteAccountItemByIds
(
new
Date
(),
userInfo
==
null
?
null
:
userInfo
.
getId
(),
idArray
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
}
jshERP-boot/src/main/java/com/jsh/erp/service/depot/DepotComponent.java
0 → 100644
View file @
f4ef5aa0
package
com.jsh.erp.service.depot
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.service.ICommonQuery
;
import
com.jsh.erp.utils.Constants
;
import
com.jsh.erp.utils.QueryUtils
;
import
com.jsh.erp.utils.StringUtil
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.List
;
import
java.util.Map
;
@Service
(
value
=
"depot_component"
)
@DepotResource
public
class
DepotComponent
implements
ICommonQuery
{
@Resource
private
DepotService
depotService
;
@Override
public
Object
selectOne
(
Long
id
)
throws
Exception
{
return
depotService
.
getDepot
(
id
);
}
@Override
public
List
<?>
select
(
Map
<
String
,
String
>
map
)
throws
Exception
{
return
getDepotList
(
map
);
}
private
List
<?>
getDepotList
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
search
=
map
.
get
(
Constants
.
SEARCH
);
String
name
=
StringUtil
.
getInfo
(
search
,
"name"
);
Integer
type
=
StringUtil
.
parseInteger
(
StringUtil
.
getInfo
(
search
,
"type"
));
String
remark
=
StringUtil
.
getInfo
(
search
,
"remark"
);
String
order
=
QueryUtils
.
order
(
map
);
return
depotService
.
select
(
name
,
type
,
remark
,
QueryUtils
.
offset
(
map
),
QueryUtils
.
rows
(
map
));
}
@Override
public
Long
counts
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
search
=
map
.
get
(
Constants
.
SEARCH
);
String
name
=
StringUtil
.
getInfo
(
search
,
"name"
);
Integer
type
=
StringUtil
.
parseInteger
(
StringUtil
.
getInfo
(
search
,
"type"
));
String
remark
=
StringUtil
.
getInfo
(
search
,
"remark"
);
return
depotService
.
countDepot
(
name
,
type
,
remark
);
}
@Override
public
int
insert
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
return
depotService
.
insertDepot
(
obj
,
request
);
}
@Override
public
int
update
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
return
depotService
.
updateDepot
(
obj
,
request
);
}
@Override
public
int
delete
(
Long
id
,
HttpServletRequest
request
)
throws
Exception
{
return
depotService
.
deleteDepot
(
id
,
request
);
}
@Override
public
int
deleteBatch
(
String
ids
,
HttpServletRequest
request
)
throws
Exception
{
return
depotService
.
batchDeleteDepot
(
ids
,
request
);
}
@Override
public
int
checkIsNameExist
(
Long
id
,
String
name
)
throws
Exception
{
return
depotService
.
checkIsNameExist
(
id
,
name
);
}
}
jshERP-boot/src/main/java/com/jsh/erp/service/depot/DepotResource.java
0 → 100644
View file @
f4ef5aa0
package
com.jsh.erp.service.depot
;
import
com.jsh.erp.service.ResourceInfo
;
import
java.lang.annotation.*
;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo
(
value
=
"depot"
)
@Inherited
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
DepotResource
{
}
jshERP-boot/src/main/java/com/jsh/erp/service/depot/DepotService.java
0 → 100644
View file @
f4ef5aa0
package
com.jsh.erp.service.depot
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.toolkit.StringUtils
;
import
com.jsh.erp.constants.BusinessConstants
;
import
com.jsh.erp.constants.ExceptionConstants
;
import
com.jsh.erp.datasource.entities.*
;
import
com.jsh.erp.datasource.mappers.*
;
import
com.jsh.erp.exception.BusinessRunTimeException
;
import
com.jsh.erp.exception.JshException
;
import
com.jsh.erp.service.log.LogService
;
import
com.jsh.erp.service.user.UserService
;
import
com.jsh.erp.utils.StringUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
@Service
public
class
DepotService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
DepotService
.
class
);
@Resource
private
DepotMapper
depotMapper
;
@Resource
private
DepotMapperEx
depotMapperEx
;
@Resource
private
UserService
userService
;
@Resource
private
LogService
logService
;
@Resource
private
DepotHeadMapperEx
depotHeadMapperEx
;
@Resource
private
DepotItemMapperEx
depotItemMapperEx
;
public
Depot
getDepot
(
long
id
)
throws
Exception
{
Depot
result
=
null
;
try
{
result
=
depotMapper
.
selectByPrimaryKey
(
id
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
public
List
<
Depot
>
getDepotListByIds
(
String
ids
)
throws
Exception
{
List
<
Long
>
idList
=
StringUtil
.
strToLongList
(
ids
);
List
<
Depot
>
list
=
new
ArrayList
<>();
try
{
DepotExample
example
=
new
DepotExample
();
example
.
createCriteria
().
andIdIn
(
idList
);
list
=
depotMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
List
<
Depot
>
getDepot
()
throws
Exception
{
DepotExample
example
=
new
DepotExample
();
example
.
createCriteria
().
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
Depot
>
list
=
null
;
try
{
list
=
depotMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
List
<
Depot
>
getAllList
()
throws
Exception
{
DepotExample
example
=
new
DepotExample
();
example
.
createCriteria
().
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
example
.
setOrderByClause
(
"sort"
);
List
<
Depot
>
list
=
null
;
try
{
list
=
depotMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
List
<
DepotEx
>
select
(
String
name
,
Integer
type
,
String
remark
,
int
offset
,
int
rows
)
throws
Exception
{
List
<
DepotEx
>
list
=
null
;
try
{
list
=
depotMapperEx
.
selectByConditionDepot
(
name
,
type
,
remark
,
offset
,
rows
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
Long
countDepot
(
String
name
,
Integer
type
,
String
remark
)
throws
Exception
{
Long
result
=
null
;
try
{
result
=
depotMapperEx
.
countsByDepot
(
name
,
type
,
remark
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
insertDepot
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
Depot
depot
=
JSONObject
.
parseObject
(
obj
.
toJSONString
(),
Depot
.
class
);
int
result
=
0
;
try
{
result
=
depotMapper
.
insertSelective
(
depot
);
logService
.
insertLog
(
"仓库"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_ADD
).
append
(
depot
.
getName
()).
toString
(),
request
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
updateDepot
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
Depot
depot
=
JSONObject
.
parseObject
(
obj
.
toJSONString
(),
Depot
.
class
);
int
result
=
0
;
try
{
result
=
depotMapper
.
updateByPrimaryKeySelective
(
depot
);
logService
.
insertLog
(
"仓库"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_EDIT
).
append
(
depot
.
getName
()).
toString
(),
request
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
deleteDepot
(
Long
id
,
HttpServletRequest
request
)
throws
Exception
{
return
batchDeleteDepotByIds
(
id
.
toString
());
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchDeleteDepot
(
String
ids
,
HttpServletRequest
request
)
throws
Exception
{
return
batchDeleteDepotByIds
(
ids
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchDeleteDepotByIds
(
String
ids
)
throws
Exception
{
int
result
=
0
;
String
[]
idArray
=
ids
.
split
(
","
);
//校验单据子表 jsh_depot_item
List
<
DepotItem
>
depotItemList
=
null
;
try
{
depotItemList
=
depotItemMapperEx
.
getDepotItemListListByDepotIds
(
idArray
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
if
(
depotItemList
!=
null
&&
depotItemList
.
size
()>
0
){
logger
.
error
(
"异常码[{}],异常提示[{}],参数,DepotIds[{}]"
,
ExceptionConstants
.
DELETE_FORCE_CONFIRM_CODE
,
ExceptionConstants
.
DELETE_FORCE_CONFIRM_MSG
,
ids
);
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
DELETE_FORCE_CONFIRM_CODE
,
ExceptionConstants
.
DELETE_FORCE_CONFIRM_MSG
);
}
//记录日志
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
BusinessConstants
.
LOG_OPERATION_TYPE_DELETE
);
List
<
Depot
>
list
=
getDepotListByIds
(
ids
);
for
(
Depot
depot:
list
){
sb
.
append
(
"["
).
append
(
depot
.
getName
()).
append
(
"]"
);
}
logService
.
insertLog
(
"仓库"
,
sb
.
toString
(),
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
());
User
userInfo
=
userService
.
getCurrentUser
();
//校验通过执行删除操作
try
{
result
=
depotMapperEx
.
batchDeleteDepotByIds
(
new
Date
(),
userInfo
==
null
?
null
:
userInfo
.
getId
(),
idArray
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
public
int
checkIsNameExist
(
Long
id
,
String
name
)
throws
Exception
{
DepotExample
example
=
new
DepotExample
();
example
.
createCriteria
().
andIdNotEqualTo
(
id
).
andNameEqualTo
(
name
).
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
Depot
>
list
=
null
;
try
{
list
=
depotMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
==
null
?
0
:
list
.
size
();
}
public
List
<
Depot
>
findUserDepot
()
throws
Exception
{
DepotExample
example
=
new
DepotExample
();
example
.
createCriteria
().
andTypeEqualTo
(
0
).
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
example
.
setOrderByClause
(
"Sort"
);
List
<
Depot
>
list
=
null
;
try
{
list
=
depotMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
List
<
Depot
>
findGiftByType
(
Integer
type
)
throws
Exception
{
DepotExample
example
=
new
DepotExample
();
example
.
createCriteria
().
andTypeEqualTo
(
type
);
example
.
setOrderByClause
(
"Sort"
);
List
<
Depot
>
list
=
null
;
try
{
list
=
depotMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
updateIsDefault
(
Long
depotId
)
throws
Exception
{
int
result
=
0
;
try
{
//全部取消默认
Depot
allDepot
=
new
Depot
();
allDepot
.
setIsDefault
(
false
);
DepotExample
allExample
=
new
DepotExample
();
allExample
.
createCriteria
();
depotMapper
.
updateByExampleSelective
(
allDepot
,
allExample
);
//给指定仓库设为默认
Depot
depot
=
new
Depot
();
depot
.
setIsDefault
(
true
);
DepotExample
example
=
new
DepotExample
();
example
.
createCriteria
().
andIdEqualTo
(
depotId
);
depotMapper
.
updateByExampleSelective
(
depot
,
example
);
logService
.
insertLog
(
"仓库"
,
BusinessConstants
.
LOG_OPERATION_TYPE_EDIT
+
depotId
,
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
());
result
=
1
;
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
/**
* 根据名称获取id
* @param name
*/
public
Long
getIdByName
(
String
name
){
Long
id
=
0L
;
DepotExample
example
=
new
DepotExample
();
example
.
createCriteria
().
andNameEqualTo
(
name
).
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
Depot
>
list
=
depotMapper
.
selectByExample
(
example
);
if
(
list
!=
null
&&
list
.
size
()>
0
)
{
id
=
list
.
get
(
0
).
getId
();
}
return
id
;
}
}
jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadComponent.java
0 → 100644
View file @
f4ef5aa0
package
com.jsh.erp.service.depotHead
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.service.ICommonQuery
;
import
com.jsh.erp.utils.Constants
;
import
com.jsh.erp.utils.QueryUtils
;
import
com.jsh.erp.utils.StringUtil
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.List
;
import
java.util.Map
;
@Service
(
value
=
"depotHead_component"
)
@DepotHeadResource
public
class
DepotHeadComponent
implements
ICommonQuery
{
@Resource
private
DepotHeadService
depotHeadService
;
@Override
public
Object
selectOne
(
Long
id
)
throws
Exception
{
return
depotHeadService
.
getDepotHead
(
id
);
}
@Override
public
List
<?>
select
(
Map
<
String
,
String
>
map
)
throws
Exception
{
return
getDepotHeadList
(
map
);
}
private
List
<?>
getDepotHeadList
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
search
=
map
.
get
(
Constants
.
SEARCH
);
String
type
=
StringUtil
.
getInfo
(
search
,
"type"
);
String
subType
=
StringUtil
.
getInfo
(
search
,
"subType"
);
String
roleType
=
StringUtil
.
getInfo
(
search
,
"roleType"
);
String
status
=
StringUtil
.
getInfo
(
search
,
"status"
);
String
number
=
StringUtil
.
getInfo
(
search
,
"number"
);
String
beginTime
=
StringUtil
.
getInfo
(
search
,
"beginTime"
);
String
endTime
=
StringUtil
.
getInfo
(
search
,
"endTime"
);
String
materialParam
=
StringUtil
.
getInfo
(
search
,
"materialParam"
);
String
depotIds
=
StringUtil
.
getInfo
(
search
,
"depotIds"
);
return
depotHeadService
.
select
(
type
,
subType
,
roleType
,
status
,
number
,
beginTime
,
endTime
,
materialParam
,
depotIds
,
QueryUtils
.
offset
(
map
),
QueryUtils
.
rows
(
map
));
}
@Override
public
Long
counts
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
search
=
map
.
get
(
Constants
.
SEARCH
);
String
type
=
StringUtil
.
getInfo
(
search
,
"type"
);
String
subType
=
StringUtil
.
getInfo
(
search
,
"subType"
);
String
roleType
=
StringUtil
.
getInfo
(
search
,
"roleType"
);
String
status
=
StringUtil
.
getInfo
(
search
,
"status"
);
String
number
=
StringUtil
.
getInfo
(
search
,
"number"
);
String
beginTime
=
StringUtil
.
getInfo
(
search
,
"beginTime"
);
String
endTime
=
StringUtil
.
getInfo
(
search
,
"endTime"
);
String
materialParam
=
StringUtil
.
getInfo
(
search
,
"materialParam"
);
String
depotIds
=
StringUtil
.
getInfo
(
search
,
"depotIds"
);
return
depotHeadService
.
countDepotHead
(
type
,
subType
,
roleType
,
status
,
number
,
beginTime
,
endTime
,
materialParam
,
depotIds
);
}
@Override
public
int
insert
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
return
depotHeadService
.
insertDepotHead
(
obj
,
request
);
}
@Override
public
int
update
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
return
depotHeadService
.
updateDepotHead
(
obj
,
request
);
}
@Override
public
int
delete
(
Long
id
,
HttpServletRequest
request
)
throws
Exception
{
return
depotHeadService
.
deleteDepotHead
(
id
,
request
);
}
@Override
public
int
deleteBatch
(
String
ids
,
HttpServletRequest
request
)
throws
Exception
{
return
depotHeadService
.
batchDeleteDepotHead
(
ids
,
request
);
}
@Override
public
int
checkIsNameExist
(
Long
id
,
String
name
)
throws
Exception
{
return
depotHeadService
.
checkIsNameExist
(
id
,
name
);
}
}
jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadResource.java
0 → 100644
View file @
f4ef5aa0
package
com.jsh.erp.service.depotHead
;
import
com.jsh.erp.service.ResourceInfo
;
import
java.lang.annotation.*
;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo
(
value
=
"depotHead"
)
@Inherited
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
DepotHeadResource
{
}
jshERP-boot/src/main/java/com/jsh/erp/service/depotHead/DepotHeadService.java
0 → 100644
View file @
f4ef5aa0
package
com.jsh.erp.service.depotHead
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.constants.BusinessConstants
;
import
com.jsh.erp.constants.ExceptionConstants
;
import
com.jsh.erp.datasource.entities.*
;
import
com.jsh.erp.datasource.mappers.DepotHeadMapper
;
import
com.jsh.erp.datasource.mappers.DepotHeadMapperEx
;
import
com.jsh.erp.datasource.mappers.DepotItemMapperEx
;
import
com.jsh.erp.datasource.vo.DepotHeadVo4InDetail
;
import
com.jsh.erp.datasource.vo.DepotHeadVo4InOutMCount
;
import
com.jsh.erp.datasource.vo.DepotHeadVo4List
;
import
com.jsh.erp.datasource.vo.DepotHeadVo4StatementAccount
;
import
com.jsh.erp.exception.BusinessRunTimeException
;
import
com.jsh.erp.exception.JshException
;
import
com.jsh.erp.service.depotItem.DepotItemService
;
import
com.jsh.erp.service.log.LogService
;
import
com.jsh.erp.service.orgaUserRel.OrgaUserRelService
;
import
com.jsh.erp.service.redis.RedisService
;
import
com.jsh.erp.service.serialNumber.SerialNumberService
;
import
com.jsh.erp.service.supplier.SupplierService
;
import
com.jsh.erp.service.user.UserService
;
import
com.jsh.erp.utils.StringUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.math.BigDecimal
;
import
java.sql.Timestamp
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
import
static
com
.
jsh
.
erp
.
utils
.
Tools
.
getCenternTime
;
@Service
public
class
DepotHeadService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
DepotHeadService
.
class
);
@Resource
private
DepotHeadMapper
depotHeadMapper
;
@Resource
private
DepotHeadMapperEx
depotHeadMapperEx
;
@Resource
private
UserService
userService
;
@Resource
DepotItemService
depotItemService
;
@Resource
private
SupplierService
supplierService
;
@Resource
private
SerialNumberService
serialNumberService
;
@Resource
private
OrgaUserRelService
orgaUserRelService
;
@Resource
DepotItemMapperEx
depotItemMapperEx
;
@Resource
private
LogService
logService
;
@Resource
private
RedisService
redisService
;
public
DepotHead
getDepotHead
(
long
id
)
throws
Exception
{
DepotHead
result
=
null
;
try
{
result
=
depotHeadMapper
.
selectByPrimaryKey
(
id
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
public
List
<
DepotHead
>
getDepotHead
()
throws
Exception
{
DepotHeadExample
example
=
new
DepotHeadExample
();
example
.
createCriteria
().
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
DepotHead
>
list
=
null
;
try
{
list
=
depotHeadMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
List
<
DepotHeadVo4List
>
select
(
String
type
,
String
subType
,
String
roleType
,
String
status
,
String
number
,
String
beginTime
,
String
endTime
,
String
materialParam
,
String
depotIds
,
int
offset
,
int
rows
)
throws
Exception
{
List
<
DepotHeadVo4List
>
resList
=
new
ArrayList
<
DepotHeadVo4List
>();
List
<
DepotHeadVo4List
>
list
=
null
;
try
{
String
[]
creatorArray
=
getCreatorArray
(
roleType
);
list
=
depotHeadMapperEx
.
selectByConditionDepotHead
(
type
,
subType
,
creatorArray
,
status
,
number
,
beginTime
,
endTime
,
materialParam
,
depotIds
,
offset
,
rows
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
if
(
null
!=
list
)
{
for
(
DepotHeadVo4List
dh
:
list
)
{
if
(
dh
.
getAccountIdList
()
!=
null
)
{
String
accountidlistStr
=
dh
.
getAccountIdList
().
replace
(
"["
,
""
).
replace
(
"]"
,
""
).
replaceAll
(
"\""
,
""
);
dh
.
setAccountIdList
(
accountidlistStr
);
}
if
(
dh
.
getAccountMoneyList
()
!=
null
)
{
String
accountmoneylistStr
=
dh
.
getAccountMoneyList
().
replace
(
"["
,
""
).
replace
(
"]"
,
""
).
replaceAll
(
"\""
,
""
);
dh
.
setAccountMoneyList
(
accountmoneylistStr
);
}
if
(
dh
.
getOtherMoneyList
()
!=
null
)
{
String
otherMoneyListStr
=
dh
.
getOtherMoneyList
().
replace
(
"["
,
""
).
replace
(
"]"
,
""
).
replaceAll
(
"\""
,
""
);
dh
.
setOtherMoneyList
(
otherMoneyListStr
);
}
if
(
dh
.
getChangeAmount
()
!=
null
)
{
dh
.
setChangeAmount
(
dh
.
getChangeAmount
().
abs
());
}
if
(
dh
.
getTotalPrice
()
!=
null
)
{
dh
.
setTotalPrice
(
dh
.
getTotalPrice
().
abs
());
}
if
(
dh
.
getOperTime
()
!=
null
)
{
dh
.
setOperTimeStr
(
getCenternTime
(
dh
.
getOperTime
()));
}
dh
.
setMaterialsList
(
findMaterialsListByHeaderId
(
dh
.
getId
()));
resList
.
add
(
dh
);
}
}
return
resList
;
}
public
Long
countDepotHead
(
String
type
,
String
subType
,
String
roleType
,
String
status
,
String
number
,
String
beginTime
,
String
endTime
,
String
materialParam
,
String
depotIds
)
throws
Exception
{
Long
result
=
null
;
try
{
String
[]
creatorArray
=
getCreatorArray
(
roleType
);
result
=
depotHeadMapperEx
.
countsByDepotHead
(
type
,
subType
,
creatorArray
,
status
,
number
,
beginTime
,
endTime
,
materialParam
,
depotIds
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
/**
* 根据角色类型获取操作员数组
* @param roleType
* @return
* @throws Exception
*/
public
String
[]
getCreatorArray
(
String
roleType
)
throws
Exception
{
String
creator
=
getCreatorByRoleType
(
roleType
);
String
[]
creatorArray
=
null
;
if
(
StringUtil
.
isNotEmpty
(
creator
)){
creatorArray
=
creator
.
split
(
","
);
}
return
creatorArray
;
}
/**
* 根据角色类型获取操作员
* @param roleType
* @return
* @throws Exception
*/
public
String
getCreatorByRoleType
(
String
roleType
)
throws
Exception
{
String
creator
=
""
;
User
user
=
userService
.
getCurrentUser
();
if
(
BusinessConstants
.
ROLE_TYPE_PRIVATE
.
equals
(
roleType
))
{
creator
=
user
.
getId
().
toString
();
}
else
if
(
BusinessConstants
.
ROLE_TYPE_THIS_ORG
.
equals
(
roleType
))
{
creator
=
orgaUserRelService
.
getUserIdListByUserId
(
user
.
getId
());
}
return
creator
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
insertDepotHead
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
DepotHead
depotHead
=
JSONObject
.
parseObject
(
obj
.
toJSONString
(),
DepotHead
.
class
);
depotHead
.
setCreateTime
(
new
Timestamp
(
System
.
currentTimeMillis
()));
depotHead
.
setStatus
(
BusinessConstants
.
BILLS_STATUS_UN_AUDIT
);
int
result
=
0
;
try
{
result
=
depotHeadMapper
.
insert
(
depotHead
);
logService
.
insertLog
(
"单据"
,
BusinessConstants
.
LOG_OPERATION_TYPE_ADD
,
request
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
updateDepotHead
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
DepotHead
depotHead
=
JSONObject
.
parseObject
(
obj
.
toJSONString
(),
DepotHead
.
class
);
DepotHead
dh
=
null
;
try
{
dh
=
depotHeadMapper
.
selectByPrimaryKey
(
depotHead
.
getId
());
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
depotHead
.
setStatus
(
dh
.
getStatus
());
depotHead
.
setCreateTime
(
dh
.
getCreateTime
());
int
result
=
0
;
try
{
result
=
depotHeadMapper
.
updateByPrimaryKey
(
depotHead
);
logService
.
insertLog
(
"单据"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_EDIT
).
append
(
depotHead
.
getId
()).
toString
(),
request
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
deleteDepotHead
(
Long
id
,
HttpServletRequest
request
)
throws
Exception
{
int
result
=
0
;
try
{
//查询单据主表信息
DepotHead
depotHead
=
getDepotHead
(
id
);
User
userInfo
=
userService
.
getCurrentUser
();
//删除出库数据回收序列号
if
(
BusinessConstants
.
DEPOTHEAD_TYPE_OUT
.
equals
(
depotHead
.
getType
())
&&!
BusinessConstants
.
SUB_TYPE_TRANSFER
.
equals
(
depotHead
.
getSubType
())){
//查询单据子表列表
List
<
DepotItem
>
depotItemList
=
null
;
try
{
depotItemList
=
depotItemMapperEx
.
findDepotItemListBydepotheadId
(
id
,
BusinessConstants
.
ENABLE_SERIAL_NUMBER_ENABLED
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
/**回收序列号*/
if
(
depotItemList
!=
null
&&
depotItemList
.
size
()>
0
){
for
(
DepotItem
depotItem:
depotItemList
){
//BasicNumber=OperNumber*ratio
serialNumberService
.
cancelSerialNumber
(
depotItem
.
getMaterialId
(),
depotItem
.
getHeaderId
(),(
depotItem
.
getBasicNumber
()==
null
?
0
:
depotItem
.
getBasicNumber
()).
intValue
(),
userInfo
);
}
}
}
/**删除单据子表数据*/
try
{
depotItemMapperEx
.
batchDeleteDepotItemByDepotHeadIds
(
new
Long
[]{
id
});
//更新当前库存
List
<
DepotItem
>
list
=
depotItemService
.
getListByHeaderId
(
id
);
for
(
DepotItem
depotItem:
list
){
Long
tenantId
=
Long
.
parseLong
(
redisService
.
getObjectFromSessionByKey
(
request
,
"tenantId"
).
toString
());
depotItemService
.
updateCurrentStock
(
depotItem
,
tenantId
);
}
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
/**删除单据主表信息*/
batchDeleteDepotHeadByIds
(
id
.
toString
());
logService
.
insertLog
(
"单据"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_DELETE
).
append
(
depotHead
.
getNumber
()).
toString
(),
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
());
result
=
1
;
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchDeleteDepotHead
(
String
ids
,
HttpServletRequest
request
)
throws
Exception
{
int
result
=
0
;
try
{
if
(
StringUtil
.
isNotEmpty
(
ids
)){
String
[]
headIds
=
ids
.
split
(
","
);
for
(
int
i
=
0
;
i
<
headIds
.
length
;
i
++){
deleteDepotHead
(
Long
.
valueOf
(
headIds
[
i
]),
request
);
}
}
result
=
1
;
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchDeleteDepotHeadByIds
(
String
ids
)
throws
Exception
{
User
userInfo
=
userService
.
getCurrentUser
();
String
[]
idArray
=
ids
.
split
(
","
);
int
result
=
0
;
try
{
result
=
depotHeadMapperEx
.
batchDeleteDepotHeadByIds
(
new
Date
(),
userInfo
==
null
?
null
:
userInfo
.
getId
(),
idArray
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
public
int
checkIsNameExist
(
Long
id
,
String
name
)
throws
Exception
{
DepotHeadExample
example
=
new
DepotHeadExample
();
example
.
createCriteria
().
andIdNotEqualTo
(
id
).
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
DepotHead
>
list
=
null
;
try
{
list
=
depotHeadMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
==
null
?
0
:
list
.
size
();
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchSetStatus
(
String
status
,
String
depotHeadIDs
)
throws
Exception
{
List
<
Long
>
ids
=
StringUtil
.
strToLongList
(
depotHeadIDs
);
DepotHead
depotHead
=
new
DepotHead
();
depotHead
.
setStatus
(
status
);
DepotHeadExample
example
=
new
DepotHeadExample
();
example
.
createCriteria
().
andIdIn
(
ids
);
int
result
=
0
;
try
{
result
=
depotHeadMapper
.
updateByExampleSelective
(
depotHead
,
example
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
public
String
findMaterialsListByHeaderId
(
Long
id
)
throws
Exception
{
String
result
=
null
;
try
{
result
=
depotHeadMapperEx
.
findMaterialsListByHeaderId
(
id
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
public
List
<
DepotHeadVo4InDetail
>
findByAll
(
String
beginTime
,
String
endTime
,
String
type
,
String
materialParam
,
Integer
depotId
,
Integer
oId
,
Integer
offset
,
Integer
rows
)
throws
Exception
{
List
<
DepotHeadVo4InDetail
>
list
=
null
;
try
{
list
=
depotHeadMapperEx
.
findByAll
(
beginTime
,
endTime
,
type
,
materialParam
,
depotId
,
oId
,
offset
,
rows
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
int
findByAllCount
(
String
beginTime
,
String
endTime
,
String
type
,
String
materialParam
,
Integer
depotId
,
Integer
oId
)
throws
Exception
{
int
result
=
0
;
try
{
result
=
depotHeadMapperEx
.
findByAllCount
(
beginTime
,
endTime
,
type
,
materialParam
,
depotId
,
oId
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
public
List
<
DepotHeadVo4InOutMCount
>
findInOutMaterialCount
(
String
beginTime
,
String
endTime
,
String
type
,
String
materialParam
,
Integer
depotId
,
Integer
oId
,
Integer
offset
,
Integer
rows
)
throws
Exception
{
List
<
DepotHeadVo4InOutMCount
>
list
=
null
;
try
{
list
=
depotHeadMapperEx
.
findInOutMaterialCount
(
beginTime
,
endTime
,
type
,
materialParam
,
depotId
,
oId
,
offset
,
rows
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
int
findInOutMaterialCountTotal
(
String
beginTime
,
String
endTime
,
String
type
,
String
materialParam
,
Integer
depotId
,
Integer
oId
)
throws
Exception
{
int
result
=
0
;
try
{
result
=
depotHeadMapperEx
.
findInOutMaterialCountTotal
(
beginTime
,
endTime
,
type
,
materialParam
,
depotId
,
oId
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
public
List
<
DepotHeadVo4StatementAccount
>
findStatementAccount
(
String
beginTime
,
String
endTime
,
Integer
organId
,
String
supType
,
Integer
offset
,
Integer
rows
)
throws
Exception
{
List
<
DepotHeadVo4StatementAccount
>
list
=
null
;
try
{
list
=
depotHeadMapperEx
.
findStatementAccount
(
beginTime
,
endTime
,
organId
,
supType
,
offset
,
rows
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
int
findStatementAccountCount
(
String
beginTime
,
String
endTime
,
Integer
organId
,
String
supType
)
throws
Exception
{
int
result
=
0
;
try
{
result
=
depotHeadMapperEx
.
findStatementAccountCount
(
beginTime
,
endTime
,
organId
,
supType
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
public
BigDecimal
findAllMoney
(
Integer
supplierId
,
String
type
,
String
subType
,
String
mode
,
String
endTime
)
throws
Exception
{
String
modeName
=
""
;
BigDecimal
allOtherMoney
=
BigDecimal
.
ZERO
;
if
(
mode
.
equals
(
"实际"
))
{
modeName
=
"change_amount"
;
}
else
if
(
mode
.
equals
(
"合计"
))
{
modeName
=
"discount_last_money"
;
allOtherMoney
=
depotHeadMapperEx
.
findAllOtherMoney
(
supplierId
,
type
,
subType
,
endTime
);
}
BigDecimal
result
=
BigDecimal
.
ZERO
;
try
{
result
=
depotHeadMapperEx
.
findAllMoney
(
supplierId
,
type
,
subType
,
modeName
,
endTime
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
if
(
allOtherMoney
!=
null
)
{
result
=
result
.
add
(
allOtherMoney
);
}
return
result
;
}
/**
* 统计总金额
* @param getS
* @param type
* @param subType
* @param mode 合计或者金额
* @return
*/
public
BigDecimal
allMoney
(
String
getS
,
String
type
,
String
subType
,
String
mode
,
String
endTime
)
{
BigDecimal
allMoney
=
BigDecimal
.
ZERO
;
try
{
Integer
supplierId
=
Integer
.
valueOf
(
getS
);
BigDecimal
sum
=
findAllMoney
(
supplierId
,
type
,
subType
,
mode
,
endTime
);
if
(
sum
!=
null
)
{
allMoney
=
sum
;
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
//返回正数,如果负数也转为正数
if
((
allMoney
.
compareTo
(
BigDecimal
.
ZERO
))==-
1
)
{
allMoney
=
allMoney
.
abs
();
}
return
allMoney
;
}
/**
* 查询单位的累计应收和累计应付,零售不能计入
* @param supplierId
* @param endTime
* @param supType
* @return
*/
public
BigDecimal
findTotalPay
(
Integer
supplierId
,
String
endTime
,
String
supType
)
{
BigDecimal
sum
=
BigDecimal
.
ZERO
;
String
getS
=
supplierId
.
toString
();
int
i
=
1
;
if
((
"customer"
).
equals
(
supType
))
{
//客户
i
=
1
;
}
else
if
((
"vendor"
).
equals
(
supType
))
{
//供应商
i
=
-
1
;
}
//进销部分
sum
=
sum
.
subtract
((
allMoney
(
getS
,
"入库"
,
"采购"
,
"合计"
,
endTime
).
subtract
(
allMoney
(
getS
,
"入库"
,
"采购"
,
"实际"
,
endTime
))).
multiply
(
new
BigDecimal
(
i
)));
sum
=
sum
.
subtract
((
allMoney
(
getS
,
"入库"
,
"销售退货"
,
"合计"
,
endTime
).
subtract
(
allMoney
(
getS
,
"入库"
,
"销售退货"
,
"实际"
,
endTime
))).
multiply
(
new
BigDecimal
(
i
)));
sum
=
sum
.
add
((
allMoney
(
getS
,
"出库"
,
"销售"
,
"合计"
,
endTime
).
subtract
(
allMoney
(
getS
,
"出库"
,
"销售"
,
"实际"
,
endTime
))).
multiply
(
new
BigDecimal
(
i
)));
sum
=
sum
.
add
((
allMoney
(
getS
,
"出库"
,
"采购退货"
,
"合计"
,
endTime
).
subtract
(
allMoney
(
getS
,
"出库"
,
"采购退货"
,
"实际"
,
endTime
))).
multiply
(
new
BigDecimal
(
i
)));
return
sum
;
}
public
List
<
DepotHeadVo4List
>
getDetailByNumber
(
String
number
)
throws
Exception
{
List
<
DepotHeadVo4List
>
resList
=
new
ArrayList
<
DepotHeadVo4List
>();
List
<
DepotHeadVo4List
>
list
=
null
;
try
{
list
=
depotHeadMapperEx
.
getDetailByNumber
(
number
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
if
(
null
!=
list
)
{
for
(
DepotHeadVo4List
dh
:
list
)
{
if
(
dh
.
getAccountIdList
()
!=
null
)
{
String
accountidlistStr
=
dh
.
getAccountIdList
().
replace
(
"["
,
""
).
replace
(
"]"
,
""
).
replaceAll
(
"\""
,
""
);
dh
.
setAccountIdList
(
accountidlistStr
);
}
if
(
dh
.
getAccountMoneyList
()
!=
null
)
{
String
accountmoneylistStr
=
dh
.
getAccountMoneyList
().
replace
(
"["
,
""
).
replace
(
"]"
,
""
).
replaceAll
(
"\""
,
""
);
dh
.
setAccountMoneyList
(
accountmoneylistStr
);
}
if
(
dh
.
getOtherMoneyList
()
!=
null
)
{
String
otherMoneyListStr
=
dh
.
getOtherMoneyList
().
replace
(
"["
,
""
).
replace
(
"]"
,
""
).
replaceAll
(
"\""
,
""
);
dh
.
setOtherMoneyList
(
otherMoneyListStr
);
}
if
(
dh
.
getOtherMoneyItem
()
!=
null
)
{
String
otherMoneyItemStr
=
dh
.
getOtherMoneyItem
().
replace
(
"["
,
""
).
replace
(
"]"
,
""
).
replaceAll
(
"\""
,
""
);
dh
.
setOtherMoneyItem
(
otherMoneyItemStr
);
}
if
(
dh
.
getChangeAmount
()
!=
null
)
{
dh
.
setChangeAmount
(
dh
.
getChangeAmount
().
abs
());
}
if
(
dh
.
getTotalPrice
()
!=
null
)
{
dh
.
setTotalPrice
(
dh
.
getTotalPrice
().
abs
());
}
dh
.
setOperTimeStr
(
getCenternTime
(
dh
.
getOperTime
()));
dh
.
setMaterialsList
(
findMaterialsListByHeaderId
(
dh
.
getId
()));
resList
.
add
(
dh
);
}
}
return
resList
;
}
/**
* 新增单据主表及单据子表信息
* @param beanJson
* @param rows
* @param tenantId
* @param request
* @throws Exception
*/
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
void
addDepotHeadAndDetail
(
String
beanJson
,
String
rows
,
Long
tenantId
,
HttpServletRequest
request
)
throws
Exception
{
/**处理单据主表数据*/
DepotHead
depotHead
=
JSONObject
.
parseObject
(
beanJson
,
DepotHead
.
class
);
//判断用户是否已经登录过,登录过不再处理
User
userInfo
=
userService
.
getCurrentUser
();
depotHead
.
setCreator
(
userInfo
==
null
?
null
:
userInfo
.
getId
());
depotHead
.
setCreateTime
(
new
Timestamp
(
System
.
currentTimeMillis
()));
depotHead
.
setStatus
(
BusinessConstants
.
BILLS_STATUS_UN_AUDIT
);
try
{
depotHeadMapper
.
insertSelective
(
depotHead
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
/**入库和出库处理预付款信息*/
if
(
BusinessConstants
.
PAY_TYPE_PREPAID
.
equals
(
depotHead
.
getPayType
())){
if
(
depotHead
.
getOrganId
()!=
null
)
{
supplierService
.
updateAdvanceIn
(
depotHead
.
getOrganId
(),
BigDecimal
.
ZERO
.
subtract
(
depotHead
.
getTotalPrice
()));
}
}
//根据单据编号查询单据id
DepotHeadExample
dhExample
=
new
DepotHeadExample
();
dhExample
.
createCriteria
().
andNumberEqualTo
(
depotHead
.
getNumber
()).
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
DepotHead
>
list
=
depotHeadMapper
.
selectByExample
(
dhExample
);
if
(
list
!=
null
)
{
Long
headId
=
list
.
get
(
0
).
getId
();
/**入库和出库处理单据子表信息*/
depotItemService
.
saveDetials
(
rows
,
headId
,
tenantId
,
request
);
}
/**如果关联单据号非空则更新订单的状态为2 */
if
(
depotHead
.
getLinkNumber
()!=
null
)
{
DepotHead
depotHeadOrders
=
new
DepotHead
();
depotHeadOrders
.
setStatus
(
BusinessConstants
.
BILLS_STATUS_SKIP
);
DepotHeadExample
example
=
new
DepotHeadExample
();
example
.
createCriteria
().
andNumberEqualTo
(
depotHead
.
getLinkNumber
());
try
{
depotHeadMapper
.
updateByExampleSelective
(
depotHeadOrders
,
example
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
}
logService
.
insertLog
(
"单据"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_ADD
).
append
(
depotHead
.
getNumber
()).
toString
(),
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
());
}
/**
* 更新单据主表及单据子表信息
* @param beanJson
* @param rows
* @param preTotalPrice
* @param tenantId
* @param request
* @throws Exception
*/
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
void
updateDepotHeadAndDetail
(
String
beanJson
,
String
rows
,
BigDecimal
preTotalPrice
,
Long
tenantId
,
HttpServletRequest
request
)
throws
Exception
{
/**更新单据主表信息*/
DepotHead
depotHead
=
JSONObject
.
parseObject
(
beanJson
,
DepotHead
.
class
);
try
{
depotHeadMapper
.
updateByPrimaryKeySelective
(
depotHead
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
/**入库和出库处理预付款信息*/
if
(
BusinessConstants
.
PAY_TYPE_PREPAID
.
equals
(
depotHead
.
getPayType
())){
if
(
depotHead
.
getOrganId
()!=
null
){
supplierService
.
updateAdvanceIn
(
depotHead
.
getOrganId
(),
BigDecimal
.
ZERO
.
subtract
(
depotHead
.
getTotalPrice
().
subtract
(
preTotalPrice
)));
}
}
/**入库和出库处理单据子表信息*/
depotItemService
.
saveDetials
(
rows
,
depotHead
.
getId
(),
tenantId
,
request
);
logService
.
insertLog
(
"单据"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_EDIT
).
append
(
depotHead
.
getNumber
()).
toString
(),
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
());
}
public
BigDecimal
getBuyAndSaleStatistics
(
String
type
,
String
subType
,
Integer
hasSupplier
,
String
beginTime
,
String
endTime
)
{
return
depotHeadMapperEx
.
getBuyAndSaleStatistics
(
type
,
subType
,
hasSupplier
,
beginTime
,
endTime
);
}
public
BigDecimal
getBuyAndSaleRetailStatistics
(
String
type
,
String
subType
,
Integer
hasSupplier
,
String
beginTime
,
String
endTime
)
{
return
depotHeadMapperEx
.
getBuyAndSaleRetailStatistics
(
type
,
subType
,
hasSupplier
,
beginTime
,
endTime
);
}
}
jshERP-boot/src/main/java/com/jsh/erp/service/depotItem/DepotItemComponent.java
0 → 100644
View file @
f4ef5aa0
package
com.jsh.erp.service.depotItem
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.service.ICommonQuery
;
import
com.jsh.erp.utils.Constants
;
import
com.jsh.erp.utils.QueryUtils
;
import
com.jsh.erp.utils.StringUtil
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.List
;
import
java.util.Map
;
@Service
(
value
=
"depotItem_component"
)
@DepotItemResource
public
class
DepotItemComponent
implements
ICommonQuery
{
@Resource
private
DepotItemService
depotItemService
;
@Override
public
Object
selectOne
(
Long
id
)
throws
Exception
{
return
depotItemService
.
getDepotItem
(
id
);
}
@Override
public
List
<?>
select
(
Map
<
String
,
String
>
map
)
throws
Exception
{
return
getDepotItemList
(
map
);
}
private
List
<?>
getDepotItemList
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
search
=
map
.
get
(
Constants
.
SEARCH
);
String
name
=
StringUtil
.
getInfo
(
search
,
"name"
);
Integer
type
=
StringUtil
.
parseInteger
(
StringUtil
.
getInfo
(
search
,
"type"
));
String
remark
=
StringUtil
.
getInfo
(
search
,
"remark"
);
String
order
=
QueryUtils
.
order
(
map
);
return
depotItemService
.
select
(
name
,
type
,
remark
,
QueryUtils
.
offset
(
map
),
QueryUtils
.
rows
(
map
));
}
@Override
public
Long
counts
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
search
=
map
.
get
(
Constants
.
SEARCH
);
String
name
=
StringUtil
.
getInfo
(
search
,
"name"
);
Integer
type
=
StringUtil
.
parseInteger
(
StringUtil
.
getInfo
(
search
,
"type"
));
String
remark
=
StringUtil
.
getInfo
(
search
,
"remark"
);
return
depotItemService
.
countDepotItem
(
name
,
type
,
remark
);
}
@Override
public
int
insert
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
return
depotItemService
.
insertDepotItem
(
obj
,
request
);
}
@Override
public
int
update
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
return
depotItemService
.
updateDepotItem
(
obj
,
request
);
}
@Override
public
int
delete
(
Long
id
,
HttpServletRequest
request
)
throws
Exception
{
return
depotItemService
.
deleteDepotItem
(
id
,
request
);
}
@Override
public
int
deleteBatch
(
String
ids
,
HttpServletRequest
request
)
throws
Exception
{
return
depotItemService
.
batchDeleteDepotItem
(
ids
,
request
);
}
@Override
public
int
checkIsNameExist
(
Long
id
,
String
name
)
throws
Exception
{
return
depotItemService
.
checkIsNameExist
(
id
,
name
);
}
}
jshERP-boot/src/main/java/com/jsh/erp/service/depotItem/DepotItemResource.java
0 → 100644
View file @
f4ef5aa0
package
com.jsh.erp.service.depotItem
;
import
com.jsh.erp.service.ResourceInfo
;
import
java.lang.annotation.*
;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo
(
value
=
"depotItem"
)
@Inherited
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
DepotItemResource
{
}
jshERP-boot/src/main/java/com/jsh/erp/service/depotItem/DepotItemService.java
0 → 100644
View file @
f4ef5aa0
package
com.jsh.erp.service.depotItem
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.constants.BusinessConstants
;
import
com.jsh.erp.constants.ExceptionConstants
;
import
com.jsh.erp.datasource.entities.*
;
import
com.jsh.erp.datasource.mappers.*
;
import
com.jsh.erp.datasource.vo.DepotItemStockWarningCount
;
import
com.jsh.erp.datasource.vo.DepotItemVo4Stock
;
import
com.jsh.erp.exception.BusinessRunTimeException
;
import
com.jsh.erp.exception.JshException
;
import
com.jsh.erp.service.materialExtend.MaterialExtendService
;
import
com.jsh.erp.service.log.LogService
;
import
com.jsh.erp.service.material.MaterialService
;
import
com.jsh.erp.service.serialNumber.SerialNumberService
;
import
com.jsh.erp.service.systemConfig.SystemConfigService
;
import
com.jsh.erp.service.user.UserService
;
import
com.jsh.erp.utils.QueryUtils
;
import
com.jsh.erp.utils.StringUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.math.BigDecimal
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Map
;
@Service
public
class
DepotItemService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
DepotItemService
.
class
);
private
final
static
String
TYPE
=
"入库"
;
private
final
static
String
SUM_TYPE
=
"number"
;
private
final
static
String
IN
=
"in"
;
private
final
static
String
OUT
=
"out"
;
@Resource
private
DepotItemMapper
depotItemMapper
;
@Resource
private
DepotItemMapperEx
depotItemMapperEx
;
@Resource
private
MaterialService
materialService
;
@Resource
private
MaterialExtendService
materialExtendService
;
@Resource
SerialNumberMapperEx
serialNumberMapperEx
;
@Resource
private
DepotHeadMapper
depotHeadMapper
;
@Resource
SerialNumberService
serialNumberService
;
@Resource
private
UserService
userService
;
@Resource
private
SystemConfigService
systemConfigService
;
@Resource
private
MaterialCurrentStockMapper
materialCurrentStockMapper
;
@Resource
private
LogService
logService
;
public
DepotItem
getDepotItem
(
long
id
)
throws
Exception
{
DepotItem
result
=
null
;
try
{
result
=
depotItemMapper
.
selectByPrimaryKey
(
id
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
public
List
<
DepotItem
>
getDepotItem
()
throws
Exception
{
DepotItemExample
example
=
new
DepotItemExample
();
example
.
createCriteria
().
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
DepotItem
>
list
=
null
;
try
{
list
=
depotItemMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
List
<
DepotItem
>
select
(
String
name
,
Integer
type
,
String
remark
,
int
offset
,
int
rows
)
throws
Exception
{
List
<
DepotItem
>
list
=
null
;
try
{
list
=
depotItemMapperEx
.
selectByConditionDepotItem
(
name
,
type
,
remark
,
offset
,
rows
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
Long
countDepotItem
(
String
name
,
Integer
type
,
String
remark
)
throws
Exception
{
Long
result
=
null
;
try
{
result
=
depotItemMapperEx
.
countsByDepotItem
(
name
,
type
,
remark
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
insertDepotItem
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
DepotItem
depotItem
=
JSONObject
.
parseObject
(
obj
.
toJSONString
(),
DepotItem
.
class
);
int
result
=
0
;
try
{
result
=
depotItemMapper
.
insertSelective
(
depotItem
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
updateDepotItem
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
DepotItem
depotItem
=
JSONObject
.
parseObject
(
obj
.
toJSONString
(),
DepotItem
.
class
);
int
result
=
0
;
try
{
result
=
depotItemMapper
.
updateByPrimaryKeySelective
(
depotItem
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
deleteDepotItem
(
Long
id
,
HttpServletRequest
request
)
throws
Exception
{
int
result
=
0
;
try
{
result
=
depotItemMapper
.
deleteByPrimaryKey
(
id
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchDeleteDepotItem
(
String
ids
,
HttpServletRequest
request
)
throws
Exception
{
List
<
Long
>
idList
=
StringUtil
.
strToLongList
(
ids
);
DepotItemExample
example
=
new
DepotItemExample
();
example
.
createCriteria
().
andIdIn
(
idList
);
int
result
=
0
;
try
{
result
=
depotItemMapper
.
deleteByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
public
int
checkIsNameExist
(
Long
id
,
String
name
)
throws
Exception
{
DepotItemExample
example
=
new
DepotItemExample
();
example
.
createCriteria
().
andIdNotEqualTo
(
id
).
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
DepotItem
>
list
=
null
;
try
{
list
=
depotItemMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
==
null
?
0
:
list
.
size
();
}
public
List
<
DepotItemVo4DetailByTypeAndMId
>
findDetailByTypeAndMaterialIdList
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
mIdStr
=
map
.
get
(
"mId"
);
Long
mId
=
null
;
if
(!
StringUtil
.
isEmpty
(
mIdStr
))
{
mId
=
Long
.
parseLong
(
mIdStr
);
}
List
<
DepotItemVo4DetailByTypeAndMId
>
list
=
null
;
try
{
list
=
depotItemMapperEx
.
findDetailByTypeAndMaterialIdList
(
mId
,
QueryUtils
.
offset
(
map
),
QueryUtils
.
rows
(
map
));
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
Long
findDetailByTypeAndMaterialIdCounts
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
mIdStr
=
map
.
get
(
"mId"
);
Long
mId
=
null
;
if
(!
StringUtil
.
isEmpty
(
mIdStr
))
{
mId
=
Long
.
parseLong
(
mIdStr
);
}
Long
result
=
null
;
try
{
result
=
depotItemMapperEx
.
findDetailByTypeAndMaterialIdCounts
(
mId
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
insertDepotItemWithObj
(
DepotItem
depotItem
)
throws
Exception
{
int
result
=
0
;
try
{
result
=
depotItemMapper
.
insertSelective
(
depotItem
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
updateDepotItemWithObj
(
DepotItem
depotItem
)
throws
Exception
{
int
result
=
0
;
try
{
result
=
depotItemMapper
.
updateByPrimaryKeySelective
(
depotItem
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
public
List
<
DepotItem
>
getListByHeaderId
(
Long
headerId
)
throws
Exception
{
List
<
DepotItem
>
list
=
null
;
try
{
DepotItemExample
example
=
new
DepotItemExample
();
example
.
createCriteria
().
andHeaderIdEqualTo
(
headerId
);
list
=
depotItemMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
List
<
DepotItemVo4WithInfoEx
>
getDetailList
(
Long
headerId
)
throws
Exception
{
List
<
DepotItemVo4WithInfoEx
>
list
=
null
;
try
{
list
=
depotItemMapperEx
.
getDetailList
(
headerId
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
List
<
DepotItemVo4WithInfoEx
>
findByAll
(
String
materialParam
,
String
endTime
,
Integer
offset
,
Integer
rows
)
throws
Exception
{
List
<
DepotItemVo4WithInfoEx
>
list
=
null
;
try
{
list
=
depotItemMapperEx
.
findByAll
(
materialParam
,
endTime
,
offset
,
rows
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
int
findByAllCount
(
String
materialParam
,
String
endTime
)
throws
Exception
{
int
result
=
0
;
try
{
result
=
depotItemMapperEx
.
findByAllCount
(
materialParam
,
endTime
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
public
BigDecimal
buyOrSale
(
String
type
,
String
subType
,
Long
MId
,
String
MonthTime
,
String
sumType
)
throws
Exception
{
BigDecimal
result
=
BigDecimal
.
ZERO
;
try
{
if
(
SUM_TYPE
.
equals
(
sumType
))
{
result
=
depotItemMapperEx
.
buyOrSaleNumber
(
type
,
subType
,
MId
,
MonthTime
,
sumType
);
}
else
{
result
=
depotItemMapperEx
.
buyOrSalePrice
(
type
,
subType
,
MId
,
MonthTime
,
sumType
);
}
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
/**
* 统计采购或销售的总金额
* @param type
* @param subType
* @param MonthTime
* @return
* @throws Exception
*/
public
BigDecimal
inOrOutPrice
(
String
type
,
String
subType
,
String
MonthTime
)
throws
Exception
{
BigDecimal
result
=
BigDecimal
.
ZERO
;
try
{
result
=
depotItemMapperEx
.
inOrOutPrice
(
type
,
subType
,
MonthTime
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
void
saveDetials
(
String
rows
,
Long
headerId
,
Long
tenantId
,
HttpServletRequest
request
)
throws
Exception
{
//查询单据主表信息
DepotHead
depotHead
=
depotHeadMapper
.
selectByPrimaryKey
(
headerId
);
//获得当前操作人
User
userInfo
=
userService
.
getCurrentUser
();
//首先回收序列号,如果是调拨,不用处理序列号
if
(
BusinessConstants
.
DEPOTHEAD_TYPE_OUT
.
equals
(
depotHead
.
getType
())
&&!
BusinessConstants
.
SUB_TYPE_TRANSFER
.
equals
(
depotHead
.
getSubType
())){
List
<
DepotItem
>
depotItemList
=
getListByHeaderId
(
headerId
);
for
(
DepotItem
depotItem
:
depotItemList
){
Material
material
=
materialService
.
getMaterial
(
depotItem
.
getMaterialId
());
if
(
material
==
null
){
continue
;
}
if
(
BusinessConstants
.
ENABLE_SERIAL_NUMBER_ENABLED
.
equals
(
material
.
getEnableSerialNumber
())){
serialNumberService
.
cancelSerialNumber
(
depotItem
.
getMaterialId
(),
depotItem
.
getHeaderId
(),
(
depotItem
.
getBasicNumber
()==
null
?
0
:
depotItem
.
getBasicNumber
()).
intValue
(),
userInfo
);
}
}
}
//删除单据的明细
deleteDepotItemHeadId
(
headerId
);
JSONArray
rowArr
=
JSONArray
.
parseArray
(
rows
);
if
(
null
!=
rowArr
)
{
for
(
int
i
=
0
;
i
<
rowArr
.
size
();
i
++)
{
DepotItem
depotItem
=
new
DepotItem
();
JSONObject
rowObj
=
JSONObject
.
parseObject
(
rowArr
.
getString
(
i
));
depotItem
.
setHeaderId
(
headerId
);
String
barCode
=
rowObj
.
getString
(
"barCode"
);
MaterialExtend
materialExtend
=
materialExtendService
.
getInfoByBarCode
(
barCode
);
depotItem
.
setMaterialId
(
materialExtend
.
getMaterialId
());
depotItem
.
setMaterialExtendId
(
materialExtend
.
getId
());
depotItem
.
setMaterialUnit
(
rowObj
.
getString
(
"unit"
));
if
(
StringUtil
.
isExist
(
rowObj
.
get
(
"operNumber"
)))
{
depotItem
.
setOperNumber
(
rowObj
.
getBigDecimal
(
"operNumber"
));
String
unit
=
rowObj
.
get
(
"unit"
).
toString
();
BigDecimal
oNumber
=
rowObj
.
getBigDecimal
(
"operNumber"
);
//以下进行单位换算
Unit
unitInfo
=
materialService
.
findUnit
(
materialExtend
.
getMaterialId
());
//查询计量单位信息
if
(
StringUtil
.
isNotEmpty
(
unitInfo
.
getName
()))
{
String
basicUnit
=
unitInfo
.
getBasicUnit
();
//基本单位
String
otherUnit
=
unitInfo
.
getOtherUnit
();
//副单位
Integer
ratio
=
unitInfo
.
getRatio
();
//比例
if
(
unit
.
equals
(
basicUnit
))
{
//如果等于基础单位
depotItem
.
setBasicNumber
(
oNumber
);
//数量一致
}
else
if
(
unit
.
equals
(
otherUnit
))
{
//如果等于副单位
depotItem
.
setBasicNumber
(
oNumber
.
multiply
(
new
BigDecimal
(
ratio
))
);
//数量乘以比例
}
}
else
{
depotItem
.
setBasicNumber
(
oNumber
);
//其他情况
}
}
if
(
StringUtil
.
isExist
(
rowObj
.
get
(
"unitPrice"
)))
{
depotItem
.
setUnitPrice
(
rowObj
.
getBigDecimal
(
"unitPrice"
));
}
if
(
StringUtil
.
isExist
(
rowObj
.
get
(
"taxUnitPrice"
)))
{
depotItem
.
setTaxUnitPrice
(
rowObj
.
getBigDecimal
(
"taxUnitPrice"
));
}
if
(
StringUtil
.
isExist
(
rowObj
.
get
(
"allPrice"
)))
{
depotItem
.
setAllPrice
(
rowObj
.
getBigDecimal
(
"allPrice"
));
}
if
(
StringUtil
.
isExist
(
rowObj
.
get
(
"depotId"
)))
{
depotItem
.
setDepotId
(
rowObj
.
getLong
(
"depotId"
));
}
else
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
DEPOT_HEAD_DEPOT_FAILED_CODE
,
String
.
format
(
ExceptionConstants
.
DEPOT_HEAD_DEPOT_FAILED_MSG
));
}
if
(
BusinessConstants
.
SUB_TYPE_TRANSFER
.
equals
(
depotHead
.
getSubType
()))
{
if
(
StringUtil
.
isExist
(
rowObj
.
get
(
"anotherDepotId"
)))
{
depotItem
.
setAnotherDepotId
(
rowObj
.
getLong
(
"anotherDepotId"
));
}
else
{
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
DEPOT_HEAD_ANOTHER_DEPOT_FAILED_CODE
,
String
.
format
(
ExceptionConstants
.
DEPOT_HEAD_ANOTHER_DEPOT_FAILED_MSG
));
}
}
if
(
StringUtil
.
isExist
(
rowObj
.
get
(
"taxRate"
)))
{
depotItem
.
setTaxRate
(
rowObj
.
getBigDecimal
(
"taxRate"
));
}
if
(
StringUtil
.
isExist
(
rowObj
.
get
(
"taxMoney"
)))
{
depotItem
.
setTaxMoney
(
rowObj
.
getBigDecimal
(
"taxMoney"
));
}
if
(
StringUtil
.
isExist
(
rowObj
.
get
(
"taxLastMoney"
)))
{
depotItem
.
setTaxLastMoney
(
rowObj
.
getBigDecimal
(
"taxLastMoney"
));
}
if
(
StringUtil
.
isExist
(
rowObj
.
get
(
"mType"
)))
{
depotItem
.
setMaterialType
(
rowObj
.
getString
(
"mType"
));
}
if
(
StringUtil
.
isExist
(
rowObj
.
get
(
"remark"
)))
{
depotItem
.
setRemark
(
rowObj
.
getString
(
"remark"
));
}
//出库时判断库存是否充足
if
(
BusinessConstants
.
DEPOTHEAD_TYPE_OUT
.
equals
(
depotHead
.
getType
())){
if
(
depotItem
==
null
){
continue
;
}
Material
material
=
materialService
.
getMaterial
(
depotItem
.
getMaterialId
());
if
(
material
==
null
){
continue
;
}
BigDecimal
stock
=
getStockByParam
(
depotItem
.
getDepotId
(),
depotItem
.
getMaterialId
(),
null
,
null
,
tenantId
);
BigDecimal
thisBasicNumber
=
depotItem
.
getBasicNumber
()==
null
?
BigDecimal
.
ZERO
:
depotItem
.
getBasicNumber
();
if
(
systemConfigService
.
getMinusStockFlag
()
==
false
&&
stock
.
compareTo
(
thisBasicNumber
)<
0
){
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
MATERIAL_STOCK_NOT_ENOUGH_CODE
,
String
.
format
(
ExceptionConstants
.
MATERIAL_STOCK_NOT_ENOUGH_MSG
,
material
==
null
?
""
:
material
.
getName
()));
}
//出库时处理序列号
if
(!
BusinessConstants
.
SUB_TYPE_TRANSFER
.
equals
(
depotHead
.
getSubType
()))
{
//判断商品是否开启序列号,开启的收回序列号,未开启的跳过
if
(
BusinessConstants
.
ENABLE_SERIAL_NUMBER_ENABLED
.
equals
(
material
.
getEnableSerialNumber
()))
{
//查询单据子表中开启序列号的数据列表
serialNumberService
.
checkAndUpdateSerialNumber
(
depotItem
,
userInfo
);
}
}
}
this
.
insertDepotItemWithObj
(
depotItem
);
//更新当前库存
updateCurrentStock
(
depotItem
,
tenantId
);
}
}
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
void
deleteDepotItemHeadId
(
Long
headerId
)
throws
Exception
{
DepotItemExample
example
=
new
DepotItemExample
();
example
.
createCriteria
().
andHeaderIdEqualTo
(
headerId
);
try
{
depotItemMapper
.
deleteByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
List
<
DepotItemStockWarningCount
>
findStockWarningCount
(
Integer
offset
,
Integer
rows
,
String
materialParam
,
Long
depotId
)
{
List
<
DepotItemStockWarningCount
>
list
=
null
;
try
{
list
=
depotItemMapperEx
.
findStockWarningCount
(
offset
,
rows
,
materialParam
,
depotId
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
findStockWarningCountTotal
(
String
materialParam
,
Long
depotId
)
{
int
result
=
0
;
try
{
result
=
depotItemMapperEx
.
findStockWarningCountTotal
(
materialParam
,
depotId
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
/**
* 库存统计
* @param depotId
* @param mId
* @param beginTime
* @param endTime
* @return
*/
public
BigDecimal
getStockByParam
(
Long
depotId
,
Long
mId
,
String
beginTime
,
String
endTime
,
Long
tenantId
){
//初始库存
BigDecimal
initStock
=
materialService
.
getInitStockByMid
(
depotId
,
mId
);
//盘点复盘后数量的变动
BigDecimal
stockCheckSum
=
depotItemMapperEx
.
getStockCheckSum
(
depotId
,
mId
,
beginTime
,
endTime
);
DepotItemVo4Stock
stockObj
=
depotItemMapperEx
.
getStockByParam
(
depotId
,
mId
,
beginTime
,
endTime
,
tenantId
);
BigDecimal
intNum
=
stockObj
.
getInNum
();
BigDecimal
outNum
=
stockObj
.
getOutNum
();
return
initStock
.
add
(
intNum
).
subtract
(
outNum
).
add
(
stockCheckSum
);
}
/**
* 入库统计
* @param depotId
* @param mId
* @param beginTime
* @param endTime
* @return
*/
public
BigDecimal
getInNumByParam
(
Long
depotId
,
Long
mId
,
String
beginTime
,
String
endTime
,
Long
tenantId
){
DepotItemVo4Stock
stockObj
=
depotItemMapperEx
.
getStockByParam
(
depotId
,
mId
,
beginTime
,
endTime
,
tenantId
);
return
stockObj
.
getInNum
();
}
/**
* 出库统计
* @param depotId
* @param mId
* @param beginTime
* @param endTime
* @return
*/
public
BigDecimal
getOutNumByParam
(
Long
depotId
,
Long
mId
,
String
beginTime
,
String
endTime
,
Long
tenantId
){
DepotItemVo4Stock
stockObj
=
depotItemMapperEx
.
getStockByParam
(
depotId
,
mId
,
beginTime
,
endTime
,
tenantId
);
return
stockObj
.
getOutNum
();
}
/**
* 根据单据明细来批量更新当前库存
* @param depotItem
* @param tenantId
*/
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
void
updateCurrentStock
(
DepotItem
depotItem
,
Long
tenantId
){
updateCurrentStockFun
(
depotItem
.
getMaterialId
(),
depotItem
.
getDepotId
(),
tenantId
);
if
(
depotItem
.
getAnotherDepotId
()!=
null
){
updateCurrentStockFun
(
depotItem
.
getMaterialId
(),
depotItem
.
getAnotherDepotId
(),
tenantId
);
}
}
/**
* 根据商品和仓库来更新当前库存
* @param mId
* @param dId
* @param tenantId
*/
public
void
updateCurrentStockFun
(
Long
mId
,
Long
dId
,
Long
tenantId
)
{
MaterialCurrentStockExample
example
=
new
MaterialCurrentStockExample
();
example
.
createCriteria
().
andMaterialIdEqualTo
(
mId
).
andDepotIdEqualTo
(
dId
)
.
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
MaterialCurrentStock
>
list
=
materialCurrentStockMapper
.
selectByExample
(
example
);
MaterialCurrentStock
materialCurrentStock
=
new
MaterialCurrentStock
();
materialCurrentStock
.
setMaterialId
(
mId
);
materialCurrentStock
.
setDepotId
(
dId
);
materialCurrentStock
.
setCurrentNumber
(
getStockByParam
(
dId
,
mId
,
null
,
null
,
tenantId
));
if
(
list
!=
null
&&
list
.
size
()>
0
)
{
Long
mcsId
=
list
.
get
(
0
).
getId
();
materialCurrentStock
.
setId
(
mcsId
);
materialCurrentStockMapper
.
updateByPrimaryKeySelective
(
materialCurrentStock
);
}
else
{
materialCurrentStockMapper
.
insertSelective
(
materialCurrentStock
);
}
}
}
jshERP-boot/src/main/java/com/jsh/erp/service/functions/FunctionComponent.java
0 → 100644
View file @
f4ef5aa0
package
com.jsh.erp.service.functions
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.service.ICommonQuery
;
import
com.jsh.erp.utils.Constants
;
import
com.jsh.erp.utils.QueryUtils
;
import
com.jsh.erp.utils.StringUtil
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.List
;
import
java.util.Map
;
@Service
(
value
=
"function_component"
)
@FunctionResource
public
class
FunctionComponent
implements
ICommonQuery
{
@Resource
private
FunctionService
functionService
;
@Override
public
Object
selectOne
(
Long
id
)
throws
Exception
{
return
functionService
.
getFunction
(
id
);
}
@Override
public
List
<?>
select
(
Map
<
String
,
String
>
map
)
throws
Exception
{
return
getFunctionsList
(
map
);
}
private
List
<?>
getFunctionsList
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
search
=
map
.
get
(
Constants
.
SEARCH
);
String
name
=
StringUtil
.
getInfo
(
search
,
"name"
);
String
type
=
StringUtil
.
getInfo
(
search
,
"type"
);
String
order
=
QueryUtils
.
order
(
map
);
return
functionService
.
select
(
name
,
type
,
QueryUtils
.
offset
(
map
),
QueryUtils
.
rows
(
map
));
}
@Override
public
Long
counts
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
search
=
map
.
get
(
Constants
.
SEARCH
);
String
name
=
StringUtil
.
getInfo
(
search
,
"name"
);
String
type
=
StringUtil
.
getInfo
(
search
,
"type"
);
return
functionService
.
countFunction
(
name
,
type
);
}
@Override
public
int
insert
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
return
functionService
.
insertFunction
(
obj
,
request
);
}
@Override
public
int
update
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
return
functionService
.
updateFunction
(
obj
,
request
);
}
@Override
public
int
delete
(
Long
id
,
HttpServletRequest
request
)
throws
Exception
{
return
functionService
.
deleteFunction
(
id
,
request
);
}
@Override
public
int
deleteBatch
(
String
ids
,
HttpServletRequest
request
)
throws
Exception
{
return
functionService
.
batchDeleteFunction
(
ids
,
request
);
}
@Override
public
int
checkIsNameExist
(
Long
id
,
String
name
)
throws
Exception
{
return
functionService
.
checkIsNameExist
(
id
,
name
);
}
}
jshERP-boot/src/main/java/com/jsh/erp/service/functions/FunctionResource.java
0 → 100644
View file @
f4ef5aa0
package
com.jsh.erp.service.functions
;
import
com.jsh.erp.service.ResourceInfo
;
import
java.lang.annotation.*
;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo
(
value
=
"function"
)
@Inherited
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
FunctionResource
{
}
jshERP-boot/src/main/java/com/jsh/erp/service/functions/FunctionService.java
0 → 100644
View file @
f4ef5aa0
package
com.jsh.erp.service.functions
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.constants.BusinessConstants
;
import
com.jsh.erp.datasource.entities.Function
;
import
com.jsh.erp.datasource.entities.FunctionExample
;
import
com.jsh.erp.datasource.entities.User
;
import
com.jsh.erp.datasource.mappers.FunctionMapper
;
import
com.jsh.erp.datasource.mappers.FunctionMapperEx
;
import
com.jsh.erp.exception.JshException
;
import
com.jsh.erp.service.log.LogService
;
import
com.jsh.erp.service.user.UserService
;
import
com.jsh.erp.utils.StringUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
@Service
public
class
FunctionService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
FunctionService
.
class
);
@Resource
private
FunctionMapper
functionsMapper
;
@Resource
private
FunctionMapperEx
functionMapperEx
;
@Resource
private
UserService
userService
;
@Resource
private
LogService
logService
;
public
Function
getFunction
(
long
id
)
throws
Exception
{
Function
result
=
null
;
try
{
result
=
functionsMapper
.
selectByPrimaryKey
(
id
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
public
List
<
Function
>
getFunctionListByIds
(
String
ids
)
throws
Exception
{
List
<
Long
>
idList
=
StringUtil
.
strToLongList
(
ids
);
List
<
Function
>
list
=
new
ArrayList
<>();
try
{
FunctionExample
example
=
new
FunctionExample
();
example
.
createCriteria
().
andIdIn
(
idList
);
list
=
functionsMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
List
<
Function
>
getFunction
()
throws
Exception
{
FunctionExample
example
=
new
FunctionExample
();
example
.
createCriteria
().
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
Function
>
list
=
null
;
try
{
list
=
functionsMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
List
<
Function
>
select
(
String
name
,
String
type
,
int
offset
,
int
rows
)
throws
Exception
{
List
<
Function
>
list
=
null
;
try
{
list
=
functionMapperEx
.
selectByConditionFunction
(
name
,
type
,
offset
,
rows
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
Long
countFunction
(
String
name
,
String
type
)
throws
Exception
{
Long
result
=
null
;
try
{
result
=
functionMapperEx
.
countsByFunction
(
name
,
type
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
insertFunction
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
Function
functions
=
JSONObject
.
parseObject
(
obj
.
toJSONString
(),
Function
.
class
);
int
result
=
0
;
try
{
result
=
functionsMapper
.
insertSelective
(
functions
);
logService
.
insertLog
(
"功能"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_ADD
).
append
(
functions
.
getName
()).
toString
(),
request
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
updateFunction
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
Function
functions
=
JSONObject
.
parseObject
(
obj
.
toJSONString
(),
Function
.
class
);
int
result
=
0
;
try
{
result
=
functionsMapper
.
updateByPrimaryKeySelective
(
functions
);
logService
.
insertLog
(
"功能"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_EDIT
).
append
(
functions
.
getName
()).
toString
(),
request
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
deleteFunction
(
Long
id
,
HttpServletRequest
request
)
throws
Exception
{
return
batchDeleteFunctionByIds
(
id
.
toString
());
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchDeleteFunction
(
String
ids
,
HttpServletRequest
request
)
throws
Exception
{
return
batchDeleteFunctionByIds
(
ids
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchDeleteFunctionByIds
(
String
ids
)
throws
Exception
{
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
BusinessConstants
.
LOG_OPERATION_TYPE_DELETE
);
List
<
Function
>
list
=
getFunctionListByIds
(
ids
);
for
(
Function
functions:
list
){
sb
.
append
(
"["
).
append
(
functions
.
getName
()).
append
(
"]"
);
}
logService
.
insertLog
(
"功能"
,
sb
.
toString
(),
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
());
User
userInfo
=
userService
.
getCurrentUser
();
String
[]
idArray
=
ids
.
split
(
","
);
int
result
=
0
;
try
{
result
=
functionMapperEx
.
batchDeleteFunctionByIds
(
new
Date
(),
userInfo
==
null
?
null
:
userInfo
.
getId
(),
idArray
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
public
int
checkIsNameExist
(
Long
id
,
String
name
)
throws
Exception
{
FunctionExample
example
=
new
FunctionExample
();
example
.
createCriteria
().
andIdNotEqualTo
(
id
).
andNameEqualTo
(
name
).
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
Function
>
list
=
null
;
try
{
list
=
functionsMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
==
null
?
0
:
list
.
size
();
}
public
List
<
Function
>
getRoleFunction
(
String
pNumber
)
throws
Exception
{
FunctionExample
example
=
new
FunctionExample
();
example
.
createCriteria
().
andEnabledEqualTo
(
true
).
andParentNumberEqualTo
(
pNumber
)
.
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
example
.
setOrderByClause
(
"Sort"
);
List
<
Function
>
list
=
null
;
try
{
list
=
functionsMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
List
<
Function
>
findRoleFunction
(
String
pnumber
)
throws
Exception
{
FunctionExample
example
=
new
FunctionExample
();
example
.
createCriteria
().
andEnabledEqualTo
(
true
).
andParentNumberEqualTo
(
pnumber
)
.
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
example
.
setOrderByClause
(
"Sort"
);
List
<
Function
>
list
=
null
;
try
{
list
=
functionsMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
List
<
Function
>
findByIds
(
String
functionsIds
)
throws
Exception
{
List
<
Long
>
idList
=
StringUtil
.
strToLongList
(
functionsIds
);
FunctionExample
example
=
new
FunctionExample
();
example
.
createCriteria
().
andEnabledEqualTo
(
true
).
andIdIn
(
idList
)
.
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
example
.
setOrderByClause
(
"Sort asc"
);
List
<
Function
>
list
=
null
;
try
{
list
=
functionsMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
}
jshERP-boot/src/main/java/com/jsh/erp/service/inOutItem/InOutItemComponent.java
0 → 100644
View file @
f4ef5aa0
package
com.jsh.erp.service.inOutItem
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.service.ICommonQuery
;
import
com.jsh.erp.utils.Constants
;
import
com.jsh.erp.utils.QueryUtils
;
import
com.jsh.erp.utils.StringUtil
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.List
;
import
java.util.Map
;
@Service
(
value
=
"inOutItem_component"
)
@InOutItemResource
public
class
InOutItemComponent
implements
ICommonQuery
{
@Resource
private
InOutItemService
inOutItemService
;
@Override
public
Object
selectOne
(
Long
id
)
throws
Exception
{
return
inOutItemService
.
getInOutItem
(
id
);
}
@Override
public
List
<?>
select
(
Map
<
String
,
String
>
map
)
throws
Exception
{
return
getFunctionsList
(
map
);
}
private
List
<?>
getFunctionsList
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
search
=
map
.
get
(
Constants
.
SEARCH
);
String
name
=
StringUtil
.
getInfo
(
search
,
"name"
);
String
type
=
StringUtil
.
getInfo
(
search
,
"type"
);
String
remark
=
StringUtil
.
getInfo
(
search
,
"remark"
);
String
order
=
QueryUtils
.
order
(
map
);
return
inOutItemService
.
select
(
name
,
type
,
remark
,
QueryUtils
.
offset
(
map
),
QueryUtils
.
rows
(
map
));
}
@Override
public
Long
counts
(
Map
<
String
,
String
>
map
)
throws
Exception
{
String
search
=
map
.
get
(
Constants
.
SEARCH
);
String
name
=
StringUtil
.
getInfo
(
search
,
"name"
);
String
type
=
StringUtil
.
getInfo
(
search
,
"type"
);
String
remark
=
StringUtil
.
getInfo
(
search
,
"remark"
);
return
inOutItemService
.
countInOutItem
(
name
,
type
,
remark
);
}
@Override
public
int
insert
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
return
inOutItemService
.
insertInOutItem
(
obj
,
request
);
}
@Override
public
int
update
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
return
inOutItemService
.
updateInOutItem
(
obj
,
request
);
}
@Override
public
int
delete
(
Long
id
,
HttpServletRequest
request
)
throws
Exception
{
return
inOutItemService
.
deleteInOutItem
(
id
,
request
);
}
@Override
public
int
deleteBatch
(
String
ids
,
HttpServletRequest
request
)
throws
Exception
{
return
inOutItemService
.
batchDeleteInOutItem
(
ids
,
request
);
}
@Override
public
int
checkIsNameExist
(
Long
id
,
String
name
)
throws
Exception
{
return
inOutItemService
.
checkIsNameExist
(
id
,
name
);
}
}
jshERP-boot/src/main/java/com/jsh/erp/service/inOutItem/InOutItemResource.java
0 → 100644
View file @
f4ef5aa0
package
com.jsh.erp.service.inOutItem
;
import
com.jsh.erp.service.ResourceInfo
;
import
java.lang.annotation.*
;
/**
* @author jishenghua qq752718920 2018-10-7 15:26:27
*/
@ResourceInfo
(
value
=
"inOutItem"
)
@Inherited
@Target
(
ElementType
.
TYPE
)
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
@interface
InOutItemResource
{
}
jshERP-boot/src/main/java/com/jsh/erp/service/inOutItem/InOutItemService.java
0 → 100644
View file @
f4ef5aa0
package
com.jsh.erp.service.inOutItem
;
import
com.alibaba.fastjson.JSONObject
;
import
com.baomidou.mybatisplus.core.toolkit.StringUtils
;
import
com.jsh.erp.constants.BusinessConstants
;
import
com.jsh.erp.constants.ExceptionConstants
;
import
com.jsh.erp.datasource.entities.*
;
import
com.jsh.erp.datasource.mappers.AccountItemMapperEx
;
import
com.jsh.erp.datasource.mappers.InOutItemMapper
;
import
com.jsh.erp.datasource.mappers.InOutItemMapperEx
;
import
com.jsh.erp.exception.BusinessRunTimeException
;
import
com.jsh.erp.exception.JshException
;
import
com.jsh.erp.service.log.LogService
;
import
com.jsh.erp.service.user.UserService
;
import
com.jsh.erp.utils.StringUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.web.context.request.RequestContextHolder
;
import
org.springframework.web.context.request.ServletRequestAttributes
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
@Service
public
class
InOutItemService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
InOutItemService
.
class
);
@Resource
private
InOutItemMapper
inOutItemMapper
;
@Resource
private
InOutItemMapperEx
inOutItemMapperEx
;
@Resource
private
UserService
userService
;
@Resource
private
LogService
logService
;
@Resource
private
AccountItemMapperEx
accountItemMapperEx
;
public
InOutItem
getInOutItem
(
long
id
)
throws
Exception
{
InOutItem
result
=
null
;
try
{
result
=
inOutItemMapper
.
selectByPrimaryKey
(
id
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
public
List
<
InOutItem
>
getInOutItemListByIds
(
String
ids
)
throws
Exception
{
List
<
Long
>
idList
=
StringUtil
.
strToLongList
(
ids
);
List
<
InOutItem
>
list
=
new
ArrayList
<>();
try
{
InOutItemExample
example
=
new
InOutItemExample
();
example
.
createCriteria
().
andIdIn
(
idList
);
list
=
inOutItemMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
List
<
InOutItem
>
getInOutItem
()
throws
Exception
{
InOutItemExample
example
=
new
InOutItemExample
();
example
.
createCriteria
().
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
InOutItem
>
list
=
null
;
try
{
list
=
inOutItemMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
List
<
InOutItem
>
select
(
String
name
,
String
type
,
String
remark
,
int
offset
,
int
rows
)
throws
Exception
{
List
<
InOutItem
>
list
=
null
;
try
{
list
=
inOutItemMapperEx
.
selectByConditionInOutItem
(
name
,
type
,
remark
,
offset
,
rows
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
public
Long
countInOutItem
(
String
name
,
String
type
,
String
remark
)
throws
Exception
{
Long
result
=
null
;
try
{
result
=
inOutItemMapperEx
.
countsByInOutItem
(
name
,
type
,
remark
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
insertInOutItem
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
InOutItem
inOutItem
=
JSONObject
.
parseObject
(
obj
.
toJSONString
(),
InOutItem
.
class
);
int
result
=
0
;
try
{
result
=
inOutItemMapper
.
insertSelective
(
inOutItem
);
logService
.
insertLog
(
"收支项目"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_ADD
).
append
(
inOutItem
.
getName
()).
toString
(),
request
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
updateInOutItem
(
JSONObject
obj
,
HttpServletRequest
request
)
throws
Exception
{
InOutItem
inOutItem
=
JSONObject
.
parseObject
(
obj
.
toJSONString
(),
InOutItem
.
class
);
int
result
=
0
;
try
{
result
=
inOutItemMapper
.
updateByPrimaryKeySelective
(
inOutItem
);
logService
.
insertLog
(
"收支项目"
,
new
StringBuffer
(
BusinessConstants
.
LOG_OPERATION_TYPE_EDIT
).
append
(
inOutItem
.
getName
()).
toString
(),
request
);
}
catch
(
Exception
e
){
JshException
.
writeFail
(
logger
,
e
);
}
return
result
;
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
deleteInOutItem
(
Long
id
,
HttpServletRequest
request
)
throws
Exception
{
return
batchDeleteInOutItemByIds
(
id
.
toString
());
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchDeleteInOutItem
(
String
ids
,
HttpServletRequest
request
)
throws
Exception
{
return
batchDeleteInOutItemByIds
(
ids
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchDeleteInOutItemByIds
(
String
ids
)
throws
Exception
{
int
result
=
0
;
String
[]
idArray
=
ids
.
split
(
","
);
//校验财务子表 jsh_accountitem
List
<
AccountItem
>
accountItemList
=
null
;
try
{
accountItemList
=
accountItemMapperEx
.
getAccountItemListByInOutItemIds
(
idArray
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
if
(
accountItemList
!=
null
&&
accountItemList
.
size
()>
0
){
logger
.
error
(
"异常码[{}],异常提示[{}],参数,InOutItemIds[{}]"
,
ExceptionConstants
.
DELETE_FORCE_CONFIRM_CODE
,
ExceptionConstants
.
DELETE_FORCE_CONFIRM_MSG
,
ids
);
throw
new
BusinessRunTimeException
(
ExceptionConstants
.
DELETE_FORCE_CONFIRM_CODE
,
ExceptionConstants
.
DELETE_FORCE_CONFIRM_MSG
);
}
//校验通过执行删除操作
StringBuffer
sb
=
new
StringBuffer
();
sb
.
append
(
BusinessConstants
.
LOG_OPERATION_TYPE_DELETE
);
List
<
InOutItem
>
list
=
getInOutItemListByIds
(
ids
);
for
(
InOutItem
inOutItem:
list
){
sb
.
append
(
"["
).
append
(
inOutItem
.
getName
()).
append
(
"]"
);
}
logService
.
insertLog
(
"收支项目"
,
sb
.
toString
(),
((
ServletRequestAttributes
)
RequestContextHolder
.
getRequestAttributes
()).
getRequest
());
User
userInfo
=
userService
.
getCurrentUser
();
try
{
result
=
inOutItemMapperEx
.
batchDeleteInOutItemByIds
(
new
Date
(),
userInfo
==
null
?
null
:
userInfo
.
getId
(),
idArray
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
result
;
}
public
int
checkIsNameExist
(
Long
id
,
String
name
)
throws
Exception
{
InOutItemExample
example
=
new
InOutItemExample
();
example
.
createCriteria
().
andIdNotEqualTo
(
id
).
andNameEqualTo
(
name
).
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
List
<
InOutItem
>
list
=
null
;
try
{
list
=
inOutItemMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
==
null
?
0
:
list
.
size
();
}
public
List
<
InOutItem
>
findBySelect
(
String
type
)
throws
Exception
{
InOutItemExample
example
=
new
InOutItemExample
();
if
(
type
.
equals
(
"in"
))
{
example
.
createCriteria
().
andTypeEqualTo
(
"收入"
).
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
}
else
if
(
type
.
equals
(
"out"
))
{
example
.
createCriteria
().
andTypeEqualTo
(
"支出"
).
andDeleteFlagNotEqualTo
(
BusinessConstants
.
DELETE_FLAG_DELETED
);
}
example
.
setOrderByClause
(
"id desc"
);
List
<
InOutItem
>
list
=
null
;
try
{
list
=
inOutItemMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
){
JshException
.
readFail
(
logger
,
e
);
}
return
list
;
}
}
Prev
1
…
7
8
9
10
11
12
13
Next
Write
Preview
Supports
Markdown
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