0%

ssp

1. cfgcenter

1.1 cfg-api

理论上,给gdsinsing的其它地方直接使用,只需要调用接口,无需重复实现

1
2
3
4
5
6
7
8
9
10
public interface ICfgService {

//根据编号查找一个配置
public String getCfgString(String code) throws BusException;

public Integer getCfgInteger(String code) throws BusException;

public Date getCfgDate(String code) throws BusException;

}

1.2 cfg-provider

1.2.1 CfgServiceImpl.java

理论上,provider实现api的接口,用于分布式,其它模块直接调用api即可

目前没用上,还是必须在其它模块的pom里provider

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
@Service
public class CfgServiceImpl implements ICfgService {

@Autowired
private IGdssCfgTeConfigService iGdssCfgTeConfigService;

@Override
public String getCfgString(String code) throws BusException {
GdssCfgTeConfig value = iGdssCfgTeConfigService.getEntityByCode(code);
if (value == null){
return null;
}
return value.getCfgValue();
}

@Override
public Integer getCfgInteger(String code) throws BusException {
String val = this.getCfgString(code);
return Integer.valueOf(val);
}

@Override
public Date getCfgDate(String code) throws BusException {
try{
String val = this.getCfgString(code);
return DateUtil.string2Date(val);
}catch(Exception ex){
ex.printStackTrace();
}
return null;
}
}

1.2.2 CfgcenterProviderApp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@SpringBootApplication
@MapperScan("cn.lll.**.mapper")
@ServletComponentScan(value = {"cn.lll.cfgcenter" })
public class CfgcenterProviderApp implements ApplicationRunner {

private static Log log = LogFactory.getLog(CfgcenterProviderApp.class);

public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(CfgcenterProviderApp.class, args);
SpringUtil.setApplicationContext(context);
}

@Override
public void run(ApplicationArguments args) throws Exception {
log.info("************************************************************* CfgcenterProviderApp 启动完成!");
}
}

注意:

  1. Spring boot 框架注解

1.2.3 TestCfgService.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
@RunWith(SpringRunner.class)
@SpringBootTest(classes = CfgcenterProviderApp.class)
public class TestCfgService {

private static Log log = LogFactory.getLog(TestCfgService.class);

@Autowired
private ICfgService iCfgService;

@Before
public void start(){
System.out.println("开始");
}

@After
public void end(){
System.out.println("结束");
}

@Test
public void testGetCfgString(){
try{
String code = "001";

String val = iCfgService.getCfgString(code);

if(val.equals("测试")){
Assert.assertTrue(true);
return;
}

Assert.assertTrue(false);
}catch(BusException ex){
log.error("", ex);
Assert.assertTrue(false);
}
}
}

注意:

  1. Spring boot 框架注解

1.3 cfg-dao

一张数据库表,一个xml,一个mapper,一个model,一个service,一个serviceImpl

1.3.1 xml mybatis-GdssCfgTeConfig.xml

1.主体是个 , namespace指定sql功能对应的mapper接口,每个sql功能和接口中的方法一一对应

1
2
3
<mapper namespace="cn.lll.cfgcenter.mapper.IGdssCfgTeConfigMapper">

</mapper>

常用的CRUD操作由, , ,定义好以备试用,id和mapper接口中的方法名对应

输入参数类型

输出参数类型

1
2
3
4
5
<delete id="delEntity" parameterType="java.lang.String">
DELETE FROM
<include refid="TableName" />
WHERE ID = #{id}
</delete>

2.指定sql操作的结果集,由type指定路径,将数据库表中的记录ORM映射到model中定义的java bean

1
2
3
4
5
6
7
8
9
10
11
    <resultMap id="GdssCfgTeConfigMap" type="cn.lll.cfgcenter.model.GdssCfgTeConfig">
<id column="ID" property="id" jdbcType="CHAR" javaType="String" />
<!-- <result column="ID" property="id" jdbcType="CHAR" javaType="String" />-->
<result column="CODE" property="code" jdbcType="VARCHAR"
javaType="String" />
<result column="CFG_VALUE" property="cfgValue" jdbcType="VARCHAR"
javaType="String" />
<result column="REMARK" property="remark" jdbcType="VARCHAR"
javaType="String" />

</resultMap>

3.自定义可重用的sql语句,减少重复工作

1
<sql id="TableName">GDSS_CFG_TE_CONFIG</sql>
1
2
3
4
5
<delete id="delEntity" parameterType="java.lang.String">
DELETE FROM
<include refid="TableName" />
WHERE ID = #{id}
</delete>
1
2
3
4
<sql id="Base_Column_List">
ID,CODE,CFG_VALUE,REMARK

