mitao
2025-04-07 18891c60ab1c06a4acc85d0ec54dee50d1b1a19f
finance-system/src/main/java/com/finance/system/service/impl/TbBasicDataServiceImpl.java
@@ -29,6 +29,7 @@
import com.finance.common.utils.EasyExcelUtil;
import com.finance.common.utils.SecurityUtils;
import com.finance.common.utils.StringUtils;
import com.finance.system.constants.QuarterConstant;
import com.finance.system.domain.TbBasicData;
import com.finance.system.domain.TbBasicDataConfig;
import com.finance.system.domain.TbBasicDataConfigDetail;
@@ -128,6 +129,8 @@
            if (tbBasicDataField != null) {
                field.setValue(
                        tbBasicDataField.getFieldValue());
            } else {
                field.setValue("");
            }
            if (field.getChildren() != null && !field.getChildren().isEmpty()) {
                setFieldValues(field.getChildren(), fieldMap);
@@ -154,10 +157,13 @@
        LocalDate quarterStartLocalDate = instant.atZone(ZoneId.systemDefault()).toLocalDate();
        LocalDate fifteenDaysLimit = quarterStartLocalDate.plusDays(14);
        LocalDate now = LocalDate.now();
        vo.setQuarter(DateUtils.getNowQuarter());
        String previousQuarter = DateUtils.getPreviousQuarter();
        previousQuarter = QuarterConstant.CURRENT_QUARTER;
        DateUtils.getQuarterDate(previousQuarter);
        vo.setQuarter(previousQuarter);
        vo.setStatus(ReportingStatusEnum.UNFILLED);
        // 如果当前时间不在规定范围内:季度初1-15号 TODO
     /*   if (now.isBefore(quarterStartLocalDate) || now.isAfter(fifteenDaysLimit)) {
        // 如果当前时间不在规定范围内:季度初1-15号
        /*if (now.isBefore(quarterStartLocalDate) || now.isAfter(fifteenDaysLimit)) {
            return R.ok(vo, "请于季度初1-15号上传季度数据。");
        }*/
        // 查询是否有当前季度的填报记录
@@ -165,10 +171,10 @@
                this.getOne(
                        Wrappers.<TbBasicData>lambdaQuery()
                                .eq(TbBasicData::getDeptAreaCode, dept.getAreaCode())
                                .between(TbBasicData::getReportingTime, quarterStart, quarterEnd));
                                .eq(TbBasicData::getQuarter, previousQuarter));
        if (Objects.nonNull(basicData)) {
            vo.setCreateTime(basicData.getCreateTime());
            vo.setUpdateTime(basicData.getUpdateTime());
            vo.setFinishedTime(basicData.getUpdateTime());
        }
        // 查询需要填写的字段
        List<TbField> list =
