|
|
@ -21,10 +21,15 @@ import com.lzbi.draft.mapper.DcBusiTargetDraftMonthMapper; |
|
|
|
import com.lzbi.targetFolder.domain.DcBaseAssetTarget; |
|
|
|
import com.lzbi.targetFolder.mapper.DcBaseAssetTargetMapper; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.apache.commons.collections4.IteratorUtils; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.poi.ss.usermodel.*; |
|
|
|
import org.apache.poi.xssf.usermodel.*; |
|
|
|
import org.apache.poi.ss.usermodel.Cell; |
|
|
|
import org.apache.poi.ss.usermodel.CellType; |
|
|
|
import org.apache.poi.ss.usermodel.DataFormatter; |
|
|
|
import org.apache.poi.ss.usermodel.FormulaEvaluator; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFRow; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet; |
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
import org.springframework.util.CollectionUtils; |
|
|
@ -35,10 +40,7 @@ import javax.annotation.Resource; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.*; |
|
|
|
import java.util.concurrent.locks.Lock; |
|
|
|
import java.util.concurrent.locks.ReentrantLock; |
|
|
|
import java.util.regex.Pattern; |
|
|
@ -180,6 +182,7 @@ public class DcBusiTargetInputMasterService extends ServiceImpl<DcBusiTargetInpu |
|
|
|
// 获取单元格内容的类型
|
|
|
|
CellType cellType = cell.getCellType(); |
|
|
|
if (null != cellType && cellType.equals(CellType.FORMULA)) { |
|
|
|
cellList.add(""); |
|
|
|
// throw new RuntimeException("excel中不能存在公式!");
|
|
|
|
} else { |
|
|
|
cellList.add(formatter.formatCellValue(cell, formulaEvaluator)); |
|
|
@ -218,6 +221,7 @@ public class DcBusiTargetInputMasterService extends ServiceImpl<DcBusiTargetInpu |
|
|
|
Map<String, Map<String, DcBaseAssetTarget>> targetMap = new HashMap<>(); |
|
|
|
for (ProductionDailySheetReq productionDailySheetReq : list) { |
|
|
|
String name = productionDailySheetReq.getName(); |
|
|
|
name = name.trim(); |
|
|
|
DcBaseAssetInfo dcBaseAssetInfo = dcBaseAssetInfoMapper.selectDcBaseAssetInfoByAliasName(name); |
|
|
|
if (ObjectUtils.isEmpty(dcBaseAssetInfo)) { |
|
|
|
return AjaxResult.error(name + "sheet页没有对应的统计单元"); |
|
|
@ -235,6 +239,7 @@ public class DcBusiTargetInputMasterService extends ServiceImpl<DcBusiTargetInpu |
|
|
|
} |
|
|
|
for (ProductionDailySheetReq productionDailySheetReq : list) { |
|
|
|
String name = productionDailySheetReq.getName(); |
|
|
|
name = name.trim(); |
|
|
|
DcBaseAssetInfo dcBaseAssetInfo = assetMap.get(name); |
|
|
|
Map<String, DcBaseAssetTarget> dcBaseAssetTargetMap = targetMap.get(name); |
|
|
|
List<List<String>> data = productionDailySheetReq.getData(); |
|
|
@ -259,6 +264,15 @@ public class DcBusiTargetInputMasterService extends ServiceImpl<DcBusiTargetInpu |
|
|
|
break; |
|
|
|
} |
|
|
|
dayMap.put(day, j); |
|
|
|
} else if (Pattern.matches("\\d+[日小计]+", column)) { |
|
|
|
String day = column.substring(0, column.length() - 3); |
|
|
|
if (Integer.parseInt(day) > confirmReq.getDays()) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (dayMap.containsKey(day)) { |
|
|
|
break; |
|
|
|
} |
|
|
|
dayMap.put(day, j); |
|
|
|
} |
|
|
|
} |
|
|
|
sign = true; |
|
|
@ -273,7 +287,13 @@ public class DcBusiTargetInputMasterService extends ServiceImpl<DcBusiTargetInpu |
|
|
|
if (!ObjectUtils.isEmpty(dcBaseAssetTarget)) { |
|
|
|
dayMap.forEach((day, index) -> { |
|
|
|
String v = row.get(index); |
|
|
|
if (StringUtils.isNotBlank(v) && !v.contains("-")) { |
|
|
|
if (Pattern.matches(".*[-!@#$%^&*()_+={}\\[\\]\"<>/;':\\\\|`~].*", v)) { |
|
|
|
return; |
|
|
|
} |
|
|
|
if (v.contains(",")) { |
|
|
|
v = v.replaceAll(",", ""); |
|
|
|
} |
|
|
|
if (StringUtils.isNotBlank(v)) { |
|
|
|
DcBusiTargetInputSub dcBusiTargetInputSub = new DcBusiTargetInputSub(); |
|
|
|
dcBusiTargetInputSub.setTargetCode(dcBaseAssetTarget.getTargetCode()); |
|
|
|
dcBusiTargetInputSub.setTargetName(dcBaseAssetTarget.getTargetName()); |
|
|
@ -290,14 +310,13 @@ public class DcBusiTargetInputMasterService extends ServiceImpl<DcBusiTargetInpu |
|
|
|
dcBusiTargetInputSub.setTagetUnit(dcBaseAssetTarget.getFieldUnit()); |
|
|
|
dcBusiTargetInputSub.setDay(String.valueOf(day)); |
|
|
|
try { |
|
|
|
if (v.contains(",")) { |
|
|
|
v = v.replaceAll(",", ""); |
|
|
|
} |
|
|
|
BigDecimal bigDecimal = new BigDecimal(v); |
|
|
|
dcBusiTargetInputSub.setValResult(bigDecimal.setScale(4, BigDecimal.ROUND_HALF_EVEN)); |
|
|
|
} catch (RuntimeException e) { |
|
|
|
log.error("值转换错误,v:{}, AssetName:{},TargetName:{},day:{},index:{}", v, dcBaseAssetInfo.getAssetName(), dcBaseAssetTarget.getTargetName(), day, index); |
|
|
|
throw e; |
|
|
|
String format = "数值转换错误,sheet页:%s,指标:%s,日:%s,索引:%s,数据:%s"; |
|
|
|
String msg = String.format(format, dcBaseAssetInfo.getAssetNameAlias(), dcBaseAssetTarget.getTargetName(), day, index, v); |
|
|
|
log.error(msg, e); |
|
|
|
throw new RuntimeException(msg); |
|
|
|
} |
|
|
|
dcBusiTargetInputSub.setBillNoMaster(confirmReq.getBillNo()); |
|
|
|
result.add(dcBusiTargetInputSub); |
|
|
@ -346,8 +365,10 @@ public class DcBusiTargetInputMasterService extends ServiceImpl<DcBusiTargetInpu |
|
|
|
List<DcBusiTargetDraftDaynew> dcBusiTargetDraftDaynews = dcBusiTargetDraftDaynewMapper.selectDcBusiTargetDraftDaynewByTargetInput(master); |
|
|
|
if (!CollectionUtils.isEmpty(dcBusiTargetDraftDaynews)) { |
|
|
|
DcBusiTargetDraftDaynew dcBusiTargetDraftDaynew = dcBusiTargetDraftDaynews.get(0); |
|
|
|
String msg = "%s中,%s(指标)%s年%s月%s日,已存在"; |
|
|
|
throw new RuntimeException(String.format(msg, dcBusiTargetDraftDaynew.getAssetNameAlias(), dcBusiTargetDraftDaynew.getTagetName(), dcBusiTargetDraftDaynew.getDateYear(), dcBusiTargetDraftDaynew.getDateMonth(), dcBusiTargetDraftDaynew.getDateDay())); |
|
|
|
String format = "%s(sheet页)中,%s(指标)%s年%s月%s日,已存在"; |
|
|
|
String msg = String.format(format, dcBusiTargetDraftDaynew.getAssetNameAlias(), dcBusiTargetDraftDaynew.getTagetName(), dcBusiTargetDraftDaynew.getDateYear(), dcBusiTargetDraftDaynew.getDateMonth(), dcBusiTargetDraftDaynew.getDateDay()); |
|
|
|
log.error(msg); |
|
|
|
throw new RuntimeException(msg); |
|
|
|
} |
|
|
|
|
|
|
|
DcBusiTargetInputSub subParams = new DcBusiTargetInputSub(); |
|
|
@ -461,7 +482,19 @@ public class DcBusiTargetInputMasterService extends ServiceImpl<DcBusiTargetInpu |
|
|
|
if (!CollectionUtils.isEmpty(dateNewList)) { |
|
|
|
List<String> idList = dateNewList.stream().map(dcBusiTargetDraftDaynew -> String.valueOf(dcBusiTargetDraftDaynew.getId())).collect(Collectors.toList()); |
|
|
|
String[] ids = idList.toArray(new String[]{}); |
|
|
|
dcBusiTargetDraftDaynewMapper.deleteDcBusiTargetDraftDaynewByIds(ids); |
|
|
|
int len = ids.length; |
|
|
|
int range = 1000; |
|
|
|
int remainder = len % range; |
|
|
|
int count = len / range; |
|
|
|
String[] idsNew; |
|
|
|
for (int i = 0; i < count; i++) { |
|
|
|
idsNew = Arrays.copyOfRange(ids, i * range, (i + 1) * range); |
|
|
|
dcBusiTargetDraftDaynewMapper.deleteDcBusiTargetDraftDaynewByIds(idsNew); |
|
|
|
} |
|
|
|
if (remainder > 0) { |
|
|
|
idsNew = Arrays.copyOfRange(ids, count * range, len); |
|
|
|
dcBusiTargetDraftDaynewMapper.deleteDcBusiTargetDraftDaynewByIds(idsNew); |
|
|
|
} |
|
|
|
} |
|
|
|
DcBusiTargetInputSub subParams = new DcBusiTargetInputSub(); |
|
|
|
subParams.setBillNoMaster(billNo); |
|
|
|