Es 工具封装
parent
6ffb1685d7
commit
cf4506b475
@ -0,0 +1,51 @@
|
||||
package cn.estsh.i3plus.core.apiservice.controller;
|
||||
|
||||
import cn.estsh.i3plus.platform.common.tool.ExcelTool;
|
||||
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
|
||||
import cn.estsh.i3plus.platform.plugin.elasticsearch.ElasticSearchPack;
|
||||
import cn.estsh.i3plus.platform.plugin.elasticsearch.ElasticSearchTool;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.platform.platbean.SysLogOperate;
|
||||
import cn.estsh.impp.framework.base.controller.CoreBaseController;
|
||||
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
|
||||
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
||||
import cn.estsh.impp.framework.boot.util.ResultBean;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Description :
|
||||
* @Reference :
|
||||
* @Author : wei.peng
|
||||
* @CreateDate : 20-3-10 下午1:16
|
||||
* @Modify:
|
||||
**/
|
||||
@RestController
|
||||
@Api(tags = "测试Demo ")
|
||||
@RequestMapping(PlatformConstWords.BASE_URL + "/demo")
|
||||
public class DemoController extends CoreBaseController {
|
||||
|
||||
|
||||
|
||||
@GetMapping(value = "/query")
|
||||
@ApiOperation(value = "添加操作日志", notes = "添加操作日志,可用于国际化")
|
||||
public ResultBean insertLogOperate() {
|
||||
try {
|
||||
// org.elasticsearch.common.xcontent.DeprecationHandler handler;
|
||||
ElasticSearchTool.init("http://192.168.3.40:9200");
|
||||
ElasticSearchPack pack = ElasticSearchPack.imppBuild(SysLogOperate.class);
|
||||
List<SysLogOperate> list = ElasticSearchTool.searchList(pack, SysLogOperate.class);
|
||||
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultList(list);
|
||||
} catch (ImppBusiException busExcep) {
|
||||
return ResultBean.fail(busExcep).build();
|
||||
} catch (Exception e) {
|
||||
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,202 @@
|
||||
package cn.estsh.i3plus.core.apiservice.controller;
|
||||
|
||||
import cn.estsh.i3plus.core.api.iservice.base.ISysLogService;
|
||||
import cn.estsh.i3plus.core.api.iservice.busi.*;
|
||||
import cn.estsh.i3plus.core.apiservice.controller.busi.PersonnelController;
|
||||
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
|
||||
import cn.estsh.i3plus.pojo.base.common.Pager;
|
||||
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
|
||||
import cn.estsh.i3plus.pojo.model.platform.UserDetailModel;
|
||||
import cn.estsh.i3plus.pojo.platform.bean.SysDepartment;
|
||||
import cn.estsh.i3plus.pojo.platform.bean.SysPosition;
|
||||
import cn.estsh.i3plus.pojo.platform.bean.SysRole;
|
||||
import cn.estsh.i3plus.pojo.platform.platbean.SysLogOperate;
|
||||
import cn.estsh.impp.framework.base.controller.CoreBaseController;
|
||||
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
|
||||
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
||||
import cn.estsh.impp.framework.boot.exception.ImppExceptionEnum;
|
||||
import cn.estsh.impp.framework.boot.util.ResultBean;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.commons.lang3.RandomUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
/**
|
||||
* @Description : 系统资源服务demo
|
||||
* @Reference :
|
||||
* @Author : alwaysfrin
|
||||
* @CreateDate : 2018-09-26 10:34
|
||||
* @Modify:
|
||||
**/
|
||||
@RestController
|
||||
@Api(tags = "系统服务demo")
|
||||
@RequestMapping(PlatformConstWords.BASE_URL + "/test/user-info")
|
||||
public class DemoUserInfoController extends CoreBaseController {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(DemoUserInfoController.class);
|
||||
|
||||
@Autowired
|
||||
private IPersonnelService personnelService;
|
||||
|
||||
@Autowired
|
||||
private ISysOrganizeService organizeService;
|
||||
|
||||
@Autowired
|
||||
private ISysDepartmentService departmentService;
|
||||
|
||||
@Autowired
|
||||
private ISysRoleService roleService;
|
||||
|
||||
@Autowired
|
||||
private ISysPositionService positionService;
|
||||
|
||||
@Autowired
|
||||
private ISysDictionaryService dictionaryService;
|
||||
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(50);
|
||||
|
||||
private List<SysRole> roleList;
|
||||
private List<SysDepartment> departmentList;
|
||||
private List<SysPosition> positionList;
|
||||
private Random roleListRandom;//默认构造方法
|
||||
private Random departmentListRandom;//默认构造方法
|
||||
private Random positionListRandom;//默认构造方法
|
||||
|
||||
private static Random random = new Random(10);
|
||||
|
||||
@Autowired
|
||||
private PersonnelController personnelController;
|
||||
|
||||
|
||||
/**
|
||||
* 添加操作日志
|
||||
*
|
||||
* @return 处理结果
|
||||
*/
|
||||
@PostMapping(value = "/insert")
|
||||
@ApiOperation(value = "添加操作日志", notes = "添加操作日志,可用于国际化")
|
||||
public ResultBean insertLogOperate() {
|
||||
try {
|
||||
initData();
|
||||
for (int i = 0; i < 50; i++) {
|
||||
executorService.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int j = 0; j < 10000; j++) {
|
||||
try {
|
||||
System.out.println(Thread.currentThread().getName() + "----> Start insert " + j);
|
||||
personnelController.insertUserDetailModel(getUserDetailModel());
|
||||
System.out.println(Thread.currentThread().getName() + "----> End insert " + j);
|
||||
}catch (Exception e){
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
|
||||
} catch (ImppBusiException busExcep) {
|
||||
return ResultBean.fail(busExcep).build();
|
||||
} catch (Exception e) {
|
||||
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void initData() {
|
||||
roleList = roleService.findSysRoleAll();
|
||||
departmentList = departmentService.findSysDepartmentList();
|
||||
positionList = positionService.findSysPositionAll();
|
||||
|
||||
roleListRandom = new Random(roleList.size() - 1);
|
||||
departmentListRandom = new Random(departmentList.size() - 1);
|
||||
positionListRandom = new Random(positionList.size() - 1);
|
||||
}
|
||||
|
||||
public synchronized UserDetailModel getUserDetailModel() {
|
||||
UserDetailModel model = new UserDetailModel();
|
||||
|
||||
model.setInfoName(RandomStringUtils.randomAlphanumeric(RandomUtils.nextInt(20, 50)));
|
||||
model.setInfoEmpNo(RandomStringUtils.randomAlphanumeric(RandomUtils.nextInt(20, 50)));
|
||||
model.setInfoEmployeeType(2);
|
||||
model.setInfoGrade(2);
|
||||
model.setInfoSex(2);
|
||||
model.setInfoMarriage(2);
|
||||
model.setInfoCardType(1);
|
||||
model.setInfoCardNumber(RandomStringUtils.randomAlphanumeric(18));
|
||||
model.setInfoSchoolEducation(1);
|
||||
model.setInfoSchoolLeaveDate("2020-03-09 19:38:41");
|
||||
model.setInfoRace(2);
|
||||
model.setInfoJoinDate("2020-03-09 19:39:12");
|
||||
model.setInfoResignationDate("2020-03-09 19:39:12");
|
||||
model.setInfoPoliticalStatus(2);
|
||||
model.setInfoBornDate("2020-03-09 19:39:59");
|
||||
model.setUserLoginName(RandomStringUtils.randomAlphanumeric(RandomUtils.nextInt(15, 20)));
|
||||
model.setUserLoginPassword("123456");
|
||||
model.setUserLanguageCode("CN/zh");
|
||||
model.setUserPhone(RandomStringUtils.randomAlphanumeric(11));
|
||||
model.setUserEmail(RandomStringUtils.randomAlphanumeric(11) + "qq.com");
|
||||
|
||||
model.setInfoDepartmentId(getSysDepartment().getId().toString());
|
||||
model.setInfoDepartmentIdList(getSysDepartmentList());
|
||||
model.setInfoPositionId(getSysPosition().getId().toString());
|
||||
model.setInfoPositionIdList(getSysPositionList());
|
||||
model.setUserDepartmentId(getSysDepartment().getId().toString());
|
||||
model.setUserDepartmentIdList(getSysDepartmentList());
|
||||
model.setUserRoleIdList(getSysRoleList());
|
||||
|
||||
return model;
|
||||
}
|
||||
|
||||
|
||||
public SysRole getSysRole() {
|
||||
return roleList.get(roleListRandom.nextInt(roleList.size()));
|
||||
}
|
||||
|
||||
public List<String> getSysRoleList() {
|
||||
List<String> result = new ArrayList<>();
|
||||
int length = random.nextInt(5);
|
||||
for (int i = 0; i < length; i++) {
|
||||
result.add(roleList.get(roleListRandom.nextInt(roleList.size())).getId().toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public SysDepartment getSysDepartment() {
|
||||
return departmentList.get(departmentListRandom.nextInt(departmentList.size()));
|
||||
}
|
||||
|
||||
public List<String> getSysDepartmentList() {
|
||||
List<String> result = new ArrayList<>();
|
||||
int length = random.nextInt(5);
|
||||
for (int i = 0; i < length; i++) {
|
||||
result.add(departmentList.get(departmentListRandom.nextInt(departmentList.size())).getId().toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public SysPosition getSysPosition() {
|
||||
do {
|
||||
return positionList.get(positionListRandom.nextInt(positionList.size()));
|
||||
} while (true);
|
||||
}
|
||||
|
||||
public List<String> getSysPositionList() {
|
||||
List<String> result = new ArrayList<>();
|
||||
int length = random.nextInt(5);
|
||||
for (int i = 0; i < length; i++) {
|
||||
result.add(positionList.get(positionListRandom.nextInt(positionList.size())).getId().toString());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue