Search in sources :

Example 21 with WriterUser

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

the class TextbookServiceImpl method updateTextbookAndMaterial.

@Override
public Integer updateTextbookAndMaterial(Long[] ids, String sessionId, Long materialId) throws CheckedServiceException, Exception {
    // 获取当前用户
    PmphUser pmphUser = SessionUtil.getPmphUserBySessionId(sessionId);
    if (null == pmphUser || null == pmphUser.getId()) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MATERIAL, CheckedExceptionResult.NULL_PARAM, "请求用户不存在");
    }
    // if (!pmphUser.getIsAdmin()) {
    // throw new CheckedServiceException(CheckedExceptionBusiness.GROUP,
    // CheckedExceptionResult.ILLEGAL_PARAM,
    // "该用户没有操作权限");
    // }
    // 教材权限的检查
    List<PmphRole> pmphRoles = pmphUserService.getListUserRole(pmphUser.getId());
    Integer power = null;
    // 系统管理员权限检查
    for (PmphRole pmphRole : pmphRoles) {
        if (null != pmphRole && null != pmphRole.getRoleName() && "系统管理员".equals(pmphRole.getRoleName())) {
            // 我是系统管理原
            power = 1;
        }
    }
    // 教材主任检查
    Material material = materialService.getMaterialById(materialId);
    if (null == power) {
        if (null != material && null != material.getDirector() && pmphUser.getId().equals(material.getDirector())) {
            // 我是教材的主任
            power = 2;
        }
    }
    List<Textbook> textbooks = textbookDao.getTextbooks(ids);
    if (textbooks.size() > 0) {
        for (Textbook textbook : textbooks) {
            // 是否存在策划编辑
            if (ObjectUtil.isNull(textbook.getPlanningEditor())) {
                throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.NULL_PARAM, "还未选择策划编辑,不能进行公布");
            }
            // 是否发布主编
            if (!textbook.getIsChiefPublished()) {
                throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.NULL_PARAM, "还未发布主编/副主编,不能进行公布");
            }
            List<DecPosition> decPosition = decPositionService.getDecPositionByTextbookId(textbook.getId());
            // 是否确认编委
            if (decPosition.size() == 0) {
                throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK, CheckedExceptionResult.NULL_PARAM, "还未确认编委,不能进行公布");
            }
        }
    }
    Material materials = new Material();
    List<Long> textBookIds = new ArrayList<>(textbooks.size());
    for (Textbook textbook : textbooks) {
        // if(Const.TRUE==textbook.getIsPublished()){
        // throw new CheckedServiceException(CheckedExceptionBusiness.TEXTBOOK,
        // CheckedExceptionResult.ILLEGAL_PARAM,"名单已确认");
        // }
        // if(textbook.getIsPublished()) {
        Textbook textbook2 = new Textbook(textbook.getId(), textbook.getRevisionTimes().intValue() + 1).setIsPublished(true);
        textbook2.setRevisionTimes(textbook.getRevisionTimes().intValue() + 1);
        textbookDao.updateTextbook(textbook2);
        // }else {
        // Textbook textbook2 = new Textbook(textbook.getId(), 0).setIsPublished(true);
        // textbook2.setRevisionTimes(0) ;
        // textbookDao.updateTextbook(textbook2);
        // }
        materials.setId(textbook.getMaterialId());
        textBookIds.add(textbook.getId());
    }
    // textbookDao.updateBookPublished(textBooks);
    // textbookDao.updateTextbook(textbook);
    /**
     * 下面是发布更新最终结果表的数据
     */
    // 获取这些书的申报者
    List<DecPosition> lst = decPositionService.listDecPositionsByTextBookIds(textBookIds);
    // 这些书的被遴选者
    List<DecPositionPublished> decPositionPublishedLst = new ArrayList<DecPositionPublished>(lst.size());
    for (DecPosition decPosition : lst) {
        if (null == decPosition || null == decPosition.getChosenPosition() || decPosition.getChosenPosition() <= 0) {
            continue;
        }
        DecPositionPublished decPositionPublished = new DecPositionPublished();
        decPositionPublished.setPublisherId(pmphUser.getId());
        decPositionPublished.setDeclarationId(decPosition.getDeclarationId());
        decPositionPublished.setTextbookId(decPosition.getTextbookId());
        decPositionPublished.setPresetPosition(decPosition.getPresetPosition());
        decPositionPublished.setIsOnList(true);
        decPositionPublished.setChosenPosition(decPosition.getChosenPosition());
        decPositionPublished.setRank(decPosition.getRank());
        decPositionPublished.setSyllabusId(decPosition.getSyllabusId());
        decPositionPublished.setSyllabusName(decPosition.getSyllabusName());
        decPositionPublishedLst.add(decPositionPublished);
    }
    List<DecPositionPublished> olds = decPositionPublishedService.getDecPositionPublishedListByBookIds(textBookIds);
    List<DecPositionPublished> sends = new ArrayList<>();
    for (DecPositionPublished now : decPositionPublishedLst) {
        if (ObjectUtil.notNull(now.getRank())) {
            sends.add(now);
        } else {
            DecPositionPublished published = decPositionPublishedService.getDecPositionByDeclarationId(now.getDeclarationId(), now.getTextbookId());
            if (ObjectUtil.isNull(published)) {
                sends.add(now);
            }
            for (DecPositionPublished old : olds) {
                if (old.getDeclarationId().equals(now.getDeclarationId()) && old.getTextbookId().equals(now.getTextbookId())) {
                    if (!old.getChosenPosition().equals(now.getChosenPosition())) {
                        sends.add(now);
                    } else {
                        if (null == now.getRank() && null == now.getRank()) {
                        } else if (null != now.getRank() && null != now.getRank()) {
                            if (!now.getRank().equals(now.getRank())) {
                                sends.add(now);
                            }
                        } else {
                            sends.add(now);
                        }
                    }
                }
            }
        }
    }
    // 先删除dec_position_published表中的所有数据
    decPositionPublishedService.deleteDecPositionPublishedByBookIds(textBookIds);
    // 向dec_position_published插入新数据
    decPositionPublishedService.batchInsertDecPositionPublished(decPositionPublishedLst);
    /**
     * 发布更新最终结果表的数据 ---end ---
     */
    // List<Textbook> books = materialDao.getMaterialAndTextbook(materials);
    List<Textbook> books = textbookService.getTextbookByMaterialId(materials.getId());
    Integer count = 0;
    /* 通过遍历查看教材下面所有书籍是否公布,当数据全部公布则该教材改为最终公布 */
    for (Textbook book : books) {
        if (book.getIsPublished()) {
            count++;
        }
    }
    if (count == books.size()) {
        // 检查有没有再次公布
        PageResult<BookPositionVO> listBookPosition = this.listBookPosition(1, 9999999, null, null, null, materials.getId(), sessionId);
        boolean haveNo = true;
        for (BookPositionVO bookPositionVO : listBookPosition.getRows()) {
            if (bookPositionVO.getIsPublished() && bookPositionVO.getRepub()) {
                haveNo = false;
                break;
            }
        }
        if (haveNo) {
            count = materialDao.updateMaterialPublished(materials);
        }
    }
    // 发送消息
    for (Textbook textbook : textbooks) {
        systemMessageService.sendWhenPubfinalResult(textbook.getId(), sends);
    }
    // 当教材遴选结束时给为遴选上的用户推送消息
    Material material2 = materialService.getMaterialById(materialId);
    if (ObjectUtil.notNull(material2)) {
        if (material2.getIsAllTextbookPublished()) {
            List<Declaration> declaration = declarationService.getPositionChooseLossByMaterialId(materialId);
            systemMessageService.sendWhenPositionChooserLoss(materialId, declaration);
        }
    }
    // 遍历被遴选人发送动态 和被修改成专家
    for (DecPositionPublished decPositionPublished : decPositionPublishedLst) {
        if (null == decPositionPublished || null == decPositionPublished.getChosenPosition() || decPositionPublished.getChosenPosition() <= 0) {
            continue;
        }
        // 获取申报表
        Declaration declarationById = declarationService.getDeclarationById(decPositionPublished.getDeclarationId());
        // 修改成专家
        WriterUser writerUser = new WriterUser();
        writerUser.setId(declarationById.getUserId());
        writerUser.setIsExpert(true);
        writerUser.setRank(3);
        writerUserService.update(writerUser);
        // 获取书籍
        Textbook textbook = textbookService.getTextbookById(decPositionPublished.getTextbookId());
        // 作家遴选
        String showChosenPosition = "";
        if (decPositionPublished.getChosenPosition() != 0) {
            switch(decPositionPublished.getChosenPosition()) {
                case 1:
                    showChosenPosition = "编委";
                    break;
                case 2:
                    showChosenPosition = "副主编";
                    break;
                case 3:
                    showChosenPosition = "副主编,编委";
                    break;
                case 4:
                    showChosenPosition = "主编";
                    break;
                case 5:
                    showChosenPosition = "主编,编委";
                    break;
                case 6:
                    showChosenPosition = "主编,副主编";
                    break;
                case 7:
                    showChosenPosition = "主编,副主编,编委";
                    break;
                case 8:
                    showChosenPosition = "数字编委";
                    break;
                case 9:
                    showChosenPosition = "编委,数字编委";
                    break;
                case 10:
                    showChosenPosition = "副主编,数字编委";
                    break;
                case 11:
                    showChosenPosition = "副主编,编委,数字编委";
                    break;
                case 12:
                    showChosenPosition = "主编,数字编委";
                    break;
                case 13:
                    showChosenPosition = "主编,编委,数字编委";
                    break;
                case 14:
                    showChosenPosition = "主编,副主编,数字编委";
                    break;
                case 15:
                    showChosenPosition = "主编,副主编,编委,数字编委";
                    break;
                default:
                    break;
            }
        }
        // 添加动态信息
        WriterUserTrendst writerUserTrendst = new WriterUserTrendst();
        writerUserTrendst.setUserId(declarationById.getUserId());
        // 自己可见
        writerUserTrendst.setIsPublic(false);
        writerUserTrendst.setType(8);
        String detail = "";
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("title", CheckedExceptionBusiness.MATERIAL);
        map.put("content", "您已被遴选为《" + textbook.getTextbookName() + "》的" + showChosenPosition + "。");
        map.put("img", 1);
        detail = new Gson().toJson(map);
        writerUserTrendst.setDetail(detail);
        writerUserTrendst.setCmsContentId(null);
        writerUserTrendst.setBookId(declarationById.getMaterialId());
        writerUserTrendst.setBookCommentId(null);
        writerUserTrendstService.addWriterUserTrendst(writerUserTrendst);
    }
    return count;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) PmphRole(com.bc.pmpheep.back.po.PmphRole) Declaration(com.bc.pmpheep.back.po.Declaration) WriterUser(com.bc.pmpheep.back.po.WriterUser) WriterUserTrendst(com.bc.pmpheep.back.po.WriterUserTrendst) PmphUser(com.bc.pmpheep.back.po.PmphUser) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) Material(com.bc.pmpheep.back.po.Material) DecPositionPublished(com.bc.pmpheep.back.po.DecPositionPublished) BookPositionVO(com.bc.pmpheep.back.vo.BookPositionVO) DecPosition(com.bc.pmpheep.back.po.DecPosition) Textbook(com.bc.pmpheep.back.po.Textbook)

Example 22 with WriterUser

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

the class UserMessageServiceImpl method updateMyMessageDetail.

@Override
public MyMessageVO updateMyMessageDetail(Long id) throws CheckedServiceException {
    if (ObjectUtil.isNull(id)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "消息id为空!");
    }
    MyMessageVO myMessageVO = userMessageDao.getMyMessageDetail(id);
    switch(myMessageVO.getSenderType()) {
        case 0:
            myMessageVO.setSenderName("系统");
            break;
        case 1:
            PmphUser pmphUser = pmphUserService.get(myMessageVO.getSenderId());
            myMessageVO.setSenderAvatar(pmphUser.getAvatar());
            myMessageVO.setSenderName(pmphUser.getRealname());
            break;
        case 2:
            WriterUser writerUser = writerUserService.get(myMessageVO.getSenderId());
            myMessageVO.setSenderAvatar(writerUser.getAvatar());
            myMessageVO.setSenderName(writerUser.getRealname());
            break;
        case 3:
            // 现在没有机构用户
            break;
        default:
            throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "发送者类型不正确!");
    }
    Message message = messageService.get(myMessageVO.getMsgId());
    if (ObjectUtil.isNull(message)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.MESSAGE, CheckedExceptionResult.NULL_PARAM, "没有获取到消息详情");
    }
    myMessageVO.setContent(message.getContent());
    List<MessageAttachment> messageAttachments = messageAttachmentService.getMessageAttachmentByMsgId(myMessageVO.getMsgId());
    for (MessageAttachment messageAttachment : messageAttachments) {
        messageAttachment.setAttachment(RouteUtil.MONGODB_FILE + messageAttachment.getAttachment());
    }
    myMessageVO.setMessageAttachments(messageAttachments);
    UserMessage userMessage = new UserMessage();
    userMessage.setId(id);
    userMessage.setIsRead(true);
    userMessageDao.updateUserMessage(userMessage);
    return myMessageVO;
}
Also used : MessageAttachment(com.bc.pmpheep.back.po.MessageAttachment) UserMessage(com.bc.pmpheep.back.po.UserMessage) WebScocketMessage(com.bc.pmpheep.websocket.WebScocketMessage) Message(com.bc.pmpheep.general.po.Message) PmphUser(com.bc.pmpheep.back.po.PmphUser) MyMessageVO(com.bc.pmpheep.back.vo.MyMessageVO) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) UserMessage(com.bc.pmpheep.back.po.UserMessage) WriterUser(com.bc.pmpheep.back.po.WriterUser)

Example 23 with WriterUser

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

the class WriterLoginController method login.

/**
 * <pre>
 * 功能描述:登陆
 * 使用示范:
 *
 * &#64;param user
 * &#64;param model
 * &#64;return
 * </pre>
 */
@ResponseBody
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ResponseBean login(@RequestParam("username") String username, @RequestParam("password") String password, HttpServletRequest request) {
    logger.info("username => " + username);
    logger.info("password => " + password);
    Map<String, Object> resultMap = new HashMap<String, Object>();
    try {
        WriterUser writerUser = writerUserService.login(username, new DesRun("", password).enpsw);
        writerUser.setLoginType(Const.LOGIN_TYPE_WRITER);
        if (!RouteUtil.DEFAULT_USER_AVATAR.equals(writerUser.getAvatar())) {
            writerUser.setAvatar(RouteUtil.userAvatar(writerUser.getAvatar()));
        }
        // 根据用户Id查询对应权限Id
        List<Long> writerUserPermissionIds = writerUserService.getWriterUserPermissionByUserId(writerUser.getId());
        // 验证成功在Session中保存用户信息
        request.getSession().setAttribute(Const.SESSION_WRITER_USER, writerUser);
        // 验证成功在Session中保存用户Token信息
        request.getSession().setAttribute(Const.SEESION_WRITER_USER_TOKEN, new DesRun(password, username).enpsw);
        resultMap.put(Const.USER_SEESION_ID, new DesRun("", request.getSession().getId()).enpsw);
        resultMap.put(Const.SESSION_WRITER_USER, writerUser);
        resultMap.put(Const.SEESION_WRITER_USER_TOKEN, new DesRun(password, username).enpsw);
        resultMap.put("writerUserPermissionIds", writerUserPermissionIds);
        return new ResponseBean(resultMap);
    } catch (CheckedServiceException cException) {
        return new ResponseBean(cException);
    }
}
Also used : HashMap(java.util.HashMap) DesRun(com.bc.pmpheep.back.util.DesRun) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) WriterUser(com.bc.pmpheep.back.po.WriterUser) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with WriterUser

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

the class WriterUserController method resources.

/**
 * <pre>
 * 功能描述:根据用户 id 跳转到用户权限的列表页面
 * 使用示范:
 *
 * &#64;param userId
 * &#64;param model
 * &#64;return
 * </pre>
 */
@ResponseBody
@LogDetail(businessType = BUSSINESS_TYPE, logRemark = "跳转到用户权限的列表页面")
@RequestMapping(value = "/resources/{id}", method = RequestMethod.GET)
public ResponseBean resources(@PathVariable("id") Long userId) {
    Map<String, Object> result = new HashMap<String, Object>();
    List<WriterPermission> resourceList = writerUserService.getListAllResource(userId);
    WriterUser user = writerUserService.get(userId);
    result.put("resources", resourceList);
    result.put("user", user);
    return new ResponseBean(result);
}
Also used : WriterPermission(com.bc.pmpheep.back.po.WriterPermission) HashMap(java.util.HashMap) ResponseBean(com.bc.pmpheep.controller.bean.ResponseBean) WriterUser(com.bc.pmpheep.back.po.WriterUser) LogDetail(com.bc.pmpheep.annotation.LogDetail) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 25 with WriterUser

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

the class MigrationStageOne method writerUser.

protected void writerUser() {
    String tableName = "sys_user";
    String sql = "SELECT a.userid,a.usercode,a.`password`,a.isvalid,d.new_pk org_new_pk,a.username,b.sex," + "b.birthdate,b.seniority,b.unitid,b.duties,b.positional,b.fax,b.handset,b.phone,b.idcard,b.email," + "b.address,b.postcode," + "CASE WHEN b.usertype=4 THEN 1 WHEN b.usertype=1 OR b.usertype=6 THEN 2 " + "WHEN b.usertype=5 OR b.usertype=7 THEN 3 ELSE 0 END rank," + "CASE WHEN b.isteacher=2 THEN 1 ELSE 0 END is_teacher,f.filedir,b.teacherauditdate," + "CASE WHEN g.sysflag=0 THEN 1 WHEN g.sysflag=1 THEN 2 END auth_user_type," + "g.new_pk auth_user_id," + "CASE WHEN b.usertype=1 OR b.usertype=6 THEN 1 ELSE 0 END is_writer," + "CASE WHEN b.usertype=5 OR b.usertype=7 THEN 1 ELSE 0 END is_expert," + "e.filedir avatar,b.usersign,a.memo,a.sortno " + "FROM sys_user a " + "LEFT JOIN sys_userext b ON a.userid = b.userid " + "LEFT JOIN sys_userorganize c ON b.userid = c.userid " + "LEFT JOIN ba_organize d ON c.orgid = d.orgid " + "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))e " + "ON a.userid = e.operuserid " + "LEFT JOIN (SELECT * FROM pub_addfileinfo y WHERE y.fileid IN (SELECT MAX(p.fileid) " + "FROM pub_addfileinfo p WHERE p.childsystemname='sys_userext_teacher' GROUP BY p.operuserid))f " + "ON a.userid = f.operuserid " + "LEFT JOIN sys_user g ON b.teacheraudituser = g.userid " + "WHERE a.sysflag=1 AND b.usertype !=2 ;";
    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 };
    StringBuilder reason = new StringBuilder();
    StringBuilder dealWith = new StringBuilder();
    for (Map<String, Object> map : maps) {
        StringBuilder sb = new StringBuilder();
        String userId = (String) map.get("userid");
        String username = (String) map.get("usercode");
        if (StringUtil.isEmpty(username)) {
            map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("未找到用户的登陆名。"));
            excel.add(map);
            if (state[1] == 0) {
                reason.append("未找到用户的登陆账号。");
                dealWith.append("放弃迁入。");
                state[1] = 1;
            }
            continue;
        }
        username = username.replace("&middot;", "·");
        if ("admin".equals(username)) {
            map.put(SQLParameters.EXCEL_EX_HEADER, "系统管理员账号。");
            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[2] == 0) {
                reason.append("用户的登录名重复。");
                dealWith.append("放弃迁入。");
                state[2] = 1;
            }
            continue;
        }
        list.add(username);
        String password = "888888";
        Integer isDisabled = (Integer) map.get("isvalid");
        Long orgid = (Long) map.get("org_new_pk");
        String realName = (String) map.get("username");
        if (StringUtil.isEmpty(realName)) {
            realName = username;
        }
        String sexNum = (String) map.get("sex");
        Integer sex = 0;
        if (StringUtil.notEmpty(sexNum)) {
            sex = Integer.parseInt(sexNum);
        }
        Date birthday = (Date) map.get("birthdate");
        String experienceNum = (String) map.get("seniority");
        if (JdbcHelper.judgeExperience(experienceNum)) {
            // 如果教龄数据不符合规范,调用公共方法将其转变为合乎规范的数据
            experienceNum = JdbcHelper.correctExperience(experienceNum);
            if ("0".equals(experienceNum)) {
                map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("此教龄数据没有值,为“无”,“、”," + "“其他”或数字远远超出人的寿命,无法通过合适方法修改插入新数据库,"));
                excel.add(map);
                if (state[3] == 0) {
                    reason.append("教龄数据不合规范。");
                    dealWith.append("经过合理规则转换迁入数据库。");
                    state[3] = 1;
                }
            }
        }
        Integer experience = Integer.parseInt(experienceNum);
        String workPlace = (String) map.get("unitid");
        if (StringUtil.notEmpty(workPlace) && ("null".equals(workPlace) || "nu".equals(workPlace))) {
            workPlace = "-";
        }
        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 = "-";
        }
        Long rankNum = (Long) map.get("rank");
        Integer rank = 0;
        if (ObjectUtil.notNull(rankNum)) {
            rank = rankNum.intValue();
        }
        String cert = (String) map.get("filedir");
        Timestamp authTime = (Timestamp) map.get("teacherauditdate");
        Long isTeacher = (Long) map.get("is_teacher");
        Long authUserTypeNum = (Long) map.get("auth_user_type");
        Integer authUserType = 0;
        if (ObjectUtil.notNull(authUserTypeNum)) {
            authUserType = authUserTypeNum.intValue();
        }
        Long authUserId = (Long) map.get("auth_user_id");
        Long isWriter = (Long) map.get("is_writer");
        Long isExpert = (Long) map.get("is_expert");
        String avatar = (String) map.get("avatar");
        String signature = (String) map.get("usersign");
        String note = (String) map.get("memo");
        if (StringUtil.notEmpty(note) && ("null".equals(note) || "nu".equals(note))) {
            note = "-";
        }
        Integer sort = (Integer) map.get("sortno");
        // 此重复用户只能通过个人信息多少判断保留,保留个人信息较全的一条,另一条删除
        if (("王训".equals(realName) || "赵舒武".equals(realName)) && ObjectUtil.isNull(sort)) {
            map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("已删除"));
            excel.add(map);
            if (state[4] == 0) {
                reason.append("用户重复。");
                dealWith.append("放弃迁入。");
                state[4] = 1;
            }
            continue;
        }
        if (ObjectUtil.notNull(sort) && sort < 0) {
            sort = 999;
        }
        WriterUser writerUser = new WriterUser();
        writerUser.setUsername(username);
        writerUser.setNickname(username);
        writerUser.setPassword(password);
        writerUser.setIsDisabled(isDisabled != 1);
        writerUser.setOrgId(orgid);
        writerUser.setRealname(realName);
        writerUser.setSex(sex);
        writerUser.setBirthday(birthday);
        writerUser.setExperience(experience);
        writerUser.setWorkPlace(workPlace);
        writerUser.setPosition(position);
        writerUser.setTitle(title);
        writerUser.setFax(fax);
        writerUser.setHandphone(handphone);
        writerUser.setTelephone(telephone);
        writerUser.setIdcard(idcard);
        writerUser.setEmail(email);
        writerUser.setAddress(address);
        writerUser.setPostcode(postcode);
        writerUser.setRank(rank);
        writerUser.setIsTeacher(isTeacher == 1);
        writerUser.setAuthTime(authTime);
        writerUser.setAuthUserType(authUserType);
        writerUser.setAuthUserId(authUserId);
        writerUser.setIsWriter(isWriter == 1);
        writerUser.setIsExpert(isExpert == 1);
        writerUser.setAvatar("DEFAULT");
        writerUser.setSignature(signature);
        writerUser.setNote(note);
        writerUser.setSort(sort);
        if (writerUser.getIsTeacher() && ObjectUtil.isNull(writerUser.getAuthTime())) {
            map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("认证通过但认证时间为空。"));
            excel.add(map);
            if (state[5] == 0) {
                reason.append("认证通过但认证时间为空。");
                dealWith.append("依据客户要求照常迁入数据库。");
                state[5] = 1;
            }
        }
        writerUser = writerUserService.add(writerUser);
        Long pk = writerUser.getId();
        JdbcHelper.updateNewPrimaryKey(tableName, pk, "userid", userId);
        JdbcHelper.updateNewPrimaryKey("sys_userext", pk, "userid", userId);
        count++;
        if (StringUtil.notEmpty(cert)) {
            String certMongoId;
            try {
                certMongoId = fileService.migrateFile(cert, ImageType.WRITER_USER_CERT, pk);
            } catch (IOException ex) {
                certMongoId = "DEFAULT";
                logger.error("文件读取异常,路径<{}>,异常信息:{}", cert, ex.getMessage());
                map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("教师资格证文件读取异常。"));
                excel.add(map);
                if (state[6] == 0) {
                    reason.append("教师资格证文件丢失。");
                    dealWith.append("设为默认图片迁入数据库。");
                    state[6] = 1;
                }
            }
            writerUser.setCert(certMongoId);
        }
        if (StringUtil.notEmpty(avatar)) {
            String avatarMongoId;
            try {
                avatarMongoId = fileService.migrateFile(avatar, ImageType.WRITER_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[7] == 0) {
                    reason.append("作家用户头像丢失。");
                    dealWith.append("设为默认头像迁入数据库。");
                    state[7] = 1;
                }
            }
            writerUser.setAvatar(avatarMongoId);
        }
        writerUser.setPassword(null);
        writerUserService.update(writerUser);
        if (null == map.get("exception")) {
            correctCount++;
        }
    }
    if (excel.size() > 0) {
        try {
            excelHelper.exportFromMaps(excel, "作家用户表", "writer_user");
        } catch (IOException ex) {
            logger.error("异常数据导出到Excel失败", ex);
        }
    }
    if (correctCount != maps.size()) {
        result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "writer_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("writer_user表迁移完成");
    logger.info("原数据库表共有{}条数据,迁移了{}条数据", maps.size(), count);
    // 记录信息
    Map<String, Object> msg = new HashMap<String, Object>();
    msg.put("result", "writer_user表迁移完成" + count + "/" + maps.size());
    SQLParameters.STATISTICS.add(msg);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Timestamp(java.sql.Timestamp) LinkedList(java.util.LinkedList) WriterPoint(com.bc.pmpheep.back.po.WriterPoint) Date(java.util.Date) LinkedHashMap(java.util.LinkedHashMap) WriterUser(com.bc.pmpheep.back.po.WriterUser) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

WriterUser (com.bc.pmpheep.back.po.WriterUser)49 BaseTest (com.bc.pmpheep.test.BaseTest)26 Test (org.junit.Test)26 Rollback (org.springframework.test.annotation.Rollback)24 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)17 ArrayList (java.util.ArrayList)14 PmphUser (com.bc.pmpheep.back.po.PmphUser)11 UserMessage (com.bc.pmpheep.back.po.UserMessage)7 OrgUser (com.bc.pmpheep.back.po.OrgUser)6 WebScocketMessage (com.bc.pmpheep.websocket.WebScocketMessage)6 DesRun (com.bc.pmpheep.back.util.DesRun)4 Message (com.bc.pmpheep.general.po.Message)4 HashMap (java.util.HashMap)4 PageResult (com.bc.pmpheep.back.plugin.PageResult)3 MyMessageVO (com.bc.pmpheep.back.vo.MyMessageVO)3 PageParameter (com.bc.pmpheep.back.plugin.PageParameter)2 Material (com.bc.pmpheep.back.po.Material)2 MessageAttachment (com.bc.pmpheep.back.po.MessageAttachment)2 Org (com.bc.pmpheep.back.po.Org)2 PmphRole (com.bc.pmpheep.back.po.PmphRole)2