Search in sources :

Example 1 with WriterPoint

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

the class MigrationStageOne method writerPoint.

protected void writerPoint() {
    String tableName = "sys_user";
    String sql = "select sysu.*,sysu.new_pk id from sys_user sysu " + "left join sys_userext sysue ON sysu.userid = sysue.userid " + "where sysu.sysflag=1 and sysue.usertype !=2";
    List<Map<String, Object>> maps = JdbcHelper.getJdbcTemplate().queryForList(sql);
    Map<String, Object> result = new LinkedHashMap<>();
    // 迁移成功的条目数
    int count = 0;
    // 统计正常数据的数量
    int correctCount = 0;
    int[] state = { 0 };
    StringBuilder reason = new StringBuilder();
    StringBuilder dealWith = new StringBuilder();
    List<Map<String, Object>> excel = new LinkedList<>();
    for (Map<String, Object> map : maps) {
        StringBuilder sb = new StringBuilder();
        // 旧表主键值
        String id = (String) map.get("userid");
        // 用户id
        Long userId = (Long) map.get("id");
        WriterPoint writerPoint = new WriterPoint();
        if (ObjectUtil.isNull(userId) || userId.intValue() == 0) {
            map.put(SQLParameters.EXCEL_EX_HEADER, sb.append("未找到用户id对应的关联结果。"));
            excel.add(map);
            logger.debug("未找到用户id对应的关联结果,此结果将被记录在Excel中");
            if (state[0] == 0) {
                reason.append("未找到用户的积分。");
                dealWith.append("放弃迁入。");
                state[0] = 1;
            }
            continue;
        }
        writerPoint.setUserId(userId);
        writerPoint.setTotal(0);
        writerPoint.setGain(0);
        writerPoint.setLoss(0);
        writerPoint = writerPointService.addWriterPoint(writerPoint);
        long pk = writerPoint.getId();
        JdbcHelper.updateNewPrimaryKey(tableName, pk, "userid", id);
        count++;
        if (null == map.get("exception")) {
            correctCount++;
        }
    }
    if (excel.size() > 0) {
        try {
            excelHelper.exportFromMaps(excel, "用户积分表", "writer_point");
        } catch (IOException ex) {
            logger.error("异常数据导出到Excel失败", ex);
        }
    }
    if (correctCount != maps.size()) {
        result.put(SQLParameters.EXCEL_HEADER_TABLENAME, "writer_point");
        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_point表迁移完成");
    logger.info("原数据库表共有{}条数据,迁移了{}条数据", maps.size(), count);
    // 记录信息
    Map<String, Object> msg = new HashMap<String, Object>();
    msg.put("result", "writer_point表迁移完成" + count + "/" + maps.size());
    SQLParameters.STATISTICS.add(msg);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IOException(java.io.IOException) WriterPoint(com.bc.pmpheep.back.po.WriterPoint) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) WriterPoint(com.bc.pmpheep.back.po.WriterPoint)

Example 2 with WriterPoint

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

the class WriterPointServiceTest method getListWriterPoint.

@SuppressWarnings({ "unused", "rawtypes", "unchecked" })
@Test
@Rollback(Const.ISROLLBACK)
public void getListWriterPoint() {
    WriterPoint writerPoint = this.addWriterPoints();
    PageParameter pageParameter = new PageParameter<>();
    PageResult pageResult = new PageResult<>();
    WriterPointVO writerPointVO = new WriterPointVO();
    pageParameter.setParameter(writerPointVO);
    pageParameter.setPageSize(10);
    pageResult = writerPointService.getListWriterPoint(pageParameter);
    Assert.assertNotNull("分页数据失败", pageResult);
}
Also used : WriterPointVO(com.bc.pmpheep.back.vo.WriterPointVO) PageParameter(com.bc.pmpheep.back.plugin.PageParameter) WriterPoint(com.bc.pmpheep.back.po.WriterPoint) PageResult(com.bc.pmpheep.back.plugin.PageResult) Test(org.junit.Test) BaseTest(com.bc.pmpheep.test.BaseTest) Rollback(org.springframework.test.annotation.Rollback)

Example 3 with WriterPoint

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

the class WriterPointLogServiceImpl method addWriterPointLogByRuleName.

@Override
public void addWriterPointLogByRuleName(String ruleName, Long userId) throws CheckedServiceException {
    if (StringUtil.isEmpty(ruleName)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.WRITER_POINT_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "规则名称为空");
    }
    if (ObjectUtil.isNull(userId)) {
        throw new CheckedServiceException(CheckedExceptionBusiness.WRITER_POINT_MANAGEMENT, CheckedExceptionResult.NULL_PARAM, "作者Id为空");
    }
    // 获取积分规则
    WriterPointRule writerPointRuleVOs = writerPointRuleService.getWriterPointRuleByName(ruleName);
    if (null != writerPointRuleVOs) {
        if (writerPointRuleVOs.getIsDisabled() == false) {
            // 查询用户之前的积分值
            List<WriterPointLog> writerPointLog2 = this.getWriterPointLogByUserId(userId);
            WriterPointLog writerPointLog = new WriterPointLog();
            // 现在的规则的积分值+以前的积分
            // 获取的总积分
            Integer temp = 0;
            if (!writerPointLog2.isEmpty()) {
                // 以前的总积分
                Integer newTemp = 0;
                // 遍历以前获取的积分
                for (WriterPointLog writerPointLogNew : writerPointLog2) {
                    newTemp += writerPointLogNew.getPoint();
                }
                temp = writerPointRuleVOs.getPoint() + newTemp;
            } else {
                temp = writerPointRuleVOs.getPoint();
            }
            writerPointLog.setPoint(writerPointRuleVOs.getPoint());
            // 积分规则id
            writerPointLog.setRuleId(writerPointRuleVOs.getId());
            writerPointLog.setUserId(userId);
            // 增加积分记录
            this.add(writerPointLog);
            // 查询用户积分
            WriterPoint point = writerPointService.getWriterPointByUserId(userId);
            if (ObjectUtil.notNull(point)) {
                writerPointService.updateWriterPoint(new WriterPoint(point.getId(), userId, temp + point.getLoss(), temp, point.getLoss()));
            } else {
                writerPointService.addWriterPoint(new WriterPoint(userId, temp, temp, 0));
            }
        }
    }
}
Also used : CheckedServiceException(com.bc.pmpheep.service.exception.CheckedServiceException) WriterPointRule(com.bc.pmpheep.back.po.WriterPointRule) WriterPointLog(com.bc.pmpheep.back.po.WriterPointLog) WriterPoint(com.bc.pmpheep.back.po.WriterPoint)

Aggregations

WriterPoint (com.bc.pmpheep.back.po.WriterPoint)3 PageParameter (com.bc.pmpheep.back.plugin.PageParameter)1 PageResult (com.bc.pmpheep.back.plugin.PageResult)1 WriterPointLog (com.bc.pmpheep.back.po.WriterPointLog)1 WriterPointRule (com.bc.pmpheep.back.po.WriterPointRule)1 WriterPointVO (com.bc.pmpheep.back.vo.WriterPointVO)1 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)1 BaseTest (com.bc.pmpheep.test.BaseTest)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 Test (org.junit.Test)1 Rollback (org.springframework.test.annotation.Rollback)1