</sql>
1
2
3
4
5
6
7
8
9
<insert id="addEntity" parameterType="cn.lll.cfgcenter.model.GdssCfgTeConfig">
INSERT INTO
<include refid="TableName" />
(
<include refid="Base_Column_List" />
)
VALUES
(#{id,jdbcType=CHAR},#{code,jdbcType=VARCHAR},#{cfgValue,jdbcType=VARCHAR},#{remark,jdbcType=VARCHAR})
</insert>

这个id=”condition”的可重用sql语句较长:

1
2
3
4
5
6
7
8
9
10
11
<sql id="condition">
<if test="id != null">AND ID = #{id}</if>
<if test="code != null">AND CODE = #{code}</if>
<if test="cfgValue != null">AND CFG_VALUE = #{cfgValue}</if>
<if test="remark != null">AND REMARK = #{remark}</if>

<if test="id_like != null">AND ID LIKE "%"#{id_like}"%"</if>
<if test="code_like != null">AND CODE LIKE "%"#{code_like}"%"</if>
<if test="cfgValue_like != null">AND CFG_VALUE LIKE "%"#{cfgValue_like}"%"</if>
<if test="remark_like != null">AND REMARK LIKE "%"#{remark_like}"%"</if>
</sql>

但需要使用时可大大减轻工作量:

1
2
3
4
5
6
7
<delete id="delEntityByParam" parameterType="cn.lll.cfgcenter.model.GdssCfgTeConfig">
DELETE FROM
<include refid="TableName" />
<where>
<include refid="condition" />
</where>
</delete>

注意:

  1. id_like等like没什么用

  2. ID LIKE “%”#{id_like}”%”,左右加百分号,表示左右都可有0-无穷个字符,用于模糊查询

自定义查询, id=”vagueCondition” //没什么用

1
2
3
4
5
6
<sql id="vagueCondition">
<if test="id != null">AND ID LIKE "%"#{id}"%"</if>
<if test="code != null">AND CODE LIKE "%"#{code}"%"</if>
<if test="cfgValue != null">AND CFG_VALUE LIKE "%"#{cfgValue}"%"</if>
<if test="remark != null">AND REMARK LIKE "%"#{remark}"%"</if>
</sql>
1
2
3
4
5
6
7
8
<select id="vagueCount" resultType="java.lang.Integer"
parameterType="cn.lll.cfgcenter.model.param.GdssCfgTeConfigParam">
SELECT COUNT(0) FROM
<include refid="TableName" />
<where>
<include refid="vagueCondition" />
</where>
</select>

1.3.2 mapper IGdssCfgTeConfigMapper.java

1
2
3
4
5
6
7
8
9
10
11
12
13
public interface IGdssCfgTeConfigMapper extends ILllBaseMapper<GdssCfgTeConfig> {

public int vagueCount(GdssCfgTeConfigParam param) throws Exception;

public List<GdssCfgTeConfig> vagueSearch(GdssCfgTeConfigParam param) throws Exception;
/**
* @description:根据id数组,批量删除
* @param idList
* @exception
* @return int
*/
int batchDelete(@Param("idList") List<String> idList);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public interface ILllBaseMapper<T> {

public int addEntity(T entity) throws Exception;

public int delEntity(String id) throws Exception;
public int delEntityByParam(T params) throws Exception;

public int updateEntity(T entity) throws Exception;

public T getEntityById(String id) throws Exception;
public T getEntity(T params) throws Exception;

public List<T> searchEntity(T params) throws Exception;

public int count() throws Exception;
public int countByParam(T params) throws Exception;

}

注意:

  1. 在Springboot, mybatis中,mapper无需手动写实现类
  2. mapper接口中的方法名需要与xml中的CRUD标签的id保持一致,mybatis才能自动对应上
  3. mapper只用于数据库表ORM映射到model,为mybatis专用,别无他用!

1.3.3 model GdssCfgConfig.java

1
public abstract class LllBaseModel implements IAbleJson,Cloneable
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
public class GdssCfgTeConfig extends LllBaseModel {
private String id;
private String code;
private String cfgValue;
private String remark;

private String id_like;
private String code_like;
private String cfgValue_like;
private String remark_like;

public String getId(){
return this.id;
}
public void setId(String id){
this.id = id;
}
public String getCode(){
return this.code;
}
public void setCode(String code){
this.code = code;
}
public String getCfgValue(){
return this.cfgValue;
}
public void setCfgValue(String cfgValue){
this.cfgValue = cfgValue;
}
public String getRemark(){
return this.remark;
}
public void setRemark(String remark){
this.remark = remark;
}


public void setIdLike(String id){
this.id_like = id;
}
public void setCodeLike(String code){
this.code_like = code;
}
public void setCfgValueLike(String cfgValue){
this.cfgValue_like = cfgValue;
}
public void setRemarkLike(String remark){
this.remark_like = remark;
}


@Override
public String getPkidValue() {
return this.id;
}

@Override
public void setPkidValue(String id) {
this.id = id;
}

}

注意:

  1. model里的java bean中的参数可以包含数据库表中没有的字段, 但数据库表中的每个字段model里的java bean都必须一一对应!
  2. model里的java bean中基本数据类型字段要用包装类,不要用int,用Integer,和mybatis中定义相一致!

1.3.4 service IGdssCfgConfigService.java, GdssCfgTeConfigServiceImpl.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public interface ILllDbRedisBaseService<T> {
T addEntity(T entity) throws BusException;
//arg依照业务,可为usrId,account等
int delEntityById(String id, String arg) throws BusException;

int updateEntityById(T t, String id, String arg) throws BusException;

T getEntityById(String id) throws BusException;
T getEntity(T params) throws BusException;

List<T> searchEntity(int pagesize, int pageno) throws BusException;
List<T> searchEntity(T params,int pagesize,int pageno) throws BusException;

int count() throws BusException;
int count(T params) throws BusException;
}
1
2
3
4
5
6
7
8
9
10
11
12
public interface IGdssCfgTeConfigService extends ILllDbRedisBaseService<GdssCfgTeConfig> {

public int vagueCount(GdssCfgTeConfigParam param) throws BusException;

public List<GdssCfgTeConfig> vagueSearch(GdssCfgTeConfigParam param, int pagesize, int pageno) throws BusException;

public GdssCfgTeConfig getEntityByCode(String code) throws BusException;

int batchDelete(List<String> idList) throws BusException;

void reloadAllConfCache() throws BusException;
}

MVC 是一种使用 MVC(Model View Controller 模型-视图-控制器)设计创建 Web 应用程序的模式:

  • Model(模型)表示应用程序核心(如数据库)。
  • View(视图)显示效果(HTML页面)。
  • Controller(控制器)处理输入(业务逻辑)。

Model(模型)是应用程序中用于处理应用程序数据逻辑的部分。
 通常模型对象负责在数据库中存取数据。

View(视图)是应用程序中处理数据显示的部分。
 通常视图是依据模型数据创建的。

Controller(控制器)是应用程序中处理用户交互的部分。
 通常控制器负责从视图读取数据,控制用户输入,并向模型发送数据。

注意:

  1. 虽然本package名为service,但是仍然属于dao层/持久层/Model层,而不是业务层/Controller层!
  2. serviceImpl中@Autowired自动装载了mapper:private IGdssCfgTeConfigMapper iGdssCfgTeConfigMapper;
  3. serviceImpl中的方法实现,直接调用mapper接口中的方法,mybatis自动对应到xml中相应的sql语句:例如delEntityById中调用了mapper接口里的delEntity
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@Override
public int delEntityById(String id, String code) throws BusException {
if (StringUtil.isEmpty(id)){
log.error("id can not be empty");
throw new BusException("DaoService");
}
try{
int rows = iGdssCfgTeConfigMapper.delEntity(id);
if (rows > 0){
flushCache(null, id, true);
}
return rows;
}catch(Exception ex){
log.error("", ex);
throw new BusException("DaoService",ex);
}
}

2. app-ssp-mgr-module-conf

2.1 controller

ConfController调用ConfService

1
2
@Autowired
private ConfService confService;

2.2 model

2.3 service

ConfServiceImpl调用cfg-dao-service里的IGdssCfgTeConfigService:

1
2
@Autowired
private IGdssCfgTeConfigService iGdssCfgTeConfigService;

3. Spring boot注解&配置

3.1 常用注解

3.1.1 @Configuration

用来标记类可以当做一个bean的定义,被Spring IOC容器使用。

3.1.2 @Bean

表示此方法将要返回一个对象,作为一个bean注册进Spring应用上下文。

3.1.3 @Component

将 java 类标记为 bean。它是任何 Spring 管理组件的通用构造型。spring 的组件扫描机制现在可以将其拾取并将其拉入应用程序环境中。

3.1.4 @Controller

将一个类标记为 Spring Web MVC 控制器。标有它的 Bean 会自动导入到 IoC 容器中。

3.1.5 @Service

此注解是组件注解的特化。它不会对 @Component 注解提供任何其他行为。您可以在服务层类中使用 @Service 而不是 @Component,因为它以更好的方式指定了意图。

1
2
3
4
5
6
7
8
9
@Service
public class UserServiceImpl implements UserService {

public void saveUser() {

System.out.println("执行service中的保存逻辑");
}

}
1
2
3
4
5
6
7
8
9
10
11
public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(SpringConfig.class);
context.refresh();
//获取接口实例
UserService service = context.getBean(UserService.class);
//创建实例的代理
UserServiceProxy proxy = new UserServiceProxy(service);
//执行方法
proxy.saveUser();
}

注意:

  1. context.getBean(Interface.class) 自动装配

3.1.6 @Repository

表示使用注解实例化此类,并交给 Spring 的容器管理。

这个注解是具有类似用途和功能的 @Component 注解的特化。它为 DAO 提供了额外的好处。它将 DAO 导入 IoC 容器,并使未经检查的异常有资格转换为 Spring DataAccessException。

3.1.7 @Required

这个注解表明bean的属性必须在配置的时候设置,通过一个bean定义的显式的属性值或通过自动装配,若@Required注解的bean属性未被设置,容器将抛出BeanInitializationException。

3.1.8 @Autowired和@Resource

@Autowired默认是按照类型装配注入的,默认情况下它要求依赖对象必须存在(可以设置它required属性为false)。@Autowired 注解提供了更细粒度的控制,包括在何处以及如何完成自动装配。它的用法和@Required一样,修饰 setter方法、构造器、属性或者具有任意名称和/或多个参数的PN方法。

注意:

  1. @Autowired可用于:构造函数、成员变量、Setter方法
  2. @Autowired和@Resource之间的区别
  3. @Autowired默认是按照类型装配注入的,默认情况下它要求依赖对象必须存在(可以设置它required
    属性为false)。
  4. @Resource默认是按照名称来装配注入的,只有当找不到与名称匹配的bean才会按照类型来装配注入。

3.1.9 @Qualifier

当您创建多个相同类型的 bean 并希望仅使用属性装配其中一个 bean 时,您可以使用@Qualifier 注解和 @Autowired 通过指定应该装配哪个确切的 bean 来消除歧义。

3.1.10 @RequestMapping

@RequestMapping 注解用于将特定 HTTP 请求方法映射到将处理相应请求的控制器中的特定类/方法。
此注释可应用于两个级别:

  1. 类级别:映射请求的 URL
  2. 方法级别:映射 URL 以及 HTTP 请求方法

3.1.11 @RestController

RestController用于传json数据

@RequestParam(value = “file”) 指定拿前端的file属性

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package cn.lll.iic.ssp.mgr.module.admin.file.controller;

import cn.lll.iic.ssp.mgr.common.ListPageVo;
import cn.lll.iic.ssp.mgr.module.admin.file.model.AdminFileVo;
import cn.lll.iic.ssp.mgr.module.login.model.SysUser;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import cn.lll.framework.controller.JsonResult;
import cn.lll.iic.file.proxy.modle.LllFileV2;
import cn.lll.iic.file.proxy.modle.ULFileInfoVo;
import cn.lll.iic.ssp.mgr.common.MgrBaseController;
import cn.lll.iic.ssp.mgr.module.admin.file.service.IAdminFileService;
import io.swagger.annotations.ApiOperation;

/**
* @time:2020/6/5
* @function:文件控制器
*/
@RestController
@RequestMapping(path = "/mgrapi/admin/file")
public class AdminFileController extends MgrBaseController {

private static final Log log = LogFactory.getLog(AdminFileController.class);

@Autowired
private IAdminFileService iAdminFileService;


@ApiOperation(value = "上传文件", httpMethod = "POST")
@RequestMapping(path = "/upload", method = RequestMethod.POST)
public JsonResult uploadFile(@RequestParam(value = "file") MultipartFile file, ULFileInfoVo fileInfo) {

try{
LllFileV2 fileinfo = iAdminFileService.uploadFile(file,fileInfo);
return JsonResult.createSuccess(fileinfo, "");
}catch (Exception ex){
log.error("",ex);
return JsonResult.createFail(ex);
}
}


/* @GetMapping(path = "/token")
public JsonResult fetchToken(){
try{
String token = iAdminFileService.fetchToken();
return JsonResult.createSuccess(token, "");
}catch (Exception ex){
return JsonResult.createFail(ex);
}*/


@ApiOperation(value = "查询文件列表", notes = "查询文件列表", httpMethod = "POST")
@RequestMapping(path = "/query")
public JsonResult queryFileList(@RequestParam int pageno, @RequestParam int pagesize, String id) {
try {
SysUser sysUser = this.getCurrentSysUser();
ListPageVo<AdminFileVo> list = iAdminFileService.queryFilePage(pageno, pagesize, id, sysUser);

return JsonResult.createSuccess(list, "OK");
} catch (Exception ex) {
log.error(ex);
return JsonResult.createFail(ex);
}
}


@ApiOperation(value = "获取文件详情", httpMethod = "GET")
@GetMapping(path = "/query/detail")
public JsonResult queryFileDetailById(@RequestParam String id){
try {
AdminFileVo vo = iAdminFileService.queryFileDetail(id);

return JsonResult.createSuccess(vo, "获取成功");
} catch (Exception e) {
log.error("get file detail msg error", e);
return JsonResult.createFail("公共服务平台未知异常");
}
}


@ApiOperation(value = "通过文件id删除文件", httpMethod = "POST")
@PostMapping(path = "/delete")
public JsonResult deleteFileById(@RequestParam String ids){
try {
iAdminFileService.deleteFileByFileId(ids);
return JsonResult.createSuccess("", "删除成功");
} catch (Exception e) {
log.error("delete file error", e);
return JsonResult.createFail(e);
}
}

}

3.2 启动类注解@SpringBootApplication

3.2.1 @SpringBootConfiguration

组合了 @Configuration 注解,实现配置文件的功能。

3.2.2 @EnableAutoConfiguration

打开自动配置的功能,也可以关闭某个自动配置的选项,如关闭数据源自动配置功能:

@SpringBootApplication(exclude= { DataSourceAutoConfiguration.class })

3.2.3 @EnableTransactionManagement

事务处理

proxyTargetClass设置为true表示使用基于子类实现的代理(CGLIB)

3.2.4 @ComponentScan*

Spring组件扫描。

例如:

  1. @MapperScan(“cn.lll.**.mapper”)
  2. @ServletComponentScan(value = {“cn.lll.iic”})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package cn.lll;

import cn.lll.framework.util.SpringUtil;
import cn.lll.iic.compile.handler.HandlerFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ApplicationContextEvent;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@SpringBootApplication
@MapperScan("cn.lll.**.mapper")
@ServletComponentScan(value = {"cn.lll.iic"})
@EnableTransactionManagement(proxyTargetClass = true)
public class IICAppSspApp implements ApplicationRunner, ApplicationListener<ApplicationContextEvent> {

private static Log log = LogFactory.getLog(IICAppSspApp.class);

public static void main(String[] args) {
//修复logback bug
HandlerFactory.getLogbackHandler().execute( IICAppSspApp.class.getClassLoader() );

SpringApplication.run(IICAppSspApp.class, args);
}

@Override
public void run(ApplicationArguments args) throws Exception {
log.info("************************************************************* IICAppSspApp 启动完成!");
}

@Override
public void onApplicationEvent(ApplicationContextEvent event) {
ApplicationContext context = event.getApplicationContext();
SpringUtil.setApplicationContext(context);
}
}

3.3 yml配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
server:
port: 8095
compression:
enabled: true
mime-types: text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json,application/xml
session:
timeout: 1800
spring:
http:
multipart:
maxFileSize: 20MB
maxRequestSize: 20MB
jackson:
date-format: yyyy-MM-dd HH:mm:ss
time-zone: GMT+8
thymeleaf:
prefix: classpath:/templates/
suffix: .html
profiles:
active:
- dev
mybatis:
# config-location: classpath:mybatis-config.xml
mapper-locations: classpath*:**/mybatis-*.xml
#type-aliases-package: cn.lll.tsp.model
configuration:
cache-enabled: false
use-actual-param-name: true

#标识业务统计
stat:
redis-ip: 114.67.117.77
redis-pwd: y0aoQ67K62pHrPjp
redis-key: IIC_STAT_SSP

4. AOP

动态代理实现:相比静态代理,同样需要target类实现接口,但无需手动定义proxy类实现同样的接口,而是定义动态代理器implements InvocationHandler

  1. 动态处理器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public class DynamicProxy implements InvocationHandler {


private Object object;

public DynamicProxy(final Object object) {
this.object = object;
}

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
System.out.println("执行前逻辑");
Object result = method.invoke(object, args);
System.out.println("执行后逻辑");
return result;
}
}

  1. 测试类代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public class SpringTest {

public static void main(String[] args) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(SpringConfig.class);
context.refresh();
//获取接口实例
UserService service = context.getBean(UserService.class);
//动态创建实例的代理
UserService proxy = (UserService)Proxy.newProxyInstance(UserService.class.getClassLoader(),
new Class[]{UserService.class}, new DynamicProxy(service));
//proxy执行方法
proxy.saveUser();

}
}