@@ -193,7 +199,7 @@
            vo.setFields(roots);
        }
        if (Objects.isNull(basicData)) {
            vo.setQuarter(DateUtils.getNowQuarter());
            vo.setQuarter(previousQuarter);
            vo.setStatus(ReportingStatusEnum.UNFILLED);
            return R.ok(vo);
        } else {
@@ -226,7 +232,8 @@
        if (Objects.isNull(dto) || CollUtils.isEmpty(dto.getFields())) {
            return;
        }
        String nowQuarter = DateUtils.getNowQuarter();
        String previousQuarter = DateUtils.getPreviousQuarter();
        previousQuarter = QuarterConstant.CURRENT_QUARTER;
        // 查询需要填写的动态字段
        List<TbField> fieldList =
                tbFieldService.lambdaQuery().eq(TbField::getStatus, ShowStatusEnum.SHOW).list();
@@ -234,8 +241,10 @@
                fieldList.stream().collect(Collectors.toMap(TbField::getId, e -> e));
        Optional<TbBasicData> basicDataOpt = this.lambdaQuery()
                .eq(TbBasicData::getDeptAreaCode, areaCode)
                .eq(TbBasicData::getQuarter, nowQuarter).oneOpt();
                .eq(TbBasicData::getQuarter, previousQuarter).oneOpt();
        TbBasicData tbBasicData = BeanUtils.copyBean(dto, TbBasicData.class);
        tbBasicData.setCurrentGdp(tbBasicData.getCurrentGdp().replace(",", ""));
        tbBasicData.setTransferPaymentScale(tbBasicData.getTransferPaymentScale().replace(",", ""));
        if (basicDataOpt.isPresent()) {
            tbBasicData.setId(basicDataOpt.get().getId());
            tbBasicData.setDeptAreaCode(areaCode);
@@ -251,8 +260,8 @@
        } else {
            tbBasicData.setDeptAreaCode(areaCode);
            tbBasicData.setStatus(ReportingStatusEnum.MISSING_DATA);
            tbBasicData.setQuarter(nowQuarter);
            tbBasicData.setReportingTime(DateUtils.getQuarterDate(nowQuarter));
            tbBasicData.setQuarter(previousQuarter);
            tbBasicData.setReportingTime(DateUtils.getQuarterDate(previousQuarter));
            this.save(tbBasicData);
        }
        // 保存基础数据动态字段数据
@@ -329,6 +338,7 @@
                        && StringUtils.isNotEmpty(dto.getCurrentGdp()));
        if (flag) {
            tbBasicData.setStatus(ReportingStatusEnum.FILLED);
            tbBasicData.setFinishedTime(new Date());
            this.updateById(tbBasicData);
        }
        /*if (ReportingStatusEnum.FILLED.equals(tbBasicData.getStatus())) {
@@ -450,6 +460,7 @@
                        field.getFieldValue(), tbOperlogList, result.toString());
            }
        }
        tbOperLogService.saveBatch(tbOperlogList);
    }
    private static void wrapOperLog(LoginUser loginUser, TbBasicData tbBasicData, String before,
@@ -486,7 +497,8 @@
        }*/
        LoginUser loginUser = SecurityUtils.getLoginUser();
        String areaCode = loginUser.getUser().getAreaCode();
        String nowQuarter = DateUtils.getNowQuarter();
        String previousQuarter = DateUtils.getPreviousQuarter();
        previousQuarter = QuarterConstant.CURRENT_QUARTER;
        EasyExcel.read(
                        file.getInputStream(),
                        new BasicDataListener(
@@ -496,7 +508,7 @@
                                tbBasicDataFieldService,
                                tbBasicDataConfigService,
                                tbBasicDataConfigDetailService,
                                tbScoreService, tbDataScreenScoreService, nowQuarter,
                                tbScoreService, tbDataScreenScoreService, previousQuarter,
                                tbDataScreenConfigService,
                                asyncService))
                .sheet()
