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
85d96bb2
Commit
85d96bb2
authored
Jan 11, 2019
by
cjl
Browse files
添加事务控制
parent
5df1748c
Changes
25
Hide whitespace changes
Inline
Side-by-side
src/main/java/com/jsh/erp/service/supplier/SupplierService.java
View file @
85d96bb2
package
com.jsh.erp.service.supplier
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.datasource.entities.Supplier
;
import
com.jsh.erp.datasource.entities.SupplierExample
;
import
com.jsh.erp.datasource.mappers.SupplierMapper
;
import
com.jsh.erp.utils.StringUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.List
;
@Service
public
class
SupplierService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
SupplierService
.
class
);
@Resource
private
SupplierMapper
supplierMapper
;
public
Supplier
getSupplier
(
long
id
)
{
return
supplierMapper
.
selectByPrimaryKey
(
id
);
}
public
List
<
Supplier
>
getSupplier
()
{
SupplierExample
example
=
new
SupplierExample
();
return
supplierMapper
.
selectByExample
(
example
);
}
public
List
<
Supplier
>
select
(
String
supplier
,
String
type
,
String
phonenum
,
String
telephone
,
String
description
,
int
offset
,
int
rows
)
{
return
supplierMapper
.
selectByConditionSupplier
(
supplier
,
type
,
phonenum
,
telephone
,
description
,
offset
,
rows
);
}
public
int
countSupplier
(
String
supplier
,
String
type
,
String
phonenum
,
String
telephone
,
String
description
)
{
return
supplierMapper
.
countsBySupplier
(
supplier
,
type
,
phonenum
,
telephone
,
description
);
}
public
int
insertSupplier
(
String
beanJson
,
HttpServletRequest
request
)
{
Supplier
supplier
=
JSONObject
.
parseObject
(
beanJson
,
Supplier
.
class
);
return
supplierMapper
.
insertSelective
(
supplier
);
}
public
int
updateSupplier
(
String
beanJson
,
Long
id
)
{
Supplier
supplier
=
JSONObject
.
parseObject
(
beanJson
,
Supplier
.
class
);
supplier
.
setId
(
id
);
return
supplierMapper
.
updateByPrimaryKeySelective
(
supplier
);
}
public
int
deleteSupplier
(
Long
id
)
{
return
supplierMapper
.
deleteByPrimaryKey
(
id
);
}
public
int
batchDeleteSupplier
(
String
ids
)
{
List
<
Long
>
idList
=
StringUtil
.
strToLongList
(
ids
);
SupplierExample
example
=
new
SupplierExample
();
example
.
createCriteria
().
andIdIn
(
idList
);
return
supplierMapper
.
deleteByExample
(
example
);
}
public
int
checkIsNameExist
(
Long
id
,
String
name
)
{
SupplierExample
example
=
new
SupplierExample
();
example
.
createCriteria
().
andIdNotEqualTo
(
id
).
andSupplierEqualTo
(
name
);
List
<
Supplier
>
list
=
supplierMapper
.
selectByExample
(
example
);
return
list
.
size
();
}
public
int
updateAdvanceIn
(
Long
supplierId
,
Double
advanceIn
){
Supplier
supplier
=
supplierMapper
.
selectByPrimaryKey
(
supplierId
);
supplier
.
setAdvancein
(
supplier
.
getAdvancein
()
+
advanceIn
);
//增加预收款的金额,可能增加的是负值
return
supplierMapper
.
updateByPrimaryKeySelective
(
supplier
);
}
public
List
<
Supplier
>
findBySelectCus
()
{
SupplierExample
example
=
new
SupplierExample
();
example
.
createCriteria
().
andTypeLike
(
"客户"
).
andEnabledEqualTo
(
true
);
example
.
setOrderByClause
(
"id desc"
);
return
supplierMapper
.
selectByExample
(
example
);
}
public
List
<
Supplier
>
findBySelectSup
()
{
SupplierExample
example
=
new
SupplierExample
();
example
.
createCriteria
().
andTypeLike
(
"供应商"
).
andEnabledEqualTo
(
true
);
example
.
setOrderByClause
(
"id desc"
);
return
supplierMapper
.
selectByExample
(
example
);
}
public
List
<
Supplier
>
findBySelectRetail
()
{
SupplierExample
example
=
new
SupplierExample
();
example
.
createCriteria
().
andTypeLike
(
"会员"
).
andEnabledEqualTo
(
true
);
example
.
setOrderByClause
(
"id desc"
);
return
supplierMapper
.
selectByExample
(
example
);
}
public
List
<
Supplier
>
findById
(
Long
supplierId
)
{
SupplierExample
example
=
new
SupplierExample
();
example
.
createCriteria
().
andIdEqualTo
(
supplierId
);
example
.
setOrderByClause
(
"id desc"
);
return
supplierMapper
.
selectByExample
(
example
);
}
public
int
batchSetEnable
(
Boolean
enabled
,
String
supplierIDs
)
{
List
<
Long
>
ids
=
StringUtil
.
strToLongList
(
supplierIDs
);
Supplier
supplier
=
new
Supplier
();
supplier
.
setEnabled
(
enabled
);
SupplierExample
example
=
new
SupplierExample
();
example
.
createCriteria
().
andIdIn
(
ids
);
return
supplierMapper
.
updateByExampleSelective
(
supplier
,
example
);
}
public
List
<
Supplier
>
findUserCustomer
(){
SupplierExample
example
=
new
SupplierExample
();
example
.
createCriteria
().
andTypeEqualTo
(
"客户"
);
example
.
setOrderByClause
(
"id desc"
);
List
<
Supplier
>
list
=
supplierMapper
.
selectByExample
(
example
);
return
list
;
}
}
package
com.jsh.erp.service.supplier
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.datasource.entities.Supplier
;
import
com.jsh.erp.datasource.entities.SupplierExample
;
import
com.jsh.erp.datasource.mappers.SupplierMapper
;
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.util.List
;
@Service
public
class
SupplierService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
SupplierService
.
class
);
@Resource
private
SupplierMapper
supplierMapper
;
public
Supplier
getSupplier
(
long
id
)
{
return
supplierMapper
.
selectByPrimaryKey
(
id
);
}
public
List
<
Supplier
>
getSupplier
()
{
SupplierExample
example
=
new
SupplierExample
();
return
supplierMapper
.
selectByExample
(
example
);
}
public
List
<
Supplier
>
select
(
String
supplier
,
String
type
,
String
phonenum
,
String
telephone
,
String
description
,
int
offset
,
int
rows
)
{
return
supplierMapper
.
selectByConditionSupplier
(
supplier
,
type
,
phonenum
,
telephone
,
description
,
offset
,
rows
);
}
public
int
countSupplier
(
String
supplier
,
String
type
,
String
phonenum
,
String
telephone
,
String
description
)
{
return
supplierMapper
.
countsBySupplier
(
supplier
,
type
,
phonenum
,
telephone
,
description
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
insertSupplier
(
String
beanJson
,
HttpServletRequest
request
)
{
Supplier
supplier
=
JSONObject
.
parseObject
(
beanJson
,
Supplier
.
class
);
return
supplierMapper
.
insertSelective
(
supplier
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
updateSupplier
(
String
beanJson
,
Long
id
)
{
Supplier
supplier
=
JSONObject
.
parseObject
(
beanJson
,
Supplier
.
class
);
supplier
.
setId
(
id
);
return
supplierMapper
.
updateByPrimaryKeySelective
(
supplier
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
deleteSupplier
(
Long
id
)
{
return
supplierMapper
.
deleteByPrimaryKey
(
id
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchDeleteSupplier
(
String
ids
)
{
List
<
Long
>
idList
=
StringUtil
.
strToLongList
(
ids
);
SupplierExample
example
=
new
SupplierExample
();
example
.
createCriteria
().
andIdIn
(
idList
);
return
supplierMapper
.
deleteByExample
(
example
);
}
public
int
checkIsNameExist
(
Long
id
,
String
name
)
{
SupplierExample
example
=
new
SupplierExample
();
example
.
createCriteria
().
andIdNotEqualTo
(
id
).
andSupplierEqualTo
(
name
);
List
<
Supplier
>
list
=
supplierMapper
.
selectByExample
(
example
);
return
list
.
size
();
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
updateAdvanceIn
(
Long
supplierId
,
Double
advanceIn
){
Supplier
supplier
=
supplierMapper
.
selectByPrimaryKey
(
supplierId
);
supplier
.
setAdvancein
(
supplier
.
getAdvancein
()
+
advanceIn
);
//增加预收款的金额,可能增加的是负值
return
supplierMapper
.
updateByPrimaryKeySelective
(
supplier
);
}
public
List
<
Supplier
>
findBySelectCus
()
{
SupplierExample
example
=
new
SupplierExample
();
example
.
createCriteria
().
andTypeLike
(
"客户"
).
andEnabledEqualTo
(
true
);
example
.
setOrderByClause
(
"id desc"
);
return
supplierMapper
.
selectByExample
(
example
);
}
public
List
<
Supplier
>
findBySelectSup
()
{
SupplierExample
example
=
new
SupplierExample
();
example
.
createCriteria
().
andTypeLike
(
"供应商"
).
andEnabledEqualTo
(
true
);
example
.
setOrderByClause
(
"id desc"
);
return
supplierMapper
.
selectByExample
(
example
);
}
public
List
<
Supplier
>
findBySelectRetail
()
{
SupplierExample
example
=
new
SupplierExample
();
example
.
createCriteria
().
andTypeLike
(
"会员"
).
andEnabledEqualTo
(
true
);
example
.
setOrderByClause
(
"id desc"
);
return
supplierMapper
.
selectByExample
(
example
);
}
public
List
<
Supplier
>
findById
(
Long
supplierId
)
{
SupplierExample
example
=
new
SupplierExample
();
example
.
createCriteria
().
andIdEqualTo
(
supplierId
);
example
.
setOrderByClause
(
"id desc"
);
return
supplierMapper
.
selectByExample
(
example
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchSetEnable
(
Boolean
enabled
,
String
supplierIDs
)
{
List
<
Long
>
ids
=
StringUtil
.
strToLongList
(
supplierIDs
);
Supplier
supplier
=
new
Supplier
();
supplier
.
setEnabled
(
enabled
);
SupplierExample
example
=
new
SupplierExample
();
example
.
createCriteria
().
andIdIn
(
ids
);
return
supplierMapper
.
updateByExampleSelective
(
supplier
,
example
);
}
public
List
<
Supplier
>
findUserCustomer
(){
SupplierExample
example
=
new
SupplierExample
();
example
.
createCriteria
().
andTypeEqualTo
(
"客户"
);
example
.
setOrderByClause
(
"id desc"
);
List
<
Supplier
>
list
=
supplierMapper
.
selectByExample
(
example
);
return
list
;
}
}
src/main/java/com/jsh/erp/service/systemConfig/SystemConfigService.java
View file @
85d96bb2
package
com.jsh.erp.service.systemConfig
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.datasource.entities.SystemConfig
;
import
com.jsh.erp.datasource.entities.SystemConfigExample
;
import
com.jsh.erp.datasource.mappers.SystemConfigMapper
;
import
com.jsh.erp.utils.StringUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.List
;
@Service
public
class
SystemConfigService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
SystemConfigService
.
class
);
@Resource
private
SystemConfigMapper
systemConfigMapper
;
public
SystemConfig
getSystemConfig
(
long
id
)
{
return
systemConfigMapper
.
selectByPrimaryKey
(
id
);
}
public
List
<
SystemConfig
>
getSystemConfig
()
{
SystemConfigExample
example
=
new
SystemConfigExample
();
return
systemConfigMapper
.
selectByExample
(
example
);
}
public
List
<
SystemConfig
>
select
(
int
offset
,
int
rows
)
{
return
systemConfigMapper
.
selectByConditionSystemConfig
(
offset
,
rows
);
}
public
int
countSystemConfig
()
{
return
systemConfigMapper
.
countsBySystemConfig
();
}
public
int
insertSystemConfig
(
String
beanJson
,
HttpServletRequest
request
)
{
SystemConfig
systemConfig
=
JSONObject
.
parseObject
(
beanJson
,
SystemConfig
.
class
);
return
systemConfigMapper
.
insertSelective
(
systemConfig
);
}
public
int
updateSystemConfig
(
String
beanJson
,
Long
id
)
{
SystemConfig
systemConfig
=
JSONObject
.
parseObject
(
beanJson
,
SystemConfig
.
class
);
systemConfig
.
setId
(
id
);
return
systemConfigMapper
.
updateByPrimaryKeySelective
(
systemConfig
);
}
public
int
deleteSystemConfig
(
Long
id
)
{
return
systemConfigMapper
.
deleteByPrimaryKey
(
id
);
}
public
int
batchDeleteSystemConfig
(
String
ids
)
{
List
<
Long
>
idList
=
StringUtil
.
strToLongList
(
ids
);
SystemConfigExample
example
=
new
SystemConfigExample
();
example
.
createCriteria
().
andIdIn
(
idList
);
return
systemConfigMapper
.
deleteByExample
(
example
);
}
public
int
checkIsNameExist
(
Long
id
,
String
name
)
{
SystemConfigExample
example
=
new
SystemConfigExample
();
example
.
createCriteria
().
andIdNotEqualTo
(
id
).
andNameEqualTo
(
name
);
List
<
SystemConfig
>
list
=
systemConfigMapper
.
selectByExample
(
example
);
return
list
.
size
();
}
}
package
com.jsh.erp.service.systemConfig
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.datasource.entities.SystemConfig
;
import
com.jsh.erp.datasource.entities.SystemConfigExample
;
import
com.jsh.erp.datasource.mappers.SystemConfigMapper
;
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.util.List
;
@Service
public
class
SystemConfigService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
SystemConfigService
.
class
);
@Resource
private
SystemConfigMapper
systemConfigMapper
;
public
SystemConfig
getSystemConfig
(
long
id
)
{
return
systemConfigMapper
.
selectByPrimaryKey
(
id
);
}
public
List
<
SystemConfig
>
getSystemConfig
()
{
SystemConfigExample
example
=
new
SystemConfigExample
();
return
systemConfigMapper
.
selectByExample
(
example
);
}
public
List
<
SystemConfig
>
select
(
int
offset
,
int
rows
)
{
return
systemConfigMapper
.
selectByConditionSystemConfig
(
offset
,
rows
);
}
public
int
countSystemConfig
()
{
return
systemConfigMapper
.
countsBySystemConfig
();
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
insertSystemConfig
(
String
beanJson
,
HttpServletRequest
request
)
{
SystemConfig
systemConfig
=
JSONObject
.
parseObject
(
beanJson
,
SystemConfig
.
class
);
return
systemConfigMapper
.
insertSelective
(
systemConfig
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
updateSystemConfig
(
String
beanJson
,
Long
id
)
{
SystemConfig
systemConfig
=
JSONObject
.
parseObject
(
beanJson
,
SystemConfig
.
class
);
systemConfig
.
setId
(
id
);
return
systemConfigMapper
.
updateByPrimaryKeySelective
(
systemConfig
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
deleteSystemConfig
(
Long
id
)
{
return
systemConfigMapper
.
deleteByPrimaryKey
(
id
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchDeleteSystemConfig
(
String
ids
)
{
List
<
Long
>
idList
=
StringUtil
.
strToLongList
(
ids
);
SystemConfigExample
example
=
new
SystemConfigExample
();
example
.
createCriteria
().
andIdIn
(
idList
);
return
systemConfigMapper
.
deleteByExample
(
example
);
}
public
int
checkIsNameExist
(
Long
id
,
String
name
)
{
SystemConfigExample
example
=
new
SystemConfigExample
();
example
.
createCriteria
().
andIdNotEqualTo
(
id
).
andNameEqualTo
(
name
);
List
<
SystemConfig
>
list
=
systemConfigMapper
.
selectByExample
(
example
);
return
list
.
size
();
}
}
src/main/java/com/jsh/erp/service/unit/UnitService.java
View file @
85d96bb2
package
com.jsh.erp.service.unit
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.datasource.entities.Unit
;
import
com.jsh.erp.datasource.entities.UnitExample
;
import
com.jsh.erp.datasource.mappers.UnitMapper
;
import
com.jsh.erp.utils.StringUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.List
;
@Service
public
class
UnitService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
UnitService
.
class
);
@Resource
private
UnitMapper
unitMapper
;
public
Unit
getUnit
(
long
id
)
{
return
unitMapper
.
selectByPrimaryKey
(
id
);
}
public
List
<
Unit
>
getUnit
()
{
UnitExample
example
=
new
UnitExample
();
return
unitMapper
.
selectByExample
(
example
);
}
public
List
<
Unit
>
select
(
String
name
,
int
offset
,
int
rows
)
{
return
unitMapper
.
selectByConditionUnit
(
name
,
offset
,
rows
);
}
public
int
countUnit
(
String
name
)
{
return
unitMapper
.
countsByUnit
(
name
);
}
public
int
insertUnit
(
String
beanJson
,
HttpServletRequest
request
)
{
Unit
unit
=
JSONObject
.
parseObject
(
beanJson
,
Unit
.
class
);
return
unitMapper
.
insertSelective
(
unit
);
}
public
int
updateUnit
(
String
beanJson
,
Long
id
)
{
Unit
unit
=
JSONObject
.
parseObject
(
beanJson
,
Unit
.
class
);
unit
.
setId
(
id
);
return
unitMapper
.
updateByPrimaryKeySelective
(
unit
);
}
public
int
deleteUnit
(
Long
id
)
{
return
unitMapper
.
deleteByPrimaryKey
(
id
);
}
public
int
batchDeleteUnit
(
String
ids
)
{
List
<
Long
>
idList
=
StringUtil
.
strToLongList
(
ids
);
UnitExample
example
=
new
UnitExample
();
example
.
createCriteria
().
andIdIn
(
idList
);
return
unitMapper
.
deleteByExample
(
example
);
}
public
int
checkIsNameExist
(
Long
id
,
String
name
)
{
UnitExample
example
=
new
UnitExample
();
example
.
createCriteria
().
andIdNotEqualTo
(
id
).
andUnameEqualTo
(
name
);
List
<
Unit
>
list
=
unitMapper
.
selectByExample
(
example
);
return
list
.
size
();
}
}
package
com.jsh.erp.service.unit
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.datasource.entities.Unit
;
import
com.jsh.erp.datasource.entities.UnitExample
;
import
com.jsh.erp.datasource.mappers.UnitMapper
;
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.util.List
;
@Service
public
class
UnitService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
UnitService
.
class
);
@Resource
private
UnitMapper
unitMapper
;
public
Unit
getUnit
(
long
id
)
{
return
unitMapper
.
selectByPrimaryKey
(
id
);
}
public
List
<
Unit
>
getUnit
()
{
UnitExample
example
=
new
UnitExample
();
return
unitMapper
.
selectByExample
(
example
);
}
public
List
<
Unit
>
select
(
String
name
,
int
offset
,
int
rows
)
{
return
unitMapper
.
selectByConditionUnit
(
name
,
offset
,
rows
);
}
public
int
countUnit
(
String
name
)
{
return
unitMapper
.
countsByUnit
(
name
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
insertUnit
(
String
beanJson
,
HttpServletRequest
request
)
{
Unit
unit
=
JSONObject
.
parseObject
(
beanJson
,
Unit
.
class
);
return
unitMapper
.
insertSelective
(
unit
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
updateUnit
(
String
beanJson
,
Long
id
)
{
Unit
unit
=
JSONObject
.
parseObject
(
beanJson
,
Unit
.
class
);
unit
.
setId
(
id
);
return
unitMapper
.
updateByPrimaryKeySelective
(
unit
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
deleteUnit
(
Long
id
)
{
return
unitMapper
.
deleteByPrimaryKey
(
id
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchDeleteUnit
(
String
ids
)
{
List
<
Long
>
idList
=
StringUtil
.
strToLongList
(
ids
);
UnitExample
example
=
new
UnitExample
();
example
.
createCriteria
().
andIdIn
(
idList
);
return
unitMapper
.
deleteByExample
(
example
);
}
public
int
checkIsNameExist
(
Long
id
,
String
name
)
{
UnitExample
example
=
new
UnitExample
();
example
.
createCriteria
().
andIdNotEqualTo
(
id
).
andUnameEqualTo
(
name
);
List
<
Unit
>
list
=
unitMapper
.
selectByExample
(
example
);
return
list
.
size
();
}
}
src/main/java/com/jsh/erp/service/user/UserService.java
View file @
85d96bb2
package
com.jsh.erp.service.user
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.datasource.entities.User
;
import
com.jsh.erp.datasource.entities.UserExample
;
import
com.jsh.erp.datasource.mappers.UserMapper
;
import
com.jsh.erp.utils.*
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.security.NoSuchAlgorithmException
;
import
java.util.List
;
import
java.util.Map
;
@Service
public
class
UserService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
UserService
.
class
);
@Resource
private
UserMapper
userMapper
;
public
User
getUser
(
long
id
)
{
return
userMapper
.
selectByPrimaryKey
(
id
);
}
public
List
<
User
>
getUser
()
{
UserExample
example
=
new
UserExample
();
return
userMapper
.
selectByExample
(
example
);
}
public
List
<
User
>
select
(
String
userName
,
String
loginName
,
int
offset
,
int
rows
)
{
return
userMapper
.
selectByConditionUser
(
userName
,
loginName
,
offset
,
rows
);
}
public
int
countUser
(
String
userName
,
String
loginName
)
{
return
userMapper
.
countsByUser
(
userName
,
loginName
);
}
public
int
insertUser
(
String
beanJson
,
HttpServletRequest
request
)
{
User
user
=
JSONObject
.
parseObject
(
beanJson
,
User
.
class
);
String
password
=
"123456"
;
//因密码用MD5加密,需要对密码进行转化
try
{
password
=
Tools
.
md5Encryp
(
password
);
user
.
setPassword
(
password
);
}
catch
(
NoSuchAlgorithmException
e
)
{
e
.
printStackTrace
();
logger
.
error
(
">>>>>>>>>>>>>>转化MD5字符串错误 :"
+
e
.
getMessage
());
}
return
userMapper
.
insertSelective
(
user
);
}
public
int
updateUser
(
String
beanJson
,
Long
id
)
{
User
user
=
JSONObject
.
parseObject
(
beanJson
,
User
.
class
);
user
.
setId
(
id
);
return
userMapper
.
updateByPrimaryKeySelective
(
user
);
}
public
int
updateUserByObj
(
User
user
)
{
return
userMapper
.
updateByPrimaryKeySelective
(
user
);
}
public
int
resetPwd
(
String
md5Pwd
,
Long
id
)
{
User
user
=
new
User
();
user
.
setId
(
id
);
user
.
setPassword
(
md5Pwd
);
return
userMapper
.
updateByPrimaryKeySelective
(
user
);
}
public
int
deleteUser
(
Long
id
)
{
return
userMapper
.
deleteByPrimaryKey
(
id
);
}
public
int
batchDeleteUser
(
String
ids
)
{
List
<
Long
>
idList
=
StringUtil
.
strToLongList
(
ids
);
UserExample
example
=
new
UserExample
();
example
.
createCriteria
().
andIdIn
(
idList
);
return
userMapper
.
deleteByExample
(
example
);
}
public
int
validateUser
(
String
username
,
String
password
)
throws
JshException
{
try
{
/**默认是可以登录的*/
List
<
User
>
list
=
null
;
try
{
UserExample
example
=
new
UserExample
();
example
.
createCriteria
().
andLoginameEqualTo
(
username
);
list
=
userMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
)
{
logger
.
error
(
">>>>>>>>访问验证用户姓名是否存在后台信息异常"
,
e
);
return
ExceptionCodeConstants
.
UserExceptionCode
.
USER_ACCESS_EXCEPTION
;
}
if
(
null
!=
list
&&
list
.
size
()
==
0
)
{
return
ExceptionCodeConstants
.
UserExceptionCode
.
USER_NOT_EXIST
;
}
try
{
UserExample
example
=
new
UserExample
();
example
.
createCriteria
().
andLoginameEqualTo
(
username
).
andPasswordEqualTo
(
password
);
list
=
userMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
)
{
logger
.
error
(
">>>>>>>>>>访问验证用户密码后台信息异常"
,
e
);
return
ExceptionCodeConstants
.
UserExceptionCode
.
USER_ACCESS_EXCEPTION
;
}
if
(
null
!=
list
&&
list
.
size
()
==
0
)
{
return
ExceptionCodeConstants
.
UserExceptionCode
.
USER_PASSWORD_ERROR
;
}
return
ExceptionCodeConstants
.
UserExceptionCode
.
USER_CONDITION_FIT
;
}
catch
(
Exception
e
)
{
throw
new
JshException
(
"unknown exception"
,
e
);
}
}
public
User
getUserByUserName
(
String
username
)
{
UserExample
example
=
new
UserExample
();
example
.
createCriteria
().
andLoginameEqualTo
(
username
);
List
<
User
>
list
=
userMapper
.
selectByExample
(
example
);
User
user
=
list
.
get
(
0
);
return
user
;
}
public
int
checkIsNameExist
(
Long
id
,
String
name
)
{
UserExample
example
=
new
UserExample
();
example
.
createCriteria
().
andIdNotEqualTo
(
id
).
andLoginameEqualTo
(
name
);
List
<
User
>
list
=
userMapper
.
selectByExample
(
example
);
return
list
.
size
();
}
}
package
com.jsh.erp.service.user
;
import
com.alibaba.fastjson.JSONArray
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.datasource.entities.User
;
import
com.jsh.erp.datasource.entities.UserExample
;
import
com.jsh.erp.datasource.mappers.UserMapper
;
import
com.jsh.erp.utils.*
;
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.security.NoSuchAlgorithmException
;
import
java.util.List
;
import
java.util.Map
;
@Service
public
class
UserService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
UserService
.
class
);
@Resource
private
UserMapper
userMapper
;
public
User
getUser
(
long
id
)
{
return
userMapper
.
selectByPrimaryKey
(
id
);
}
public
List
<
User
>
getUser
()
{
UserExample
example
=
new
UserExample
();
return
userMapper
.
selectByExample
(
example
);
}
public
List
<
User
>
select
(
String
userName
,
String
loginName
,
int
offset
,
int
rows
)
{
return
userMapper
.
selectByConditionUser
(
userName
,
loginName
,
offset
,
rows
);
}
public
int
countUser
(
String
userName
,
String
loginName
)
{
return
userMapper
.
countsByUser
(
userName
,
loginName
);
}
/**
* create by: cjl
* description:
* 添加事务控制
* create time: 2019/1/11 14:30
* @Param: beanJson
* @Param: request
* @return int
*/
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
insertUser
(
String
beanJson
,
HttpServletRequest
request
)
{
User
user
=
JSONObject
.
parseObject
(
beanJson
,
User
.
class
);
String
password
=
"123456"
;
//因密码用MD5加密,需要对密码进行转化
try
{
password
=
Tools
.
md5Encryp
(
password
);
user
.
setPassword
(
password
);
}
catch
(
NoSuchAlgorithmException
e
)
{
e
.
printStackTrace
();
logger
.
error
(
">>>>>>>>>>>>>>转化MD5字符串错误 :"
+
e
.
getMessage
());
}
return
userMapper
.
insertSelective
(
user
);
}
/**
* create by: cjl
* description:
* 添加事务控制
* create time: 2019/1/11 14:31
* @Param: beanJson
* @Param: id
* @return int
*/
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
updateUser
(
String
beanJson
,
Long
id
)
{
User
user
=
JSONObject
.
parseObject
(
beanJson
,
User
.
class
);
user
.
setId
(
id
);
return
userMapper
.
updateByPrimaryKeySelective
(
user
);
}
/**
* create by: cjl
* description:
* 添加事务控制
* create time: 2019/1/11 14:32
* @Param: user
* @return int
*/
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
updateUserByObj
(
User
user
)
{
return
userMapper
.
updateByPrimaryKeySelective
(
user
);
}
/**
* create by: cjl
* description:
* 添加事务控制
* create time: 2019/1/11 14:33
* @Param: md5Pwd
* @Param: id
* @return int
*/
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
resetPwd
(
String
md5Pwd
,
Long
id
)
{
User
user
=
new
User
();
user
.
setId
(
id
);
user
.
setPassword
(
md5Pwd
);
return
userMapper
.
updateByPrimaryKeySelective
(
user
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
deleteUser
(
Long
id
)
{
return
userMapper
.
deleteByPrimaryKey
(
id
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchDeleteUser
(
String
ids
)
{
List
<
Long
>
idList
=
StringUtil
.
strToLongList
(
ids
);
UserExample
example
=
new
UserExample
();
example
.
createCriteria
().
andIdIn
(
idList
);
return
userMapper
.
deleteByExample
(
example
);
}
public
int
validateUser
(
String
username
,
String
password
)
throws
JshException
{
try
{
/**默认是可以登录的*/
List
<
User
>
list
=
null
;
try
{
UserExample
example
=
new
UserExample
();
example
.
createCriteria
().
andLoginameEqualTo
(
username
);
list
=
userMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
)
{
logger
.
error
(
">>>>>>>>访问验证用户姓名是否存在后台信息异常"
,
e
);
return
ExceptionCodeConstants
.
UserExceptionCode
.
USER_ACCESS_EXCEPTION
;
}
if
(
null
!=
list
&&
list
.
size
()
==
0
)
{
return
ExceptionCodeConstants
.
UserExceptionCode
.
USER_NOT_EXIST
;
}
try
{
UserExample
example
=
new
UserExample
();
example
.
createCriteria
().
andLoginameEqualTo
(
username
).
andPasswordEqualTo
(
password
);
list
=
userMapper
.
selectByExample
(
example
);
}
catch
(
Exception
e
)
{
logger
.
error
(
">>>>>>>>>>访问验证用户密码后台信息异常"
,
e
);
return
ExceptionCodeConstants
.
UserExceptionCode
.
USER_ACCESS_EXCEPTION
;
}
if
(
null
!=
list
&&
list
.
size
()
==
0
)
{
return
ExceptionCodeConstants
.
UserExceptionCode
.
USER_PASSWORD_ERROR
;
}
return
ExceptionCodeConstants
.
UserExceptionCode
.
USER_CONDITION_FIT
;
}
catch
(
Exception
e
)
{
throw
new
JshException
(
"unknown exception"
,
e
);
}
}
public
User
getUserByUserName
(
String
username
)
{
UserExample
example
=
new
UserExample
();
example
.
createCriteria
().
andLoginameEqualTo
(
username
);
List
<
User
>
list
=
userMapper
.
selectByExample
(
example
);
User
user
=
list
.
get
(
0
);
return
user
;
}
public
int
checkIsNameExist
(
Long
id
,
String
name
)
{
UserExample
example
=
new
UserExample
();
example
.
createCriteria
().
andIdNotEqualTo
(
id
).
andLoginameEqualTo
(
name
);
List
<
User
>
list
=
userMapper
.
selectByExample
(
example
);
return
list
.
size
();
}
}
src/main/java/com/jsh/erp/service/userBusiness/UserBusinessService.java
View file @
85d96bb2
package
com.jsh.erp.service.userBusiness
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.datasource.entities.UserBusiness
;
import
com.jsh.erp.datasource.entities.UserBusinessExample
;
import
com.jsh.erp.datasource.mappers.UserBusinessMapper
;
import
com.jsh.erp.utils.StringUtil
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.List
;
@Service
public
class
UserBusinessService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
UserBusinessService
.
class
);
@Resource
private
UserBusinessMapper
userBusinessMapper
;
public
UserBusiness
getUserBusiness
(
long
id
)
{
return
userBusinessMapper
.
selectByPrimaryKey
(
id
);
}
public
List
<
UserBusiness
>
getUserBusiness
()
{
UserBusinessExample
example
=
new
UserBusinessExample
();
return
userBusinessMapper
.
selectByExample
(
example
);
}
public
int
insertUserBusiness
(
String
beanJson
,
HttpServletRequest
request
)
{
UserBusiness
userBusiness
=
JSONObject
.
parseObject
(
beanJson
,
UserBusiness
.
class
);
return
userBusinessMapper
.
insertSelective
(
userBusiness
);
}
public
int
updateUserBusiness
(
String
beanJson
,
Long
id
)
{
UserBusiness
userBusiness
=
JSONObject
.
parseObject
(
beanJson
,
UserBusiness
.
class
);
userBusiness
.
setId
(
id
);
return
userBusinessMapper
.
updateByPrimaryKeySelective
(
userBusiness
);
}
public
int
deleteUserBusiness
(
Long
id
)
{
return
userBusinessMapper
.
deleteByPrimaryKey
(
id
);
}
public
int
batchDeleteUserBusiness
(
String
ids
)
{
List
<
Long
>
idList
=
StringUtil
.
strToLongList
(
ids
);
UserBusinessExample
example
=
new
UserBusinessExample
();
example
.
createCriteria
().
andIdIn
(
idList
);
return
userBusinessMapper
.
deleteByExample
(
example
);
}
public
int
checkIsNameExist
(
Long
id
,
String
name
)
{
return
1
;
}
public
List
<
UserBusiness
>
getBasicData
(
String
keyId
,
String
type
){
UserBusinessExample
example
=
new
UserBusinessExample
();
example
.
createCriteria
().
andKeyidEqualTo
(
keyId
).
andTypeEqualTo
(
type
);
List
<
UserBusiness
>
list
=
userBusinessMapper
.
selectByExample
(
example
);
return
list
;
}
public
Long
checkIsValueExist
(
String
type
,
String
keyId
)
{
UserBusinessExample
example
=
new
UserBusinessExample
();
example
.
createCriteria
().
andTypeEqualTo
(
type
).
andKeyidEqualTo
(
keyId
);
List
<
UserBusiness
>
list
=
userBusinessMapper
.
selectByExample
(
example
);
Long
id
=
null
;
if
(
list
.
size
()
>
0
)
{
id
=
list
.
get
(
0
).
getId
();
}
return
id
;
}
public
Boolean
checkIsUserBusinessExist
(
String
TypeVale
,
String
KeyIdValue
,
String
UBValue
)
{
UserBusinessExample
example
=
new
UserBusinessExample
();
String
newVaule
=
"%"
+
UBValue
+
"%"
;
if
(
TypeVale
!=
null
&&
KeyIdValue
!=
null
)
{
example
.
createCriteria
().
andTypeEqualTo
(
TypeVale
).
andKeyidEqualTo
(
KeyIdValue
).
andValueLike
(
newVaule
);
}
else
{
example
.
createCriteria
().
andValueLike
(
newVaule
);
}
List
<
UserBusiness
>
list
=
userBusinessMapper
.
selectByExample
(
example
);
if
(
list
.
size
()
>
0
)
{
return
true
;
}
else
{
return
false
;
}
}
public
int
updateBtnStr
(
Long
userBusinessId
,
String
btnStr
)
{
UserBusiness
userBusiness
=
new
UserBusiness
();
userBusiness
.
setBtnstr
(
btnStr
);
UserBusinessExample
example
=
new
UserBusinessExample
();
example
.
createCriteria
().
andIdEqualTo
(
userBusinessId
);
return
userBusinessMapper
.
updateByExampleSelective
(
userBusiness
,
example
);
}
}
package
com.jsh.erp.service.userBusiness
;
import
com.alibaba.fastjson.JSONObject
;
import
com.jsh.erp.datasource.entities.UserBusiness
;
import
com.jsh.erp.datasource.entities.UserBusinessExample
;
import
com.jsh.erp.datasource.mappers.UserBusinessMapper
;
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.util.List
;
@Service
public
class
UserBusinessService
{
private
Logger
logger
=
LoggerFactory
.
getLogger
(
UserBusinessService
.
class
);
@Resource
private
UserBusinessMapper
userBusinessMapper
;
public
UserBusiness
getUserBusiness
(
long
id
)
{
return
userBusinessMapper
.
selectByPrimaryKey
(
id
);
}
public
List
<
UserBusiness
>
getUserBusiness
()
{
UserBusinessExample
example
=
new
UserBusinessExample
();
return
userBusinessMapper
.
selectByExample
(
example
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
insertUserBusiness
(
String
beanJson
,
HttpServletRequest
request
)
{
UserBusiness
userBusiness
=
JSONObject
.
parseObject
(
beanJson
,
UserBusiness
.
class
);
return
userBusinessMapper
.
insertSelective
(
userBusiness
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
updateUserBusiness
(
String
beanJson
,
Long
id
)
{
UserBusiness
userBusiness
=
JSONObject
.
parseObject
(
beanJson
,
UserBusiness
.
class
);
userBusiness
.
setId
(
id
);
return
userBusinessMapper
.
updateByPrimaryKeySelective
(
userBusiness
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
deleteUserBusiness
(
Long
id
)
{
return
userBusinessMapper
.
deleteByPrimaryKey
(
id
);
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
batchDeleteUserBusiness
(
String
ids
)
{
List
<
Long
>
idList
=
StringUtil
.
strToLongList
(
ids
);
UserBusinessExample
example
=
new
UserBusinessExample
();
example
.
createCriteria
().
andIdIn
(
idList
);
return
userBusinessMapper
.
deleteByExample
(
example
);
}
public
int
checkIsNameExist
(
Long
id
,
String
name
)
{
return
1
;
}
public
List
<
UserBusiness
>
getBasicData
(
String
keyId
,
String
type
){
UserBusinessExample
example
=
new
UserBusinessExample
();
example
.
createCriteria
().
andKeyidEqualTo
(
keyId
).
andTypeEqualTo
(
type
);
List
<
UserBusiness
>
list
=
userBusinessMapper
.
selectByExample
(
example
);
return
list
;
}
public
Long
checkIsValueExist
(
String
type
,
String
keyId
)
{
UserBusinessExample
example
=
new
UserBusinessExample
();
example
.
createCriteria
().
andTypeEqualTo
(
type
).
andKeyidEqualTo
(
keyId
);
List
<
UserBusiness
>
list
=
userBusinessMapper
.
selectByExample
(
example
);
Long
id
=
null
;
if
(
list
.
size
()
>
0
)
{
id
=
list
.
get
(
0
).
getId
();
}
return
id
;
}
public
Boolean
checkIsUserBusinessExist
(
String
TypeVale
,
String
KeyIdValue
,
String
UBValue
)
{
UserBusinessExample
example
=
new
UserBusinessExample
();
String
newVaule
=
"%"
+
UBValue
+
"%"
;
if
(
TypeVale
!=
null
&&
KeyIdValue
!=
null
)
{
example
.
createCriteria
().
andTypeEqualTo
(
TypeVale
).
andKeyidEqualTo
(
KeyIdValue
).
andValueLike
(
newVaule
);
}
else
{
example
.
createCriteria
().
andValueLike
(
newVaule
);
}
List
<
UserBusiness
>
list
=
userBusinessMapper
.
selectByExample
(
example
);
if
(
list
.
size
()
>
0
)
{
return
true
;
}
else
{
return
false
;
}
}
@Transactional
(
value
=
"transactionManager"
,
rollbackFor
=
Exception
.
class
)
public
int
updateBtnStr
(
Long
userBusinessId
,
String
btnStr
)
{
UserBusiness
userBusiness
=
new
UserBusiness
();
userBusiness
.
setBtnstr
(
btnStr
);
UserBusinessExample
example
=
new
UserBusinessExample
();
example
.
createCriteria
().
andIdEqualTo
(
userBusinessId
);
return
userBusinessMapper
.
updateByExampleSelective
(
userBusiness
,
example
);
}
}
Prev
1
2
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