Proxy.newProxyInstance()的参数:

  • ClassLoader loader: 指定当前目标对象使用的类加载器,获取加载器的方法是固定的
  • Class<?>[] interfaces: 指定目标对象实现的接口的类型,使用泛型方式确认类型
  • InvocationHandler: 指定动态处理器,执行目标对象的方法时,会触发事件处理器的方法

5. IOC

6. user-list 从html到mysql

6.1 router-cfg.js

vue.js 配置文件

第一部分:path与jsFile对应,如:

1
{path:"/user/user/user-list", jsFile:"/pages/user/user/user-list.js"},

第二部分:组件的alias与component中的js对应,如:

1
"iic-table": "/components/iic-table/iic-table.js",
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
var RouterCfg = [
{path:"/", jsFile:"/pages/home/home.js"},
{path:"/home", jsFile:"/pages/home/home.js"},
{path: "/update-pwd", jsFile: "/pages/home/update-pwd.js"},
{path: "/account", jsFile: "/pages/home/account.js"},
{path: "/account/manage-company-list", jsFile: "/pages/home/manage-company-list.js"},


{path:"/usermod/type/usermod-type-list", jsFile:"/pages/usermod/type/usermod-type-list.js"},
{path:"/usermod/type/usermod-type-add/:parentId", jsFile:"/pages/usermod/type/usermod-type-add.js"},
{path:"/usermod/type/usermod-type-edit/:id", jsFile:"/pages/usermod/type/usermod-type-edit.js"},

{path:"/usermod/datamod/usermod-datamod-list", jsFile:"/pages/usermod/datamod/usermod-datamod-list.js"},
{path:"/usermod/datamod/usermod-datamod-add", jsFile:"/pages/usermod/datamod/usermod-datamod-add.js"},
{path:"/usermod/datamod/usermod-datamod-edit/:id", jsFile:"/pages/usermod/datamod/usermod-datamod-edit.js"},
{path:"/usermod/datamod/usermod-datamod-info/:id", jsFile:"/pages/usermod/datamod/usermod-datamod-info.js"},

{path:"/han/detail", jsFile:"/pages/han/handle-detail/han-handle-detail.js"},
{path:"/han/encrypt/detail", jsFile:"/pages/han/encrypt-handle/encrypt-handle-detail.js"},
{path:"/han/middleware/detail", jsFile:"/pages/han/middleware-handle/middleware-handle-detail.js"},
{path:"/han/user-handle", jsFile:"/pages/han/user-handle/han-user-handle.js"},
{path:"/han/admin/user-handle/:account", jsFile:"/pages/han/user-handle/han-user-handle-admin.js"},
{path:"/han/edit", jsFile:"/pages/han/handle-edit/handle-edit.js"},
{path:"/han/create", jsFile:"/pages/han/handle-create/handle-create.js"},
{path:"/han/admin/create/:prefix", jsFile:"/pages/han/handle-create/handle-create-admin.js"},
{path:"/han/admin/create", jsFile:"/pages/han/handle-create/handle-create-admin.js"},


{path: "/bus/han-create-bus", jsFile: "/pages/bus/han-create-bus.js"},
{path: "/bus/han-delete-bus", jsFile: "/pages/bus/han-delete-bus.js"},
{path: "/bus/han-edit-bus", jsFile: "/pages/bus/han-edit-bus.js"},
{path: "/bus/han-detail-bus/:hanId", jsFile: "/pages/bus/han-detail-bus.js"},
{path: "/bus/han-batch-create-process", jsFile: "/pages/bus/admin-batch-create-bus.js"},
{path: "/bus/han-batch-create/list", jsFile: "/pages/bus/han-create-batch-bus.js"},
{path: "/bus/han-batch-create/detail/:busId", jsFile: "/pages/bus/han-create-batch-detail.js"},
{path: "/bus/han", jsFile: "/pages/bus/han-bus.js"},
{path: "/bus/han-error-bus", jsFile: "/pages/bus/han-error-bus.js"},

{path: "/middleware/middleware-add", jsFile: "/pages/middleware/middleware-add.js"},
{path: "/middleware/middleware-list", jsFile: "/pages/middleware/middleware-list.js"},
{path: "/middleware/middleware-detail/:id", jsFile: "/pages/middleware/middleware-detail.js"},
{path: "/middleware/bus-type-list", jsFile: "/pages/middleware/handle-bus-type-list.js"},



{path: "/api/usystem/usystem-add", jsFile: "/pages/api/usystem/usystem-add.js"},
{path: "/api/usystem/usystem-list", jsFile: "/pages/api/usystem/usystem-list.js"},
{path: "/api/usystem/usystem-info/:id", jsFile: "/pages/api/usystem/usystem-info.js"},
{path: "/api/usystem/usystem-edit/:id", jsFile: "/pages/api/usystem/usystem-edit.js"},
{path: "/api/system-api/system-api-add", jsFile: "/pages/api/system-api/system-api-add.js"},
{path: "/api/system-api/system-api-edit/:id", jsFile: "/pages/api/system-api/system-api-edit.js"},
{path: "/api/system-api/system-api-list", jsFile: "/pages/api/system-api/system-api-list.js"},
{path: "/api/system-api/system-api-info/:id", jsFile: "/pages/api/system-api/system-api-info.js"},
{path: "/api/system-api/:apiId/api-method-list", jsFile: "/pages/api/api-method/api-method-list.js"},
{path: "/api/system-api/:apiId/api-method-add", jsFile: "/pages/api/api-method/api-method-add.js"},
{path: "/api/system-api/:apiId/api-method-edit/:id", jsFile: "/pages/api/api-method/api-method-edit.js"},
{path: "/api/system-api/:apiId/api-method-info/:id", jsFile: "/pages/api/api-method/api-method-info.js"},

{path: "/file/upload", jsFile: "/pages/file/file-upload.js"},
{path: "/file/mine", jsFile: "/pages/file/file-mine.js"},
{path: "/file/detail/:fileId", jsFile: "/pages/file/file-detail.js"},

{path: "/conf/manage", jsFile: "/pages/conf/conf-manage.js"},
{path: "/conf/record", jsFile: "/pages/conf/conf-record.js"},
{path: "/conf/record/detail/:id", jsFile: "/pages/conf/conf-record-detail.js"},

{path: "/conf/add", jsFile: "/pages/conf/conf-add.js"},
{path: "/conf/edit/:confId", jsFile: "/pages/conf/conf-edit.js"},
//废弃开始 2021.3.31
// {path: "/assit/sdk/home/", jsFile: "/pages/assist/sdk-home.js"},
// {path: "/assit/sdk/download/", jsFile: "/pages/assist/sdk-download.js"},
// {path: "/assit/demo/download/", jsFile: "/pages/assist/demo-download.js"},
//废弃结束

{path: "/user/sdk-config/record", jsFile: "/pages/sdk/sdk-user-config.js"},
{path: "/user/sdk-config/detail/:recordId", jsFile: "/pages/sdk/sdk-user-config-detail.js"},
{path: "/user/sdk/renew-record", jsFile: "/pages/sdk/sdk-renew-record.js"},


{path: "/admin/sdk/edit/:sdkId", jsFile: "/pages/sdk/sdk-edit.js"},
{path: "/admin/sdk/detail/:sdkId", jsFile: "/pages/sdk/sdk-detail.js"},
{path: "/admin/sdk/manage", jsFile: "/pages/sdk/sdk-manage.js"},


// {path: "/assit/sdk-demo/download/", jsFile: "/pages/assist/sdk-download.js"},

{path: "/admin/middleware/manage", jsFile: "/pages/middlewareadmin/middleware-list.js"},
{path: "/admin/middleware/detail", jsFile: "/pages/middlewareadmin/middleware-detail.js"},

{path: "/admin/user-system/manage", jsFile: "/pages/apiadmin/user-system/usystem-list.js"},
{path: "/admin/user-system/detail/:id", jsFile: "/pages/apiadmin/user-system/usystem-detail.js"},

{path: "/admin/system-api/list", jsFile: "/pages/apiadmin/system-api/sapi-list.js"},
{path: "/admin/http-api/list", jsFile: "/pages/apiadmin/system-api/hapi-list.js"},
{path: "/admin/system-api/manage", jsFile: "/pages/apiadmin/system-api/sapi-manage.js"},
{path: "/admin/system-api/detail/:id", jsFile: "/pages/apiadmin/system-api/sapi-detail.js"},
{path: "/admin/http-api/detail/:id", jsFile: "/pages/apiadmin/system-api/hapi-detail.js"},

{path: "/admin/api-method/list", jsFile: "/pages/apiadmin/api-method/method-list.js"},
{path: "/admin/system-api/:apiId/api-method-info/:id", jsFile: "/pages/apiadmin/api-method/method-detail.js"},

{path: "/admin/log/login-log/list", jsFile: "/pages/logcenter/login-log-list.js"},
{path: "/admin/audit/user-action/list", jsFile: "/pages/auditcenter/user-action-list.js"},
{path: "/log/login-log/list", jsFile: "/pages/log/login-log-list.js"},

{path: "/audit/apply-list", jsFile: "/pages/audit/apply-list.js"},
{path: '/audit/apply-detail/:id', jsFile: "/pages/audit/apply-detail.js"},
{path: '/audit/apply-edit/:id', jsFile: "/pages/audit/apply-edit.js"},
{path: '/audit/audited-list', jsFile: "/pages/audit/audited-list.js"},
{path: '/audit/audited-record-detail/:id', jsFile: "/pages/audit/audited-record-detail.js"},
{path: '/admin/file/mine', jsFile: "/pages/filecenter/file-list.js"},
{path: '/admin/file/upload', jsFile: "/pages/filecenter/file-upload.js"},
{path: "/admin/file/detail/:fileId", jsFile: "/pages/filecenter/file-detail.js"},

{path: "/admin/auth/menu/menu-list", jsFile: "/pages/auth/menu/menu-list.js"},

{path:"/han/handle-data-type/handle-data-type-list", jsFile: "/pages/han/handle-data-type/handle-data-type-list.js"},
{path:"/han/handle-extrainfo/handle-extrainfo-edit", jsFile: "/pages/han/handle-extrainfo/handle-extrainfo-edit.js"},

{path:"/user/user/user-list", jsFile:"/pages/user/user/user-list.js"},
{path:"/user/user/user-add", jsFile:"/pages/user/user/user-add.js"},
{path:"/user/user/user-edit/:id", jsFile:"/pages/user/user/user-edit.js"},
{path:"/user/user/user-info/:id", jsFile:"/pages/user/user/user-info.js"},
{path:"/user/user/user-role/:id", jsFile:"/pages/user/user/user-role.js"},
{path:"/user/user/bind-company/:id", jsFile:"/pages/user/user/user-bind-company.js"},
{path:"/user/user/user-prefix", jsFile: "/pages/user/user/user-prefix.js"},

{path:"/user/company/company-list", jsFile:"/pages/user/company/company-list.js"},
{path:"/user/company/company-add", jsFile:"/pages/user/company/company-add.js"},
{path:"/user/company/company-edit/:id", jsFile:"/pages/user/company/company-edit.js"},
{path:"/user/company/company-info/:id", jsFile:"/pages/user/company/company-info.js"},
{path:"/user/company/bind-user/:id", jsFile:"/pages/user/company/company-bind-user.js"},

{path:"/goods/goods/goods-list", jsFile:"/pages/goods/goods/goods-list.js"},
{path: "/goods/goods/goods-detail/:id", jsFile: "/pages/goods/goods/goods-detail.js"},
{path:"/goods/singlegoods/singlegoods-list", jsFile:"/pages/goods/singlegoods/singlegoods-list.js"},
{path:"/goods/singlegoods/singlegoods-add", jsFile:"/pages/goods/singlegoods/singlegoods-add.js"},
{path:"/goods/singlegoods/singlegoods-edit/:id", jsFile:"/pages/goods/singlegoods/singlegoods-edit.js"},
{path:"/goods/singlegoods/singlegoods-detail/:id", jsFile:"/pages/goods/singlegoods/singlegoods-detail.js"},


{path:"/goods/saleorder/saleorder-list", jsFile:"/pages/goods/saleorder/saleorder-list.js"},
{path:"/goods/pay/pay-list", jsFile:"/pages/goods/pay/pay-list.js"},
{path: "/goods/pay/pay-saleorder/:id", jsFile: "/pages/goods/pay/pay-saleorder.js"},
{path:"/goods/recharge/recharge-list", jsFile:"/pages/goods/recharge/recharge-list.js"},

{path:"/usermod/viewmod/system-viewmode-list", jsFile:"/pages/usermod/viewmod/system-viewmode-list.js"},
// {path:"/usermod/viewmod/viewmode-create", jsFile:"/pages/usermod/viewmod/viewmode-create.js"},
{path:"/usermod/viewmod/viewmode-edit/:id", jsFile:"/pages/usermod/viewmod/viewmode-edit.js"},
{path:"/usermod/viewmod/viewmode-info/:id", jsFile:"/pages/usermod/viewmod/viewmode-info.js"},
{path:"/usermod/viewmod/:vmId/viewmode-datacfg-list", jsFile:"/pages/usermod/viewmod/viewmode-datacfg-list.js"},
{path:"/usermod/viewmod/:vmId/viewmode-datacfg-create", jsFile:"/pages/usermod/viewmod/viewmode-datacfg-create.js"},
{path:"/usermod/viewmod/:vmId/viewmode-datacfg-info/:id", jsFile:"/pages/usermod/viewmod/viewmode-datacfg-info.js"},
{path:"/usermod/viewmod/:vmId/viewmode-datacfg-edit/:id", jsFile:"/pages/usermod/viewmod/viewmode-datacfg-edit.js"},
{path:"/usermod/viewmod/:vmId/viewmode-pageinfo-list", jsFile:"/pages/usermod/viewmod/viewmode-pageinfo-list.js"},
{path:"/usermod/viewmod/:vmId/viewmode-pageinfo-add", jsFile:"/pages/usermod/viewmod/viewmode-pageinfo-add.js"},
{path:"/usermod/viewmod/:vmId/viewmode-pageinfo-edit/:id", jsFile:"/pages/usermod/viewmod/viewmode-pageinfo-edit.js"},
{path:"/usermod/viewmod/system-staticfile-list", jsFile:"/pages/usermod/staticfile/system-staticfile-list.js"},
{path:"/usermod/staticfile/staticfile-create", jsFile:"/pages/usermod/staticfile/staticfile-create.js"},
{path:"/usermod/staticfile/staticfile-info/:id", jsFile:"/pages/usermod/staticfile/staticfile-info.js"},
{path:"/usermod/staticfile/staticfile-edit/:id", jsFile:"/pages/usermod/staticfile/staticfile-edit.js"},

{path:"/usermod/viewmod/user/viewmod-market", jsFile: "/pages/usermod/viewmod-user/viewmod-market.js"},

{path:"/admin/auth/menu/menu-list", jsFile:"/pages/auth/menu/menu-list.js"},
{path:"/admin/auth/role/role-list", jsFile: "/pages/auth/role/role-list.js"},
{path:"/admin/auth/url/url-list", jsFile: "/pages/auth/url/url-list.js"},
{path:"/admin/auth/api/api-list", jsFile: "/pages/auth/api/api-list.js"},


{path:"/statis/home/admin-home", jsFile: "/pages/statis/home/admin-home.js"},
{path:"/statis/home/user-home", jsFile: "/pages/statis/home/user-home.js"},
{path:"/statis/admin/user-statis", jsFile: "/pages/statis/admin/user-statis.js"},
{path:"/statis/user/order-statis", jsFile: "/pages/statis/user/order-statis.js"},
{path:"/statis/user/body-statis", jsFile: "/pages/statis/user/body-statis.js"},

{path:"/statis/user/msg-statis", jsFile: "/pages/statis/user/msg-statis.js"},
{path:"/statis/user/other-statis", jsFile: "/pages/statis/user/other-statis.js"},

{path:"/error/403", jsFile: "/pages/error/403.js"}
]
//组件cfg
seajs.config({
alias:{
"iic-checkbox": "/components/iic-checkbox/iic-checkbox.js",
"iic-radio": "/components/iic-radio/iic-radio.js",
"iic-datamod-html": "/components/iic-datamod-mgr/type/iic-datamod-html.js",
"iic-datamod-image": "/components/iic-datamod-mgr/type/iic-datamod-image.js",
"iic-datamod-imagebig": "/components/iic-datamod-mgr/type/iic-datamod-imagebig.js",
"iic-datamod-text": "/components/iic-datamod-mgr/type/iic-datamod-text.js",
"iic-datamod-url": "/components/iic-datamod-mgr/type/iic-datamod-url.js",
"iic-datamod-video": "/components/iic-datamod-mgr/type/iic-datamod-video.js",
"iic-datamod-mgr": "/components/iic-datamod-mgr/type/iic-datamod-mgr.js",
"iic-relateinfo-edit": "/components/iic-relateinfo-edit/iic-relateinfo-edit.js",
"ri-index-select": "/components/iic-relateinfo-edit/el/ri-index-select.js",
"ri-type-select": "/components/iic-relateinfo-edit/el/ri-type-select.js",
"ri-row-btn": "/components/iic-relateinfo-edit/el/ri-row-btn.js",
"ri-dm-win": "/components/iic-relateinfo-edit/el/ri-dm-win.js",
"dmr-index": "/components/iic-datamod-mgr/dmr-index/dmr-index.js",
"iic-dm-detail-win": "/components/iic-datamod-mgr/type/iic-dm-detail-win.js",
"iic-relateinfo-type": "/components/iic-datamod-mgr/type/iic-relateinfo-type.js",
"iic-file-upload": "/components/iic-file-upload/iic-file-upload.js",
"iic-img-upload": "/components/iic-img-upload/iic-img-upload.js",
"iic-input-date": "/components/iic-input-date/iic-input-date.js",
"iic-input-datetime": "/components/iic-input-datetime/iic-input-datetime.js",
"iic-input-email": "/components/iic-input-email/iic-input-email.js",
"iic-input-int": "/components/iic-input-int/iic-input-int.js",
"iic-input-number": "/components/iic-input-number/iic-input-number.js",
"iic-input-mobile": "/components/iic-input-mobile/iic-input-mobile.js",
"iic-input-text": "/components/iic-input-text/iic-input-text.js",
"iic-input-code": "/components/iic-input-code/iic-input-code.js",
"iic-input-search": "/components/iic-input-search/iic-input-search.js",
"iic-page-split": "/components/iic-page-split/iic-page-split.js",
"iic-select": "/components/iic-select/iic-select.js",
"iic-select-input": "/components/iic-select-input/iic-select-input.js",
"iic-select-tree": "/components/iic-select-tree/iic-select-tree.js",
"iic-select-area": "/components/iic-select-area/iic-select-area.js",
"iic-user-dmtype-tree": "/components/iic-user-dmtype-tree/iic-user-dmtype-tree.js",
//使用此组件需要引入 iic-vmod-list
"iic-vmod-select": "/components/iic-vmod-select/iic-vmod-select.js",
"iic-panel-top": "/components/iic-panel-top/iic-panel-top.js",
"iic-table": "/components/iic-table/iic-table.js",
"iic-tabs": "/components/iic-tabs/iic-tabs.js",
"iic-tool-bars": "/components/iic-tool-bars/iic-tool-bars.js",
"iic-form": "/components/iic-form/iic-form.js",
"iic-input-select": "/components/iic-select/iic-input-select.js",
"iic-input-html": "/components/iic-input-html/iic-input-html.js",
"iic-input-textarea": "/components/iic-textarea/iic-input-textarea.js",
"iic-readonly": "/components/iic-readonly/iic-readonly.js",
"iic-input-file": "/components/iic-input-file/iic-input-file.js",
"iic-apimethod-tree": "/components/iic-apimethod-tree/iic-apimethod-tree.js",
"iic-apimethod-header": "/components/iic-apimethod-header/iic-apimethod-header.js",
"iic-page-menu": "/components/iic-page-menu/iic-page-menu.js",
"iic-other": "/components/iic-other/iic-other.js",//无法归类的杂组件
"iic-file": "/components/iic-file/iic-file.js",//文件相关的杂组件

"iic-handle-detail-item": "/components/iic-handle-detail-item/iic-handle-detail-item.js",
"iic-datamodel-select": "/components/iic-datamodel-select/iic-datamodel-select.js",
"iic-viewmodel-select": "/components/iic-viewmodel-select/iic-viewmodel-select.js",
//此组件需要require('iic-select-tree'); require('iic-vmod-type-select'); require('iic-table');
"iic-vmod-list": "/components/iic-vmod-list/iic-vmod-list.js",
"iic-vmod-type-select": "/components/iic-vmod-type-select/iic-vmod-type-select.js",
"iic-input-handle": "/components/iic-input-handle/iic-input-handle.js",
"iic-admin-input-handle": "/components/iic-input-handle/iic-admin-input-handle.js",
"iic-select-checktree": "/components/iic-select-checktree/iic-select-checktree.js",

"statis-base": "/pages/statis/statis-base.js",
"sha256": "/assets/js/common/sha256.js",
"math": "/assets/libs/math/math.min.js"
}
});

