Search in sources :

Example 1 with WriterProfile

use of com.bc.pmpheep.back.po.WriterProfile in project pmph by BCSquad.

the class MigrationStageTwo method writerProfile.

protected void writerProfile() {
    String sql = "SELECT b.userid,b.new_pk,b.usercode,b.username,c.seniority," + "a.userid tag_userid,c.introduce,GROUP_CONCAT(d.tagname SEPARATOR '%') tag_name," + "c.usertype FROM sys_usertagmap a LEFT JOIN sys_user b ON a.userid = b.userid " + "LEFT JOIN sys_userext c ON b.userid = c.userid " + "LEFT JOIN book_tag d ON a.tagid = d.tagid GROUP BY a.userid ;";
    List<Map<String, Object>> maps = JdbcHelper.getJdbcTemplate().queryForList(sql);
    List<Map<String, Object>> excel = new LinkedList<>();
    Map<String, Object> result = new LinkedHashMap<>();
    int count = 0;
    // 统计正确数据数量
    int correctCount = 0;
    int[] state = { 0, 0, 0, 0 };
    StringBuilder reason = new StringBuilder();
    StringBuilder dealWith = new StringBuilder();
    for (Map<String, Object> map : maps) {
        Long userId = (Long) map.get("new_pk");
        if (ObjectUtil.isNull(userId)) {
            map.put(SQLParameters.EXCEL_EX_HEADER, "此用户不存在");
            excel.add(map);
            if (state[0] == 0) {
                reason.append("用户不存在。");
                dealWith.append("放弃迁移。");
                state[0] = 1;
            }
            continue;
        }
        Integer usertype = (Integer) map.get("usertype");
        // 按客户反馈直接删除该数据
        if (ObjectUtil.notNull(usertype) && 2 == usertype.intValue()) {
            map.put(SQLParameters.EXCEL_EX_HEADER, "已删除。");
            excel.add(map);
            if (state[1] == 0) {
                reason.append("用户为机构管理员。");
                dealWith.append("根据客户反馈,放弃迁移。");
                state[1] = 1;
            }
            continue;
        }
        if (userId == 0) {
            map.put(SQLParameters.EXCEL_EX_HEADER, "此用户为社内用户。");
            excel.add(map);
            if (state[2] == 0) {
                reason.append("用户为社内用户。");
                dealWith.append("放弃迁移。");
                state[2] = 1;
            }
            continue;
        }
        String profile = (String) map.get("introduce");
        String tagName = (String) map.get("tag_name");
        if (StringUtil.isEmpty(tagName)) {
            map.put(SQLParameters.EXCEL_EX_HEADER, "此标签不存在");
            excel.add(map);
            if (state[3] == 0) {
                reason.append("标签不存在。");
                dealWith.append("标签可以为空,照常迁入数据库。");
                state[3] = 1;
            }
        }
        WriterProfile writerProfile = new WriterProfile();
        writerProfile.setUserId(userId);
        writerProfile.setProfile(profile);
        writerProfile.setTag(tagName);
        writerProfile = writerProfileService.addWriterProfile(writerProfile);
        count++;
        // 此表原系统数据不存在,所以无需反向更新
        if (null == map.get("exception")) {
            correctCount++;
        }
    }
    if (excel.size() > 0) {
        try {
            excelHelper.exportFromMaps(excel, "作家标签表", "writer_profile");
        } catch (IOException ex) {
            logger.error("异常数据导出到Excel失败", ex);
        }
    }
    if (correctCount != maps.size()) {
        result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "writer_profile");
        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("writer_profile表迁移完成");
    logger.info("原数据库表共{}条数据,迁移了{}条数据", maps.size(), count);
    // 记录信息
    Map<String, Object> msg = new HashMap<String, Object>();
    msg.put("result", "writer_profile表迁移完成" + count + "/" + maps.size());
    SQLParameters.STATISTICS.add(msg);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IOException(java.io.IOException) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) WriterProfile(com.bc.pmpheep.back.po.WriterProfile) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with WriterProfile

use of com.bc.pmpheep.back.po.WriterProfile in project pmph by BCSquad.

the class WriterProfileServiceTest method testUpdateWriterProfile.

@Test
@Rollback(Const.ISROLLBACK)
public void testUpdateWriterProfile() {
    WriterProfile writerProfile = new WriterProfile(2L, "物理学专家,机械工程学教授", "科研大赛冠军");
    writerProfileService.addWriterProfile(writerProfile);
    writerProfile.setId(writerProfile.getId());
    writerProfile.setTag("中科院名誉教授");
    Assert.assertTrue("数据更新失败", writerProfileService.updateWriterProfile(writerProfile) > 0);
}
Also used : WriterProfile(com.bc.pmpheep.back.po.WriterProfile) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 3 with WriterProfile

use of com.bc.pmpheep.back.po.WriterProfile in project pmph by BCSquad.

the class WriterProfileServiceTest method testGetWriterProfileById.

