Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
dj
/
bs-cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit f1b07933
authored
Aug 05, 2026
by
叶立庆
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
优化项目内容
1 parent
61b0a724
Hide whitespace changes
Inline
Side-by-side
Showing
33 changed files
with
26 additions
and
3454 deletions
bs-auth/pom.xml
bs-auth/src/main/java/com/bs/web/controller/relation/SpStoreRelationController.java
bs-auth/src/main/java/com/bs/web/controller/relation/SysUserSpRelationController.java
bs-auth/src/main/java/com/bs/web/controller/relation/SysUserStoreRelationController.java
bs-auth/src/main/java/com/bs/web/controller/role/SpRoleController.java
bs-auth/src/main/java/com/bs/web/controller/sp/SpInfoController.java
bs-auth/src/main/java/com/bs/web/controller/sp/SpUserController.java
bs-auth/src/main/java/com/bs/web/controller/store/BusinessStoreController.java
bs-auth/src/main/java/com/bs/web/feign/FileFeignClient.java
bs-auth/src/main/java/com/bs/web/mapper/relation/SpStoreRelationMapper.java
bs-auth/src/main/java/com/bs/web/mapper/relation/SysUserSpRelationMapper.java
bs-auth/src/main/java/com/bs/web/mapper/relation/SysUserStoreRelationMapper.java
bs-auth/src/main/java/com/bs/web/mapper/role/SpRoleMapper.java
bs-auth/src/main/java/com/bs/web/mapper/sp/SpInfoMapper.java
bs-auth/src/main/java/com/bs/web/mapper/store/BusinessStoreMapper.java
bs-auth/src/main/java/com/bs/web/service/relation/ISpStoreRelationService.java
bs-auth/src/main/java/com/bs/web/service/relation/ISysUserSpRelationService.java
bs-auth/src/main/java/com/bs/web/service/relation/ISysUserStoreRelationService.java
bs-auth/src/main/java/com/bs/web/service/relation/impl/SpStoreRelationServiceImpl.java
bs-auth/src/main/java/com/bs/web/service/relation/impl/SysUserSpRelationServiceImpl.java
bs-auth/src/main/java/com/bs/web/service/relation/impl/SysUserStoreRelationServiceImpl.java
bs-auth/src/main/java/com/bs/web/service/role/ISpRoleService.java
bs-auth/src/main/java/com/bs/web/service/role/impl/SpRoleServiceImpl.java
bs-auth/src/main/java/com/bs/web/service/sp/ISpInfoService.java
bs-auth/src/main/java/com/bs/web/service/sp/impl/SpInfoServiceImpl.java
bs-auth/src/main/java/com/bs/web/service/store/IBusinessStoreService.java
bs-auth/src/main/java/com/bs/web/service/store/impl/BusinessStoreServiceImpl.java
bs-auth/src/main/resources/mapper/relation/SpStoreRelationMapper.xml
bs-auth/src/main/resources/mapper/relation/SysUserSpRelationMapper.xml
bs-auth/src/main/resources/mapper/relation/SysUserStoreRelationMapper.xml
bs-auth/src/main/resources/mapper/role/SpRoleMapper.xml
bs-auth/src/main/resources/mapper/sp/SpInfoMapper.xml
bs-auth/src/main/resources/mapper/store/BusinessStoreMapper.xml
bs-auth/pom.xml
View file @
f1b0793
...
...
@@ -64,11 +64,6 @@
</dependency>
<dependency>
<groupId>
com.bs
</groupId>
<artifactId>
bs-service
</artifactId>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
</dependency>
...
...
@@ -115,6 +110,31 @@
<artifactId>
hutool-all
</artifactId>
</dependency>
<dependency>
<groupId>
jakarta.validation
</groupId>
<artifactId>
jakarta.validation-api
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter-amqp
</artifactId>
</dependency>
<dependency>
<groupId>
io.github.openfeign
</groupId>
<artifactId>
feign-httpclient
</artifactId>
</dependency>
<dependency>
<groupId>
com.github.wechatpay-apiv3
</groupId>
<artifactId>
wechatpay-apache-httpclient
</artifactId>
</dependency>
<dependency>
<groupId>
org.redisson
</groupId>
<artifactId>
redisson
</artifactId>
</dependency>
</dependencies>
...
...
bs-auth/src/main/java/com/bs/web/controller/relation/SpStoreRelationController.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
controller
.
relation
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.bs.common.annotation.Log
;
import
com.bs.common.core.controller.BaseController
;
import
com.bs.common.core.domain.AjaxResult
;
import
com.bs.common.core.domain.entity.relation.SpStoreRelation
;
import
com.bs.common.core.page.TableDataInfo
;
import
com.bs.common.enums.BusinessType
;
import
com.bs.common.enums.OperatorType
;
import
com.bs.web.service.relation.ISpStoreRelationService
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
jakarta.annotation.Resource
;
import
org.springframework.web.bind.annotation.*
;
import
com.bs.common.core.domain.entity.store.BusinessStore
;
import
com.bs.web.domain.vo.sp.SpStoreListReq
;
import
com.bs.web.domain.vo.sp.SpStoreRelationMaintainReq
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.annotation.Validated
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/sp/relation/sp-store"
)
@Tag
(
name
=
"服务商-门店关联"
)
public
class
SpStoreRelationController
extends
BaseController
{
@Resource
private
ISpStoreRelationService
spStoreRelationService
;
@Log
(
title
=
"维护服务商关联门店关系"
,
businessType
=
BusinessType
.
UPDATE
,
operatorType
=
OperatorType
.
MANAGE
)
@PostMapping
(
"/maintain"
)
@Operation
(
summary
=
"维护服务商关联门店关系"
)
public
AjaxResult
<
Boolean
>
maintainRelation
(
@RequestBody
@Validated
SpStoreRelationMaintainReq
req
)
{
return
AjaxResult
.
success
(
spStoreRelationService
.
maintainRelation
(
req
));
}
@GetMapping
(
value
=
"/storeList"
)
@Operation
(
summary
=
"查询指定服务商关联的所有门店列表"
)
public
TableDataInfo
<
List
<
BusinessStore
>>
getStoreListBySpId
(
@Validated
SpStoreListReq
req
)
{
if
(
req
==
null
)
req
=
new
SpStoreListReq
();
com
.
bs
.
common
.
core
.
page
.
PageDomain
pageDomain
=
com
.
bs
.
common
.
core
.
page
.
TableSupport
.
buildPageRequest
();
Integer
pageNum
=
pageDomain
.
getPageNum
();
Integer
pageSize
=
pageDomain
.
getPageSize
();
if
(
pageNum
==
null
)
pageNum
=
1
;
if
(
pageSize
==
null
)
pageSize
=
10
;
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
BusinessStore
>
pageResult
=
spStoreRelationService
.
getStoreListBySpIdPage
(
req
.
getSpId
(),
req
.
getStoreName
(),
pageNum
,
pageSize
);
TableDataInfo
<
List
<
BusinessStore
>>
rspData
=
new
TableDataInfo
<>();
rspData
.
setCode
(
com
.
bs
.
common
.
constant
.
HttpStatus
.
SUCCESS
);
rspData
.
setMsg
(
"查询成功"
);
rspData
.
setRows
(
pageResult
.
getRecords
());
rspData
.
setTotal
(
pageResult
.
getTotal
());
return
rspData
;
}
@RequestMapping
(
value
=
"/list"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
@Operation
(
summary
=
"列表"
)
public
AjaxResult
<
List
<
SpStoreRelation
>>
list
(
SpStoreRelation
query
)
{
List
<
SpStoreRelation
>
list
=
spStoreRelationService
.
list
(
query
);
return
AjaxResult
.
success
(
list
);
}
@RequestMapping
(
value
=
"/page"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
@Operation
(
summary
=
"分页列表"
)
public
TableDataInfo
page
(
@RequestBody
(
required
=
false
)
SpStoreRelation
query
)
{
com
.
bs
.
common
.
core
.
page
.
PageDomain
pageDomain
=
com
.
bs
.
common
.
core
.
page
.
TableSupport
.
buildPageRequest
();
Integer
pageNum
=
pageDomain
.
getPageNum
();
Integer
pageSize
=
pageDomain
.
getPageSize
();
if
(
pageNum
==
null
&&
query
!=
null
&&
query
.
getParams
()
!=
null
&&
query
.
getParams
().
get
(
"pageNum"
)
!=
null
)
{
pageNum
=
Integer
.
parseInt
(
query
.
getParams
().
get
(
"pageNum"
).
toString
());
}
if
(
pageSize
==
null
&&
query
!=
null
&&
query
.
getParams
()
!=
null
&&
query
.
getParams
().
get
(
"pageSize"
)
!=
null
)
{
pageSize
=
Integer
.
parseInt
(
query
.
getParams
().
get
(
"pageSize"
).
toString
());
}
if
(
pageNum
==
null
)
pageNum
=
1
;
if
(
pageSize
==
null
)
pageSize
=
10
;
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SpStoreRelation
>
pageResult
=
spStoreRelationService
.
page
(
query
,
pageNum
,
pageSize
);
TableDataInfo
rspData
=
new
TableDataInfo
();
rspData
.
setCode
(
com
.
bs
.
common
.
constant
.
HttpStatus
.
SUCCESS
);
rspData
.
setMsg
(
"查询成功"
);
rspData
.
setRows
(
pageResult
.
getRecords
());
rspData
.
setTotal
(
pageResult
.
getTotal
());
return
rspData
;
}
@PostMapping
(
"/{id}"
)
@Operation
(
summary
=
"详情"
)
public
AjaxResult
<
SpStoreRelation
>
get
(
@PathVariable
(
"id"
)
Long
id
)
{
return
AjaxResult
.
success
(
spStoreRelationService
.
get
(
id
));
}
@Log
(
title
=
"门店关联"
,
businessType
=
BusinessType
.
INSERT
,
operatorType
=
OperatorType
.
MANAGE
)
@PostMapping
(
"/add"
)
@Operation
(
summary
=
"新增"
)
public
AjaxResult
add
(
@RequestBody
SpStoreRelation
info
)
{
spStoreRelationService
.
add
(
info
);
return
AjaxResult
.
success
();
}
@Log
(
title
=
"门店关联"
,
businessType
=
BusinessType
.
UPDATE
,
operatorType
=
OperatorType
.
MANAGE
)
@PostMapping
(
"/edit"
)
@Operation
(
summary
=
"编辑"
)
public
AjaxResult
edit
(
@RequestBody
SpStoreRelation
info
)
{
spStoreRelationService
.
edit
(
info
);
return
AjaxResult
.
success
();
}
@Log
(
title
=
"门店关联"
,
businessType
=
BusinessType
.
DELETE
,
operatorType
=
OperatorType
.
MANAGE
)
@PostMapping
(
"/delete/{id}"
)
@Operation
(
summary
=
"删除"
)
public
AjaxResult
remove
(
@PathVariable
(
"id"
)
Long
id
)
{
spStoreRelationService
.
remove
(
id
);
return
AjaxResult
.
success
();
}
@PostMapping
(
"/code/{storeCode}"
)
@Operation
(
summary
=
"根据门店编码查未删除的关联列表"
)
public
AjaxResult
<
List
<
SpStoreRelation
>>
listActiveByStoreCode
(
@PathVariable
(
"storeCode"
)
String
storeCode
)
{
return
AjaxResult
.
success
(
spStoreRelationService
.
listByStoreCodeActive
(
storeCode
));
}
}
bs-auth/src/main/java/com/bs/web/controller/relation/SysUserSpRelationController.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
controller
.
relation
;
import
com.bs.common.core.controller.BaseController
;
import
com.bs.common.core.domain.AjaxResult
;
import
com.bs.common.core.domain.entity.relation.SysUserSpRelation
;
import
com.bs.common.core.page.TableDataInfo
;
import
com.bs.web.service.relation.ISysUserSpRelationService
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
jakarta.annotation.Resource
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/sp/relation/user-sp"
)
@Tag
(
name
=
"用户-服务商关联"
)
public
class
SysUserSpRelationController
extends
BaseController
{
@Resource
private
ISysUserSpRelationService
sysUserSpRelationService
;
@PostMapping
(
"/list"
)
@Operation
(
summary
=
"列表"
)
public
AjaxResult
<
List
<
SysUserSpRelation
>>
list
(
SysUserSpRelation
query
)
{
List
<
SysUserSpRelation
>
list
=
sysUserSpRelationService
.
list
(
query
);
return
AjaxResult
.
success
(
list
);
}
@GetMapping
(
value
=
"/page"
)
@Operation
(
summary
=
"分页列表"
)
public
TableDataInfo
page
(
SysUserSpRelation
query
)
{
com
.
bs
.
common
.
core
.
page
.
PageDomain
pageDomain
=
com
.
bs
.
common
.
core
.
page
.
TableSupport
.
buildPageRequest
();
Integer
pageNum
=
pageDomain
.
getPageNum
();
Integer
pageSize
=
pageDomain
.
getPageSize
();
if
(
pageNum
==
null
&&
query
!=
null
&&
query
.
getParams
()
!=
null
&&
query
.
getParams
().
get
(
"pageNum"
)
!=
null
)
{
pageNum
=
Integer
.
parseInt
(
query
.
getParams
().
get
(
"pageNum"
).
toString
());
}
if
(
pageSize
==
null
&&
query
!=
null
&&
query
.
getParams
()
!=
null
&&
query
.
getParams
().
get
(
"pageSize"
)
!=
null
)
{
pageSize
=
Integer
.
parseInt
(
query
.
getParams
().
get
(
"pageSize"
).
toString
());
}
if
(
pageNum
==
null
)
pageNum
=
1
;
if
(
pageSize
==
null
)
pageSize
=
10
;
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SysUserSpRelation
>
pageResult
=
sysUserSpRelationService
.
page
(
query
,
pageNum
,
pageSize
);
TableDataInfo
rspData
=
new
TableDataInfo
();
rspData
.
setCode
(
com
.
bs
.
common
.
constant
.
HttpStatus
.
SUCCESS
);
rspData
.
setMsg
(
"查询成功"
);
rspData
.
setRows
(
pageResult
.
getRecords
());
rspData
.
setTotal
(
pageResult
.
getTotal
());
return
rspData
;
}
@PostMapping
(
"/{id}"
)
@Operation
(
summary
=
"详情"
)
public
AjaxResult
<
SysUserSpRelation
>
get
(
@PathVariable
(
"id"
)
Long
id
)
{
return
AjaxResult
.
success
(
sysUserSpRelationService
.
get
(
id
));
}
@PostMapping
(
"/add"
)
@Operation
(
summary
=
"新增"
)
public
AjaxResult
add
(
@RequestBody
SysUserSpRelation
info
)
{
sysUserSpRelationService
.
add
(
info
);
return
AjaxResult
.
success
();
}
@PostMapping
(
"/edit"
)
@Operation
(
summary
=
"编辑"
)
public
AjaxResult
edit
(
@RequestBody
SysUserSpRelation
info
)
{
sysUserSpRelationService
.
edit
(
info
);
return
AjaxResult
.
success
();
}
@PostMapping
(
"/delete/{id}"
)
@Operation
(
summary
=
"删除"
)
public
AjaxResult
remove
(
@PathVariable
(
"id"
)
Long
id
)
{
sysUserSpRelationService
.
remove
(
id
);
return
AjaxResult
.
success
();
}
}
bs-auth/src/main/java/com/bs/web/controller/relation/SysUserStoreRelationController.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
controller
.
relation
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.bs.common.core.controller.BaseController
;
import
com.bs.common.core.domain.AjaxResult
;
import
com.bs.common.core.domain.entity.relation.SysUserStoreRelation
;
import
com.bs.common.core.page.TableDataInfo
;
import
com.bs.web.domain.vo.relation.SysUserStoreRelationVO
;
import
com.bs.web.service.relation.ISysUserStoreRelationService
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
jakarta.annotation.Resource
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/sp/relation/user-store"
)
@Tag
(
name
=
"用户-门店关联"
)
public
class
SysUserStoreRelationController
extends
BaseController
{
@Resource
private
ISysUserStoreRelationService
sysUserStoreRelationService
;
@PostMapping
(
"/list"
)
@Operation
(
summary
=
"列表"
)
public
AjaxResult
<
List
<
SysUserStoreRelation
>>
list
(
SysUserStoreRelation
query
)
{
List
<
SysUserStoreRelation
>
list
=
sysUserStoreRelationService
.
list
(
query
);
return
AjaxResult
.
success
(
list
);
}
@GetMapping
(
value
=
"/page"
)
@Operation
(
summary
=
"分页列表"
)
public
TableDataInfo
page
(
com
.
bs
.
web
.
domain
.
vo
.
relation
.
SysUserStoreRelationQueryReq
query
)
{
com
.
bs
.
common
.
core
.
page
.
PageDomain
pageDomain
=
com
.
bs
.
common
.
core
.
page
.
TableSupport
.
buildPageRequest
();
Integer
pageNum
=
pageDomain
.
getPageNum
();
Integer
pageSize
=
pageDomain
.
getPageSize
();
if
(
pageNum
==
null
)
pageNum
=
1
;
if
(
pageSize
==
null
)
pageSize
=
10
;
IPage
<
SysUserStoreRelationVO
>
pageResult
=
sysUserStoreRelationService
.
pageCustom
(
query
,
pageNum
,
pageSize
);
TableDataInfo
rspData
=
new
TableDataInfo
();
rspData
.
setCode
(
com
.
bs
.
common
.
constant
.
HttpStatus
.
SUCCESS
);
rspData
.
setMsg
(
"查询成功"
);
rspData
.
setRows
(
pageResult
.
getRecords
());
rspData
.
setTotal
(
pageResult
.
getTotal
());
return
rspData
;
}
@PostMapping
(
"/{id}"
)
@Operation
(
summary
=
"详情"
)
public
AjaxResult
<
SysUserStoreRelation
>
get
(
@PathVariable
(
"id"
)
Long
id
)
{
return
AjaxResult
.
success
(
sysUserStoreRelationService
.
get
(
id
));
}
@PostMapping
(
"/add"
)
@Operation
(
summary
=
"新增"
)
public
AjaxResult
add
(
@RequestBody
SysUserStoreRelation
info
)
{
sysUserStoreRelationService
.
add
(
info
);
return
AjaxResult
.
success
();
}
@PostMapping
(
"/edit"
)
@Operation
(
summary
=
"编辑"
)
public
AjaxResult
edit
(
@RequestBody
SysUserStoreRelation
info
)
{
sysUserStoreRelationService
.
edit
(
info
);
return
AjaxResult
.
success
();
}
@PostMapping
(
"/delete/{id}"
)
@Operation
(
summary
=
"删除"
)
public
AjaxResult
remove
(
@PathVariable
(
"id"
)
Long
id
)
{
sysUserStoreRelationService
.
remove
(
id
);
return
AjaxResult
.
success
();
}
}
bs-auth/src/main/java/com/bs/web/controller/role/SpRoleController.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
controller
.
role
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.bs.common.annotation.Log
;
import
com.bs.common.core.controller.BaseController
;
import
com.bs.common.core.domain.AjaxResult
;
import
com.bs.common.core.domain.entity.role.SpRole
;
import
com.bs.common.core.page.TableDataInfo
;
import
com.bs.common.enums.BusinessType
;
import
com.bs.common.enums.OperatorType
;
import
com.bs.web.service.role.ISpRoleService
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
jakarta.annotation.Resource
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/sp/role"
)
@Tag
(
name
=
"服务商角色"
)
public
class
SpRoleController
extends
BaseController
{
@Resource
private
ISpRoleService
spRoleService
;
@PostMapping
(
"/list"
)
@Operation
(
summary
=
"列表"
)
public
AjaxResult
<
List
<
SpRole
>>
list
(
SpRole
query
)
{
List
<
SpRole
>
list
=
spRoleService
.
list
(
query
);
return
AjaxResult
.
success
(
list
);
}
@RequestMapping
(
value
=
"/page"
,
method
=
{
RequestMethod
.
GET
,
RequestMethod
.
POST
})
@Operation
(
summary
=
"分页列表"
)
public
TableDataInfo
page
(
@RequestBody
(
required
=
false
)
SpRole
query
)
{
com
.
bs
.
common
.
core
.
page
.
PageDomain
pageDomain
=
com
.
bs
.
common
.
core
.
page
.
TableSupport
.
buildPageRequest
();
Integer
pageNum
=
pageDomain
.
getPageNum
();
Integer
pageSize
=
pageDomain
.
getPageSize
();
if
(
pageNum
==
null
&&
query
!=
null
&&
query
.
getParams
()
!=
null
&&
query
.
getParams
().
get
(
"pageNum"
)
!=
null
)
{
pageNum
=
Integer
.
parseInt
(
query
.
getParams
().
get
(
"pageNum"
).
toString
());
}
if
(
pageSize
==
null
&&
query
!=
null
&&
query
.
getParams
()
!=
null
&&
query
.
getParams
().
get
(
"pageSize"
)
!=
null
)
{
pageSize
=
Integer
.
parseInt
(
query
.
getParams
().
get
(
"pageSize"
).
toString
());
}
if
(
pageNum
==
null
)
pageNum
=
1
;
if
(
pageSize
==
null
)
pageSize
=
10
;
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SpRole
>
pageResult
=
spRoleService
.
page
(
query
,
pageNum
,
pageSize
);
TableDataInfo
rspData
=
new
TableDataInfo
();
rspData
.
setCode
(
com
.
bs
.
common
.
constant
.
HttpStatus
.
SUCCESS
);
rspData
.
setMsg
(
"查询成功"
);
rspData
.
setRows
(
pageResult
.
getRecords
());
rspData
.
setTotal
(
pageResult
.
getTotal
());
return
rspData
;
}
@PostMapping
(
"/{id}"
)
@Operation
(
summary
=
"详情"
)
public
AjaxResult
<
SpRole
>
get
(
@PathVariable
(
"id"
)
Long
id
)
{
return
AjaxResult
.
success
(
spRoleService
.
get
(
id
));
}
@Log
(
title
=
"服务商角色新增"
,
businessType
=
BusinessType
.
INSERT
,
operatorType
=
OperatorType
.
MANAGE
)
@PostMapping
(
"/add"
)
@Operation
(
summary
=
"新增"
)
public
AjaxResult
add
(
@RequestBody
SpRole
info
)
{
spRoleService
.
add
(
info
);
return
AjaxResult
.
success
();
}
@Log
(
title
=
"服务商角色编辑"
,
businessType
=
BusinessType
.
UPDATE
,
operatorType
=
OperatorType
.
MANAGE
)
@PostMapping
(
"/edit"
)
@Operation
(
summary
=
"编辑"
)
public
AjaxResult
edit
(
@RequestBody
SpRole
info
)
{
spRoleService
.
edit
(
info
);
return
AjaxResult
.
success
();
}
@Log
(
title
=
"服务商角色删除"
,
businessType
=
BusinessType
.
DELETE
,
operatorType
=
OperatorType
.
MANAGE
)
@PostMapping
(
"/delete/{id}"
)
@Operation
(
summary
=
"删除"
)
public
AjaxResult
remove
(
@PathVariable
(
"id"
)
Long
id
)
{
spRoleService
.
remove
(
id
);
return
AjaxResult
.
success
();
}
}
bs-auth/src/main/java/com/bs/web/controller/sp/SpInfoController.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
controller
.
sp
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.bs.common.annotation.Log
;
import
com.bs.common.core.controller.BaseController
;
import
com.bs.common.core.domain.AjaxResult
;
import
com.bs.common.core.domain.entity.sp.SpInfo
;
import
com.bs.common.core.page.PageDomain
;
import
com.bs.common.core.page.TableDataInfo
;
import
com.bs.common.core.page.TableSupport
;
import
com.bs.common.enums.BusinessType
;
import
com.bs.common.enums.OperatorType
;
import
com.bs.web.service.sp.ISpInfoService
;
import
com.bs.common.core.domain.entity.store.BusinessStore
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
jakarta.annotation.Resource
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/sp/info"
)
@Tag
(
name
=
"服务商信息"
)
public
class
SpInfoController
extends
BaseController
{
@Resource
private
ISpInfoService
spInfoService
;
@PostMapping
(
"/list"
)
@Operation
(
summary
=
"列表"
)
public
AjaxResult
<
List
<
SpInfo
>>
list
(
SpInfo
query
)
{
List
<
SpInfo
>
list
=
spInfoService
.
list
(
query
);
return
AjaxResult
.
success
(
list
);
}
@GetMapping
(
value
=
"/page"
)
@Operation
(
summary
=
"分页列表"
)
public
TableDataInfo
page
(
SpInfo
query
)
{
com
.
bs
.
common
.
core
.
page
.
PageDomain
pageDomain
=
com
.
bs
.
common
.
core
.
page
.
TableSupport
.
buildPageRequest
();
Integer
pageNum
=
pageDomain
.
getPageNum
();
Integer
pageSize
=
pageDomain
.
getPageSize
();
if
(
pageNum
==
null
&&
query
!=
null
&&
query
.
getParams
()
!=
null
&&
query
.
getParams
().
get
(
"pageNum"
)
!=
null
)
{
pageNum
=
Integer
.
parseInt
(
query
.
getParams
().
get
(
"pageNum"
).
toString
());
}
if
(
pageSize
==
null
&&
query
!=
null
&&
query
.
getParams
()
!=
null
&&
query
.
getParams
().
get
(
"pageSize"
)
!=
null
)
{
pageSize
=
Integer
.
parseInt
(
query
.
getParams
().
get
(
"pageSize"
).
toString
());
}
if
(
pageNum
==
null
)
pageNum
=
1
;
if
(
pageSize
==
null
)
pageSize
=
10
;
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SpInfo
>
pageResult
=
spInfoService
.
page
(
query
,
pageNum
,
pageSize
);
TableDataInfo
rspData
=
new
TableDataInfo
();
rspData
.
setCode
(
com
.
bs
.
common
.
constant
.
HttpStatus
.
SUCCESS
);
rspData
.
setMsg
(
"查询成功"
);
rspData
.
setRows
(
pageResult
.
getRecords
());
rspData
.
setTotal
(
pageResult
.
getTotal
());
return
rspData
;
}
@PostMapping
(
"/{id}"
)
@Operation
(
summary
=
"详情"
)
public
AjaxResult
<
SpInfo
>
get
(
@PathVariable
(
"id"
)
Long
id
)
{
return
AjaxResult
.
success
(
spInfoService
.
get
(
id
));
}
@Log
(
title
=
"服务商信息"
,
businessType
=
BusinessType
.
INSERT
,
operatorType
=
OperatorType
.
MANAGE
)
@PostMapping
(
"/add"
)
@Operation
(
summary
=
"新增"
)
public
AjaxResult
add
(
@RequestBody
@Validated
SpInfo
info
,
BindingResult
br
)
{
if
(
br
.
hasErrors
())
{
return
AjaxResult
.
error
(
br
.
getFieldError
().
getDefaultMessage
());
}
spInfoService
.
add
(
info
);
return
AjaxResult
.
success
();
}
@Log
(
title
=
"服务商信息"
,
businessType
=
BusinessType
.
UPDATE
,
operatorType
=
OperatorType
.
MANAGE
)
@PostMapping
(
"/edit"
)
@Operation
(
summary
=
"编辑"
)
public
AjaxResult
edit
(
@RequestBody
@Validated
SpInfo
info
,
BindingResult
br
)
{
if
(
br
.
hasErrors
())
{
return
AjaxResult
.
error
(
br
.
getFieldError
().
getDefaultMessage
());
}
spInfoService
.
edit
(
info
);
return
AjaxResult
.
success
();
}
@Log
(
title
=
"服务商信息"
,
businessType
=
BusinessType
.
DELETE
,
operatorType
=
OperatorType
.
MANAGE
)
@PostMapping
(
"/delete/{id}"
)
@Operation
(
summary
=
"删除"
)
public
AjaxResult
remove
(
@PathVariable
(
"id"
)
Long
id
)
{
spInfoService
.
remove
(
id
);
return
AjaxResult
.
success
();
}
@GetMapping
(
value
=
"/storeInfo/list/{spCode}"
)
@Operation
(
summary
=
"根据服务商编码查询关联的门店分页列表"
)
public
TableDataInfo
<
List
<
BusinessStore
>>
selectStoreListBySpCode
(
@PathVariable
(
"spCode"
)
String
spCode
)
{
PageDomain
pageDomain
=
TableSupport
.
buildPageRequest
();
Integer
pageNum
=
pageDomain
.
getPageNum
();
Integer
pageSize
=
pageDomain
.
getPageSize
();
if
(
pageNum
==
null
)
pageNum
=
1
;
if
(
pageSize
==
null
)
pageSize
=
10
;
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
BusinessStore
>
pageResult
=
spInfoService
.
selectStoreListBySpCodePage
(
spCode
,
pageNum
,
pageSize
);
TableDataInfo
<
List
<
BusinessStore
>>
rspData
=
new
TableDataInfo
<>();
rspData
.
setCode
(
com
.
bs
.
common
.
constant
.
HttpStatus
.
SUCCESS
);
rspData
.
setMsg
(
"查询成功"
);
rspData
.
setRows
(
pageResult
.
getRecords
());
rspData
.
setTotal
(
pageResult
.
getTotal
());
return
rspData
;
}
}
bs-auth/src/main/java/com/bs/web/controller/sp/SpUserController.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
controller
.
sp
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.bs.common.annotation.Log
;
import
com.bs.common.constant.HttpStatus
;
import
com.bs.common.core.controller.BaseController
;
import
com.bs.common.core.domain.AjaxResult
;
import
com.bs.common.core.page.PageDomain
;
import
com.bs.common.core.page.TableDataInfo
;
import
com.bs.common.core.page.TableSupport
;
import
com.bs.common.enums.BusinessType
;
import
com.bs.common.enums.OperatorType
;
import
com.bs.web.domain.vo.sp.SpUserCreateReq
;
import
com.bs.web.domain.vo.sp.SpUserListReq
;
import
com.bs.web.domain.vo.sp.SpUserUpdateReq
;
import
com.bs.web.domain.vo.sp.SpUserBatchUpdateReq
;
import
com.bs.web.domain.vo.sp.SpUserVo
;
import
com.bs.web.service.sp.ISpInfoService
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
jakarta.annotation.Resource
;
import
org.springframework.util.StringUtils
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
java.util.List
;
@RestController
@RequestMapping
(
"/sp/user"
)
@Tag
(
name
=
"服务商用户管理"
)
public
class
SpUserController
extends
BaseController
{
@Resource
private
ISpInfoService
spInfoService
;
@Log
(
title
=
"服务商用户管理"
,
businessType
=
BusinessType
.
INSERT
)
@PostMapping
(
"/add"
)
@Operation
(
summary
=
"新增服务商用户"
)
public
AjaxResult
<
Long
>
add
(
@RequestBody
@Validated
SpUserCreateReq
req
)
{
return
AjaxResult
.
success
(
spInfoService
.
addSpUser
(
req
));
}
@Log
(
title
=
"服务商用户管理"
,
businessType
=
BusinessType
.
UPDATE
,
operatorType
=
OperatorType
.
MANAGE
)
@PostMapping
(
"/edit"
)
@Operation
(
summary
=
"设置服务商用户"
)
public
AjaxResult
edit
(
@RequestBody
@Validated
SpUserUpdateReq
req
)
{
spInfoService
.
editSpUser
(
req
);
return
AjaxResult
.
success
();
}
@Log
(
title
=
"服务商用户管理"
,
businessType
=
BusinessType
.
UPDATE
,
operatorType
=
OperatorType
.
MANAGE
)
@PostMapping
(
"/editBatch"
)
@Operation
(
summary
=
"批量设置服务商用户"
)
public
AjaxResult
editBatch
(
@RequestBody
@Validated
SpUserBatchUpdateReq
req
)
{
spInfoService
.
editBatchSpUser
(
req
);
return
AjaxResult
.
success
();
}
@GetMapping
(
value
=
"/list"
)
@Operation
(
summary
=
"查询服务商用户列表"
)
public
TableDataInfo
<
List
<
SpUserVo
>>
list
(
SpUserListReq
req
)
{
PageDomain
pageDomain
=
TableSupport
.
buildPageRequest
();
Integer
pageNum
=
pageDomain
.
getPageNum
();
Integer
pageSize
=
pageDomain
.
getPageSize
();
if
(
pageNum
==
null
)
pageNum
=
1
;
if
(
pageSize
==
null
)
pageSize
=
10
;
IPage
<
SpUserVo
>
pageResult
=
spInfoService
.
selectSpUserPage
(
req
,
pageNum
,
pageSize
);
TableDataInfo
<
List
<
SpUserVo
>>
rspData
=
new
TableDataInfo
<>();
rspData
.
setCode
(
HttpStatus
.
SUCCESS
);
rspData
.
setMsg
(
"查询成功"
);
rspData
.
setRows
(
pageResult
.
getRecords
());
rspData
.
setTotal
(
pageResult
.
getTotal
());
return
rspData
;
}
@GetMapping
(
"/checkPhone"
)
@Operation
(
summary
=
"服务商员工手机号重复校验"
)
public
AjaxResult
<
Boolean
>
checkPhone
(
@RequestParam
(
value
=
"phone"
,
required
=
true
)
String
phone
,
@RequestParam
(
value
=
"userName"
,
required
=
false
)
String
userName
)
{
if
(
StringUtils
.
isEmpty
(
phone
))
{
return
AjaxResult
.
error
(
"手机号不能为空"
);
}
return
AjaxResult
.
success
(
spInfoService
.
checkSpUserPhone
(
phone
,
userName
));
}
@Log
(
title
=
"服务商用户管理"
,
businessType
=
BusinessType
.
DELETE
,
operatorType
=
OperatorType
.
MANAGE
)
@PostMapping
(
"/delete/{userId}"
)
@Operation
(
summary
=
"删除服务商用户"
)
public
AjaxResult
<
Boolean
>
remove
(
@PathVariable
(
"userId"
)
Long
userId
)
{
return
AjaxResult
.
success
(
spInfoService
.
deleteSpUser
(
userId
));
}
@Log
(
title
=
"服务商用户管理"
,
businessType
=
BusinessType
.
DELETE
,
operatorType
=
OperatorType
.
MANAGE
)
@PostMapping
(
"/deleteBatch"
)
@Operation
(
summary
=
"批量删除服务商用户"
)
public
AjaxResult
<
Boolean
>
removeBatch
(
@RequestBody
List
<
Long
>
userIds
)
{
return
AjaxResult
.
success
(
spInfoService
.
deleteBatchSpUser
(
userIds
));
}
}
bs-auth/src/main/java/com/bs/web/controller/store/BusinessStoreController.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
controller
.
store
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.bs.common.core.controller.BaseController
;
import
com.bs.common.core.domain.AjaxResult
;
import
com.bs.common.core.domain.entity.store.BusinessStore
;
import
com.bs.common.core.page.PageDomain
;
import
com.bs.common.core.page.TableDataInfo
;
import
com.bs.common.core.page.TableSupport
;
import
com.bs.web.service.store.IBusinessStoreService
;
import
com.bs.web.domain.vo.store.BusinessStoreCreateReq
;
import
com.bs.web.domain.vo.store.BusinessStoreUpdateReq
;
import
io.swagger.v3.oas.annotations.Operation
;
import
io.swagger.v3.oas.annotations.tags.Tag
;
import
jakarta.annotation.Resource
;
import
org.springframework.validation.BindingResult
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.util.List
;
import
com.bs.common.core.domain.entity.sp.SpInfo
;
@RestController
@RequestMapping
(
"/sp/store"
)
@Tag
(
name
=
"门店信息"
)
public
class
BusinessStoreController
extends
BaseController
{
@Resource
private
IBusinessStoreService
businessStoreService
;
@PostMapping
(
"/spInfo/list/{storeCode}"
)
@Operation
(
summary
=
"根据门店编码查询关联的服务商分页列表"
)
public
TableDataInfo
selectSpListByStoreCode
(
@PathVariable
(
"storeCode"
)
String
storeCode
)
{
PageDomain
pageDomain
=
TableSupport
.
buildPageRequest
();
Integer
pageNum
=
pageDomain
.
getPageNum
();
Integer
pageSize
=
pageDomain
.
getPageSize
();
if
(
pageNum
==
null
)
pageNum
=
1
;
if
(
pageSize
==
null
)
pageSize
=
10
;
IPage
<
SpInfo
>
pageResult
=
businessStoreService
.
selectSpListByStoreCodePage
(
storeCode
,
pageNum
,
pageSize
);
TableDataInfo
rspData
=
new
TableDataInfo
();
rspData
.
setCode
(
com
.
bs
.
common
.
constant
.
HttpStatus
.
SUCCESS
);
rspData
.
setMsg
(
"查询成功"
);
rspData
.
setRows
(
pageResult
.
getRecords
());
rspData
.
setTotal
(
pageResult
.
getTotal
());
return
rspData
;
}
@GetMapping
(
"/list"
)
@Operation
(
summary
=
"列表"
)
public
AjaxResult
<
List
<
BusinessStore
>>
list
(
BusinessStore
query
)
{
List
<
BusinessStore
>
list
=
businessStoreService
.
list
(
query
);
return
AjaxResult
.
success
(
list
);
}
@GetMapping
(
value
=
"/page"
)
@Operation
(
summary
=
"分页列表"
)
public
TableDataInfo
page
(
BusinessStore
query
)
{
PageDomain
pageDomain
=
TableSupport
.
buildPageRequest
();
Integer
pageNum
=
pageDomain
.
getPageNum
();
Integer
pageSize
=
pageDomain
.
getPageSize
();
if
(
pageNum
==
null
&&
query
!=
null
&&
query
.
getParams
()
!=
null
&&
query
.
getParams
().
get
(
"pageNum"
)
!=
null
)
{
pageNum
=
Integer
.
parseInt
(
query
.
getParams
().
get
(
"pageNum"
).
toString
());
}
if
(
pageSize
==
null
&&
query
!=
null
&&
query
.
getParams
()
!=
null
&&
query
.
getParams
().
get
(
"pageSize"
)
!=
null
)
{
pageSize
=
Integer
.
parseInt
(
query
.
getParams
().
get
(
"pageSize"
).
toString
());
}
if
(
pageNum
==
null
)
pageNum
=
1
;
if
(
pageSize
==
null
)
pageSize
=
10
;
IPage
<
BusinessStore
>
pageResult
=
businessStoreService
.
page
(
query
,
pageNum
,
pageSize
);
TableDataInfo
rspData
=
new
TableDataInfo
();
rspData
.
setCode
(
com
.
bs
.
common
.
constant
.
HttpStatus
.
SUCCESS
);
rspData
.
setMsg
(
"查询成功"
);
rspData
.
setRows
(
pageResult
.
getRecords
());
rspData
.
setTotal
(
pageResult
.
getTotal
());
return
rspData
;
}
@PostMapping
(
"/{id}"
)
@Operation
(
summary
=
"详情"
)
public
AjaxResult
<
BusinessStore
>
get
(
@PathVariable
(
"id"
)
Long
id
)
{
return
AjaxResult
.
success
(
businessStoreService
.
get
(
id
));
}
@PostMapping
(
"/code/{code}"
)
@Operation
(
summary
=
"根据编码查询详情"
)
public
AjaxResult
<
BusinessStore
>
getByCode
(
@PathVariable
(
"code"
)
String
code
)
{
return
AjaxResult
.
success
(
businessStoreService
.
getByCode
(
code
));
}
@PostMapping
(
"/add"
)
@Operation
(
summary
=
"新增"
)
public
AjaxResult
add
(
@RequestBody
@Validated
BusinessStoreCreateReq
req
,
BindingResult
br
)
{
if
(
br
.
hasErrors
())
{
return
AjaxResult
.
error
(
br
.
getFieldError
().
getDefaultMessage
());
}
return
AjaxResult
.
success
(
businessStoreService
.
add
(
req
));
}
@PostMapping
(
"/edit"
)
@Operation
(
summary
=
"编辑"
)
public
AjaxResult
edit
(
@RequestBody
@Validated
BusinessStoreUpdateReq
req
,
BindingResult
br
)
{
if
(
br
.
hasErrors
())
{
return
AjaxResult
.
error
(
br
.
getFieldError
().
getDefaultMessage
());
}
businessStoreService
.
edit
(
req
);
return
AjaxResult
.
success
();
}
@PostMapping
(
"/delete/{id}"
)
@Operation
(
summary
=
"删除"
)
public
AjaxResult
remove
(
@PathVariable
(
"id"
)
Long
id
)
{
businessStoreService
.
remove
(
id
);
return
AjaxResult
.
success
();
}
@GetMapping
(
"/import/template"
)
@Operation
(
summary
=
"导入模板下载"
)
public
AjaxResult
importStoreTemplateDownLode
()
{
return
AjaxResult
.
success
(
businessStoreService
.
importStoreTemplateDownLode
());
}
@GetMapping
(
"/import"
)
@Operation
(
summary
=
"导入"
)
public
AjaxResult
importStore
(
@RequestParam
(
"url"
)
String
url
)
{
// 参数校验
if
(
url
==
null
||
url
.
isEmpty
())
{
return
AjaxResult
.
error
(
"导入文件URL不能为空"
);
}
return
AjaxResult
.
success
(
businessStoreService
.
importStore
(
url
));
}
@GetMapping
(
"/import/progress/{importId}"
)
@Operation
(
summary
=
"获取导入进度"
)
public
AjaxResult
getImportProgress
(
@PathVariable
(
"importId"
)
String
importId
)
{
return
AjaxResult
.
success
(
businessStoreService
.
getImportProgress
(
importId
));
}
}
bs-auth/src/main/java/com/bs/web/feign/FileFeignClient.java
View file @
f1b0793
...
...
@@ -8,7 +8,7 @@ import org.springframework.web.bind.annotation.PostMapping;
import
org.springframework.web.bind.annotation.RequestPart
;
import
org.springframework.web.multipart.MultipartFile
;
@FeignClient
(
name
=
"
linkwe-file"
,
contextId
=
"AuthFileFeignClient"
,
path
=
"/fil
e"
)
@FeignClient
(
name
=
"
bs-fileservice"
,
contextId
=
"AuthFileFeignClient"
,
path
=
"/fileservic
e"
)
public
interface
FileFeignClient
{
/**
* 文件上传
...
...
bs-auth/src/main/java/com/bs/web/mapper/relation/SpStoreRelationMapper.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
mapper
.
relation
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.bs.common.core.domain.entity.relation.SpStoreRelation
;
public
interface
SpStoreRelationMapper
extends
BaseMapper
<
SpStoreRelation
>
{
}
bs-auth/src/main/java/com/bs/web/mapper/relation/SysUserSpRelationMapper.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
mapper
.
relation
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.bs.common.core.domain.entity.relation.SysUserSpRelation
;
import
org.apache.ibatis.annotations.MapKey
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
import
java.util.Map
;
public
interface
SysUserSpRelationMapper
extends
BaseMapper
<
SysUserSpRelation
>
{
/**
* 统计每个服务商下的店长数量(满足三个条件:用户未删除、门店关联存在且未删除、服务商关联存在且未删除)
*
* @param spCodes 服务商编码列表
* @param roleCode 角色编码
* @param storeCode 门店编码
* @return List<Map<String, Object>>,每个 map 包含 sp_code 和 user_count
*/
@MapKey
(
"sp_code"
)
List
<
Map
<
String
,
Object
>>
countStoreManagersBySpCode
(
@Param
(
"spCodes"
)
List
<
String
>
spCodes
,
@Param
(
"roleCode"
)
String
roleCode
,
@Param
(
"storeCode"
)
String
storeCode
);
/**
* 统计指定服务商下各个门店的成员数量(满足三个条件:用户未删除、门店关联存在且未删除、服务商关联存在且未删除、指定角色)
*
* @param spCode 服务商编码
* @param storeCodes 门店编码列表
* @param roleCode 角色编码
* @return List<Map<String, Object>>,每个 map 包含 store_code 和 user_count
*/
@MapKey
(
"store_code"
)
List
<
Map
<
String
,
Object
>>
countUsersBySpCodeAndStoreCodes
(
@Param
(
"spCode"
)
String
spCode
,
@Param
(
"storeCodes"
)
List
<
String
>
storeCodes
,
@Param
(
"roleCode"
)
String
roleCode
);
}
bs-auth/src/main/java/com/bs/web/mapper/relation/SysUserStoreRelationMapper.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
mapper
.
relation
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.bs.common.core.domain.entity.relation.SysUserStoreRelation
;
import
com.bs.web.domain.vo.relation.SysUserStoreRelationQueryReq
;
import
com.bs.web.domain.vo.relation.SysUserStoreRelationVO
;
import
org.apache.ibatis.annotations.Param
;
public
interface
SysUserStoreRelationMapper
extends
BaseMapper
<
SysUserStoreRelation
>
{
IPage
<
SysUserStoreRelationVO
>
selectUserStoreRelationPage
(
@Param
(
"page"
)
IPage
<
SysUserStoreRelationVO
>
page
,
@Param
(
"req"
)
SysUserStoreRelationQueryReq
req
);
}
bs-auth/src/main/java/com/bs/web/mapper/role/SpRoleMapper.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
mapper
.
role
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.bs.common.core.domain.entity.role.SpRole
;
public
interface
SpRoleMapper
extends
BaseMapper
<
SpRole
>
{
}
bs-auth/src/main/java/com/bs/web/mapper/sp/SpInfoMapper.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
mapper
.
sp
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.bs.common.core.domain.entity.sp.SpInfo
;
import
com.bs.web.domain.vo.sp.SpUserVo
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
public
interface
SpInfoMapper
extends
BaseMapper
<
SpInfo
>
{
/**
* 查询服务商用户列表
* @param spId 服务商ID
* @param keyword 关键词(姓名或手机号)
* @param spRoleCode 角色编码
* @param storeCode 门店编码
* @return 用户列表
*/
List
<
SpUserVo
>
selectSpUserList
(
@Param
(
"spId"
)
Long
spId
,
@Param
(
"keyword"
)
String
keyword
,
@Param
(
"spRoleCode"
)
String
spRoleCode
,
@Param
(
"storeCode"
)
String
storeCode
);
/**
* 查询服务商用户分页列表
* @param page 分页对象
* @param spId 服务商ID
* @param keyword 关键词(姓名或手机号)
* @param spRoleCode 角色编码
* @param storeCode 门店编码
* @return 用户分页列表
*/
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SpUserVo
>
selectSpUserList
(
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SpUserVo
>
page
,
@Param
(
"spId"
)
Long
spId
,
@Param
(
"keyword"
)
String
keyword
,
@Param
(
"spRoleCode"
)
String
spRoleCode
,
@Param
(
"storeCode"
)
String
storeCode
);
}
bs-auth/src/main/java/com/bs/web/mapper/store/BusinessStoreMapper.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
mapper
.
store
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.bs.common.core.domain.entity.store.BusinessStore
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
public
interface
BusinessStoreMapper
extends
BaseMapper
<
BusinessStore
>
{
/**
* 根据服务商编码查询关联的门店列表
* @param spCode 服务商编码
* @param storeName 门店名称(模糊搜索)
* @return 门店列表
*/
List
<
BusinessStore
>
selectStoreListBySpId
(
@Param
(
"spCode"
)
String
spCode
,
@Param
(
"storeName"
)
String
storeName
);
/**
* 根据服务商编码分页查询关联的门店列表
* @param page 分页参数
* @param spCode 服务商编码
* @param storeName 门店名称(模糊搜索)
* @return 门店分页列表
*/
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
BusinessStore
>
selectStoreListBySpIdPage
(
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
BusinessStore
>
page
,
@Param
(
"spCode"
)
String
spCode
,
@Param
(
"storeName"
)
String
storeName
);
}
bs-auth/src/main/java/com/bs/web/service/relation/ISpStoreRelationService.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
service
.
relation
;
import
com.bs.common.core.domain.entity.relation.SpStoreRelation
;
import
com.bs.common.core.domain.entity.store.BusinessStore
;
import
com.bs.web.domain.vo.sp.SpStoreRelationMaintainReq
;
import
java.util.List
;
/**
* 服务商-门店关联服务接口
* 定义关联关系的基础增删改查方法
*/
public
interface
ISpStoreRelationService
{
/**
* 列表查询
*/
List
<
SpStoreRelation
>
list
(
SpStoreRelation
query
);
/**
* 分页列表查询
*/
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SpStoreRelation
>
page
(
SpStoreRelation
query
,
Integer
pageNum
,
Integer
pageSize
);
/**
* 详情查询
*/
SpStoreRelation
get
(
Long
id
);
/**
* 新增关联
*/
void
add
(
SpStoreRelation
info
);
/**
* 编辑关联
*/
void
edit
(
SpStoreRelation
info
);
/**
* 删除关联
*/
void
remove
(
Long
id
);
/**
* 根据门店编码查询未删除的关联列表,并确保服务商信息未删除
*/
List
<
SpStoreRelation
>
listByStoreCodeActive
(
String
storeCode
);
/**
* 维护服务商关联门店关系
* @param req 请求参数
* @return 是否成功
*/
Boolean
maintainRelation
(
SpStoreRelationMaintainReq
req
);
/**
* 查询指定服务商关联的所有门店列表
* @param spId 服务商ID
* @param storeName 门店名称(模糊搜索)
* @return 门店列表
*/
List
<
BusinessStore
>
getStoreListBySpId
(
Long
spId
,
String
storeName
);
/**
* 分页查询指定服务商关联的所有门店列表
* @param spId 服务商ID
* @param storeName 门店名称(模糊搜索)
* @param pageNum 页码
* @param pageSize 每页大小
* @return 门店分页列表
*/
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
BusinessStore
>
getStoreListBySpIdPage
(
Long
spId
,
String
storeName
,
Integer
pageNum
,
Integer
pageSize
);
}
bs-auth/src/main/java/com/bs/web/service/relation/ISysUserSpRelationService.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
service
.
relation
;
import
com.bs.common.core.domain.entity.relation.SysUserSpRelation
;
import
java.util.List
;
/**
* 用户-服务商关联服务接口
* 定义关联关系的基础增删改查方法
*/
public
interface
ISysUserSpRelationService
{
/**
* 列表查询
*/
List
<
SysUserSpRelation
>
list
(
SysUserSpRelation
query
);
/**
* 分页查询
*/
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SysUserSpRelation
>
page
(
SysUserSpRelation
query
,
Integer
pageNum
,
Integer
pageSize
);
/**
* 详情查询
*/
SysUserSpRelation
get
(
Long
id
);
/**
* 新增关联
*/
void
add
(
SysUserSpRelation
info
);
/**
* 编辑关联
*/
void
edit
(
SysUserSpRelation
info
);
/**
* 删除关联
*/
void
remove
(
Long
id
);
}
bs-auth/src/main/java/com/bs/web/service/relation/ISysUserStoreRelationService.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
service
.
relation
;
import
com.bs.common.core.domain.entity.relation.SysUserStoreRelation
;
import
com.bs.web.domain.vo.relation.SysUserStoreRelationQueryReq
;
import
com.bs.web.domain.vo.relation.SysUserStoreRelationVO
;
import
java.util.List
;
/**
* 用户-门店关联服务接口
* 定义关联关系的基础增删改查方法
*/
public
interface
ISysUserStoreRelationService
{
/**
* 列表查询
*/
List
<
SysUserStoreRelation
>
list
(
SysUserStoreRelation
query
);
/**
* 分页查询
*/
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SysUserStoreRelation
>
page
(
SysUserStoreRelation
query
,
Integer
pageNum
,
Integer
pageSize
);
/**
* 自定义分页查询(带门店名称和关联表排序)
*/
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SysUserStoreRelationVO
>
pageCustom
(
SysUserStoreRelationQueryReq
req
,
Integer
pageNum
,
Integer
pageSize
);
/**
* 详情查询
*/
SysUserStoreRelation
get
(
Long
id
);
/**
* 新增关联
*/
void
add
(
SysUserStoreRelation
info
);
/**
* 编辑关联
*/
void
edit
(
SysUserStoreRelation
info
);
/**
* 删除关联
*/
void
remove
(
Long
id
);
}
bs-auth/src/main/java/com/bs/web/service/relation/impl/SpStoreRelationServiceImpl.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
service
.
relation
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.bs.common.core.domain.entity.relation.SpStoreRelation
;
import
com.bs.common.core.domain.entity.store.BusinessStore
;
import
com.bs.common.exception.CustomException
;
import
com.bs.common.utils.DateUtils
;
import
com.bs.common.utils.SecurityUtils
;
import
com.bs.web.domain.vo.sp.SpStoreRelationMaintainReq
;
import
com.bs.web.mapper.relation.SpStoreRelationMapper
;
import
com.bs.web.mapper.sp.SpInfoMapper
;
import
com.bs.web.mapper.store.BusinessStoreMapper
;
import
com.bs.common.core.domain.entity.sp.SpInfo
;
import
com.bs.web.service.relation.ISpStoreRelationService
;
import
jakarta.annotation.Resource
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
/**
* 服务商-门店关联服务实现
* 负责关联关系的基础增删改查
*/
@Service
public
class
SpStoreRelationServiceImpl
implements
ISpStoreRelationService
{
@Resource
private
SpStoreRelationMapper
spStoreRelationMapper
;
@Resource
private
SpInfoMapper
spInfoMapper
;
@Resource
private
BusinessStoreMapper
businessStoreMapper
;
/**
* 列表查询
*/
@Override
public
List
<
SpStoreRelation
>
list
(
SpStoreRelation
query
)
{
LambdaQueryWrapper
<
SpStoreRelation
>
wrapper
=
buildQueryWrapper
(
query
);
return
spStoreRelationMapper
.
selectList
(
wrapper
);
}
/**
* 分页列表查询
*/
@Override
public
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SpStoreRelation
>
page
(
SpStoreRelation
query
,
Integer
pageNum
,
Integer
pageSize
)
{
LambdaQueryWrapper
<
SpStoreRelation
>
wrapper
=
buildQueryWrapper
(
query
);
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<
SpStoreRelation
>
page
=
new
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<>(
pageNum
,
pageSize
);
return
spStoreRelationMapper
.
selectPage
(
page
,
wrapper
);
}
private
LambdaQueryWrapper
<
SpStoreRelation
>
buildQueryWrapper
(
SpStoreRelation
query
)
{
LambdaQueryWrapper
<
SpStoreRelation
>
wrapper
=
new
LambdaQueryWrapper
<>();
if
(
query
!=
null
)
{
if
(
query
.
getSpCode
()
!=
null
&&
!
query
.
getSpCode
().
isEmpty
())
{
wrapper
.
eq
(
SpStoreRelation:
:
getSpCode
,
query
.
getSpCode
());
}
if
(
query
.
getStoreCode
()
!=
null
&&
!
query
.
getStoreCode
().
isEmpty
())
{
wrapper
.
eq
(
SpStoreRelation:
:
getStoreCode
,
query
.
getStoreCode
());
}
if
(
query
.
getStatus
()
!=
null
)
{
wrapper
.
eq
(
SpStoreRelation:
:
getStatus
,
query
.
getStatus
());
}
if
(
query
.
getDelFlag
()
!=
null
)
{
wrapper
.
eq
(
SpStoreRelation:
:
getDelFlag
,
query
.
getDelFlag
());
}
}
return
wrapper
;
}
/**
* 详情查询
*/
@Override
public
SpStoreRelation
get
(
Long
id
)
{
return
spStoreRelationMapper
.
selectById
(
id
);
}
/**
* 新增关联
*/
@Override
public
void
add
(
SpStoreRelation
info
)
{
spStoreRelationMapper
.
insert
(
info
);
}
/**
* 编辑关联
*/
@Override
public
void
edit
(
SpStoreRelation
info
)
{
spStoreRelationMapper
.
updateById
(
info
);
}
/**
* 删除关联
*/
@Override
public
void
remove
(
Long
id
)
{
spStoreRelationMapper
.
deleteById
(
id
);
}
/**
* 根据门店编码查询有效的关联关系
*/
@Override
public
List
<
SpStoreRelation
>
listByStoreCodeActive
(
String
storeCode
)
{
LambdaQueryWrapper
<
SpStoreRelation
>
qw
=
new
LambdaQueryWrapper
<>();
qw
.
eq
(
SpStoreRelation:
:
getStoreCode
,
storeCode
)
.
eq
(
SpStoreRelation:
:
getDelFlag
,
0
);
List
<
SpStoreRelation
>
relations
=
spStoreRelationMapper
.
selectList
(
qw
);
if
(
relations
==
null
||
relations
.
isEmpty
())
{
return
relations
;
}
// 收集关联的服务商编码
java
.
util
.
Set
<
String
>
spCodes
=
new
java
.
util
.
HashSet
<>();
for
(
SpStoreRelation
r
:
relations
)
{
if
(
r
.
getSpCode
()
!=
null
&&
!
r
.
getSpCode
().
isBlank
())
{
spCodes
.
add
(
r
.
getSpCode
());
}
}
if
(
spCodes
.
isEmpty
())
{
return
java
.
util
.
Collections
.
emptyList
();
}
// 查询未删除的服务商编码集合
List
<
SpInfo
>
spInfos
=
spInfoMapper
.
selectList
(
new
LambdaQueryWrapper
<
SpInfo
>()
.
in
(
SpInfo:
:
getSpCode
,
spCodes
)
.
eq
(
SpInfo:
:
getDelFlag
,
0
));
java
.
util
.
Set
<
String
>
aliveSpCodes
=
new
java
.
util
.
HashSet
<>();
for
(
SpInfo
s
:
spInfos
)
{
if
(
s
.
getSpCode
()
!=
null
&&
!
s
.
getSpCode
().
isBlank
())
{
aliveSpCodes
.
add
(
s
.
getSpCode
());
}
}
// 仅保留服务商未删除的关联
List
<
SpStoreRelation
>
result
=
new
java
.
util
.
ArrayList
<>();
for
(
SpStoreRelation
r
:
relations
)
{
if
(
aliveSpCodes
.
contains
(
r
.
getSpCode
()))
{
result
.
add
(
r
);
}
}
// 按创建时间倒序
result
.
sort
((
o1
,
o2
)
->
o2
.
getCreateTime
().
compareTo
(
o1
.
getCreateTime
()));
return
result
;
}
/**
* 维护服务商关联门店关系
*/
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Boolean
maintainRelation
(
SpStoreRelationMaintainReq
req
)
{
// 1. 校验服务商存在
SpInfo
spInfo
=
spInfoMapper
.
selectById
(
req
.
getSpId
());
if
(
spInfo
==
null
||
spInfo
.
getDelFlag
()
==
1
)
{
throw
new
CustomException
(
"服务商不存在"
);
}
String
spCode
=
spInfo
.
getSpCode
();
List
<
String
>
inputStoreCodes
=
req
.
getStoreCodes
();
if
(
inputStoreCodes
==
null
||
inputStoreCodes
.
isEmpty
())
{
// 如果入参为空,则删除该服务商下所有关联关系
spStoreRelationMapper
.
delete
(
new
LambdaQueryWrapper
<
SpStoreRelation
>()
.
eq
(
SpStoreRelation:
:
getSpCode
,
spCode
));
return
true
;
}
// 2. 校验门店是否存在且启用
List
<
BusinessStore
>
validStores
=
businessStoreMapper
.
selectList
(
new
LambdaQueryWrapper
<
BusinessStore
>()
.
in
(
BusinessStore:
:
getStoreCode
,
inputStoreCodes
)
.
eq
(
BusinessStore:
:
getDelFlag
,
0
));
Set
<
String
>
validStoreCodeSet
=
validStores
.
stream
()
.
map
(
BusinessStore:
:
getStoreCode
)
.
collect
(
Collectors
.
toSet
());
for
(
String
code
:
inputStoreCodes
)
{
if
(!
validStoreCodeSet
.
contains
(
code
))
{
throw
new
CustomException
(
"门店编码 ["
+
code
+
"] 不存在"
);
}
// 检查状态 (Requirement: 校验门店是否是启用状态)
BusinessStore
store
=
validStores
.
stream
().
filter
(
s
->
s
.
getStoreCode
().
equals
(
code
)).
findFirst
().
orElse
(
null
);
if
(
store
!=
null
&&
store
.
getStatus
()
!=
1
)
{
// 使用 storeCode 而非 storeName 避免潜在的循环引用问题
throw
new
CustomException
(
"门店 ["
+
store
.
getStoreName
()
+
"] 对应的门店未启用"
);
}
}
// 3. 获取现有关系
List
<
SpStoreRelation
>
existingRelations
=
spStoreRelationMapper
.
selectList
(
new
LambdaQueryWrapper
<
SpStoreRelation
>()
.
eq
(
SpStoreRelation:
:
getSpCode
,
spCode
));
Set
<
String
>
existingStoreCodes
=
existingRelations
.
stream
()
.
map
(
SpStoreRelation:
:
getStoreCode
)
.
collect
(
Collectors
.
toSet
());
// 4. 处理新增 (In input, not in DB)
List
<
String
>
toAdd
=
inputStoreCodes
.
stream
()
.
filter
(
code
->
!
existingStoreCodes
.
contains
(
code
))
.
collect
(
Collectors
.
toList
());
for
(
String
code
:
toAdd
)
{
SpStoreRelation
relation
=
SpStoreRelation
.
builder
()
.
spCode
(
spCode
)
.
storeCode
(
code
)
.
relationType
(
0
)
.
status
(
1
)
.
sortNo
(
1
)
.
serviceLevel
(
1
)
.
isDefault
(
0
)
.
startDate
(
DateUtils
.
getNowDate
())
.
delFlag
(
0
)
.
build
();
relation
.
setCreateBy
(
SecurityUtils
.
getUserName
());
relation
.
setCreateTime
(
DateUtils
.
getNowDate
());
relation
.
setUpdateBy
(
SecurityUtils
.
getUserName
());
relation
.
setUpdateTime
(
DateUtils
.
getNowDate
());
spStoreRelationMapper
.
insert
(
relation
);
}
// 5. 处理删除 (In DB, not in input)
List
<
Long
>
toDeleteIds
=
existingRelations
.
stream
()
.
filter
(
r
->
!
inputStoreCodes
.
contains
(
r
.
getStoreCode
()))
.
map
(
SpStoreRelation:
:
getId
)
.
collect
(
Collectors
.
toList
());
if
(!
toDeleteIds
.
isEmpty
())
{
spStoreRelationMapper
.
deleteBatchIds
(
toDeleteIds
);
}
return
true
;
}
/**
* 查询指定服务商关联的所有门店列表
*/
@Override
public
List
<
BusinessStore
>
getStoreListBySpId
(
Long
spId
,
String
storeName
)
{
SpInfo
spInfo
=
spInfoMapper
.
selectById
(
spId
);
if
(
spInfo
==
null
)
{
throw
new
CustomException
(
"服务商不存在"
);
}
return
businessStoreMapper
.
selectStoreListBySpId
(
spInfo
.
getSpCode
(),
storeName
);
}
/**
* 分页查询指定服务商关联的所有门店列表
*/
@Override
public
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
BusinessStore
>
getStoreListBySpIdPage
(
Long
spId
,
String
storeName
,
Integer
pageNum
,
Integer
pageSize
)
{
SpInfo
spInfo
=
spInfoMapper
.
selectById
(
spId
);
if
(
spInfo
==
null
)
{
throw
new
CustomException
(
"服务商不存在"
);
}
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<
BusinessStore
>
page
=
new
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<>(
pageNum
,
pageSize
);
return
businessStoreMapper
.
selectStoreListBySpIdPage
(
page
,
spInfo
.
getSpCode
(),
storeName
);
}
}
bs-auth/src/main/java/com/bs/web/service/relation/impl/SysUserSpRelationServiceImpl.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
service
.
relation
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.bs.common.core.domain.entity.relation.SysUserSpRelation
;
import
com.bs.web.mapper.relation.SysUserSpRelationMapper
;
import
com.bs.web.service.relation.ISysUserSpRelationService
;
import
jakarta.annotation.Resource
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
/**
* 用户-服务商关联服务实现
* 负责关联关系的基础增删改查
*/
@Service
public
class
SysUserSpRelationServiceImpl
implements
ISysUserSpRelationService
{
@Resource
private
SysUserSpRelationMapper
sysUserSpRelationMapper
;
/**
* 列表查询
*/
@Override
public
List
<
SysUserSpRelation
>
list
(
SysUserSpRelation
query
)
{
return
sysUserSpRelationMapper
.
selectList
(
new
LambdaQueryWrapper
<>());
}
/**
* 分页查询
*/
@Override
public
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SysUserSpRelation
>
page
(
SysUserSpRelation
query
,
Integer
pageNum
,
Integer
pageSize
)
{
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<
SysUserSpRelation
>
page
=
new
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<>(
pageNum
,
pageSize
);
return
sysUserSpRelationMapper
.
selectPage
(
page
,
new
LambdaQueryWrapper
<>());
}
/**
* 详情查询
*/
@Override
public
SysUserSpRelation
get
(
Long
id
)
{
return
sysUserSpRelationMapper
.
selectById
(
id
);
}
/**
* 新增关联
*/
@Override
public
void
add
(
SysUserSpRelation
info
)
{
sysUserSpRelationMapper
.
insert
(
info
);
}
/**
* 编辑关联
*/
@Override
public
void
edit
(
SysUserSpRelation
info
)
{
sysUserSpRelationMapper
.
updateById
(
info
);
}
/**
* 删除关联
*/
@Override
public
void
remove
(
Long
id
)
{
sysUserSpRelationMapper
.
deleteById
(
id
);
}
}
bs-auth/src/main/java/com/bs/web/service/relation/impl/SysUserStoreRelationServiceImpl.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
service
.
relation
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.bs.common.core.domain.entity.relation.SysUserStoreRelation
;
import
com.bs.web.domain.vo.relation.SysUserStoreRelationQueryReq
;
import
com.bs.web.domain.vo.relation.SysUserStoreRelationVO
;
import
com.bs.web.mapper.relation.SysUserStoreRelationMapper
;
import
com.bs.web.service.relation.ISysUserStoreRelationService
;
import
jakarta.annotation.Resource
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
/**
* 用户-门店关联服务实现
* 负责关联关系的基础增删改查
*/
@Service
public
class
SysUserStoreRelationServiceImpl
implements
ISysUserStoreRelationService
{
@Resource
private
SysUserStoreRelationMapper
sysUserStoreRelationMapper
;
/**
* 列表查询
*/
@Override
public
List
<
SysUserStoreRelation
>
list
(
SysUserStoreRelation
query
)
{
return
sysUserStoreRelationMapper
.
selectList
(
new
LambdaQueryWrapper
<>());
}
/**
* 分页查询
*/
@Override
public
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SysUserStoreRelation
>
page
(
SysUserStoreRelation
query
,
Integer
pageNum
,
Integer
pageSize
)
{
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<
SysUserStoreRelation
>
page
=
new
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<>(
pageNum
,
pageSize
);
return
sysUserStoreRelationMapper
.
selectPage
(
page
,
new
LambdaQueryWrapper
<>());
}
/**
* 自定义分页查询
*/
@Override
public
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SysUserStoreRelationVO
>
pageCustom
(
SysUserStoreRelationQueryReq
req
,
Integer
pageNum
,
Integer
pageSize
)
{
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<
SysUserStoreRelationVO
>
page
=
new
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<>(
pageNum
,
pageSize
);
return
sysUserStoreRelationMapper
.
selectUserStoreRelationPage
(
page
,
req
);
}
/**
* 详情查询
*/
@Override
public
SysUserStoreRelation
get
(
Long
id
)
{
return
sysUserStoreRelationMapper
.
selectById
(
id
);
}
/**
* 新增关联
*/
@Override
public
void
add
(
SysUserStoreRelation
info
)
{
sysUserStoreRelationMapper
.
insert
(
info
);
}
/**
* 编辑关联
*/
@Override
public
void
edit
(
SysUserStoreRelation
info
)
{
sysUserStoreRelationMapper
.
updateById
(
info
);
}
/**
* 删除关联
*/
@Override
public
void
remove
(
Long
id
)
{
sysUserStoreRelationMapper
.
deleteById
(
id
);
}
}
bs-auth/src/main/java/com/bs/web/service/role/ISpRoleService.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
service
.
role
;
import
com.bs.common.core.domain.entity.role.SpRole
;
import
java.util.List
;
/**
* 服务商角色服务接口
* 定义服务商角色的基础增删改查方法
*/
public
interface
ISpRoleService
{
/**
* 列表查询
* @param query 查询条件
* @return 角色列表
*/
List
<
SpRole
>
list
(
SpRole
query
);
/**
* 分页查询
* @param query 查询条件
* @param pageNum 页码
* @param pageSize 每页条数
* @return 角色分页列表
*/
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SpRole
>
page
(
SpRole
query
,
Integer
pageNum
,
Integer
pageSize
);
/**
* 详情查询
* @param id 角色ID
* @return 角色详情
*/
SpRole
get
(
Long
id
);
/**
* 新增角色
* @param info 角色信息
*/
void
add
(
SpRole
info
);
/**
* 编辑角色
* @param info 角色信息
*/
void
edit
(
SpRole
info
);
/**
* 删除角色
* @param id 角色ID
*/
void
remove
(
Long
id
);
}
bs-auth/src/main/java/com/bs/web/service/role/impl/SpRoleServiceImpl.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
service
.
role
.
impl
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.bs.common.core.domain.entity.role.SpRole
;
import
com.bs.web.mapper.role.SpRoleMapper
;
import
com.bs.web.service.role.ISpRoleService
;
import
jakarta.annotation.Resource
;
import
org.springframework.stereotype.Service
;
import
java.util.List
;
/**
* 服务商角色服务实现
* 负责角色的基础增删改查
*/
@Service
public
class
SpRoleServiceImpl
implements
ISpRoleService
{
@Resource
private
SpRoleMapper
spRoleMapper
;
/**
* 列表查询
*/
@Override
public
List
<
SpRole
>
list
(
SpRole
query
)
{
return
spRoleMapper
.
selectList
(
new
LambdaQueryWrapper
<>());
}
/**
* 分页查询
*/
@Override
public
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SpRole
>
page
(
SpRole
query
,
Integer
pageNum
,
Integer
pageSize
)
{
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<
SpRole
>
page
=
new
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<>(
pageNum
,
pageSize
);
return
spRoleMapper
.
selectPage
(
page
,
new
LambdaQueryWrapper
<>());
}
/**
* 详情查询
*/
@Override
public
SpRole
get
(
Long
id
)
{
return
spRoleMapper
.
selectById
(
id
);
}
/**
* 新增角色
*/
@Override
public
void
add
(
SpRole
info
)
{
spRoleMapper
.
insert
(
info
);
}
/**
* 编辑角色
*/
@Override
public
void
edit
(
SpRole
info
)
{
spRoleMapper
.
updateById
(
info
);
}
/**
* 删除角色
*/
@Override
public
void
remove
(
Long
id
)
{
spRoleMapper
.
deleteById
(
id
);
}
}
bs-auth/src/main/java/com/bs/web/service/sp/ISpInfoService.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
service
.
sp
;
import
com.bs.common.core.domain.entity.sp.SpInfo
;
import
com.bs.common.core.domain.entity.store.BusinessStore
;
import
com.bs.web.domain.vo.sp.SpUserCreateReq
;
import
com.bs.web.domain.vo.sp.SpUserListReq
;
import
com.bs.web.domain.vo.sp.SpUserUpdateReq
;
import
com.bs.web.domain.vo.sp.SpUserBatchUpdateReq
;
import
com.bs.web.domain.vo.sp.SpUserVo
;
import
java.util.List
;
/**
* 服务商信息服务接口
* 定义服务商信息的基础增删改查方法
*/
public
interface
ISpInfoService
{
/**
* 列表查询
* @param query 查询条件
* @return 服务商列表
*/
List
<
SpInfo
>
list
(
SpInfo
query
);
/**
* 分页查询
* @param query 查询条件
* @param pageNum 页码
* @param pageSize 每页条数
* @return 服务商分页列表
*/
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SpInfo
>
page
(
SpInfo
query
,
Integer
pageNum
,
Integer
pageSize
);
/**
* 详情查询
* @param id 服务商ID
* @return 服务商详情
*/
SpInfo
get
(
Long
id
);
/**
* 新增服务商
* @param info 服务商信息
*/
void
add
(
SpInfo
info
);
/**
* 编辑服务商
* @param info 服务商信息
*/
void
edit
(
SpInfo
info
);
/**
* 删除服务商
* @param id 服务商ID
*/
void
remove
(
Long
id
);
/**
* 新增服务商用户
* @param req 请求参数
* @return 用户ID
*/
Long
addSpUser
(
SpUserCreateReq
req
);
/**
* 编辑服务商用户
* @param req 请求参数
*/
void
editSpUser
(
SpUserUpdateReq
req
);
/**
* 批量编辑服务商用户
* @param req 请求参数
*/
void
editBatchSpUser
(
SpUserBatchUpdateReq
req
);
/**
* 查询服务商用户列表
* @param req 查询参数
* @return 用户列表
*/
List
<
SpUserVo
>
selectSpUserList
(
SpUserListReq
req
);
/**
* 查询服务商用户分页列表
* @param req 查询参数
* @param pageNum 页码
* @param pageSize 每页条数
* @return 用户分页列表
*/
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SpUserVo
>
selectSpUserPage
(
SpUserListReq
req
,
Integer
pageNum
,
Integer
pageSize
);
/**
* 校验服务商员工手机号是否重复
*
* @param phone 手机号
* @param userName
* @return true-不重复,false-重复
*/
Boolean
checkSpUserPhone
(
String
phone
,
String
userName
);
/**
* 删除服务商用户
* @param userId 用户ID
* @return 是否成功
*/
Boolean
deleteSpUser
(
Long
userId
);
/**
* 批量删除服务商用户
* @param userIds 用户ID列表
* @return 是否成功
*/
Boolean
deleteBatchSpUser
(
List
<
Long
>
userIds
);
/**
* 根据服务商编码查询关联的门店分页列表
* @param spCode 服务商编码
* @return 门店列表
*/
List
<
BusinessStore
>
selectStoreListBySpCode
(
String
spCode
);
/**
* 根据服务商编码查询关联的门店分页列表 (带原生分页)
* @param spCode 服务商编码
* @param pageNum 页码
* @param pageSize 每页条数
* @return 门店分页列表
*/
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
BusinessStore
>
selectStoreListBySpCodePage
(
String
spCode
,
Integer
pageNum
,
Integer
pageSize
);
}
bs-auth/src/main/java/com/bs/web/service/sp/impl/SpInfoServiceImpl.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
service
.
sp
.
impl
;
import
cn.hutool.crypto.SecureUtil
;
import
cn.hutool.crypto.asymmetric.KeyType
;
import
cn.hutool.crypto.asymmetric.RSA
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
;
import
com.bs.common.constant.UserConstants
;
import
com.bs.common.core.domain.entity.SysDept
;
import
com.bs.common.core.domain.entity.SysUser
;
import
com.bs.common.core.domain.entity.SysUserDept
;
import
com.bs.common.core.domain.entity.relation.SpStoreRelation
;
import
com.bs.common.core.domain.entity.relation.SysUserSpRelation
;
import
com.bs.common.core.domain.entity.relation.SysUserStoreRelation
;
import
com.bs.common.core.domain.entity.role.SpRole
;
import
com.bs.common.core.domain.entity.sp.SpInfo
;
import
com.bs.common.core.domain.entity.store.BusinessStore
;
import
com.bs.common.exception.CustomException
;
import
com.bs.common.utils.DateUtils
;
import
com.bs.common.utils.SecurityUtils
;
import
com.bs.common.utils.StringUtils
;
import
com.bs.web.domain.vo.sp.SpUserCreateReq
;
import
com.bs.web.domain.vo.sp.SpUserListReq
;
import
com.bs.web.domain.vo.sp.SpUserUpdateReq
;
import
com.bs.web.domain.vo.sp.SpUserBatchUpdateReq
;
import
com.bs.web.domain.vo.sp.SpUserVo
;
import
com.bs.web.mapper.SysUserDeptMapper
;
import
com.bs.web.mapper.SysUserMapper
;
import
com.bs.web.mapper.SysUserRoleMapper
;
import
com.bs.web.mapper.relation.SpStoreRelationMapper
;
import
com.bs.web.mapper.relation.SysUserSpRelationMapper
;
import
com.bs.web.mapper.relation.SysUserStoreRelationMapper
;
import
com.bs.web.mapper.role.SpRoleMapper
;
import
com.bs.web.mapper.sp.SpInfoMapper
;
import
com.bs.web.mapper.store.BusinessStoreMapper
;
import
com.bs.web.service.ISysDeptService
;
import
com.bs.web.service.ISysUserService
;
import
com.bs.web.service.sp.ISpInfoService
;
import
jakarta.annotation.Resource
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.core.env.Environment
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.stream.Collectors
;
/**
* 服务商信息服务实现
* 负责服务商的基础增删改查
*/
@Slf4j
@Service
public
class
SpInfoServiceImpl
implements
ISpInfoService
{
@Resource
private
SpInfoMapper
spInfoMapper
;
@Resource
private
SpStoreRelationMapper
spStoreRelationMapper
;
@Resource
private
SysUserSpRelationMapper
sysUserSpRelationMapper
;
@Resource
private
ISysUserService
sysUserService
;
@Resource
private
SpRoleMapper
spRoleMapper
;
@Resource
private
BusinessStoreMapper
businessStoreMapper
;
@Resource
private
SysUserStoreRelationMapper
sysUserStoreRelationMapper
;
@Resource
private
SysUserMapper
sysUserMapper
;
@Resource
private
SysUserDeptMapper
userDeptMapper
;
@Resource
private
SysUserRoleMapper
sysUserRoleMapper
;
@Resource
private
ISysDeptService
sysDeptService
;
@Value
(
"${rsa.privateKey}"
)
private
String
rasPriKey
;
@Value
(
"${rsa.publicKey}"
)
private
String
rsaPubKey
;
@Autowired
private
Environment
env
;
/**
* 列表查询
*/
@Override
public
List
<
SpInfo
>
list
(
SpInfo
query
)
{
LambdaQueryWrapper
<
SpInfo
>
wrapper
=
buildQueryWrapper
(
query
);
List
<
SpInfo
>
list
=
spInfoMapper
.
selectList
(
wrapper
);
fillRelationCounts
(
list
,
query
);
return
list
;
}
@Override
public
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SpInfo
>
page
(
SpInfo
query
,
Integer
pageNum
,
Integer
pageSize
)
{
LambdaQueryWrapper
<
SpInfo
>
wrapper
=
buildQueryWrapper
(
query
);
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<
SpInfo
>
page
=
new
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<>(
pageNum
,
pageSize
);
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SpInfo
>
pageResult
=
spInfoMapper
.
selectPage
(
page
,
wrapper
);
fillRelationCounts
(
pageResult
.
getRecords
(),
query
);
return
pageResult
;
}
private
LambdaQueryWrapper
<
SpInfo
>
buildQueryWrapper
(
SpInfo
query
)
{
LambdaQueryWrapper
<
SpInfo
>
wrapper
=
new
LambdaQueryWrapper
<>();
if
(
query
!=
null
)
{
wrapper
.
like
(
StringUtils
.
isNotEmpty
(
query
.
getSpName
()),
SpInfo:
:
getSpName
,
query
.
getSpName
());
}
wrapper
.
eq
(
SpInfo:
:
getDelFlag
,
0
)
.
orderByDesc
(
SpInfo:
:
getId
);
return
wrapper
;
}
private
void
fillRelationCounts
(
List
<
SpInfo
>
list
,
SpInfo
query
)
{
if
(
query
!=
null
&&
Boolean
.
TRUE
.
equals
(
query
.
getNeedCountRelation
())
&&
!
list
.
isEmpty
())
{
for
(
SpInfo
info
:
list
)
{
// 统计关联门店数
Long
storeCount
=
spStoreRelationMapper
.
selectCount
(
new
LambdaQueryWrapper
<
SpStoreRelation
>()
.
eq
(
SpStoreRelation:
:
getSpCode
,
info
.
getSpCode
())
.
eq
(
SpStoreRelation:
:
getDelFlag
,
0
));
info
.
setStoreCount
(
storeCount
.
intValue
());
// 统计成员数
Long
userCount
=
sysUserSpRelationMapper
.
selectCount
(
new
LambdaQueryWrapper
<
SysUserSpRelation
>()
.
eq
(
SysUserSpRelation:
:
getSpCode
,
info
.
getSpCode
())
.
eq
(
SysUserSpRelation:
:
getDelFlag
,
0
));
info
.
setUserCount
(
userCount
.
intValue
());
}
}
}
/**
* 详情查询
*/
@Override
public
SpInfo
get
(
Long
id
)
{
return
spInfoMapper
.
selectById
(
id
);
}
/**
* 新增服务商
*/
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
add
(
SpInfo
info
)
{
// 1.2、服务商名称需要校验重复
Long
count
=
spInfoMapper
.
selectCount
(
new
LambdaQueryWrapper
<
SpInfo
>()
.
eq
(
SpInfo:
:
getSpName
,
info
.
getSpName
())
.
eq
(
SpInfo:
:
getDelFlag
,
0
));
if
(
count
>
0
)
{
throw
new
CustomException
(
"服务商名称已存在"
);
}
// 1.2、服务商编码内部生成SP+时间戳
info
.
setSpCode
(
"SP"
+
System
.
currentTimeMillis
());
// 1.3、从登录参数中获取通用的审计字段封装
info
.
setCreateBy
(
SecurityUtils
.
getUserName
());
info
.
setCreateTime
(
DateUtils
.
getNowDate
());
info
.
setDelFlag
(
0
);
spInfoMapper
.
insert
(
info
);
}
/**
* 编辑服务商
*/
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
edit
(
SpInfo
info
)
{
if
(
info
.
getId
()
==
null
)
{
throw
new
CustomException
(
"服务商ID不能为空"
);
}
// 2.2、服务商名称需要校验重复
Long
count
=
spInfoMapper
.
selectCount
(
new
LambdaQueryWrapper
<
SpInfo
>()
.
eq
(
SpInfo:
:
getSpName
,
info
.
getSpName
())
.
eq
(
SpInfo:
:
getDelFlag
,
0
)
.
ne
(
SpInfo:
:
getId
,
info
.
getId
()));
if
(
count
>
0
)
{
throw
new
CustomException
(
"服务商名称已存在"
);
}
// 2.2、服务商编码不接受参数修改 (prevent modification)
info
.
setSpCode
(
null
);
// 2.3、登录参数中获取通用的审计字段封装
info
.
setUpdateBy
(
SecurityUtils
.
getUserName
());
info
.
setUpdateTime
(
DateUtils
.
getNowDate
());
spInfoMapper
.
updateById
(
info
);
}
/**
* 删除服务商
*/
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
remove
(
Long
id
)
{
SpInfo
exist
=
spInfoMapper
.
selectById
(
id
);
if
(
exist
!=
null
&&
exist
.
getDelFlag
()
!=
null
&&
exist
.
getDelFlag
()
==
0
)
{
String
spCode
=
exist
.
getSpCode
();
if
(
spCode
!=
null
&&
!
spCode
.
isBlank
())
{
List
<
SysUserSpRelation
>
spUserRelations
=
sysUserSpRelationMapper
.
selectList
(
new
LambdaQueryWrapper
<
SysUserSpRelation
>()
.
eq
(
SysUserSpRelation:
:
getSpCode
,
spCode
)
.
eq
(
SysUserSpRelation:
:
getDelFlag
,
0
)
);
if
(
spUserRelations
!=
null
&&
!
spUserRelations
.
isEmpty
())
{
List
<
Long
>
userIds
=
spUserRelations
.
stream
()
.
map
(
SysUserSpRelation:
:
getUserId
)
.
filter
(
java
.
util
.
Objects
::
nonNull
)
.
collect
(
Collectors
.
toList
());
if
(!
userIds
.
isEmpty
())
{
deleteBatchSpUser
(
userIds
);
}
}
SpStoreRelation
spUpdate
=
new
SpStoreRelation
();
spUpdate
.
setDelFlag
(
1
);
spUpdate
.
setUpdateBy
(
SecurityUtils
.
getUserName
());
spUpdate
.
setUpdateTime
(
DateUtils
.
getNowDate
());
spUpdate
.
setUpdateById
(
SecurityUtils
.
getUserId
());
spStoreRelationMapper
.
update
(
spUpdate
,
new
LambdaQueryWrapper
<
SpStoreRelation
>()
.
eq
(
SpStoreRelation:
:
getSpCode
,
spCode
));
}
}
SpInfo
info
=
new
SpInfo
();
info
.
setId
(
id
);
info
.
setDelFlag
(
1
);
info
.
setUpdateBy
(
SecurityUtils
.
getUserName
());
info
.
setUpdateTime
(
DateUtils
.
getNowDate
());
spInfoMapper
.
updateById
(
info
);
}
/**
* 新增服务商用户
*/
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Long
addSpUser
(
SpUserCreateReq
req
)
{
// 1. 校验服务商
SpInfo
spInfo
=
spInfoMapper
.
selectById
(
req
.
getSpId
());
if
(
spInfo
==
null
||
spInfo
.
getDelFlag
()
==
1
)
{
throw
new
CustomException
(
"服务商不存在"
);
}
// 2. 校验部门
String
defaultDeptId
=
env
.
getProperty
(
"sp.user.default.deptId"
);
if
(
StringUtils
.
isEmpty
(
defaultDeptId
))
{
throw
new
CustomException
(
"未配置服务商用户默认部门"
);
}
Long
deptId
=
Long
.
valueOf
(
defaultDeptId
);
SysDept
sysDept
=
sysDeptService
.
selectDeptById
(
deptId
);
if
(
sysDept
==
null
)
{
throw
new
CustomException
(
"部门不存在"
);
}
// 3. 创建系统用户
SysUser
user
=
new
SysUser
();
user
.
setDeptId
(
deptId
);
user
.
setUserName
(
req
.
getUserName
());
user
.
setNickName
(
req
.
getUserName
());
user
.
setWeUserId
(
req
.
getUserName
());
user
.
setPhoneNumber
(
req
.
getPhoneNumber
());
user
.
setSex
(
"2"
);
// 默认未知
user
.
setUserType
(
"02"
);
user
.
setStatus
(
"0"
);
user
.
setDelFlag
(
0
);
user
.
setIsUserLeave
(
0
);
user
.
setDataScope
(
5
);
user
.
setCreateBy
(
SecurityUtils
.
getUserName
());
user
.
setCreateById
(
SecurityUtils
.
getUserId
());
user
.
setUpdateBy
(
SecurityUtils
.
getUserName
());
user
.
setUpdateById
(
SecurityUtils
.
getUserId
());
user
.
setUpdateTime
(
new
Date
());
// 密码逻辑:使用手机号后6位
String
rawPassword
=
(
req
.
getPhoneNumber
().
length
()
>
5
?
req
.
getPhoneNumber
().
substring
(
req
.
getPhoneNumber
().
length
()
-
6
)
:
"123456"
);
RSA
rsa
=
SecureUtil
.
rsa
(
rasPriKey
,
rsaPubKey
);
String
encPwd
=
rsa
.
encryptBase64
(
rawPassword
,
KeyType
.
PublicKey
);
user
.
setPassword
(
encPwd
);
// 唯一性校验
if
(!
sysUserService
.
checkUserNameUnique
(
user
.
getUserName
()).
equals
(
UserConstants
.
UNIQUE
))
{
throw
new
CustomException
(
"新增用户'"
+
user
.
getUserName
()
+
"'失败,登录账号已存在"
);
}
if
(
StringUtils
.
isNotEmpty
(
user
.
getPhoneNumber
())
&&
!
sysUserService
.
checkPhoneUnique
(
user
).
equals
(
UserConstants
.
UNIQUE
))
{
throw
new
CustomException
(
"新增用户'"
+
user
.
getUserName
()
+
"'失败,手机号码已存在"
);
}
sysUserService
.
insertUser
(
user
);
Long
userId
=
user
.
getUserId
();
// 4. 插入 SysUserDept
SysUserDept
userDept
=
new
SysUserDept
();
userDept
.
setUserId
(
userId
);
userDept
.
setDeptId
(
deptId
);
userDept
.
setWeUserId
(
user
.
getUserName
());
userDept
.
setOrderInDept
(
"0"
);
userDept
.
setLeaderInDept
(
0
);
userDept
.
setDelFlag
(
"0"
);
userDept
.
setCreateBy
(
SecurityUtils
.
getUserName
());
userDept
.
setCreateById
(
SecurityUtils
.
getUserId
());
userDept
.
setCreateTime
(
new
Date
());
userDept
.
setUpdateBy
(
SecurityUtils
.
getUserName
());
userDept
.
setUpdateById
(
SecurityUtils
.
getUserId
());
userDept
.
setUpdateTime
(
new
Date
());
userDeptMapper
.
insert
(
userDept
);
// 5. 增加用户-服务商关联关系
String
roleCode
=
null
;
if
(
req
.
getSpRoleId
()
!=
null
)
{
SpRole
role
=
spRoleMapper
.
selectById
(
req
.
getSpRoleId
());
if
(
role
!=
null
)
{
roleCode
=
role
.
getRoleCode
();
}
}
SysUserSpRelation
spRelation
=
SysUserSpRelation
.
builder
()
.
userId
(
userId
)
.
spCode
(
spInfo
.
getSpCode
())
.
roleCode
(
roleCode
)
.
delFlag
(
0
)
.
build
();
spRelation
.
setCreateBy
(
SecurityUtils
.
getUserName
());
spRelation
.
setCreateTime
(
DateUtils
.
getNowDate
());
sysUserSpRelationMapper
.
insert
(
spRelation
);
// 6. 增加用户-门店关联关系
if
(
req
.
getStoreCodes
()
!=
null
&&
!
req
.
getStoreCodes
().
isEmpty
())
{
// 校验所有传入的门店编码是否都属于该服务商且状态为启用
List
<
SpStoreRelation
>
validRelations
=
spStoreRelationMapper
.
selectList
(
new
LambdaQueryWrapper
<
SpStoreRelation
>()
.
eq
(
SpStoreRelation:
:
getSpCode
,
spInfo
.
getSpCode
())
.
in
(
SpStoreRelation:
:
getStoreCode
,
req
.
getStoreCodes
())
.
eq
(
SpStoreRelation:
:
getStatus
,
1
)
// 关联启用
.
eq
(
SpStoreRelation:
:
getDelFlag
,
0
));
Set
<
String
>
validStoreCodeSet
=
validRelations
.
stream
()
.
map
(
SpStoreRelation:
:
getStoreCode
)
.
collect
(
Collectors
.
toSet
());
for
(
String
storeCode
:
req
.
getStoreCodes
())
{
if
(!
validStoreCodeSet
.
contains
(
storeCode
))
{
throw
new
CustomException
(
"门店编码["
+
storeCode
+
"]未与该服务商关联或关联已禁用"
);
}
}
// 再次校验门店本身是否启用 (BusinessStore)
List
<
BusinessStore
>
stores
=
businessStoreMapper
.
selectList
(
new
LambdaQueryWrapper
<
BusinessStore
>()
.
in
(
BusinessStore:
:
getStoreCode
,
req
.
getStoreCodes
())
.
eq
(
BusinessStore:
:
getDelFlag
,
0
));
for
(
String
storeCode
:
req
.
getStoreCodes
())
{
BusinessStore
store
=
stores
.
stream
().
filter
(
s
->
s
.
getStoreCode
().
equals
(
storeCode
)).
findFirst
().
orElse
(
null
);
if
(
store
==
null
)
{
throw
new
CustomException
(
"门店编码["
+
storeCode
+
"]不存在"
);
}
if
(
store
.
getStatus
()
!=
1
)
{
// 假设 1 为启用
throw
new
CustomException
(
"门店["
+
store
.
getStoreName
()
+
"]未启用"
);
}
}
for
(
String
storeCode
:
req
.
getStoreCodes
())
{
SysUserStoreRelation
storeRelation
=
SysUserStoreRelation
.
builder
()
.
userId
(
userId
)
.
storeCode
(
storeCode
)
.
relationType
(
1
)
.
status
(
1
)
.
isPrimary
(
0
)
.
delFlag
(
0
)
.
build
();
storeRelation
.
setCreateBy
(
SecurityUtils
.
getUserName
());
storeRelation
.
setCreateTime
(
DateUtils
.
getNowDate
());
sysUserStoreRelationMapper
.
insert
(
storeRelation
);
}
}
return
userId
;
}
/**
* 编辑服务商用户
*/
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
editSpUser
(
SpUserUpdateReq
req
)
{
Long
userId
=
req
.
getUserId
();
SysUser
user
=
sysUserService
.
selectUserById
(
userId
);
if
(
user
==
null
)
{
throw
new
CustomException
(
"用户不存在"
);
}
// 1. 修改用户服务商角色
if
(
req
.
getSpRoleId
()
!=
null
)
{
// Check if relation exists
SysUserSpRelation
spRelation
=
sysUserSpRelationMapper
.
selectOne
(
new
LambdaQueryWrapper
<
SysUserSpRelation
>()
.
eq
(
SysUserSpRelation:
:
getUserId
,
userId
)
.
eq
(
SysUserSpRelation:
:
getDelFlag
,
0
));
String
roleCode
=
null
;
SpRole
role
=
spRoleMapper
.
selectById
(
req
.
getSpRoleId
());
if
(
role
!=
null
)
{
roleCode
=
role
.
getRoleCode
();
}
if
(
spRelation
!=
null
)
{
spRelation
.
setRoleCode
(
roleCode
);
spRelation
.
setUpdateBy
(
SecurityUtils
.
getUserName
());
spRelation
.
setUpdateTime
(
DateUtils
.
getNowDate
());
sysUserSpRelationMapper
.
updateById
(
spRelation
);
}
else
{
log
.
error
(
"用户【{}】未关联服务商"
,
user
.
getUserName
());
throw
new
CustomException
(
"用户【"
+
user
.
getUserName
()
+
"】未关联服务商"
);
}
}
// 2. 修改用户-门店关联关系
List
<
String
>
inputStoreCodes
=
req
.
getStoreCodes
();
if
(
inputStoreCodes
!=
null
)
{
// Only process if not null
// 2.1 校验用户是否已关联服务商,获取服务商编码
SysUserSpRelation
spRelation
=
sysUserSpRelationMapper
.
selectOne
(
new
LambdaQueryWrapper
<
SysUserSpRelation
>()
.
eq
(
SysUserSpRelation:
:
getUserId
,
userId
)
.
eq
(
SysUserSpRelation:
:
getDelFlag
,
0
));
if
(
spRelation
==
null
)
{
log
.
error
(
"用户【{}】未关联服务商"
,
user
.
getUserName
());
throw
new
CustomException
(
"用户【"
+
user
.
getUserName
()
+
"】未关联服务商"
);
}
String
spCode
=
spRelation
.
getSpCode
();
if
(!
inputStoreCodes
.
isEmpty
())
{
// 2.2 校验所有传入的门店编码是否都属于该服务商且状态为启用
List
<
SpStoreRelation
>
validRelations
=
spStoreRelationMapper
.
selectList
(
new
LambdaQueryWrapper
<
SpStoreRelation
>()
.
eq
(
SpStoreRelation:
:
getSpCode
,
spCode
)
.
in
(
SpStoreRelation:
:
getStoreCode
,
inputStoreCodes
)
.
eq
(
SpStoreRelation:
:
getStatus
,
1
)
// 关联启用
.
eq
(
SpStoreRelation:
:
getDelFlag
,
0
));
Set
<
String
>
validStoreCodeSet
=
validRelations
.
stream
()
.
map
(
SpStoreRelation:
:
getStoreCode
)
.
collect
(
Collectors
.
toSet
());
for
(
String
storeCode
:
inputStoreCodes
)
{
if
(!
validStoreCodeSet
.
contains
(
storeCode
))
{
throw
new
CustomException
(
"门店编码["
+
storeCode
+
"]未与该服务商关联或关联已禁用"
);
}
}
// 2.3 再次校验门店本身是否启用 (BusinessStore)
List
<
BusinessStore
>
stores
=
businessStoreMapper
.
selectList
(
new
LambdaQueryWrapper
<
BusinessStore
>()
.
in
(
BusinessStore:
:
getStoreCode
,
inputStoreCodes
)
.
eq
(
BusinessStore:
:
getDelFlag
,
0
));
for
(
String
storeCode
:
inputStoreCodes
)
{
BusinessStore
store
=
stores
.
stream
().
filter
(
s
->
s
.
getStoreCode
().
equals
(
storeCode
)).
findFirst
().
orElse
(
null
);
if
(
store
==
null
)
{
throw
new
CustomException
(
"门店编码["
+
storeCode
+
"]不存在"
);
}
if
(
store
.
getStatus
()
==
null
||
store
.
getStatus
()
!=
1
)
{
// 假设 1 为启用
throw
new
CustomException
(
"门店["
+
store
.
getStoreName
()
+
"]未启用"
);
}
}
}
List
<
SysUserStoreRelation
>
existingRelations
=
sysUserStoreRelationMapper
.
selectList
(
new
LambdaQueryWrapper
<
SysUserStoreRelation
>()
.
eq
(
SysUserStoreRelation:
:
getUserId
,
userId
)
.
eq
(
SysUserStoreRelation:
:
getDelFlag
,
0
));
Set
<
String
>
existingCodes
=
existingRelations
.
stream
()
.
map
(
SysUserStoreRelation:
:
getStoreCode
)
.
collect
(
Collectors
.
toSet
());
// Add new
List
<
String
>
toAdd
=
inputStoreCodes
.
stream
()
.
filter
(
code
->
!
existingCodes
.
contains
(
code
))
.
collect
(
Collectors
.
toList
());
if
(!
toAdd
.
isEmpty
())
{
for
(
String
code
:
toAdd
)
{
SysUserStoreRelation
relation
=
SysUserStoreRelation
.
builder
()
.
userId
(
userId
)
.
storeCode
(
code
)
.
relationType
(
1
)
.
status
(
1
)
.
isPrimary
(
0
)
.
delFlag
(
0
)
.
build
();
relation
.
setCreateBy
(
SecurityUtils
.
getUserName
());
relation
.
setCreateTime
(
DateUtils
.
getNowDate
());
relation
.
setUpdateBy
(
SecurityUtils
.
getUserName
());
relation
.
setUpdateTime
(
DateUtils
.
getNowDate
());
sysUserStoreRelationMapper
.
insert
(
relation
);
}
}
// 不在请求参数中,但是在表里已经存在,则删除
List
<
Long
>
toDeleteIds
=
existingRelations
.
stream
()
.
filter
(
r
->
!
inputStoreCodes
.
contains
(
r
.
getStoreCode
()))
.
map
(
SysUserStoreRelation:
:
getId
)
.
collect
(
Collectors
.
toList
());
if
(!
toDeleteIds
.
isEmpty
())
{
sysUserStoreRelationMapper
.
deleteBatchIds
(
toDeleteIds
);
}
}
else
{
// 移除此员工所有关联门店
sysUserStoreRelationMapper
.
delete
(
new
LambdaQueryWrapper
<
SysUserStoreRelation
>().
eq
(
SysUserStoreRelation:
:
getUserId
,
userId
));
}
}
/**
* 批量编辑服务商用户
*/
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
void
editBatchSpUser
(
SpUserBatchUpdateReq
req
)
{
if
(
req
.
getUserIds
()
==
null
||
req
.
getUserIds
().
isEmpty
())
{
throw
new
CustomException
(
"用户ID列表不能为空"
);
}
for
(
Long
userId
:
req
.
getUserIds
())
{
SpUserUpdateReq
singleReq
=
new
SpUserUpdateReq
();
singleReq
.
setUserId
(
userId
);
singleReq
.
setSpRoleId
(
req
.
getSpRoleId
());
singleReq
.
setStoreCodes
(
req
.
getStoreCodes
());
editSpUser
(
singleReq
);
}
}
/**
* 查询服务商用户列表
*/
@Override
public
List
<
SpUserVo
>
selectSpUserList
(
SpUserListReq
req
)
{
// Need to implement custom SQL in mapper to join tables
// Assuming we add selectSpUserList to SpInfoMapper
return
spInfoMapper
.
selectSpUserList
(
req
.
getSpId
(),
req
.
getKeyword
(),
req
.
getSpRoleCode
(),
req
.
getStoreCode
());
}
/**
* 查询服务商用户分页列表
*/
@Override
public
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SpUserVo
>
selectSpUserPage
(
SpUserListReq
req
,
Integer
pageNum
,
Integer
pageSize
)
{
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<
SpUserVo
>
page
=
new
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<>(
pageNum
,
pageSize
);
return
spInfoMapper
.
selectSpUserList
(
page
,
req
.
getSpId
(),
req
.
getKeyword
(),
req
.
getSpRoleCode
(),
req
.
getStoreCode
());
}
/**
* 根据服务商编码查询关联的门店分页列表
*/
@Override
public
List
<
BusinessStore
>
selectStoreListBySpCode
(
String
spCode
)
{
// 1. 查询服务商关联的门店编码
List
<
SpStoreRelation
>
relations
=
spStoreRelationMapper
.
selectList
(
new
LambdaQueryWrapper
<
SpStoreRelation
>()
.
eq
(
SpStoreRelation:
:
getSpCode
,
spCode
)
.
eq
(
SpStoreRelation:
:
getDelFlag
,
0
));
if
(
relations
.
isEmpty
())
{
return
java
.
util
.
Collections
.
emptyList
();
}
List
<
String
>
storeCodes
=
relations
.
stream
()
.
map
(
SpStoreRelation:
:
getStoreCode
)
.
collect
(
Collectors
.
toList
());
// 2. 查询门店详情
List
<
BusinessStore
>
storeList
=
businessStoreMapper
.
selectList
(
new
LambdaQueryWrapper
<
BusinessStore
>()
.
in
(
BusinessStore:
:
getStoreCode
,
storeCodes
)
.
eq
(
BusinessStore:
:
getDelFlag
,
0
));
fillStoreUserCounts
(
spCode
,
storeList
);
return
storeList
;
}
@Override
public
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
BusinessStore
>
selectStoreListBySpCodePage
(
String
spCode
,
Integer
pageNum
,
Integer
pageSize
)
{
// 1. 查询服务商关联的门店编码
List
<
SpStoreRelation
>
relations
=
spStoreRelationMapper
.
selectList
(
new
LambdaQueryWrapper
<
SpStoreRelation
>()
.
eq
(
SpStoreRelation:
:
getSpCode
,
spCode
)
.
eq
(
SpStoreRelation:
:
getStatus
,
1
)
.
eq
(
SpStoreRelation:
:
getDelFlag
,
0
));
if
(
relations
.
isEmpty
())
{
return
new
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<>(
pageNum
,
pageSize
);
}
List
<
String
>
storeCodes
=
relations
.
stream
()
.
map
(
SpStoreRelation:
:
getStoreCode
)
.
collect
(
Collectors
.
toList
());
// 2. 查询门店详情 (分页)
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<
BusinessStore
>
page
=
new
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<>(
pageNum
,
pageSize
);
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
BusinessStore
>
pageResult
=
businessStoreMapper
.
selectPage
(
page
,
new
LambdaQueryWrapper
<
BusinessStore
>()
.
in
(
BusinessStore:
:
getStoreCode
,
storeCodes
)
.
eq
(
BusinessStore:
:
getDelFlag
,
0
));
fillStoreUserCounts
(
spCode
,
pageResult
.
getRecords
());
return
pageResult
;
}
private
void
fillStoreUserCounts
(
String
spCode
,
List
<
BusinessStore
>
storeList
)
{
// 3. 统计门店成员数
if
(!
storeList
.
isEmpty
())
{
List
<
String
>
queryStoreCodes
=
storeList
.
stream
()
.
map
(
BusinessStore:
:
getStoreCode
)
.
collect
(
Collectors
.
toList
());
List
<
java
.
util
.
Map
<
String
,
Object
>>
countMaps
=
sysUserSpRelationMapper
.
countUsersBySpCodeAndStoreCodes
(
spCode
,
queryStoreCodes
,
"zhudian"
);
java
.
util
.
Map
<
String
,
Integer
>
userCountMap
=
new
java
.
util
.
HashMap
<>();
for
(
java
.
util
.
Map
<
String
,
Object
>
map
:
countMaps
)
{
String
storeCodeKey
=
(
String
)
map
.
get
(
"store_code"
);
Long
count
=
(
Long
)
map
.
get
(
"user_count"
);
userCountMap
.
put
(
storeCodeKey
,
count
.
intValue
());
}
for
(
BusinessStore
store
:
storeList
)
{
store
.
setUserCount
(
userCountMap
.
getOrDefault
(
store
.
getStoreCode
(),
0
));
}
}
}
/**
* 校验服务商员工手机号是否重复
*/
@Override
public
Boolean
checkSpUserPhone
(
String
phone
,
String
userName
)
{
SysUser
sysUser
=
sysUserMapper
.
checkPhoneUnique
(
phone
,
userName
);
return
sysUser
==
null
;
}
/**
* 删除服务商用户
*/
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Boolean
deleteSpUser
(
Long
userId
)
{
// 1. 删除用户 (Logic delete)
// sysUserService.deleteUserByIds(new Long[]{userId}); // This usually checks admin rights etc.
// Or manually update delFlag
SysUser
user
=
new
SysUser
();
user
.
setUserId
(
userId
);
user
.
setDelFlag
(
1
);
// 1 is delete (usually 0 normal, 1 deleted or 2) - checking SysUser.java, delFlag is Integer. "删除标志(0代表存在 1代表删除)"
user
.
setUpdateBy
(
SecurityUtils
.
getUserName
());
user
.
setUpdateTime
(
DateUtils
.
getNowDate
());
sysUserMapper
.
updateById
(
user
);
// Use updateById
// 2. 删除用户-服务商关系
sysUserSpRelationMapper
.
delete
(
new
LambdaQueryWrapper
<
SysUserSpRelation
>()
.
eq
(
SysUserSpRelation:
:
getUserId
,
userId
));
// 3. 删除用户-门店关系
sysUserStoreRelationMapper
.
delete
(
new
LambdaQueryWrapper
<
SysUserStoreRelation
>()
.
eq
(
SysUserStoreRelation:
:
getUserId
,
userId
));
// 4. 删除用户部门关系
UpdateWrapper
<
SysUserDept
>
uw
=
new
UpdateWrapper
<>();
uw
.
lambda
().
eq
(
SysUserDept:
:
getUserId
,
userId
)
.
set
(
SysUserDept:
:
getDelFlag
,
"2"
)
.
set
(
SysUserDept:
:
getUpdateBy
,
SecurityUtils
.
getUserName
())
.
set
(
SysUserDept:
:
getUpdateById
,
SecurityUtils
.
getUserId
())
.
set
(
SysUserDept:
:
getUpdateTime
,
new
Date
());
userDeptMapper
.
update
(
null
,
uw
);
return
true
;
}
/**
* 批量删除服务商用户
*/
@Override
@Transactional
(
rollbackFor
=
Exception
.
class
)
public
Boolean
deleteBatchSpUser
(
List
<
Long
>
userIds
)
{
if
(
userIds
==
null
||
userIds
.
isEmpty
())
{
return
false
;
}
// 1. 删除用户 (逻辑删除)
UpdateWrapper
<
SysUser
>
userUw
=
new
UpdateWrapper
<>();
userUw
.
lambda
().
in
(
SysUser:
:
getUserId
,
userIds
)
.
set
(
SysUser:
:
getDelFlag
,
1
)
.
set
(
SysUser:
:
getUpdateBy
,
SecurityUtils
.
getUserName
())
.
set
(
SysUser:
:
getUpdateTime
,
DateUtils
.
getNowDate
());
sysUserMapper
.
update
(
null
,
userUw
);
// 2. 删除用户 - 服务商关系 (逻辑删除)
UpdateWrapper
<
SysUserSpRelation
>
spUw
=
new
UpdateWrapper
<>();
spUw
.
lambda
().
in
(
SysUserSpRelation:
:
getUserId
,
userIds
)
.
set
(
SysUserSpRelation:
:
getDelFlag
,
1
)
.
set
(
SysUserSpRelation:
:
getUpdateBy
,
SecurityUtils
.
getUserName
())
.
set
(
SysUserSpRelation:
:
getUpdateById
,
SecurityUtils
.
getUserId
())
.
set
(
SysUserSpRelation:
:
getUpdateTime
,
DateUtils
.
getNowDate
());
sysUserSpRelationMapper
.
update
(
null
,
spUw
);
// 3. 删除用户 - 门店关系 (逻辑删除)
UpdateWrapper
<
SysUserStoreRelation
>
storeUw
=
new
UpdateWrapper
<>();
storeUw
.
lambda
().
in
(
SysUserStoreRelation:
:
getUserId
,
userIds
)
.
set
(
SysUserStoreRelation:
:
getDelFlag
,
1
)
.
set
(
SysUserStoreRelation:
:
getUpdateBy
,
SecurityUtils
.
getUserName
())
.
set
(
SysUserStoreRelation:
:
getUpdateById
,
SecurityUtils
.
getUserId
())
.
set
(
SysUserStoreRelation:
:
getUpdateTime
,
DateUtils
.
getNowDate
());
sysUserStoreRelationMapper
.
update
(
null
,
storeUw
);
// 4. 删除用户部门关系
UpdateWrapper
<
SysUserDept
>
deptUw
=
new
UpdateWrapper
<>();
deptUw
.
lambda
().
in
(
SysUserDept:
:
getUserId
,
userIds
)
.
set
(
SysUserDept:
:
getDelFlag
,
"2"
)
.
set
(
SysUserDept:
:
getUpdateBy
,
SecurityUtils
.
getUserName
())
.
set
(
SysUserDept:
:
getUpdateById
,
SecurityUtils
.
getUserId
())
.
set
(
SysUserDept:
:
getUpdateTime
,
new
Date
());
userDeptMapper
.
update
(
null
,
deptUw
);
if
(!
userIds
.
isEmpty
()){
for
(
Long
userId
:
userIds
)
{
sysUserRoleMapper
.
deleteUserRoleByUserId
(
userId
);
}
}
return
true
;
}
}
bs-auth/src/main/java/com/bs/web/service/store/IBusinessStoreService.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
service
.
store
;
import
com.bs.common.core.domain.entity.sp.SpInfo
;
import
com.bs.common.core.domain.entity.store.BusinessStore
;
import
com.bs.web.domain.vo.store.BusinessStoreCreateReq
;
import
com.bs.web.domain.vo.store.BusinessStoreUpdateReq
;
import
java.util.List
;
import
org.springframework.web.multipart.MultipartFile
;
import
com.bs.web.domain.vo.store.BusinessStoreImportVo
;
import
java.util.Map
;
/**
* 门店信息服务接口
* 定义门店的基础增删改查与查询方法
*/
public
interface
IBusinessStoreService
{
/**
* 列表查询
* @param query 查询条件
* @return 门店列表
*/
List
<
BusinessStore
>
list
(
BusinessStore
query
);
/**
* 分页查询
* @param query 查询条件
* @param pageNum 页码
* @param pageSize 每页条数
* @return 门店分页列表
*/
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
BusinessStore
>
page
(
BusinessStore
query
,
Integer
pageNum
,
Integer
pageSize
);
/**
* 详情查询
* @param id 门店ID
* @return 门店详情
*/
BusinessStore
get
(
Long
id
);
/**
* 根据门店编码查询门店
* @param storeCode 门店代码
* @return 门店详情
*/
BusinessStore
getByCode
(
String
storeCode
);
/**
* 新增门店
* @param info 门店信息
*/
Long
add
(
BusinessStore
info
);
/**
* 新增门店
* @param req 门店信息
* @return 门店ID
*/
Long
add
(
BusinessStoreCreateReq
req
);
/**
* 编辑门店
* @param info 门店信息
*/
void
edit
(
BusinessStore
info
);
/**
* 编辑门店
* @param req 门店信息
*/
void
edit
(
BusinessStoreUpdateReq
req
);
/**
* 删除门店
* @param id 门店ID
*/
void
remove
(
Long
id
);
/**
* 导入门店信息
* @param url 导入文件URL
* @return 导入任务ID
*/
String
importStore
(
String
url
);
/**
* 获取导入进度
* @param importId 导入任务ID
* @return 进度信息
*/
Map
<
String
,
Object
>
getImportProgress
(
String
importId
);
/**
* 下载导入模板
* @return 导入模板URL
*/
String
importStoreTemplateDownLode
();
/**
* 根据门店编码查询关联的服务商列表
* @param storeCode 门店编码
* @return 服务商列表
*/
List
<
SpInfo
>
selectSpListByStoreCode
(
String
storeCode
);
/**
* 根据门店编码查询关联的服务商分页列表
* @param storeCode 门店编码
* @param pageNum 页码
* @param pageSize 每页数量
* @return 服务商分页
*/
com
.
baomidou
.
mybatisplus
.
core
.
metadata
.
IPage
<
SpInfo
>
selectSpListByStoreCodePage
(
String
storeCode
,
Integer
pageNum
,
Integer
pageSize
);
}
bs-auth/src/main/java/com/bs/web/service/store/impl/BusinessStoreServiceImpl.java
deleted
100644 → 0
View file @
61b0a72
package
com
.
bs
.
web
.
service
.
store
.
impl
;
import
cn.hutool.core.thread.ThreadUtil
;
import
com.alibaba.excel.EasyExcel
;
import
com.alibaba.excel.context.AnalysisContext
;
import
com.alibaba.excel.event.AnalysisEventListener
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper
;
import
com.baomidou.mybatisplus.core.metadata.IPage
;
import
com.baomidou.mybatisplus.extension.plugins.pagination.Page
;
import
com.bs.common.core.domain.AjaxResult
;
import
com.bs.common.core.domain.FileEntity
;
import
com.bs.common.core.domain.entity.relation.SpStoreRelation
;
import
com.bs.common.core.domain.entity.sp.SpInfo
;
import
com.bs.common.core.domain.entity.store.BusinessStore
;
import
com.bs.common.core.redis.RedisService
;
import
com.bs.common.exception.CustomException
;
import
com.bs.common.utils.SecurityUtils
;
import
com.bs.common.utils.StringUtils
;
import
com.bs.common.utils.uuid.IdUtils
;
import
com.bs.web.domain.SysArea
;
import
com.bs.web.domain.vo.store.BusinessStoreCreateReq
;
import
com.bs.web.domain.vo.store.BusinessStoreImportVo
;
import
com.bs.web.domain.vo.store.BusinessStoreUpdateReq
;
import
com.bs.web.feign.FileFeignClient
;
import
com.bs.web.mapper.relation.SpStoreRelationMapper
;
import
com.bs.web.mapper.relation.SysUserSpRelationMapper
;
import
com.bs.web.mapper.relation.SysUserStoreRelationMapper
;
import
com.bs.web.mapper.sp.SpInfoMapper
;
import
com.bs.web.mapper.store.BusinessStoreMapper
;
import
com.bs.web.service.ISysAreaService
;
import
com.bs.web.service.store.IBusinessStoreService
;
import
jakarta.annotation.Resource
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.core.env.Environment
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.util.FileCopyUtils
;
import
org.springframework.web.multipart.MultipartFile
;
import
java.io.*
;
import
java.net.URL
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
import
java.util.regex.Pattern
;
import
java.util.stream.Collectors
;
/**
* 门店信息服务实现
* 负责门店的基础增删改查
*/
@Slf4j
@Service
public
class
BusinessStoreServiceImpl
implements
IBusinessStoreService
{
@Resource
private
BusinessStoreMapper
businessStoreMapper
;
@Resource
private
ISysAreaService
sysAreaService
;
@Resource
private
SpStoreRelationMapper
spStoreRelationMapper
;
@Resource
private
RedisService
redisService
;
@Resource
private
FileFeignClient
fileFeignClient
;
@Autowired
private
Environment
env
;
@Autowired
private
SysUserSpRelationMapper
sysUserSpRelationMapper
;
@Autowired
private
SysUserStoreRelationMapper
sysUserStoreRelationMapper
;
@Autowired
private
SpInfoMapper
spInfoMapper
;
/**
* 列表查询
*
* @param query 查询条件
* @return 门店列表
*/
@Override
public
List
<
BusinessStore
>
list
(
BusinessStore
query
)
{
LambdaQueryWrapper
<
BusinessStore
>
qw
=
buildQueryWrapper
(
query
);
return
businessStoreMapper
.
selectList
(
qw
);
}
@Override
public
IPage
<
BusinessStore
>
page
(
BusinessStore
query
,
Integer
pageNum
,
Integer
pageSize
)
{
LambdaQueryWrapper
<
BusinessStore
>
qw
=
buildQueryWrapper
(
query
);
Page
<
BusinessStore
>
page
=
new
Page
<>(
pageNum
,
pageSize
);
return
businessStoreMapper
.
selectPage
(
page
,
qw
);
}
private
LambdaQueryWrapper
<
BusinessStore
>
buildQueryWrapper
(
BusinessStore
query
)
{
LambdaQueryWrapper
<
BusinessStore
>
qw
=
new
LambdaQueryWrapper
<>();
String
keyword
=
null
;
if
(
query
!=
null
)
{
// 门店信息关键词(门店名称或门店编码任取其一)
if
(
query
.
getStoreName
()
!=
null
&&
!
query
.
getStoreName
().
isBlank
())
{
keyword
=
query
.
getStoreName
();
}
else
if
(
query
.
getStoreCode
()
!=
null
&&
!
query
.
getStoreCode
().
isBlank
())
{
keyword
=
query
.
getStoreCode
();
}
if
(
keyword
!=
null
&&
!
keyword
.
isBlank
())
{
// 关键词需为 final 或“有效 final”,避免 lambda 捕获报错
final
String
kw
=
keyword
;
// 关键词分组匹配:(store_name like ? OR store_code like ?)
qw
.
nested
(
w
->
w
.
like
(
BusinessStore:
:
getStoreName
,
kw
)
.
or
()
.
like
(
BusinessStore:
:
getStoreCode
,
kw
));
}
else
{
// 分别按需添加名称/编码条件
if
(
query
.
getStoreName
()
!=
null
&&
!
query
.
getStoreName
().
isBlank
())
{
qw
.
like
(
BusinessStore:
:
getStoreName
,
query
.
getStoreName
());
}
if
(
query
.
getStoreCode
()
!=
null
&&
!
query
.
getStoreCode
().
isBlank
())
{
qw
.
eq
(
BusinessStore:
:
getStoreCode
,
query
.
getStoreCode
());
}
}
// 区域与状态按需追加
if
(
query
.
getProvinceId
()
!=
null
)
{
qw
.
eq
(
BusinessStore:
:
getProvinceId
,
query
.
getProvinceId
());
}
if
(
query
.
getCityId
()
!=
null
)
{
qw
.
eq
(
BusinessStore:
:
getCityId
,
query
.
getCityId
());
}
if
(
query
.
getDistrictId
()
!=
null
)
{
qw
.
eq
(
BusinessStore:
:
getDistrictId
,
query
.
getDistrictId
());
}
if
(
query
.
getStatus
()
!=
null
)
{
qw
.
eq
(
BusinessStore:
:
getStatus
,
query
.
getStatus
());
}
}
// 固定过滤未删除与按创建时间倒序
qw
.
eq
(
BusinessStore:
:
getDelFlag
,
0
)
.
orderByDesc
(
BusinessStore:
:
getCreateTime
);
return
qw
;
}
/**
* 详情查询
*
* @param id 门店ID
* @return 门店详情
*/
@Override
public
BusinessStore
get
(
Long
id
)
{
return
businessStoreMapper
.
selectById
(
id
);
}
/**
* 根据门店编码查询门店
*
* @param storeCode 门店编码
* @return 门店
*/
@Override
public
BusinessStore
getByCode
(
String
storeCode
)
{
return
businessStoreMapper
.
selectOne
(
new
LambdaQueryWrapper
<
BusinessStore
>()
.
eq
(
BusinessStore:
:
getStoreCode
,
storeCode
));
}
/**
* 新增门店
*
* @param info 门店信息
*/
@Override
public
Long
add
(
BusinessStore
info
)
{
info
.
setCreateBy
(
SecurityUtils
.
getUserName
());
info
.
setCreateById
(
SecurityUtils
.
getUserId
());
info
.
setCreateTime
(
new
Date
());
info
.
setUpdateBy
(
SecurityUtils
.
getUserName
());
info
.
setUpdateById
(
SecurityUtils
.
getUserId
());
info
.
setUpdateTime
(
new
Date
());
info
.
setDelFlag
(
0
);
info
.
setStatus
(
1
);
businessStoreMapper
.
insert
(
info
);
return
info
.
getId
();
}
@Override
public
Long
add
(
BusinessStoreCreateReq
req
)
{
Long
count
=
businessStoreMapper
.
selectCount
(
new
LambdaQueryWrapper
<
BusinessStore
>()
.
eq
(
BusinessStore:
:
getStoreName
,
req
.
getStoreName
())
.
eq
(
BusinessStore:
:
getDelFlag
,
0
));
if
(
count
>
0
)
{
throw
new
CustomException
(
"门店名称已存在"
);
}
if
(
req
.
getProvinceId
()
==
null
||
sysAreaService
.
getList
(
new
SysArea
()
{{
setId
(
req
.
getProvinceId
());
}}).
isEmpty
())
{
throw
new
com
.
bs
.
common
.
exception
.
CustomException
(
"省份不存在"
);
}
if
(
req
.
getCityId
()
==
null
||
sysAreaService
.
getList
(
new
SysArea
()
{{
setId
(
req
.
getCityId
());
}}).
isEmpty
())
{
throw
new
com
.
bs
.
common
.
exception
.
CustomException
(
"城市不存在"
);
}
if
(
req
.
getDistrictId
()
==
null
||
sysAreaService
.
getList
(
new
SysArea
()
{{
setId
(
req
.
getDistrictId
());
}}).
isEmpty
())
{
throw
new
com
.
bs
.
common
.
exception
.
CustomException
(
"区县不存在"
);
}
BusinessStore
info
=
new
BusinessStore
();
info
.
setStoreName
(
req
.
getStoreName
());
info
.
setStoreCode
(
createStoreCode
());
info
.
setProvinceId
(
req
.
getProvinceId
());
info
.
setCityId
(
req
.
getCityId
());
info
.
setDistrictId
(
req
.
getDistrictId
());
info
.
setProvinceName
(
req
.
getProvinceName
());
info
.
setCityName
(
req
.
getCityName
());
info
.
setDistrictName
(
req
.
getDistrictName
());
info
.
setProvinceParentId
(
req
.
getProvinceParentId
());
info
.
setCityParentId
(
req
.
getCityParentId
());
info
.
setDistrictParentId
(
req
.
getDistrictParentId
());
info
.
setProvinceExtId
(
req
.
getProvinceExtId
());
info
.
setCityExtId
(
req
.
getCityExtId
());
info
.
setDistrictExtId
(
req
.
getDistrictExtId
());
info
.
setDetailedAddress
(
req
.
getDetailedAddress
());
info
.
setLiaison
(
req
.
getLiaison
());
info
.
setPhone
(
req
.
getPhone
());
info
.
setStatus
(
1
);
return
this
.
add
(
info
);
}
/**
* 创建门店编码
*
* @return 门店编码
*/
public
static
String
createStoreCode
()
{
return
"ST"
+
System
.
currentTimeMillis
();
}
/**
* 编辑门店
*
* @param info 门店信息
*/
@Override
public
void
edit
(
BusinessStore
info
)
{
info
.
setUpdateBy
(
SecurityUtils
.
getUserName
());
info
.
setUpdateById
(
SecurityUtils
.
getUserId
());
info
.
setUpdateTime
(
new
Date
());
businessStoreMapper
.
updateById
(
info
);
}
@Override
@Transactional
public
void
edit
(
BusinessStoreUpdateReq
req
)
{
BusinessStore
exist
=
businessStoreMapper
.
selectById
(
req
.
getId
());
if
(
exist
==
null
)
{
throw
new
com
.
bs
.
common
.
exception
.
CustomException
(
"门店不存在"
);
}
Long
dup
=
businessStoreMapper
.
selectCount
(
new
LambdaQueryWrapper
<
BusinessStore
>()
.
eq
(
BusinessStore:
:
getStoreName
,
req
.
getStoreName
())
.
eq
(
BusinessStore:
:
getDelFlag
,
0
)
.
ne
(
BusinessStore:
:
getId
,
req
.
getId
()));
if
(
dup
!=
null
&&
dup
>
0
)
{
throw
new
CustomException
(
"门店名称已存在"
);
}
if
(
req
.
getProvinceId
()
==
null
||
sysAreaService
.
getList
(
new
SysArea
()
{{
setId
(
req
.
getProvinceId
());
}}).
isEmpty
())
{
throw
new
com
.
bs
.
common
.
exception
.
CustomException
(
"省份不存在"
);
}
if
(
req
.
getCityId
()
==
null
||
sysAreaService
.
getList
(
new
SysArea
()
{{
setId
(
req
.
getCityId
());
}}).
isEmpty
())
{
throw
new
com
.
bs
.
common
.
exception
.
CustomException
(
"城市不存在"
);
}
if
(
req
.
getDistrictId
()
==
null
||
sysAreaService
.
getList
(
new
SysArea
()
{{
setId
(
req
.
getDistrictId
());
}}).
isEmpty
())
{
throw
new
com
.
bs
.
common
.
exception
.
CustomException
(
"区县不存在"
);
}
BusinessStore
info
=
new
BusinessStore
();
info
.
setId
(
req
.
getId
());
info
.
setStoreName
(
req
.
getStoreName
());
info
.
setStoreCode
(
req
.
getStoreCode
());
info
.
setProvinceId
(
req
.
getProvinceId
());
info
.
setCityId
(
req
.
getCityId
());
info
.
setDistrictId
(
req
.
getDistrictId
());
info
.
setProvinceName
(
req
.
getProvinceName
());
info
.
setCityName
(
req
.
getCityName
());
info
.
setDistrictName
(
req
.
getDistrictName
());
info
.
setProvinceParentId
(
req
.
getProvinceParentId
());
info
.
setCityParentId
(
req
.
getCityParentId
());
info
.
setDistrictParentId
(
req
.
getDistrictParentId
());
info
.
setProvinceExtId
(
req
.
getProvinceExtId
());
info
.
setCityExtId
(
req
.
getCityExtId
());
info
.
setDistrictExtId
(
req
.
getDistrictExtId
());
info
.
setDetailedAddress
(
req
.
getDetailedAddress
());
info
.
setLiaison
(
req
.
getLiaison
());
info
.
setPhone
(
req
.
getPhone
());
info
.
setStatus
(
req
.
getStatus
());
this
.
edit
(
info
);
if
(
exist
.
getStatus
()
!=
null
&&
req
.
getStatus
()
!=
null
&&
req
.
getStatus
()
==
0
&&
!
req
.
getStatus
().
equals
(
exist
.
getStatus
()))
{
LambdaUpdateWrapper
<
SpStoreRelation
>
uw
=
new
LambdaUpdateWrapper
<
SpStoreRelation
>()
.
eq
(
SpStoreRelation:
:
getStoreCode
,
req
.
getStoreCode
())
.
eq
(
SpStoreRelation:
:
getDelFlag
,
0
)
.
set
(
SpStoreRelation:
:
getStatus
,
0
)
.
set
(
SpStoreRelation:
:
getUpdateBy
,
SecurityUtils
.
getUserName
())
.
set
(
SpStoreRelation:
:
getUpdateById
,
SecurityUtils
.
getUserId
())
.
set
(
SpStoreRelation:
:
getUpdateTime
,
new
Date
());
spStoreRelationMapper
.
update
(
null
,
uw
);
}
if
(
exist
.
getStatus
()
!=
null
&&
req
.
getStatus
()
!=
null
&&
req
.
getStatus
()
==
1
&&
!
req
.
getStatus
().
equals
(
exist
.
getStatus
()))
{
LambdaUpdateWrapper
<
SpStoreRelation
>
uw
=
new
LambdaUpdateWrapper
<
SpStoreRelation
>()
.
eq
(
SpStoreRelation:
:
getStoreCode
,
req
.
getStoreCode
())
.
eq
(
SpStoreRelation:
:
getDelFlag
,
0
)
.
set
(
SpStoreRelation:
:
getStatus
,
1
)
.
set
(
SpStoreRelation:
:
getUpdateBy
,
SecurityUtils
.
getUserName
())
.
set
(
SpStoreRelation:
:
getUpdateById
,
SecurityUtils
.
getUserId
())
.
set
(
SpStoreRelation:
:
getUpdateTime
,
new
Date
());
spStoreRelationMapper
.
update
(
null
,
uw
);
}
}
/**
* 删除门店
*
* @param id 门店ID
*/
@Override
public
void
remove
(
Long
id
)
{
BusinessStore
store
=
businessStoreMapper
.
selectById
(
id
);
if
(
store
!=
null
)
{
store
.
setDelFlag
(
1
);
store
.
setUpdateBy
(
SecurityUtils
.
getUserName
());
store
.
setUpdateById
(
SecurityUtils
.
getUserId
());
store
.
setUpdateTime
(
new
Date
());
businessStoreMapper
.
updateById
(
store
);
}
}
@Override
public
String
importStore
(
String
url
)
{
String
importId
=
IdUtils
.
fastSimpleUUID
();
// 初始化进度
Map
<
String
,
Object
>
progress
=
new
HashMap
<>();
progress
.
put
(
"total"
,
0
);
progress
.
put
(
"current"
,
0
);
progress
.
put
(
"success"
,
0
);
progress
.
put
(
"fail"
,
0
);
progress
.
put
(
"status"
,
0
);
// 0-处理中 1-完成
redisService
.
setCacheObject
(
"store_import_progress:"
+
importId
,
progress
,
1
,
TimeUnit
.
HOURS
);
// 异步处理
ThreadUtil
.
execAsync
(()
->
{
InputStream
in
=
null
;
try
{
in
=
new
URL
(
url
).
openStream
();
EasyExcel
.
read
(
in
,
BusinessStoreImportVo
.
class
,
new
ImportListener
(
importId
,
this
,
sysAreaService
,
redisService
,
fileFeignClient
,
businessStoreMapper
))
.
sheet
()
.
headRowNumber
(
2
)
// 第 2 行为表头,忽略第 1 行,从第 3 行开始读取数据
.
doRead
();
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
progress
.
put
(
"status"
,
2
);
// 2-异常
progress
.
put
(
"errorMsg"
,
"文件解析失败:"
+
e
.
getMessage
());
redisService
.
setCacheObject
(
"store_import_progress:"
+
importId
,
progress
,
1
,
TimeUnit
.
HOURS
);
}
finally
{
if
(
in
!=
null
)
{
try
{
in
.
close
();
}
catch
(
IOException
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
}
}
}
});
return
importId
;
}
@Override
public
Map
<
String
,
Object
>
getImportProgress
(
String
importId
)
{
return
redisService
.
getCacheObject
(
"store_import_progress:"
+
importId
);
}
@Override
public
String
importStoreTemplateDownLode
()
{
// 从配置里拿链接
return
env
.
getProperty
(
"sp.store.import.templateUrl"
);
}
/**
* 根据门店编码查询关联的服务商列表
*/
@Override
public
List
<
SpInfo
>
selectSpListByStoreCode
(
String
storeCode
)
{
// 1. 查询关联的服务商编码
List
<
SpStoreRelation
>
relations
=
spStoreRelationMapper
.
selectList
(
new
LambdaQueryWrapper
<
SpStoreRelation
>()
.
eq
(
SpStoreRelation:
:
getStoreCode
,
storeCode
)
.
eq
(
SpStoreRelation:
:
getDelFlag
,
0
));
if
(
relations
.
isEmpty
())
{
return
Collections
.
emptyList
();
}
List
<
String
>
spCodes
=
relations
.
stream
()
.
map
(
SpStoreRelation:
:
getSpCode
)
.
collect
(
Collectors
.
toList
());
// 2. 查询服务商详情
// 需要 SpInfoMapper
List
<
SpInfo
>
spList
=
spInfoMapper
.
selectList
(
new
LambdaQueryWrapper
<
SpInfo
>()
.
in
(
SpInfo:
:
getSpCode
,
spCodes
)
.
eq
(
SpInfo:
:
getDelFlag
,
0
));
// 3. 使用自定义 SQL 一次性查询所有服务商关联的成员数(驻店),并在内存中封装
// 成员数逻辑:用户未删除 + 用户 - 门店关联存在且未删除 + 用户 - 服务商关联存在且未删除 + role_code=zhudian
if
(!
spList
.
isEmpty
())
{
List
<
String
>
querySpCodes
=
spList
.
stream
()
.
map
(
SpInfo:
:
getSpCode
)
.
collect
(
Collectors
.
toList
());
// 通过多表关联查询,一次性统计每个服务商下的驻店数量
List
<
Map
<
String
,
Object
>>
countMaps
=
sysUserSpRelationMapper
.
countStoreManagersBySpCode
(
querySpCodes
,
"zhudian"
,
storeCode
);
// 构建 sp_code 到 userCount 的映射
Map
<
String
,
Integer
>
userCountMap
=
new
HashMap
<>();
for
(
Map
<
String
,
Object
>
map
:
countMaps
)
{
String
spCode
=
(
String
)
map
.
get
(
"sp_code"
);
Long
count
=
(
Long
)
map
.
get
(
"user_count"
);
userCountMap
.
put
(
spCode
,
count
.
intValue
());
}
// 为每个服务商设置成员数(驻店数)
for
(
SpInfo
sp
:
spList
)
{
sp
.
setUserCount
(
userCountMap
.
getOrDefault
(
sp
.
getSpCode
(),
0
));
}
}
return
spList
;
}
@Override
public
IPage
<
SpInfo
>
selectSpListByStoreCodePage
(
String
storeCode
,
Integer
pageNum
,
Integer
pageSize
)
{
List
<
SpStoreRelation
>
relations
=
spStoreRelationMapper
.
selectList
(
new
LambdaQueryWrapper
<
SpStoreRelation
>()
.
eq
(
SpStoreRelation:
:
getStoreCode
,
storeCode
)
.
eq
(
SpStoreRelation:
:
getDelFlag
,
0
));
if
(
relations
.
isEmpty
())
{
Page
<
SpInfo
>
empty
=
new
Page
<>(
pageNum
,
pageSize
);
empty
.
setTotal
(
0
);
empty
.
setRecords
(
Collections
.
emptyList
());
return
empty
;
}
List
<
String
>
spCodes
=
relations
.
stream
()
.
map
(
SpStoreRelation:
:
getSpCode
)
.
collect
(
Collectors
.
toList
());
Page
<
SpInfo
>
page
=
new
Page
<>(
pageNum
,
pageSize
);
IPage
<
SpInfo
>
pageResult
=
spInfoMapper
.
selectPage
(
page
,
new
LambdaQueryWrapper
<
SpInfo
>()
.
in
(
SpInfo:
:
getSpCode
,
spCodes
)
.
eq
(
SpInfo:
:
getDelFlag
,
0
)
.
orderByDesc
(
SpInfo:
:
getId
));
List
<
SpInfo
>
records
=
pageResult
.
getRecords
();
if
(!
records
.
isEmpty
())
{
List
<
String
>
querySpCodes
=
records
.
stream
()
.
map
(
SpInfo:
:
getSpCode
)
.
collect
(
Collectors
.
toList
());
List
<
Map
<
String
,
Object
>>
countMaps
=
sysUserSpRelationMapper
.
countStoreManagersBySpCode
(
querySpCodes
,
"zhudian"
,
storeCode
);
Map
<
String
,
Integer
>
userCountMap
=
new
HashMap
<>();
for
(
Map
<
String
,
Object
>
map
:
countMaps
)
{
String
code
=
(
String
)
map
.
get
(
"sp_code"
);
Long
cnt
=
(
Long
)
map
.
get
(
"user_count"
);
userCountMap
.
put
(
code
,
cnt
==
null
?
0
:
cnt
.
intValue
());
}
for
(
SpInfo
sp
:
records
)
{
sp
.
setUserCount
(
userCountMap
.
getOrDefault
(
sp
.
getSpCode
(),
0
));
}
}
return
pageResult
;
}
/**
* 导入监听器
*/
private
static
class
ImportListener
extends
AnalysisEventListener
<
BusinessStoreImportVo
>
{
private
String
importId
;
private
IBusinessStoreService
businessStoreService
;
private
ISysAreaService
sysAreaService
;
private
RedisService
redisService
;
private
FileFeignClient
fileFeignClient
;
private
BusinessStoreMapper
businessStoreMapper
;
private
List
<
BusinessStoreImportVo
>
errorList
=
new
ArrayList
<>();
private
int
successCount
=
0
;
private
int
failCount
=
0
;
private
int
totalCount
=
0
;
public
ImportListener
(
String
importId
,
IBusinessStoreService
businessStoreService
,
ISysAreaService
sysAreaService
,
RedisService
redisService
,
FileFeignClient
fileFeignClient
,
BusinessStoreMapper
businessStoreMapper
)
{
this
.
importId
=
importId
;
this
.
businessStoreService
=
businessStoreService
;
this
.
sysAreaService
=
sysAreaService
;
this
.
redisService
=
redisService
;
this
.
fileFeignClient
=
fileFeignClient
;
this
.
businessStoreMapper
=
businessStoreMapper
;
}
@Override
public
void
invokeHeadMap
(
Map
<
Integer
,
String
>
headMap
,
AnalysisContext
context
)
{
// 因为 headRowNumber 设置了 2,EasyExcel 会为前两行各调用一次此方法
// 第 1 行 (rowIndex = 0) 是说明文本,第 2 行 (rowIndex = 1) 才是真正的列名表头
if
(
context
.
readRowHolder
().
getRowIndex
()
==
1
)
{
// 表头校验
log
.
info
(
"开始解析表头: {}"
,
headMap
);
if
(
headMap
.
size
()
<
5
)
{
log
.
error
(
"表头列数不匹配,预期至少5列,实际{}列"
,
headMap
.
size
());
throw
new
RuntimeException
(
"表头列数不匹配,请检查模板"
);
}
if
(!
"门店名称"
.
equals
(
headMap
.
get
(
0
)))
throw
new
RuntimeException
(
"第1列应为[门店名称]"
);
if
(!
"所属区域"
.
equals
(
headMap
.
get
(
1
)))
throw
new
RuntimeException
(
"第2列应为[所属区域]"
);
if
(!
"详细地址"
.
equals
(
headMap
.
get
(
2
)))
throw
new
RuntimeException
(
"第3列应为[详细地址]"
);
if
(!
"联系人"
.
equals
(
headMap
.
get
(
3
)))
throw
new
RuntimeException
(
"第4列应为[联系人]"
);
if
(!
"联系电话"
.
equals
(
headMap
.
get
(
4
)))
throw
new
RuntimeException
(
"第5列应为[联系电话]"
);
log
.
info
(
"表头校验通过"
);
}
}
@Override
public
void
invoke
(
BusinessStoreImportVo
data
,
AnalysisContext
context
)
{
totalCount
++;
// 数据行日志
log
.
info
(
"开始处理第{}行数据: {}"
,
context
.
readRowHolder
().
getRowIndex
()
+
1
,
data
);
String
errorMsg
=
validateData
(
data
);
if
(
errorMsg
==
null
)
{
try
{
saveStore
(
data
);
successCount
++;
log
.
info
(
"第{}行数据保存成功"
,
context
.
readRowHolder
().
getRowIndex
()
+
1
);
}
catch
(
Exception
e
)
{
failCount
++;
log
.
error
(
"第{}行数据保存失败: {}"
,
context
.
readRowHolder
().
getRowIndex
()
+
1
,
e
.
getMessage
());
data
.
setFailureReason
(
"保存失败:"
+
e
.
getMessage
());
errorList
.
add
(
data
);
}
}
else
{
failCount
++;
log
.
warn
(
"第{}行数据校验失败: {}"
,
context
.
readRowHolder
().
getRowIndex
()
+
1
,
errorMsg
);
data
.
setFailureReason
(
errorMsg
);
errorList
.
add
(
data
);
}
updateProgress
(
0
);
}
@Override
public
void
doAfterAllAnalysed
(
AnalysisContext
context
)
{
if
(!
errorList
.
isEmpty
())
{
// 生成错误文件并上传
String
url
=
uploadErrorFile
();
updateProgress
(
1
,
url
);
}
else
{
updateProgress
(
1
);
}
}
private
String
validateData
(
BusinessStoreImportVo
vo
)
{
if
(
StringUtils
.
isBlank
(
vo
.
getStoreName
()))
{
return
"门店名称字段为必填项"
;
}
if
(
vo
.
getStoreName
().
length
()
>
40
)
{
return
"门店名称最多40个字"
;
}
if
(
StringUtils
.
isBlank
(
vo
.
getDetailedAddress
()))
{
return
"详细地址字段为必填项"
;
}
if
(
vo
.
getDetailedAddress
().
length
()
>
100
)
{
return
"详细地址最多100个字"
;
}
if
(
vo
.
getLiaison
()
!=
null
&&
vo
.
getLiaison
().
length
()
>
20
)
{
return
"联系人最多20个字"
;
}
if
(
vo
.
getPhone
()
!=
null
&&
(
vo
.
getPhone
().
length
()
>
20
||
!
Pattern
.
matches
(
"\\d+"
,
vo
.
getPhone
())))
{
return
"联系电话最多20个数字"
;
}
if
(
StringUtils
.
isBlank
(
vo
.
getArea
()))
{
return
"所属区域字段为必填项"
;
}
String
[]
areas
=
vo
.
getArea
().
split
(
"/"
);
if
(
areas
.
length
!=
3
)
{
return
"所属区域格式错误,应为 省/市/区"
;
}
return
null
;
}
private
void
saveStore
(
BusinessStoreImportVo
vo
)
{
String
[]
areas
=
vo
.
getArea
().
split
(
"/"
);
String
provName
=
areas
[
0
];
String
cityName
=
areas
[
1
];
String
distName
=
areas
[
2
];
// 校验并获取区域ID
// 省
SysArea
prov
=
getArea
(
provName
,
0
);
// 假设根parent=0
if
(
prov
==
null
)
throw
new
RuntimeException
(
"省份不存在:"
+
provName
);
// 市
SysArea
city
=
getArea
(
cityName
,
prov
.
getId
());
if
(
city
==
null
)
throw
new
RuntimeException
(
"城市不存在:"
+
cityName
);
// 区
SysArea
dist
=
getArea
(
distName
,
city
.
getId
());
if
(
dist
==
null
)
throw
new
RuntimeException
(
"区县不存在:"
+
distName
);
Long
count
=
businessStoreMapper
.
selectCount
(
new
LambdaQueryWrapper
<
BusinessStore
>()
.
eq
(
BusinessStore:
:
getStoreName
,
vo
.
getStoreName
())
.
eq
(
BusinessStore:
:
getDelFlag
,
0
));
if
(
count
>
0
)
{
throw
new
CustomException
(
"门店名称已存在"
);
}
BusinessStore
store
=
new
BusinessStore
();
store
.
setStoreName
(
vo
.
getStoreName
());
store
.
setStoreCode
(
createStoreCode
());
store
.
setProvinceId
(
prov
.
getId
());
store
.
setProvinceName
(
prov
.
getExtName
());
store
.
setProvinceParentId
(
prov
.
getParentId
());
store
.
setProvinceExtId
(
prov
.
getExtId
());
store
.
setCityId
(
city
.
getId
());
store
.
setCityName
(
city
.
getExtName
());
store
.
setCityParentId
(
city
.
getParentId
());
store
.
setCityExtId
(
city
.
getExtId
());
store
.
setDistrictId
(
dist
.
getId
());
store
.
setDistrictName
(
dist
.
getExtName
());
store
.
setDistrictParentId
(
dist
.
getParentId
());
store
.
setDistrictExtId
(
dist
.
getExtId
());
store
.
setDetailedAddress
(
vo
.
getDetailedAddress
());
store
.
setLiaison
(
vo
.
getLiaison
());
store
.
setPhone
(
vo
.
getPhone
());
store
.
setStatus
(
1
);
// 默认启用
businessStoreService
.
add
(
store
);
}
private
SysArea
getArea
(
String
name
,
Integer
parentId
)
{
// 尝试匹配 name 或 extName
List
<
SysArea
>
list
=
sysAreaService
.
list
(
new
LambdaQueryWrapper
<
SysArea
>()
.
eq
(
SysArea:
:
getName
,
name
)
.
eq
(
SysArea:
:
getParentId
,
parentId
)
.
eq
(
SysArea:
:
getDelFlag
,
0
));
if
(!
list
.
isEmpty
())
return
list
.
get
(
0
);
// 使用 LambdaQueryWrapper 匹配 extName
List
<
SysArea
>
extList
=
sysAreaService
.
list
(
new
LambdaQueryWrapper
<
SysArea
>()
.
eq
(
SysArea:
:
getExtName
,
name
)
.
eq
(
SysArea:
:
getParentId
,
parentId
)
.
eq
(
SysArea:
:
getDelFlag
,
0
));
if
(!
extList
.
isEmpty
())
return
extList
.
get
(
0
);
return
null
;
}
private
void
updateProgress
(
int
status
)
{
updateProgress
(
status
,
null
);
}
private
void
updateProgress
(
int
status
,
String
errorUrl
)
{
Map
<
String
,
Object
>
progress
=
new
HashMap
<>();
progress
.
put
(
"total"
,
totalCount
);
progress
.
put
(
"current"
,
successCount
+
failCount
);
progress
.
put
(
"success"
,
successCount
);
progress
.
put
(
"fail"
,
failCount
);
progress
.
put
(
"status"
,
status
);
if
(
errorUrl
!=
null
)
{
progress
.
put
(
"errorUrl"
,
errorUrl
);
}
redisService
.
setCacheObject
(
"store_import_progress:"
+
importId
,
progress
,
1
,
TimeUnit
.
HOURS
);
}
private
String
uploadErrorFile
()
{
try
{
String
fileName
=
"门店导入失败记录_"
+
importId
+
".xlsx"
;
File
file
=
File
.
createTempFile
(
"门店导入失败记录_"
,
".xlsx"
);
EasyExcel
.
write
(
file
,
BusinessStoreImportVo
.
class
).
sheet
(
"错误数据"
).
doWrite
(
errorList
);
// 上传
// 构造 MultipartFile
FileInputStream
input
=
new
FileInputStream
(
file
);
MultipartFile
multipartFile
=
new
MockMultipartFile
(
"file"
,
fileName
,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
,
input
);
AjaxResult
<
FileEntity
>
result
=
fileFeignClient
.
upload
(
multipartFile
);
String
url
=
""
;
if
(
result
!=
null
&&
result
.
getData
()
!=
null
)
{
url
=
result
.
getData
().
getUrl
();
}
else
{
log
.
error
(
"上传失败:{}"
,
result
);
}
input
.
close
();
file
.
delete
();
return
url
;
}
catch
(
Exception
e
)
{
log
.
error
(
e
.
getMessage
(),
e
);
return
null
;
}
}
}
// MockMultipartFile implementation since spring-test is not available in prod
public
static
class
MockMultipartFile
implements
MultipartFile
{
private
final
String
name
;
private
final
String
originalFilename
;
private
final
String
contentType
;
private
final
byte
[]
content
;
public
MockMultipartFile
(
String
name
,
String
originalFilename
,
String
contentType
,
InputStream
contentStream
)
throws
IOException
{
this
.
name
=
name
;
this
.
originalFilename
=
originalFilename
;
this
.
contentType
=
contentType
;
this
.
content
=
FileCopyUtils
.
copyToByteArray
(
contentStream
);
}
@Override
public
String
getName
()
{
return
name
;
}
@Override
public
String
getOriginalFilename
()
{
return
originalFilename
;
}
@Override
public
String
getContentType
()
{
return
contentType
;
}
@Override
public
boolean
isEmpty
()
{
return
content
.
length
==
0
;
}
@Override
public
long
getSize
()
{
return
content
.
length
;
}
@Override
public
byte
[]
getBytes
()
throws
IOException
{
return
content
;
}
@Override
public
InputStream
getInputStream
()
throws
IOException
{
return
new
ByteArrayInputStream
(
content
);
}
@Override
public
void
transferTo
(
File
dest
)
throws
IOException
,
IllegalStateException
{
FileCopyUtils
.
copy
(
content
,
dest
);
}
}
}
bs-auth/src/main/resources/mapper/relation/SpStoreRelationMapper.xml
deleted
100644 → 0
View file @
61b0a72
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.bs.web.mapper.relation.SpStoreRelationMapper"
>
</mapper>
bs-auth/src/main/resources/mapper/relation/SysUserSpRelationMapper.xml
deleted
100644 → 0
View file @
61b0a72
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.bs.web.mapper.relation.SysUserSpRelationMapper"
>
<!-- 统计每个服务商下的店长数量 -->
<select
id=
"countStoreManagersBySpCode"
resultType=
"java.util.HashMap"
>
SELECT
spr.sp_code,
COUNT(DISTINCT u.user_id) AS user_count
FROM sys_user_sp_relation spr
INNER JOIN sys_user u
ON spr.user_id = u.user_id AND u.del_flag = 0
INNER JOIN sys_user_store_relation usr
ON u.user_id = usr.user_id AND usr.del_flag = 0
WHERE spr.del_flag = 0
AND spr.role_code = #{roleCode}
<if
test=
"spCodes != null and spCodes.size() > 0"
>
AND spr.sp_code IN
<foreach
collection=
"spCodes"
item=
"spCode"
open=
"("
separator=
","
close=
")"
>
#{spCode}
</foreach>
</if>
<if
test=
"storeCode != null and storeCode != ''"
>
AND usr.store_code = #{storeCode}
</if>
GROUP BY spr.sp_code
</select>
<!-- 统计指定服务商下各个门店的成员数量 -->
<select
id=
"countUsersBySpCodeAndStoreCodes"
resultType=
"java.util.HashMap"
>
SELECT
usr.store_code,
COUNT(DISTINCT u.user_id) AS user_count
FROM sys_user_sp_relation spr
INNER JOIN sys_user u
ON spr.user_id = u.user_id AND u.del_flag = 0
INNER JOIN sys_user_store_relation usr
ON u.user_id = usr.user_id AND usr.del_flag = 0
WHERE spr.del_flag = 0
AND spr.sp_code = #{spCode}
<if
test=
"roleCode != null and roleCode != ''"
>
AND spr.role_code = #{roleCode}
</if>
<if
test=
"storeCodes != null and storeCodes.size() > 0"
>
AND usr.store_code IN
<foreach
collection=
"storeCodes"
item=
"storeCode"
open=
"("
separator=
","
close=
")"
>
#{storeCode}
</foreach>
</if>
GROUP BY usr.store_code
</select>
</mapper>
bs-auth/src/main/resources/mapper/relation/SysUserStoreRelationMapper.xml
deleted
100644 → 0
View file @
61b0a72
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.bs.web.mapper.relation.SysUserStoreRelationMapper"
>
<select
id=
"selectUserStoreRelationPage"
resultType=
"com.bs.web.domain.vo.relation.SysUserStoreRelationVO"
>
SELECT
r.*,
s.store_name
FROM sys_user_store_relation r
LEFT JOIN business_store s ON r.store_code = s.store_code AND s.del_flag = 0
WHERE r.del_flag = 0
<if
test=
"req.userId != null"
>
AND r.user_id = #{req.userId}
</if>
<if
test=
"req.storeName != null and req.storeName != ''"
>
AND s.store_name LIKE concat('%', #{req.storeName}, '%')
</if>
ORDER BY r.id ASC
</select>
</mapper>
bs-auth/src/main/resources/mapper/role/SpRoleMapper.xml
deleted
100644 → 0
View file @
61b0a72
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.bs.web.mapper.role.SpRoleMapper"
>
</mapper>
bs-auth/src/main/resources/mapper/sp/SpInfoMapper.xml
deleted
100644 → 0
View file @
61b0a72
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.bs.web.mapper.sp.SpInfoMapper"
>
<select
id=
"selectSpUserList"
resultType=
"com.bs.web.domain.vo.sp.SpUserVo"
>
SELECT
u.user_id, u.dept_id, u.user_name, u.nick_name, u.user_type, u.email, u.phone_number, u.sex, u.avatar,
u.password, u.status, u.del_flag, u.login_ip, u.login_date, u.create_by, u.create_time, u.update_by,
u.update_time, u.remark,
sp.id AS spId, sp.sp_code, sp.sp_name,
sr.id AS spRoleId, sr.role_code AS spRoleCode, sr.role_name AS spRoleName
FROM sys_user u
INNER JOIN sys_user_sp_relation susr ON u.user_id = susr.user_id
INNER JOIN sp_info sp ON susr.sp_code = sp.sp_code
LEFT JOIN sp_role sr ON susr.role_code = sr.role_code
<if
test=
"storeCode != null and storeCode != ''"
>
INNER JOIN sys_user_store_relation susr2 ON u.user_id = susr2.user_id
AND susr2.store_code = #{storeCode}
AND susr2.del_flag = 0
</if>
WHERE sp.id = #{spId}
AND u.del_flag = '0'
AND susr.del_flag = 0
<if
test=
"keyword != null and keyword != ''"
>
AND (u.user_name LIKE concat('%', #{keyword}, '%') OR u.phone_number LIKE concat('%', #{keyword}, '%'))
</if>
<if
test=
"spRoleCode != null and spRoleCode != ''"
>
AND sr.role_code = #{spRoleCode}
</if>
ORDER BY u.user_id ASC
</select>
</mapper>
bs-auth/src/main/resources/mapper/store/BusinessStoreMapper.xml
deleted
100644 → 0
View file @
61b0a72
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper
namespace=
"com.bs.web.mapper.store.BusinessStoreMapper"
>
<select
id=
"selectStoreListBySpId"
resultType=
"com.bs.common.core.domain.entity.store.BusinessStore"
>
SELECT s.*
FROM business_store s
INNER JOIN sp_store_relation r ON s.store_code = r.store_code
WHERE r.sp_code = #{spCode}
AND r.del_flag = 0
AND s.del_flag = 0
<if
test=
"storeName != null and storeName != ''"
>
AND s.store_name LIKE concat('%', #{storeName}, '%')
</if>
ORDER BY s.id DESC
</select>
<select
id=
"selectStoreListBySpIdPage"
resultType=
"com.bs.common.core.domain.entity.store.BusinessStore"
>
SELECT s.*
FROM business_store s
INNER JOIN sp_store_relation r ON s.store_code = r.store_code
WHERE r.sp_code = #{spCode}
AND r.del_flag = 0
AND s.del_flag = 0
<if
test=
"storeName != null and storeName != ''"
>
AND s.store_name LIKE concat('%', #{storeName}, '%')
</if>
ORDER BY s.id DESC
</select>
</mapper>
Write
Preview
Markdown
is supported
Attach a file
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 post a comment