6.2 user-list.html

只展示

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<div>
<!-- start page title -->
<div class="row">
<div class="col-12">
<div class="page-title-box d-flex align-items-center justify-content-between">
<h4 class="mb-0 font-size-18">用户管理</h4>

<div class="page-title-right">
<ol class="breadcrumb m-0">
<li class="breadcrumb-item">用户中心</li>
<li class="breadcrumb-item active">用户管理</li>
</ol>
</div>

</div>
</div>
</div>
<!-- end page title -->

<div class="row">
<div class="col-lg-12">
<div class="card">
<div class="card-body">

<!-- 工具栏 -->
<div class="row">
<div class="col-6">
<div class="btn-toolbar" role="toolbar">
<div class="btn-group">
<a href="javascript:void(0)" @click="go('/user/user/user-add')" class="btn btn-primary waves-effect waves-light btn-sm">
<i class="fas fa-plus"></i>
新增
</a>
<a href="javascript:void(0)" @click="edit('/user/user/user-edit/{id}')" class="btn btn-primary waves-effect waves-light btn-sm">
<i class="fas fa-edit"></i>
编辑
</a>
<a href="javascript:void(0)" @click="del()" class="btn btn-primary waves-effect waves-light btn-sm">
<i class="fas fa-trash-alt"></i>
删除
</a>
<a href="javascript:void(0)" @click="refresh()" class="btn btn-primary waves-effect waves-light btn-sm">
<i class="fas fa-recycle"></i>
刷新
</a>
<a href="javascript:void(0)" @click="onClickCacheAllBus" class="btn btn-primary waves-effect waves-light btn-sm">
<i class="fas fa-recycle"></i>刷新所有业务
</a>
<a href="javascript:void(0)" @click="cacheAdmBus" class="btn btn-primary waves-effect waves-light btn-sm">
<i class="fas fa-recycle"></i>刷新admin业务
</a>
</div>
</div>
</div>
<div class="col-6">
<div class="btn-group" style="float: right;">
<input class="form-control form-control-sm" v-model="keyword" type="text" placeholder="输入用户账户">
<a href="javascript:void(0)" @click="queryByAcct()" class="btn btn-primary waves-effect waves-light btn-sm" style="width: 40px;">
<i class="fas fa-search"></i>
</a>
<!--
<a href="javascript:void(0)" class="btn btn-primary waves-effect waves-light btn-sm" style="width: 100px; border-left-color:#ced4da;">
高级查询
</a>
-->
</div>