@Test
@Rollback(Const.ISROLLBACK)
public void testGetWriterProfileById() {
    WriterProfile writerProfile = new WriterProfile(3L, "物理学专家,机械工程学教授", "科研大赛冠军");
    writerProfileService.addWriterProfile(writerProfile);
    writerProfile.setId(writerProfile.getId());
    Assert.assertNotNull("数据获取失败", writerProfileService.getWriterProfileById(writerProfile.getId()));
}
Also used : WriterProfile(com.bc.pmpheep.back.po.WriterProfile) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 4 with WriterProfile

use of com.bc.pmpheep.back.po.WriterProfile in project pmph by BCSquad.

the class WriterUserServiceImpl method addWriterUserOfBack.

@Override
public String addWriterUserOfBack(WriterUser writerUser) throws CheckedServiceException {
    WriterUser username = writerUserDao.getUsername(writerUser.getUsername());
    if (username != null) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "用户代码已存在");
    }
    if (StringUtil.strLength(writerUser.getUsername()) > 20) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "用户名需要小于20字符");
    }
    if (StringUtil.strLength(writerUser.getRealname()) > 20) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "姓名需要小于20字符");
    }
    if (!StringUtil.isEmpty(writerUser.getHandphone())) {
        if (!ValidatUtil.checkMobileNumber(writerUser.getHandphone())) {
            throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "电话格式不正确");
        }
    }
    if (!StringUtil.isEmpty(writerUser.getEmail())) {
        if (!ValidatUtil.checkEmail(writerUser.getEmail())) {
            throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.ILLEGAL_PARAM, "邮箱格式不正确");
        }
    }
    if (StringUtil.isEmpty(writerUser.getUsername())) {
        throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "用户名为空");
    }
    if (StringUtil.isEmpty(writerUser.getRealname())) {
        writerUser.setRealname(writerUser.getUsername());
    }
    if (!StringUtil.isEmpty(writerUser.getNote())) {
        if (StringUtil.strLength(writerUser.getNote()) > 100) {
            throw new CheckedServiceException(CheckedExceptionBusiness.USER_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "备注需要小于100字符");
        }
    }
    // 后台添加用户设置默认密码为123456
    writerUser.setPassword(new DesRun("", Const.DEFAULT_PASSWORD).enpsw);
    writerUser.setNickname(writerUser.getUsername());
    // 后台添加新用户时,设置为默认头像
    writerUser.setAvatar(RouteUtil.DEFAULT_USER_AVATAR);
    writerUserDao.add(writerUser);
    Long num = writerUser.getId();
    String result = "FAIL";
    if (num > 0) {
        WriterProfile writerProfile = new WriterProfile();
        writerProfile.setUserId(num);
        writerProfileDao.addWriterProfile(writerProfile);
        result = "SUCCESS";
    }
    return result;
}
Also used : WriterProfile(com.bc.pmpheep.back.po.WriterProfile) DesRun(com.bc.pmpheep.back.util.DesRun) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) WriterUser(com.bc.pmpheep.back.po.WriterUser)

Example 5 with WriterProfile

use of com.bc.pmpheep.back.po.WriterProfile in project pmph by BCSquad.

the class WriterProfileServiceTest method testAddWriterProfile.

/*@Test
	@Rollback(Const.ISROLLBACK)
	public void testAllWriterProfile() {
		logger.info("----------作家简介与标签-----------");
		WriterProfile writerProfile = new WriterProfile(3L, "物理学专家,机械工程学教授", "科研大赛冠军");
		writerProfileService.addWriterProfile(writerProfile);
		Assert.assertTrue("数据添加失败", writerProfile.getId()>0);
		logger.info("-------数据添加成功---------");
		writerProfile.setTag("中科院名誉教授");
		Assert.assertTrue("数据更新失败", writerProfileService.updateWriterProfile(writerProfile)>0);
		logger.info("----------数据更新成功----------");
		Assert.assertNotNull("数据获取失败", writerProfileService.getWriterProfileById(writerProfile.getId()));
		logger.info("----------数据获取成功----------");
		Assert.assertTrue("删除数据失败", writerProfileService.deleteWriterProfileById(writerProfile.getId()) >= 0);
		logger.info("----------测试成功-----------");
	}*/
@Test
@Rollback(Const.ISROLLBACK)
public void testAddWriterProfile() {
    WriterProfile writerProfile = new WriterProfile(1L, "物理学专家,机械工程学教授", "科研大赛冠军");
    writerProfileService.addWriterProfile(writerProfile);
    Assert.assertTrue("数据添加失败", writerProfile.getId() > 0);
}
Also used : WriterProfile(com.bc.pmpheep.back.po.WriterProfile) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Aggregations

WriterProfile (com.bc.pmpheep.back.po.WriterProfile)6 BaseTest (com.bc.pmpheep.test.BaseTest)4 Test (org.junit.Test)4 Rollback (org.springframework.test.annotation.Rollback)4 WriterUser (com.bc.pmpheep.back.po.WriterUser)1 DesRun (com.bc.pmpheep.back.util.DesRun)1 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1