use of com.bc.pmpheep.back.po.OrgUser in project pmph by BCSquad.
the class MigrationStageOne method orgUser.
protected void orgUser() {
String tableName = "sys_user";
// 添加new_pk字段
JdbcHelper.addColumn(tableName);
// 因为是用户相关,所以用户拓展表也要添加new_pk字段
JdbcHelper.addColumn("sys_userext");
String sql = "SELECT a.userid,a.usercode,a.`password`,a.isvalid,d.new_pk,a.username,d.orgname,b.sex," + "b.duties,b.positional,b.fax,b.handset,b.phone,b.idcard,b.email,b.address,b.postcode," + "CASE WHEN b.audittype IS NOT NULL THEN 1 ELSE 0 END is_proxy_upload," + "e.filedir," + "CASE WHEN b.audittype=2 THEN 1 WHEN b.audittype=1 THEN 2 ELSE 0 END progress," + "b.auditdate,a.memo,a.sortno,f.filedir avatar " + "FROM sys_user a " + "LEFT JOIN sys_userext b ON a.userid = b.userid " + "LEFT JOIN sys_userorganize c ON a.userid = c.userid " + "LEFT JOIN ba_organize d ON c.orgid = d.orgid " + "LEFT JOIN pub_addfileinfo e ON a.userid = e.operuserid " + "LEFT JOIN (SELECT * FROM pub_addfileinfo x WHERE x.fileid IN (SELECT MAX(o.fileid) " + "FROM pub_addfileinfo o WHERE o.childsystemname='sys_userext_avatar' GROUP BY o.operuserid))f " + "ON a.userid = f.operuserid " + "WHERE a.sysflag=1 AND b.usertype=2 " + "AND NOT EXISTS (SELECT * FROM pub_addfileinfo p WHERE e.operdate<p.operdate " + "AND e.operuserid=p.operuserid) " + "GROUP BY a.usercode ORDER BY a.userid ;";
List<Map<String, Object>> maps = JdbcHelper.getJdbcTemplate().queryForList(sql);
List<Map<String, Object>> excel = new LinkedList<>();
List<String> list = new ArrayList<>();
Map<String, Object> result = new LinkedHashMap<>();
int count = 0;
// 统计正常数据数量
int correctCount = 0;
// 识别该表是否有相应异常数据的标识
int[] state = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
StringBuilder reason = new StringBuilder();
StringBuilder dealWith = new StringBuilder();
for (Map<String, Object> map : maps) {
StringBuilder sb = new StringBuilder();
String userId = map.get("userid").toString();
String username = (String) map.get("usercode");
if (StringUtil.isEmpty(username)) {
map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("找不到机构代码。"));
excel.add(map);
if (state[0] == 0) {
reason.append("找不到机构管理员账号。");
dealWith.append("放弃迁移。");
state[0] = 1;
}
continue;
}
if (JdbcHelper.nameDuplicate(list, username)) {
map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("机构代码重复。"));
excel.add(map);
if (state[1] == 0) {
reason.append("机构管理员账号重复。");
dealWith.append("放弃迁移。");
state[1] = 1;
}
continue;
}
if (StringUtil.strLength(username) > 20) {
map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("机构代码过长。"));
excel.add(map);
if (state[2] == 0) {
reason.append("机构管理员账号过长。");
dealWith.append("放弃迁移。");
state[2] = 1;
}
continue;
}
if ("jxyxgdxx".equals(username) || "zyyyzkxy".equals(username) || "qlyyxy".equals(username)) {
map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("依据客户反馈不迁移"));
excel.add(map);
if (state[3] == 0) {
reason.append("多余管理员账号。");
dealWith.append("依据客户反馈,放弃迁移。");
state[3] = 1;
}
continue;
}
list.add(username);
Long orgId = (Long) map.get("new_pk");
if (ObjectUtil.isNull(orgId)) {
map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("找不到对应的学校。"));
excel.add(map);
if (state[4] == 0) {
reason.append("找不到对应的机构。");
dealWith.append("放弃迁移。");
state[4] = 1;
}
continue;
} else {
if (null != orgUserService.getOrgUserByOrgId(orgId)) {
logger.error("迁移org_user时,机构ID(org_id={})出现了重复,机构用户名:{}", orgId, username);
continue;
}
}
String password = (String) map.get("password");
if (StringUtil.isEmpty(password)) {
password = "888888";
map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("机构用户登陆密码为空。"));
excel.add(map);
if (state[5] == 0) {
reason.append("机构用户登陆密码为空。");
dealWith.append("设为默认密码迁入数据库。");
state[5] = 1;
}
}
String realName = (String) map.get("username");
String orgName = (String) map.get("orgname");
if (StringUtil.isEmpty(realName)) {
realName = orgName;
}
String sexNum = (String) map.get("sex");
Integer sex = null;
if (StringUtil.notEmpty(sexNum)) {
sex = Integer.parseInt(sexNum);
}
String position = (String) map.get("duties");
if (StringUtil.notEmpty(position) && ("null".equals(position) || "nu".equals(position))) {
position = "-";
}
String title = (String) map.get("positional");
if (StringUtil.isEmpty(title)) {
title = "-";
}
if (!"-".equals(title)) {
switch(title) {
case "1097":
title = "教授";
break;
case "1098":
title = "副教授";
break;
case "1099":
title = "讲师";
break;
case "1100":
title = "正高";
break;
case "1101":
title = "副高";
break;
default:
title = "其他";
}
}
String fax = (String) map.get("fax");
if (StringUtil.notEmpty(fax) && ("null".equals(fax) || "nu".equals(fax))) {
fax = "-";
}
String handphone = (String) map.get("handset");
if (StringUtil.notEmpty(handphone) && ("null".equals(handphone) || "nu".equals(handphone))) {
handphone = "-";
}
String telephone = (String) map.get("phone");
if (StringUtil.notEmpty(telephone) && ("null".equals(telephone) || "nu".equals(telephone))) {
telephone = "-";
}
String idcard = (String) map.get("idcard");
if (StringUtil.notEmpty(idcard) && ("null".equals(idcard) || "nu".equals(idcard))) {
idcard = "-";
}
String email = (String) map.get("email");
if (StringUtil.notEmpty(email) && ("null".equals(email) || "nu".equals(email))) {
email = "-";
}
String address = (String) map.get("address");
if (StringUtil.notEmpty(address) && ("null".equals(address) || "nu".equals(address))) {
address = "-";
}
String postcode = (String) map.get("postcode");
if (StringUtil.notEmpty(postcode) && ("null".equals(postcode) || "nu".equals(postcode))) {
postcode = "-";
}
Integer isProxyUpload = (Integer) map.get("is_proxy_upload");
String proxy = (String) map.get("filedir");
String avatar = (String) map.get("avatar");
Integer progress = (Integer) map.get("progress");
Timestamp reviewDate = (Timestamp) map.get("auditdate");
String note = (String) map.get("memo");
if (StringUtil.notEmpty(note) && ("null".equals(note) || "nu".equals(note))) {
note = "-";
}
Integer sort = (Integer) map.get("sortno");
if (ObjectUtil.notNull(sort) && sort < 0) {
sort = 999;
}
OrgUser orgUser = new OrgUser();
orgUser.setUsername(username);
orgUser.setPassword(password);
orgUser.setIsDisabled(false);
orgUser.setOrgId(orgId);
orgUser.setRealname(realName);
orgUser.setSex(sex);
orgUser.setPosition(position);
orgUser.setTitle(title);
orgUser.setFax(fax);
orgUser.setHandphone(handphone);
orgUser.setTelephone(telephone);
orgUser.setIdcard(idcard);
orgUser.setEmail(email);
orgUser.setAddress(address);
orgUser.setPostcode(postcode);
orgUser.setAvatar("DEFAULT");
orgUser.setIsProxyUpload(isProxyUpload == 1);
orgUser.setProgress(progress);
orgUser.setReviewDate(reviewDate);
orgUser.setNote(note);
orgUser.setSort(sort);
if (orgUser.getProgress() == 1 && ObjectUtil.isNull(orgUser.getReviewDate())) {
map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("审核通过,但审核时间为空。"));
excel.add(map);
if (state[6] == 0) {
reason.append("审核通过但社和时间为空。");
dealWith.append("依据客户反馈照常迁入数据库。");
state[6] = 1;
}
}
orgUser = orgUserService.addOrgUser(orgUser);
Long pk = orgUser.getId();
JdbcHelper.updateNewPrimaryKey(tableName, pk, "userid", userId);
// 用户拓展表也要更新new_pk
JdbcHelper.updateNewPrimaryKey("sys_userext", pk, "userid", userId);
count++;
if (StringUtil.isEmpty(proxy) && isProxyUpload == 1) {
proxy = "DEFAULT";
orgUser.setProxy(proxy);
}
if (StringUtil.notEmpty(proxy)) {
String mongoId = "";
try {
mongoId = fileService.migrateFile(proxy, ImageType.ORG_USER_PROXY, pk);
} catch (IOException ex) {
mongoId = "DEFAULT";
logger.error("文件读取异常,路径<{}>,异常信息:{}", proxy, ex.getMessage());
map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("文件读取异常。"));
excel.add(map);
if (state[7] == 0) {
reason.append("机构委托书丢失。");
dealWith.append("设为默认图片迁入数据库。");
state[7] = 1;
}
}
orgUser.setProxy(mongoId);
}
if (StringUtil.notEmpty(avatar)) {
String avatarMongoId = "";
try {
avatarMongoId = fileService.migrateFile(avatar, ImageType.ORG_USER_AVATAR, pk);
} catch (IOException ex) {
avatarMongoId = "DEFAULT";
logger.error("文件读取异常,路径<{}>,异常信息:{}", avatar, ex.getMessage());
map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("机构用户头像文件读取异常。"));
excel.add(map);
if (state[8] == 0) {
reason.append("机构用户头像文件丢失。");
dealWith.append("设为默认头像迁入数据库。");
state[8] = 1;
}
}
orgUser.setAvatar(avatarMongoId);
}
orgUserService.updateOrgUser(orgUser);
if (null == map.get("exception")) {
correctCount++;
}
}
if (excel.size() > 0) {
try {
excelHelper.exportFromMaps(excel, "机构用户表", "org_user");
} catch (IOException ex) {
logger.error("异常数据导出到Excel失败", ex);
}
}
if (correctCount != maps.size()) {
result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "org_user");
result.put(SQLParameters.EXCEL_HEADER_DESCRIPTION, "机构用户表");
result.put(SQLParameters.EXCEL_HEADER_SUM_DATA, maps.size());
result.put(SQLParameters.EXCEL_HEADER_MIGRATED_DATA, count);
result.put(SQLParameters.EXCEL_HEADER_CORECT_DATA, correctCount);
result.put(SQLParameters.EXCEL_HEADER_TRANSFERED_DATA, count - correctCount);
result.put(SQLParameters.EXCEL_HEADER_NO_MIGRATED_DATA, maps.size() - count);
result.put(SQLParameters.EXCEL_HEADER_EXCEPTION_REASON, reason.toString());
result.put(SQLParameters.EXCEL_HEADER_DEAL_WITH, dealWith.toString());
SQLParameters.STATISTICS_RESULT.add(result);
}
logger.info("org_user表迁移完成");
logger.info("原数据库表共有{}条数据,迁移了{}条数据", maps.size(), count);
// 记录信息
Map<String, Object> msg = new HashMap<String, Object>();
msg.put("result", "org_user表迁移完成" + count + "/" + maps.size());
SQLParameters.STATISTICS.add(msg);
}
use of com.bc.pmpheep.back.po.OrgUser in project pmph by BCSquad.
the class OrgUserSeviceTest method testUpdateOrgUserOfBack.
@Test
public void testUpdateOrgUserOfBack() {
OrgAndOrgUserVO orgAndOrgUserVO = new OrgAndOrgUserVO();
Org org = new Org();
OrgUser orgUser = new OrgUser();
// 所属区域
org.setAreaId(12345L);
// 机构id
org.setOrgTypeId(4L);
orgUser.setRealname("s");
orgUser.setOrgId(org.getId());
// 管理员姓名
org.setOrgName("asdasdasdasda");
// 机构代码
orgUser.setUsername("m1001021");
orgUserService.addOrgUserAndOrgOfBack(orgUser, org);
orgAndOrgUserVO.setId(orgUser.getId());
orgAndOrgUserVO.setRealname("机构");
orgAndOrgUserVO.setUsername(orgUser.getUsername());
orgAndOrgUserVO.setOrgId(org.getId());
orgAndOrgUserVO.setOrgName("name");
Object result = orgUserService.updateOrgUserOfBack(orgAndOrgUserVO);
Assert.assertTrue("更新失败", result.equals("SUCCESS"));
}
use of com.bc.pmpheep.back.po.OrgUser in project pmph by BCSquad.
the class OrgUserSeviceTest method addOrgUserAndOrgOfBack.
@Test
public void addOrgUserAndOrgOfBack() {
Org org = new Org();
OrgUser orgUser = new OrgUser();
// 所属区域
org.setAreaId(12345L);
// 机构id
org.setOrgTypeId(4L);
orgUser.setRealname("s");
// 排序码
org.setSort(null);
// 备注
org.setNote(null);
orgUser.setOrgId(org.getId());
// 管理员姓名
org.setOrgName("asdasdasdasda");
// 机构代码
orgUser.setUsername("m1001021");
orgUser.setEmail(null);
orgUser.setHandphone(null);
Assert.assertNotNull("添加失败", orgUserService.addOrgUserAndOrgOfBack(orgUser, org));
}
use of com.bc.pmpheep.back.po.OrgUser in project pmph by BCSquad.
the class OrgUserSeviceTest method testAddOrgUserOfBack.
@Test
public void testAddOrgUserOfBack() {
OrgUser orgUser = new OrgUser();
orgUser.setUsername("OOO");
orgUser.setRealname("BBc");
String result = orgUserService.addOrgUserOfBack(orgUser);
Assert.assertTrue("添加失败", result.equals("SUCCESS"));
}
use of com.bc.pmpheep.back.po.OrgUser in project pmph by BCSquad.
the class AddTestUser method addTestUser.
public void addTestUser() {
String pmphUserData = "[" + "{'username':'yewutest01','realname':'业务测试账号A','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'主任'}]}," + "{'username':'yewutest02','realname':'业务测试账号B','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'系统管理员'},{'roleName':'项目编辑'}]}," + "{'username':'yewutest03','realname':'业务测试账号C','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'项目编辑'}]}," + "{'username':'yewutest04','realname':'业务测试账号D','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'项目编辑'}]}," + "{'username':'yewutest05','realname':'业务测试账号E','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'项目编辑'}]}," + "{'username':'yewutest06','realname':'业务测试账号F','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'项目编辑'}]}," + "{'username':'yewutest07','realname':'业务测试账号J','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'主任'}]}," + "{'username':'yewutest08','realname':'业务测试账号H','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[]}," + "{'username':'yewutest09','realname':'业务测试账号I','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'数字编辑'}]}," + "{'username':'yewutest10','realname':'业务测试账号J','password':'888888','department':'人民卫生出版社','avatar':'DEFAULT','roles':[{'roleName':'数字编辑'},{'roleName':'其他用户'}]}" + "]";
Gson gson = new Gson();
List<TestPmphUserBo> testPmphUsers = gson.fromJson(pmphUserData, new TypeToken<ArrayList<TestPmphUserBo>>() {
}.getType());
for (TestPmphUserBo user : testPmphUsers) {
PmphDepartment pmphDepartment = pmphDepartmentService.getPmphDepartmentByName(user.getDepartment());
PmphUser pmphUser = new PmphUser();
pmphUser.setUsername(user.getUsername());
pmphUser.setRealname(user.getRealname());
pmphUser.setPassword(user.getPassword());
pmphUser.setDepartmentId(pmphDepartment == null ? 0L : pmphDepartment.getId());
pmphUser.setAvatar(user.getAvatar());
pmphUser = pmphUserService.add(pmphUser);
for (PmphRole pmphRole : user.getRoles()) {
pmphRole = pmphRoleService.getByName(pmphRole.getRoleName());
PmphUserRole pmphUserRole = new PmphUserRole();
pmphUserRole.setUserId(pmphUser.getId());
pmphUserRole.setRoleId(pmphRole == null ? 0L : pmphRole.getId());
pmphUserRoleService.addPmphUserRole(pmphUserRole);
}
}
String orgData = "[" + "{'orgName':'北京测试学校','orgType':'本科','areaName':'北京市','username':'bjcsxxtest','password':'123456','realname':'北京学校管理员','avatar':'DEFAULT'," + "writerUsers:[" + "{'username':'bjzuojia01','password':'888888','nickname':'北京作家01','realname':'北京作家01'}," + "{'username':'bjzuojia02','password':'888888','nickname':'北京作家02','realname':'北京作家02'}," + "{'username':'bjzuojia03','password':'888888','nickname':'北京作家03','realname':'北京作家03'}," + "{'username':'bjzuojia04','password':'888888','nickname':'北京作家04','realname':'北京作家04'}," + "{'username':'bjzuojia05','password':'888888','nickname':'北京作家05','realname':'北京作家05'}," + "{'username':'bjzuojia06','password':'888888','nickname':'北京作家06','realname':'北京作家06'}," + "{'username':'bjzuojia07','password':'888888','nickname':'北京作家07','realname':'北京作家07'}," + "{'username':'bjzuojia08','password':'888888','nickname':'北京作家08','realname':'北京作家08'}," + "{'username':'bjzuojia09','password':'888888','nickname':'北京作家09','realname':'北京作家09'}," + "{'username':'bjzuojia10','password':'888888','nickname':'北京作家10','realname':'北京作家10'}," + "{'username':'bjzuojia11','password':'888888','nickname':'北京作家11','realname':'北京作家11'}" + "]" + "}," + "{'orgName':'天津测试学校','orgType':'本科','areaName':'天津市','username':'tjcsxxtest','password':'123456','realname':'天津学校管理员','avatar':'DEFAULT'," + "writerUsers:[" + "{'username':'tjzuojia01','password':'888888','nickname':'天津作家01','realname':'天津作家01'}," + "{'username':'tjzuojia02','password':'888888','nickname':'天津作家02','realname':'天津作家02'}," + "{'username':'tjzuojia03','password':'888888','nickname':'天津作家03','realname':'天津作家03'}," + "{'username':'tjzuojia04','password':'888888','nickname':'天津作家04','realname':'天津作家04'}," + "{'username':'tjzuojia05','password':'888888','nickname':'天津作家05','realname':'天津作家05'}," + "{'username':'tjzuojia06','password':'888888','nickname':'天津作家06','realname':'天津作家06'}," + "{'username':'tjzuojia07','password':'888888','nickname':'天津作家07','realname':'天津作家07'}," + "{'username':'tjzuojia08','password':'888888','nickname':'天津作家08','realname':'天津作家08'}," + "{'username':'tjzuojia09','password':'888888','nickname':'天津作家09','realname':'天津作家09'}," + "{'username':'tjzuojia10','password':'888888','nickname':'天津作家10','realname':'天津作家10'}," + "{'username':'tjzuojia11','password':'888888','nickname':'天津作家11','realname':'天津作家11'}" + "]" + "}" + "]";
List<TestOrgBo> orgBos = gson.fromJson(orgData, new TypeToken<ArrayList<TestOrgBo>>() {
}.getType());
for (TestOrgBo testOrgBo : orgBos) {
Org org = new Org();
org.setParentId(0L);
org.setOrgName(testOrgBo.getOrgName());
org.setOrgTypeId(orgTypeService.listOrgTypeByTypeName(testOrgBo.getOrgType()).get(0).getId());
org.setAreaId(areaService.getAreaIdByName(testOrgBo.getAreaName()));
org = orgService.addOrg(org);
OrgUser orgUser = new OrgUser();
orgUser.setUsername(testOrgBo.getUsername());
orgUser.setPassword(new DesRun("", testOrgBo.getPassword()).enpsw);
orgUser.setOrgId(org.getId());
orgUser.setRealname(testOrgBo.getRealname());
orgUser.setAvatar(testOrgBo.getAreaName());
orgUser = orgUserService.addOrgUser(orgUser);
for (WriterUser writerUser : testOrgBo.getWriterUsers()) {
writerUser.setOrgId(org.getId());
writerUserService.add(writerUser);
}
}
}
Aggregations