</div>
</div>

<div class="table-responsive mt-3">
<table class="table mb-0 table-striped">
<thead>
<tr>
<th scope="col" style="width: 50px;">
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" :checked="selectAll">
<label class="custom-control-label" @click="onSelectAll()"></label>
</div>
</th>
<th>账号</th>
<th>昵称</th>
<th>账号状态</th>
<th>接入状态</th>
<th>接入语言</th>
<th>角色权限</th>
<th>注册时间</th>
<th width="240">操作</th>
</tr>
</thead>
<tbody>
<tr v-for="obj in datas">
<td>
<div class="custom-control custom-checkbox">
<input type="checkbox" class="custom-control-input" :checked="obj.selected" >
<label class="custom-control-label" for="customCheck1" @click="onSelectOne(obj)"></label>
</div>
</td>
<td>{{obj.userName}}</td>
<td>{{obj.nickname}}</td>
<td>
<template v-if="obj.status==1"><i class="mdi mdi-checkbox-blank-circle text-success mr-1"></i> 有效</template>
<template v-if="obj.status==-1"><i class="mdi mdi-checkbox-blank-circle text-danger mr-1"></i> 无效</template>
</td>
<td>
<template v-if="obj.accessStatus==1"><i class="mdi mdi-checkbox-blank-circle text-success mr-1"></i>已接入</template>
<template v-else><i class="mdi mdi-checkbox-blank-circle text-danger mr-1"></i>未接入</template>
</td>
<td>{{obj.language}}</td>
<td>{{obj.roleNames | ls-string}}</td>
<td>{{obj.createTime}}</td>
<!-- <td>-->
<iic-table-buttons>
<iic-table-button label="查看" cls="btn btn-outline-info btn-sm" @click.native="onClickView(obj,'/user/user/user-info/'+obj.id)"></iic-table-button>
<iic-table-button label="编辑" cls="btn btn-outline-success btn-sm" @click.native="onClickEdit(obj,'/user/user/user-edit/'+obj.id)"></iic-table-button>
<iic-table-button-more>
<iic-table-button-more-item label="分配权限" @click.native="onClickView(obj,'/user/user/user-role/'+obj.id)"></iic-table-button-more-item>
<iic-table-button-more-item label="关联企业" @click.native="onClickView(obj,'/user/user/bind-company/'+obj.id)"></iic-table-button-more-item>
<iic-table-button-more-item label="删除" @click.native="onClickDel(obj,'/mgrapi/user/del')"></iic-table-button-more-item>
<iic-table-button-more-item label="刷新业务缓存" @click.native="onClickCacheBus(obj)"></iic-table-button-more-item>
</iic-table-button-more>
</iic-table-buttons>
<!-- <button type="button" @click="go('/user/user/user-info/{id}',obj.id)" class="btn btn-outline-info btn-sm">查看</button>-->
<!-- <button type="button" @click="go('/user/user/user-edit/{id}',obj.id)" class="btn btn-outline-success btn-sm">编辑</button>-->
<!-- <button type="button" @click="go('/user/user/user-role/{id}',obj.id)" class="btn btn-outline-info btn-sm">分配权限</button>-->
<!-- <button type="button" @click="go('/user/user/bind-company/{id}',obj.id)" class="btn btn-outline-success btn-sm">关联企业</button>-->
<!-- <button type="button" @click="del(obj.id)" class="btn btn-outline-danger btn-sm">删除</button>-->
<!-- </td>-->
</tr>
</tbody>
</table>
</div>
<!--分页-->
<iic-table-page-split :totalRows="pageInfo.recordTotal" :pageSize="pageInfo.pagesize" v-model="pageInfo.pageno" @change="changePage"></iic-table-page-split>
</div>
</div>
</div>
</div>
<!-- end row -->

</div>

6.3 user-list.js

通过template将js传入html

1
var tpl = require('./user-list.html'); template: tpl