@@ -598,19 +610,21 @@
    }
    @Override
    public PageDTO<ScoreVO> pageScore(ScoreQuery query) {
    public PageDTO<ScoreVO> pageScore(ScoreQuery query) throws Exception {
        Page<ScoreVO> page = new Page<>(query.getPageNum(), query.getPageSize());
        SysUser user = SecurityUtils.getLoginUser().getUser();
        String areaCode = user.getAreaCode();
        Date date = new Date();
        Date quarterStart = DateUtil.beginOfQuarter(date);
        Date quarterEnd = DateUtil.endOfQuarter(date);
        String previousQuarter = DateUtils.getPreviousQuarter();
        // previousQuarter = "2024年一季度";
        // 查询是否有当前季度的填报记录
        TbBasicData basicData =
                this.getOne(
                        Wrappers.<TbBasicData>lambdaQuery()
                                .eq(TbBasicData::getDeptAreaCode, areaCode)
                                .between(TbBasicData::getReportingTime, quarterStart, quarterEnd));
                                .eq(TbBasicData::getQuarter, previousQuarter));
        if (Objects.isNull(basicData)) {
            return PageDTO.empty(page);
        }
@@ -774,11 +788,12 @@
        remark.setName("备注");
        roots.add(remark);
        vo.setFields(roots);
        String nowQuarter = DateUtils.getNowQuarter();
        String previousQuarter = DateUtils.getPreviousQuarter();
        // previousQuarter = "2024年一季度";
        // 查询上报的基础数据
        List<TbBasicData> basicDataList =
                this.lambdaQuery()
                        .eq(TbBasicData::getQuarter, nowQuarter)
                        .eq(TbBasicData::getQuarter, previousQuarter)
                        .eq(TbBasicData::getStatus, ReportingStatusEnum.FILLED)
                        .list();
        if (CollUtils.isNotEmpty(basicDataList)) {
@@ -942,7 +957,7 @@
        if (quarterLocalDate.isAfter(dateLocalDate) || quarterLocalDate.equals(dateLocalDate)) {
            throw new ServiceException("请导入过去季度的数据。");
        }
        long start = System.currentTimeMillis();
        EasyExcel.read(
                        file.getInputStream(),
                        new HistoryDataListener(
@@ -956,6 +971,7 @@
                .sheet()
                .headRowNumber(0)
                .doRead();
        log.info("历史数据导入完成,耗时{}毫秒", System.currentTimeMillis() - start);
    }
    @Override
@@ -1127,12 +1143,13 @@
        if (Objects.isNull(basicData)) {
            throw new ServiceException("非法参数");
        }
        String nowQuarter = DateUtils.getNowQuarter();
        this.updateById(basicData);
        // 查询该基础数据的动态字端
        // 查询需要填写的动态字段
        List<TbField> fieldList =
                tbFieldService.lambdaQuery().eq(TbField::getStatus, ShowStatusEnum.SHOW).list();
        Map<Long, TbField> allFieldMap = fieldList.stream()
                .collect(Collectors.toMap(TbField::getId, e -> e));
        List<TbBasicDataField> originFields = tbBasicDataFieldService.lambdaQuery()
                .eq(TbBasicDataField::getBasicDataId, basicData.getId()).list();
        Set<Long> fieldIdList = originFields.stream().map(TbBasicDataField::getFieldId)
@@ -1144,7 +1161,10 @@
                        BeanUtils.copyBean(dto, BasicDataDTO.class),
                        fieldMap));
        TbBasicData tbBasicData = BeanUtils.copyBean(dto, TbBasicData.class);
        tbBasicData.setCurrentGdp(tbBasicData.getCurrentGdp().replace(",", ""));
        tbBasicData.setTransferPaymentScale(tbBasicData.getTransferPaymentScale().replace(",", ""));
        tbBasicData.setDeptAreaCode(basicData.getDeptAreaCode());
        tbBasicData.setQuarter(basicData.getQuarter());
        // 保存基础数据动态字段数据
        List<TbBasicDataField> tbBasicDataFields =
                BeanUtils.copyList(dto.getFields(), TbBasicDataField.class);
@@ -1184,6 +1204,10 @@
                        if (StringUtils.isNotBlank(item.getFieldValue())) {
                            item.setFieldValue(item.getFieldValue().replace(",", ""));
                        }
                    } else {
                        TbField field = allFieldMap.get(item.getFieldId());
                        item.setFieldName(field.getFieldName());
                        item.setBasicDataId(basicData.getId());
                    }
                }).collect(Collectors.toList());
@@ -1382,7 +1406,7 @@
    @Override
    public List<FieldAndScoreDataVO> getFieldAndScoreData(String areaCode, String nowQuarter,
            Integer yearType) {
        return baseMapper.getFieldAndScoreData(areaCode, nowQuarter, yearType);
            Integer yearType, Integer isAll) {
        return baseMapper.getFieldAndScoreData(areaCode, nowQuarter, yearType, isAll);
    }
}