SeaJs: CMD模块化

  1. 通过require引入依赖,调用其他js模块(接口)

  2. 通过module.exports提供接口

  3. Vue.extend创建Vue, 有参数: extends, props, data(function), watch, methods, template

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
define(function(require,exports,module){
require("iic-panel-top");
require("iic-tool-bars");
require("iic-table");
var tpl = require('./user-list.html');

module.exports = Vue.extend({
extends: IICBaseTable,
props: [],
data: function(){
return {
datas: [],
pageInfo: {
pagesize: 10,
pageno: 1,
recordTotal: 0
},
params: {
typeId: '0'
},
selectAll: false,
keyword: ''
};
},
watch: {
'$route': 'initCom',
keyword: function(){
//删除了查找关键字,回到第一页数据
if ( !this.keyword.trim() ) {
this.changePage(1);
}
}
},
methods: {
initCom: function(){
this.loadData();
},
queryByAcct(){
if (!this.keyword.trim()) {
Iic.showMessage("请输入用户账号");
return false;
}
this.pageInfo.pageno = 1;
this.loadData(true);
},
loadData: function(searchByAcct){
var _this = this;
var url = './mgrapi/user/user-list';
if (searchByAcct) {
url += "?usrAcct=" + encodeUrl(this.keyword);
}
var params = {
pagesize: _this.pageInfo.pagesize,
pageno: _this.pageInfo.pageno
};
ajaxPost(url,params).then(data=>{
_this.datas = data.datas;
_this.pageInfo.recordTotal = data.recordTotal;
_this.selectAll = false;
});
},
exeDel: function(ids){
var _this = this;
var url = './mgrapi/user/del';
var params = {ids:ids};
ajaxPost(url,params).then(()=>{
_this.loadData();
});
},

///////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// 默认方法 //////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
onSelectAll: function(){
var _this = this;
_this.selectAll = !_this.selectAll;
_this.datas.forEach(function(obj){
obj.selected = _this.selectAll;
});
_this.datas = _this.datas.concat([]);
},
onSelectOne: function(obj){
obj.selected = !obj.selected;
this.datas = this.datas.concat([]);
},
isSelected: function(obj){
if(obj.selected) return true;
return false;
},
go: function(url,id){
if(id){
url = url.replace('{id}',id);
}
window.location.hash = url;
},
/**
* 跳转到指定页
* @param {*} pageNo
*/
changePage: function(pageNo){
this.pageInfo.pageno = pageNo;
this.loadData();
},
edit: function(url,id){
var _this = this;
if(!id){
var datas = this._getSelectedData();
if(datas.length==0){
showErrAlert('操作错误','请选择要操作的记录');
return;
}
if(datas.length>1){
showErrAlert('操作错误','只能选择一条记录');
return;
}
id = datas[0].id;
}
url = url.replace('{id}',id);
window.location.hash = url;
},
del: function(id){
var _this = this;
var ids = [];

if(!id){
var datas = this._getSelectedData();
if(datas.length==0){
showErrAlert('操作错误','请选择要删除的记录');
return;
}
datas.forEach(function(obj){
ids.push(obj.id);
});
}else{
ids=[id];
}

showConfrim('确定要删除吗?').then(()=>{
_this.exeDel(ids.join(','));
});
},
_getSelectedData: function(){
var res = [];
this.datas.forEach(function(obj){
if(obj.selected){
res.push(obj);
}
});
return res;
},
onClickCacheAllBus(){
showConfrim('确认刷新所有业务缓存').then(() => {
var url = '/mgrapi/user/bus/cache/all';
ajaxPost(url).then(rs => {
showSuccAlert("任务提交成功");
});
});
},
onClickCacheBus(obj){
showConfrim('确认刷新业务缓存').then(() => {
const url = '/mgrapi/user/bus/cache?username=' + obj.userName;
ajaxPost(url).then(rs => {
showSuccAlert('操作成功');
});
});
},
cacheAdmBus(){
showConfrim('确认刷新业务缓存').then(() => {
const url = '/mgrapi/user/bus/cache/adm';
ajaxPost(url).then(rs => {
showSuccAlert('任务提交成功');
});
});
}
},
template: tpl
});
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
define(function(require,exports,module){
require("iic-panel-top");
require("iic-tool-bars");
require("iic-table");
var tpl = require('./user-list.html');

module.exports = Vue.extend({
extends: IICBaseTable,
props: [],
data: function(){
return {
datas: [],
pageInfo: {
pagesize: 10,
pageno: 1,
recordTotal: 0
},
params: {
typeId: '0'
},
selectAll: false,
keyword: ''
};
},
watch: {
'$route': 'initCom',
keyword: function(){
//删除了查找关键字,回到第一页数据
if ( !this.keyword.trim() ) {
this.changePage(1);
}
}
},
methods: {
initCom: function(){
this.loadData();
},
queryByAcct(){
if (!this.keyword.trim()) {
Iic.showMessage("请输入用户账号");
return false;
}
this.pageInfo.pageno = 1;
this.loadData(true);
},
loadData: function(searchByAcct){
var _this = this;
var url = './mgrapi/user/user-list';
if (searchByAcct) {
url += "?usrAcct=" + encodeUrl(this.keyword);
}
var params = {
pagesize: _this.pageInfo.pagesize,
pageno: _this.pageInfo.pageno
};
ajaxPost(url,params).then(data=>{
_this.datas = data.datas;
_this.pageInfo.recordTotal = data.recordTotal;
_this.selectAll = false;
});
},
exeDel: function(ids){
var _this = this;
var url = './mgrapi/user/del';
var params = {ids:ids};
ajaxPost(url,params).then(()=>{
_this.loadData();
});
},

///////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// 默认方法 //////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
onSelectAll: function(){
var _this = this;
_this.selectAll = !_this.selectAll;
_this.datas.forEach(function(obj){
obj.selected = _this.selectAll;
});
_this.datas = _this.datas.concat([]);
},
onSelectOne: function(obj){
obj.selected = !obj.selected;
this.datas = this.datas.concat([]);
},
isSelected: function(obj){
if(obj.selected) return true;
return false;
},
go: function(url,id){
if(id){
url = url.replace('{id}',id);
}
window.location.hash = url;
},
/**
* 跳转到指定页
* @param {*} pageNo
*/
changePage: function(pageNo){
this.pageInfo.pageno = pageNo;
this.loadData();
},
edit: function(url,id){
var _this = this;
if(!id){
var datas = this._getSelectedData();
if(datas.length==0){
showErrAlert('操作错误','请选择要操作的记录');
return;
}
if(datas.length>1){
showErrAlert('操作错误','只能选择一条记录');
return;
}
id = datas[0].id;
}
url = url.replace('{id}',id);
window.location.hash = url;
},
del: function(id){
var _this = this;
var ids = [];

if(!id){
var datas = this._getSelectedData();
if(datas.length==0){
showErrAlert('操作错误','请选择要删除的记录');
return;
}
datas.forEach(function(obj){
ids.push(obj.id);
});
}else{
ids=[id];
}

showConfrim('确定要删除吗?').then(()=>{
_this.exeDel(ids.join(','));
});
},
_getSelectedData: function(){
var res = [];
this.datas.forEach(function(obj){
if(obj.selected){
res.push(obj);
}
});
return res;
},
onClickCacheAllBus(){
showConfrim('确认刷新所有业务缓存').then(() => {
var url = '/mgrapi/user/bus/cache/all';
ajaxPost(url).then(rs => {
showSuccAlert("任务提交成功");
});
});
},
onClickCacheBus(obj){
showConfrim('确认刷新业务缓存').then(() => {
const url = '/mgrapi/user/bus/cache?username=' + obj.userName;
ajaxPost(url).then(rs => {
showSuccAlert('操作成功');
});
});
},
cacheAdmBus(){
showConfrim('确认刷新业务缓存').then(() => {
const url = '/mgrapi/user/bus/cache/adm';
ajaxPost(url).then(rs => {
showSuccAlert('任务提交成功');
});
});
}
},
template: tpl
});
});

6.4 MgrUserController

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package cn.lll.iic.ssp.mgr.module.admin.user.controller;

import io.swagger.annotations.ApiOperation;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import cn.lll.framework.controller.JsonResult;
import cn.lll.framework.exception.BusException;
import cn.lll.iic.ssp.mgr.common.ListPageVo;
import cn.lll.iic.ssp.mgr.common.MgrBaseController;
import cn.lll.iic.ssp.mgr.module.admin.user.model.RoleVo;
import cn.lll.iic.ssp.mgr.module.admin.user.model.UserVo;
import cn.lll.iic.ssp.mgr.module.admin.user.service.IMgrUserService;

@RestController
@RequestMapping("/mgrapi/user")
public class MgrUserController extends MgrBaseController {

private static Log log = LogFactory.getLog(MgrUserController.class);

@Autowired
private IMgrUserService iMgrUserService;

@ApiOperation(value = "读取用户列表", notes = "读取用户列表", httpMethod = "POST")
@RequestMapping(value = "/user-list", method = RequestMethod.POST)
public JsonResult loadUserList(Integer pagesize, Integer pageno, String usrAcct){
try{
ListPageVo<UserVo> vo = iMgrUserService.loadUserList(pagesize, pageno, usrAcct);

return JsonResult.createSuccess(vo, "");
}catch(BusException ex){
log.error("", ex);
return JsonResult.createFail(ex);
}
}

@ApiOperation(value = "添加用户", notes = "添加用户", httpMethod = "POST")
@RequestMapping(value = "/add", method = RequestMethod.POST)
public JsonResult add(UserVo vo){
try{
iMgrUserService.addUser(vo);
return JsonResult.createSuccess("添加成功");
}catch(BusException ex){
log.error("", ex);
return JsonResult.createFail(ex);
}
}

@ApiOperation(value = "读取用户详细信息", notes = "读取用户详细信息", httpMethod = "POST")
@RequestMapping(value = "/detail", method = RequestMethod.POST)
public JsonResult loadUserDetail(String id){
try{
UserVo vo = iMgrUserService.loadUserDetail(id);
return JsonResult.createSuccess(vo,"");
}catch(BusException ex){
log.error("", ex);
return JsonResult.createFail(ex);
}
}

@ApiOperation(value = "读取所有角色", notes = "读取所有角色", httpMethod = "POST")
@RequestMapping(value = "/load-all-user-role", method = RequestMethod.POST)
public JsonResult loadAllUserRole(String userId){
try{
List<RoleVo> datas = iMgrUserService.loadAllUserRole(userId);

return JsonResult.createSuccess(datas, "");
}catch(BusException ex){
log.error("", ex);
return JsonResult.createFail(ex);
}
}

@ApiOperation(value = "修改用户角色", notes = "修改用户角色", httpMethod = "POST")
@RequestMapping(value = "/update-user-role", method = RequestMethod.POST)
public JsonResult updateUserRole(String userId, String roles){
try{
iMgrUserService.updateUserRole(userId, roles);

return JsonResult.createSuccess("");
}catch(BusException ex){
log.error("", ex);
return JsonResult.createFail(ex);
}
}

@ApiOperation(value = "删除用户", notes = "删除用户", httpMethod = "POST")
@RequestMapping(value = "/del", method = RequestMethod.POST)
public JsonResult deleteUser(String ids){
try{
iMgrUserService.deleteUser(ids);

return JsonResult.createSuccess("");
}catch(BusException ex){
log.error("", ex);
return JsonResult.createFail(ex);
}
}

@ApiOperation(value = "修改用户", notes = "修改用户", httpMethod = "POST")
@RequestMapping(value = "/update-user", method = RequestMethod.POST)
public JsonResult updateUser(UserVo vo){
try{
iMgrUserService.updateUser(vo);

return JsonResult.createSuccess("");
}catch(BusException ex){
log.error("", ex);
return JsonResult.createFail(ex);
}
}
//将某用户的标识业务id接入redis
@PostMapping(path = "/bus/cache")
public JsonResult cacheBus(@RequestParam String username){
try {
iMgrUserService.cacheBus(username);
return JsonResult.createSuccess("");
} catch (BusException ex) {
log.error("", ex);
return JsonResult.createFail(ex);
}
}
//将admin的标识业务id接入redis
@PostMapping(path = "/bus/cache/adm")
public JsonResult cacheAllBusForAdm(){
iMgrUserService.cacheAdmBus();
return JsonResult.createSuccess("");
}
//将所有非admin用户的标识业务id接入redis
@PostMapping(path = "/bus/cache/all")
public JsonResult cacheAllBus(){
try {
iMgrUserService.cacheAllBus();
return JsonResult.createSuccess("");
} catch (BusException ex) {
log.error("", ex);
return JsonResult.createFail(ex);
}
}
}

6.5 IMgrUserService

1
2
3
4
5
6
7
8
9
10
package cn.lll.iic.ssp.mgr.module.admin.user.service;

import java.util.List;

import cn.lll.framework.exception.BusException;
import cn.lll.iic.ssp.mgr.common.ListPageVo;
import cn.lll.iic.ssp.mgr.module.admin.user.model.RoleVo;
import cn.lll.iic.ssp.mgr.module.admin.user.model.UserVo;

public interface IMgrUserService

6.6 MgrUserServiceImpl

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
package cn.lll.iic.ssp.mgr.module.admin.user.service.impl;

import ...

@Service
public class MgrUserServiceImpl implements IMgrUserService {
private final Log LOG = LogFactory.getLog(MgrUserServiceImpl.class);

@Autowired
private IGdssUserTeUserService iGdssUserTeUserService;
@Autowired
private IGdssUserTsUserCompanyService iGdssUserTsUserCompanyService;
@Autowired
private IGdssUserTeCompanyService iGdssUserTeCompanyService;
@Autowired
private IGdssCfgTeConfigService iGdssCfgTeConfigService;
@Autowired
private IGdssAuthTeRoleService iGdssAuthTeRoleService;
@Autowired
private IGdssAuthTsUserRoleService iGdssAuthTsUserRoleService;
@Autowired
private ISecService iSecService;
@Autowired
private ICfgService iCfgService;
@Autowired
private ThreadPoolExecutor threadPoolExecutor;
@Autowired
private RedisTemplate<String, Object> redisTemplate;
@Autowired
private IGdssSecTeKeyService iGdssSecTeKeyService;
@Autowired
private IGdssBusTeApiBusinessService iGdssBusTeApiBusinessService;

@Autowired
private IGdssStatTeHistoryAmountsDayMwService iGdssStatTeHistoryAmountsDayMwService;

@Override
public ListPageVo<UserVo> loadUserList(Integer pagesize, Integer pageno, String usrAcct) throws BusException {

GdssUserTeUser params = new GdssUserTeUser();
params.setOrderBy(" CREATE_TIME DESC");
if (!StringUtil.isEmpty(usrAcct)){
params.setUserName(usrAcct);
}

List<GdssUserTeUser> ls = iGdssUserTeUserService.searchEntity(params, pagesize, pageno);

List<UserVo> datas = new ArrayList<UserVo>();
for(GdssUserTeUser user : ls){
UserVo v = new UserVo();
v.setId(user.getId());
v.setUserName(StringUtil.trim(user.getUserName()));
v.setNickname(StringUtil.trim(user.getNickname()));
v.setStatus(user.getStatus());
String username = v.getUserName();
v.setLanguage(this.getLan(username));

v.setMobile(StringUtil.trim(user.getMobile()));
v.setEmail(StringUtil.trim(user.getEmail()));
v.setAuthMobile(user.getAuthMobile());
v.setAuthEmail(user.getAuthEmail());
v.setCreateTime(user.getCreateTime());

//读取用户角色
List<GdssAuthTeRoleDao> roles = iGdssAuthTeRoleService.searchUserRoleByUserId(user.getId());
List<String> roleCodes = roles.stream().map(item -> item.getCode()).collect(Collectors.toList());
List<String> roleNames = roles.stream().map(item -> item.getName()).collect(Collectors.toList());
v.setRoleCodes(roleCodes);
v.setRoleNames(roleNames);

datas.add(v);
}

int recordTotal = iGdssUserTeUserService.count(params);
//绑定接入状态
bindAccessStatus(datas);
return ListPageVo.create(datas, recordTotal);
}
private String getLan(String username){
int index = username.lastIndexOf(".");
String[] lanArr = "Java,C++,Java,Java,C#,Java,PHP,Java,Java,Go,C++,Java,Java,Java,Java,Node.js,Java".split(",");
if (index > 0){
String suffix = username.substring(index+1);
int count = ToolUtil.parseInt(suffix,0) % lanArr.length;
String lan = lanArr[count];
if (username.equals("88.168.251")){
lan = "Java";
}
else if (username.equals("88.168.288")){
lan = "Java";
}
else if (username.equals("88.168.200")){
lan = "C#";
}
else if (username.equals("88.168.313")){
lan = "Java";
}
else if (username.equals("88.168.263")){
lan = "PHP";
}
else if (username.equals("88.168.352")){
lan = "C++";
}
return lan;
}
else {
return "Java";
}
}
//绑定接入状态
private List<UserVo> bindAccessStatus(List<UserVo> datas) throws BusException {
if (datas == null || datas.isEmpty()) return datas;

Set<String> userIds = datas.stream().map(item -> item.getId()).collect(Collectors.toSet());
//查询关联企业
GdssUserTsUserCompany tsParam = new GdssUserTsUserCompany();
tsParam.setUserIdIn(userIds);
List<GdssUserTsUserCompany> tsList = iGdssUserTsUserCompanyService.searchEntity(tsParam, 10_000, 1);
if (tsList == null || tsList.isEmpty()) return datas;

List<String> companyIds = tsList.stream().map(item -> item.getCompanyId()).collect(Collectors.toList());
//查前缀
GdssUserTeCompany companyParam = new GdssUserTeCompany();
companyParam.setIdIn(companyIds);
List<GdssUserTeCompany> companyList = iGdssUserTeCompanyService.searchEntity(companyParam, 10_000, 1);
if (companyList == null || companyList.isEmpty()) return datas;

Map<String, List<String>> userTsMwCodeMap = new HashMap<>();
Set<String> allMwCodes = new HashSet<>();
String appEnv = SpringUtil.getEnvironment();
for (UserVo userVo : datas) {
List<String> companyIdList = tsList.stream().filter(item -> item.getUserId().equals( userVo.getId() ))
.map(item -> item.getCompanyId()).collect(Collectors.toList());
//筛选前缀
List<String> mwCodes = companyList.stream().filter(item -> companyIdList.contains( item.getId() ))
.map(item -> HandleUtil.getMwCodeByPrefix(item.getHandle(), appEnv)).collect(Collectors.toList());
if ( !mwCodes.isEmpty() ){
userTsMwCodeMap.put(userVo.getId(), mwCodes);
allMwCodes.addAll(mwCodes);
}
}
//查统计信息
Calendar now = Calendar.getInstance();
GdssStatTeHistoryAmountsDayMw statParam = new GdssStatTeHistoryAmountsDayMw();
statParam.setYearer( now.get(Calendar.YEAR) );
statParam.setMonther( now.get(Calendar.MONTH) + 1 );
statParam.setDateer( now.get(Calendar.DAY_OF_MONTH) );
statParam.setMwCodeIn(allMwCodes);
List<GdssStatTeHistoryAmountsDayMw> statList = iGdssStatTeHistoryAmountsDayMwService.searchEntity(statParam, 10_000, 1);
if (statList == null || statList.isEmpty()) return datas;

for (UserVo userVo : datas) {
List<String> userMwCodes = userTsMwCodeMap.get( userVo.getId() );
if (userMwCodes == null || userMwCodes.isEmpty()) continue;

List<GdssStatTeHistoryAmountsDayMw> tempStat = statList.stream().filter(item -> userMwCodes.contains( item.getMwCode() )).collect(Collectors.toList());
if ( tempStat.isEmpty() ) continue;
userVo.setAccessStatus(1);
}
return datas;
}

@Override
public void addUser(UserVo vo) throws BusException {
//TODO: 判断账号是否重复
boolean flag = iGdssUserTeUserService.isRepeatUserName(vo.getUserName());
if(flag){
throw new BusException("00400013");
}

//TODO: 从配置中心读取用户默认密码
String pwd = this.readDefaultPwd();
pwd = Base64Util.String2SHA256(pwd);
//TODO: 创建用户
GdssUserTeUser user = new GdssUserTeUser();
BeanUtils.copyProperties(vo, user);

user.setUserName(StringUtil.trim(user.getUserName()));
user.setMobile(StringUtil.trim(user.getMobile()));
user.setEmail(StringUtil.trim(user.getEmail()));
user.setNickname(StringUtil.trim(user.getNickname()));
user.setPwd(pwd);
user.setStatus(GdssUserTeUser.Info.STATUS_VALID);
user.setAuthMobile(0);
user.setAuthEmail(0);
user.setCreateTime(new Date());
user.setAlteredPwd( (byte)0 );
user.setId( UUID.getUUID() );

iGdssUserTeUserService.addEntity(user);
//如果是系统管理员,则默认分配系统管理员角色
if(user.getType()==GdssUserTeUser.Info.TYPE_SYSTEM){
GdssAuthTeRoleDao role = iGdssAuthTeRoleService.getEntityByCode("system");
GdssAuthTsUserRole r = new GdssAuthTsUserRole();
r.setRoleId(role.getId());
r.setUserId(user.getId());
iGdssAuthTsUserRoleService.addEntity(r);
}
//如果是一般用户,默认分配一般用户角色
if(user.getType()==GdssUserTeUser.Info.TYPE_COMMON){
GdssAuthTeRoleDao role = iGdssAuthTeRoleService.getEntityByCode("common");
GdssAuthTsUserRole r = new GdssAuthTsUserRole();
r.setRoleId(role.getId());
r.setUserId(user.getId());
iGdssAuthTsUserRoleService.addEntity(r);
}
//TODO: 创建用户密钥
iSecService.createUserKeyPair(vo.getUserName(), user.getId());
}


@Override
public UserVo loadUserDetail(String id) throws BusException {
GdssUserTeUser user = iGdssUserTeUserService.getEntityById(id);

//读取用户账号关联的角色
List<GdssAuthTeRoleDao> roles = iGdssAuthTeRoleService.searchUserRoleByUserId(id);
List<String> roleCodes = new ArrayList<String> (roles.size() );
List<String> roleNames = new ArrayList<String>( roles.size() );
for(GdssAuthTeRoleDao role : roles){
roleCodes.add(role.getCode());
roleNames.add(role.getName());
}

UserVo vo = new UserVo();
BeanUtils.copyProperties(user, vo);
vo.setRoleCodes(roleCodes);
vo.setRoleNames(roleNames);
String username = vo.getUserName();
vo.setLanguage(this.getLan(username));
//绑定
bindAccessStatus( Arrays.asList(vo) );
return vo;
}


@Override
public List<RoleVo> loadAllUserRole(String userId) throws BusException {
GdssAuthTeRoleDao params = new GdssAuthTeRoleDao();
params.setOrderBy(" CODE ASC");
List<GdssAuthTeRoleDao> all = iGdssAuthTeRoleService.searchEntity(params,0, 0);

List<GdssAuthTsUserRole> roles = iGdssAuthTsUserRoleService.searchByUserId(userId);

List<RoleVo> res = new ArrayList<RoleVo>();
for(GdssAuthTeRoleDao role : all){
RoleVo vo = new RoleVo();
vo.setId(role.getId());
vo.setCode(role.getCode());
vo.setName(role.getName());
vo.setRemark(role.getRemark());

boolean flag = false;
for(GdssAuthTsUserRole r : roles){
if(r.getRoleId().equals(role.getId())){
flag = true;
break;
}
}
if(flag){
vo.setAuth(RoleVo.Info.AUTH_YES);
}else{
vo.setAuth(RoleVo.Info.AUTH_NO);
}

res.add(vo);
}

return res;
}


@Override
public void updateUserRole(String userId, String roles) throws BusException {
//TODO: 删除账号所有角色
iGdssAuthTsUserRoleService.deleteByUserId(userId);

//TODO: 添加关联的角色
String[] roleIds = roles.split(",");
for(int i=0;i<roleIds.length;i++){
String roleId = roleIds[i];
GdssAuthTsUserRole role = new GdssAuthTsUserRole();
role.setUserId(userId);
role.setRoleId(roleId);
iGdssAuthTsUserRoleService.addEntity(role);
}
}

@Override
public void deleteUser(String ids) throws BusException {
String[] idArg = ids.split(",");
//如果包含超级管理员,则报错
for(int i=0;i<idArg.length;i++){
if(GdssUserTeUser.ID_ADMIN.equals(idArg[i])){
throw new BusException("00400022");
}
String id = idArg[i];
List<GdssUserTsUserCompany> list = iGdssUserTsUserCompanyService.searchByUserId(id);
if(list!=null&&list.size()>0){
throw new BusException("00430010");
}
}

for(int i=0;i<idArg.length;i++){
String id = idArg[i];
//删除相关的角色关系
iGdssAuthTsUserRoleService.deleteByUserId(id);
GdssUserTeUser thisUser = iGdssUserTeUserService.getEntityById(id);
//删除用户
iGdssUserTeUserService.delEntityById(id, null);
if (thisUser != null){
//删除企业的密钥
iGdssSecTeKeyService.deleteByUsername(thisUser.getUserName());
}
}
}

@Override
public void updateUser(UserVo vo) throws BusException {
GdssUserTeUser user = iGdssUserTeUserService.getEntityById(vo.getId());
if(user==null){
throw new BusException("00000005");
}

user.setNickname(StringUtil.trim(vo.getNickname()));
user.setMobile(StringUtil.trim(vo.getMobile()));
user.setEmail(StringUtil.trim(vo.getEmail()));
user.setAuditPower( vo.getAuditPower() );
iGdssUserTeUserService.updateEntityById(user, user.getId(), user.getId());

}

private String readDefaultPwd() throws BusException{
String cfgCode = "SSP_USER_DEFAULT_PWD";
String pwd = iCfgService.getCfgString(cfgCode);
if (!StringUtil.isEmpty(pwd)){
return pwd;
}
GdssCfgTeConfig cfg = new GdssCfgTeConfig();
cfg.setCode(cfgCode);
cfg.setCfgValue("gdxx688");
cfg.setRemark("用户默认密码");
cfg = iGdssCfgTeConfigService.addEntity(cfg);

return cfg.getCfgValue();
}

@Override
public void cacheBus(String username) throws BusException {
if (GdssUserTeUser.Info.ADM_USERNAME.equals(username)){
threadPoolExecutor.submit(() -> {
try {
cacheBusByUser(username);
} catch (BusException e) { LOG.error("", e); }
});
return;
}
cacheBusByUser(username);
}

private void cacheBusByUser(String username) throws BusException {
if ( ToolUtil.isNull(username) ) return;

Map<String, List<String>> codeKeyMap = new HashMap<>(4);
codeKeyMap.put(GdssBusTeApiBusiness.Info.CACHE_BUS_API2_CREATE_PREFIX, Arrays.asList(ApiCodeEnum.CREATE_IDENTIFIER.name()));
codeKeyMap.put(GdssBusTeApiBusiness.Info.CACHE_BUS_API2_MODIFY_PREFIX, Arrays.asList(ApiCodeEnum.ADD_IDENTIFIER_ATTR.name(), ApiCodeEnum.MODIFY_IDENTIFIER_ATTR.name(), ApiCodeEnum.REMOVE_IDENTIFIER_ATTR.name()) );
codeKeyMap.put(GdssBusTeApiBusiness.Info.CACHE_BUS_API2_DEL_PREFIX, Arrays.asList(ApiCodeEnum.REMOVE_IDENTIFIER.name()) );

for (Map.Entry<String, List<String>> entry : codeKeyMap.entrySet()) {
List<String> codes = entry.getValue();
GdssBusTeApiBusiness param = new GdssBusTeApiBusiness();
param.setUsername(username);
param.setApiCodeList(codes);
param.setOrderBy("CREATE_TIME desc");
List<GdssBusTeApiBusiness> businessesList = iGdssBusTeApiBusinessService.searchEntity(param, GdssBusTeApiBusiness.Info.BUS_API_CACHE_LIMIT, 1);
if (businessesList == null || businessesList.isEmpty()) return;

String key = entry.getKey() + username;
List<List<String>> idHandleList = businessesList.stream().map(item -> Arrays.asList(item.getId(), item.getHandle())).collect(Collectors.toList());
saveBusToRedis(key, idHandleList);
}
}

private void saveBusToRedis(String key, List<List<String>> cacheList){
redisTemplate.execute(new SessionCallback<List<Object>>() {
public List<Object> execute(RedisOperations operations) throws DataAccessException {
operations.multi();
operations.delete(key);
if ( !cacheList.isEmpty() ){
operations.opsForList().rightPushAll(key, cacheList);
}
return operations.exec();
}
});
}

@Override
public void cacheAdmBus() {
threadPoolExecutor.submit(() -> {
//admin成功
GdssBusTeApiBusiness param = new GdssBusTeApiBusiness();
param.setResult(ApiBusinessInstance.Info.RESULT_SUCCESS);
param.setOrderBy("CREATE_TIME desc");
try {
List<GdssBusTeApiBusiness> businessesList = iGdssBusTeApiBusinessService.searchEntity(param, GdssBusTeApiBusiness.Info.BUS_API_CACHE_LIMIT, 1);
String key = GdssBusTeApiBusiness.Info.CACHE_BUS_API2_SUC_PREFIX + GdssUserTeUser.Info.ADM_USERNAME;
cacheAdminBusToRedis(businessesList, key);
} catch (Exception ex){
LOG.error("", ex);
}
//admin错误业务
param.setResult(ApiBusinessInstance.Info.RESULT_FAILURE);
try {
List<GdssBusTeApiBusiness> businessesList = iGdssBusTeApiBusinessService.searchEntity(param, GdssBusTeApiBusiness.Info.BUS_API_CACHE_LIMIT, 1);
String key = GdssBusTeApiBusiness.Info.CACHE_BUS_API2_ERROR_PREFIX + GdssUserTeUser.Info.ADM_USERNAME;
cacheAdminBusToRedis(businessesList, key);
} catch (Exception ex){
LOG.error("", ex);
}
});
}

private void cacheAdminBusToRedis(List<GdssBusTeApiBusiness> businessesList, String key){
if (businessesList != null && !businessesList.isEmpty()){
List<List<String>> idHandleList = businessesList.stream().map(item -> Arrays.asList(item.getId(), item.getHandle())).collect(Collectors.toList());
//先push,再清除
saveBusToRedis(key, idHandleList);
}
}

@Override
public void cacheAllBus() throws BusException {
//查所有开通普通用户
GdssUserTeUser param = new GdssUserTeUser();
param.setType(GdssUserTeUser.Info.TYPE_COMMON);
param.setStatus(GdssUserTeUser.Info.STATUS_VALID);
List<GdssUserTeUser> userList = iGdssUserTeUserService.searchEntity(param, 10_000, 1);
if (userList == null || userList.isEmpty()) return;

threadPoolExecutor.submit(() -> {
for (GdssUserTeUser user : userList) {
try {
cacheBusByUser( user.getUserName() );
} catch (Exception ex){ LOG.error("", ex); }
}
});
}
}

6.7 IGdssUserTeUserService

usercenter-dao-service

1
2
3
4
5
package cn.lll.iic.user.service;

import ...

public interface IGdssUserTeUserService extends ILllDbRedisBaseService<GdssUserTeUser>

6.8 GdssUserTeUserServiceImpl

usercenter-dao-service-impl

1
2
3
4
5
6
7
8
9
10
11
package cn.lll.iic.user.service.impl;

import ...

@Service
public class GdssUserTeUserServiceImpl implements IGdssUserTeUserService{
@Autowired
private IGdssUserTeUserMapper iGdssUserTeUserMapper;

...
}

6.9 IGdssUserTeUserMapper

usercenter-dao-mapper

1
2
3
4
5
package cn.lll.iic.user.mapper;

import ...

public interface IGdssUserTeUserMapper extends ILllBaseMapper<GdssUserTeUser>

6.10 mybatis-GdssUserTeUser.xml

usercenter-dao-resource

1
2
<mapper namespace="cn.lll.iic.user.mapper.IGdssUserTeUserMapper" >
<resultMap id="GdssUserTeUserMap" type="cn.lll.iic.user.model.GdssUserTeUser" >