Commit d279d1fa authored by lcl's avatar lcl

u

parent e5aa03ac
package com.dsk.component;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.dsk.common.excel.ExcelUtils;
import com.dsk.common.exception.ServiceException;
import com.dsk.cscec.constant.CbProjectConstants;
import com.dsk.cscec.domain.CbProjectFile;
import com.dsk.cscec.domain.CbQuantitySummary;
import com.dsk.cscec.domain.bo.CbProjectBaseBo;
import com.dsk.cscec.service.CbProjectFileService;
import com.dsk.cscec.service.ICbQuantitySummaryActualService;
import com.dsk.cscec.service.ICbQuantitySummaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
import java.io.FileInputStream;
import java.util.List;
import java.util.stream.Collectors;
/**
* 数据解析组件
*
* @Author lcl
* @Data 2024/2/7 17:43
*/
@Component
public class DataAnalysisComponent {
@Autowired
private ICbQuantitySummaryService quantitySummaryService;
/**
* 工料汇总数据解析
*/
@Async
public void quantitySummaryDataAnalysis(CbProjectBaseBo bo) throws Exception {
//查询工料汇总导入文件
List<CbProjectFile> fileList = projectFileService.list(Wrappers.<CbProjectFile>lambdaQuery()
.eq(CbProjectFile::getProjectId, bo.getProjectId())
.eq(CbProjectFile::getCbType, CbProjectConstants.CB_TYPE_QUANTITY_SUMMARY)
.eq(CbProjectFile::getCbStage, bo.getCbStage()));
if (ObjectUtils.isEmpty(fileList)) return;
//文件处理
for (CbProjectFile file : fileList) {
if (file.getDelFlag() == 0) {
if (file.getFileParseStatus() == 3) break;
//文件下载
//解析数据
List<CbQuantitySummary> importList = new ExcelUtils<>(CbQuantitySummary.class).importExcelAllSheet(new FileInputStream(""), 1);
if (importList.isEmpty()) {
throw new ServiceException("表格中不存在待导入数据!");
}
importList = importList.stream().parallel()
.filter(item -> !ObjectUtils.isEmpty(item.getCbName()))
.peek(item -> {
item.setProjectId(1L);
item.setCbStage(0);
item.setCbProjectFileId(1L);
}).collect(Collectors.toList());
if (importList.isEmpty()) {
throw new ServiceException("表格中不存在有效数据数据!");
}
//分批次插入
if (importList.size() > 1000) {
int index = 0;
int sum = importList.size();
while (index < sum) {
List<CbQuantitySummary> divideList = importList.subList(index, Math.max((index + 1) * 1000, sum));
boolean b = quantitySummaryService.saveBatch(divideList);
if (!b) {
throw new ServiceException("数据插入失败!");
}
index += 1000;
}
} else {
boolean b = quantitySummaryService.saveBatch(importList);
if (!b) {
throw new ServiceException("数据插入失败!");
}
}
} else {
quantitySummaryService.remove(Wrappers.<CbQuantitySummary>lambdaQuery().eq(CbQuantitySummary::getCbProjectFileId, file.getId()));
}
}
}
@Autowired
private CbProjectFileService projectFileService;
}
......@@ -75,14 +75,5 @@ public class CbQuantitySummaryController extends BaseController {
return R.ok();
}
/**
* 数据导入
*/
@PostMapping(value = "/importData")
public R<Void> importFile(@RequestPart("file") MultipartFile file) throws Exception {
baseService.dataDealWith(new CbProjectBaseBo());
return R.ok();
}
}
......@@ -3,6 +3,7 @@ package com.dsk.cscec.domain;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
......@@ -134,6 +135,11 @@ public class CbQuantitySummary implements Serializable {
* 项目成本文件id
*/
private Long cbProjectFileId;
/**
* 删除状态(0:否、2:是)
*/
@TableLogic(value = "0", delval = "2")
private Integer delFalg;
}
......@@ -75,7 +75,7 @@ public class CbQuantitySummaryActual implements Serializable {
/**
* IPM作业编码
*/
private String ipmJobCode;
private String ipmBizCode;
}
package com.dsk.cscec.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dsk.common.core.mapper.BaseMapperPlus;
import com.dsk.cscec.domain.CbQuantitySummary;
import com.dsk.cscec.domain.bo.CbProjectBaseBo;
import com.dsk.cscec.domain.bo.CbQuantitySummaryListBo;
......@@ -17,7 +18,7 @@ import java.util.Map;
* @author lcl
* @since 2024-02-05 11:06:56
*/
public interface CbQuantitySummaryMapper extends BaseMapper<CbQuantitySummary> {
public interface CbQuantitySummaryMapper extends BaseMapperPlus<CbQuantitySummaryMapper,CbQuantitySummary,CbQuantitySummary> {
List<Map<String, Object>> selectSubject(CbProjectBaseBo bo);
......
......@@ -28,13 +28,5 @@ public interface ICbQuantitySummaryService extends IService<CbQuantitySummary> {
void pushData(CbQuantitySummaryActual bo);
/**
* 数据处理
*/
void dataDealWith(CbProjectBaseBo bo);
}
......@@ -2,21 +2,26 @@ package com.dsk.cscec.service.impl;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsk.common.excel.ExcelUtils;
import com.dsk.common.exception.ServiceException;
import com.dsk.cscec.constant.CbProjectConstants;
import com.dsk.cscec.domain.CbProjectFile;
import com.dsk.cscec.domain.CbQuantitySummary;
import com.dsk.cscec.domain.CbQuantitySummaryActual;
import com.dsk.cscec.domain.bo.CbProjectBaseBo;
import com.dsk.cscec.domain.bo.CbQuantitySummaryListBo;
import com.dsk.cscec.domain.vo.CbQuantitySummaryListVo;
import com.dsk.cscec.mapper.CbQuantitySummaryMapper;
import com.dsk.cscec.service.CbProjectFileService;
import com.dsk.cscec.service.ICbQuantitySummaryActualService;
import com.dsk.cscec.service.ICbQuantitySummaryService;
import jodd.bean.BeanException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;
......@@ -38,7 +43,7 @@ import java.util.stream.Collectors;
public class CbQuantitySummaryServiceImpl extends ServiceImpl<CbQuantitySummaryMapper, CbQuantitySummary> implements ICbQuantitySummaryService {
@Autowired
private ICbQuantitySummaryActualService actualService;
private ICbQuantitySummaryActualService baseActualService;
@Override
public Map<String, Object> subjectTree(CbProjectBaseBo bo) {
......@@ -78,7 +83,7 @@ public class CbQuantitySummaryServiceImpl extends ServiceImpl<CbQuantitySummaryM
if (ObjectUtils.isEmpty(actual.getQuantities())) throw new BeanException("工程量(本月用料)不能为空!");
if (ObjectUtils.isEmpty(actual.getRecordDate())) throw new BeanException("填写月份不能为空!");
actual.setId(ObjectUtils.isEmpty(actual.getId()) ? SecureUtil.md5(actual.getCbQuantitySummaryId() + actual.getRecordDate()) : actual.getId());
boolean b = actualService.saveOrUpdate(actual);
boolean b = baseActualService.saveOrUpdate(actual);
if (!b) {
log.error("CbQuantitySummaryServiceImpl.updateActual() data insert error! data:" + JSONUtil.toJsonStr(actual));
throw new ServiceException("数据添加错误!");
......@@ -90,43 +95,18 @@ public class CbQuantitySummaryServiceImpl extends ServiceImpl<CbQuantitySummaryM
@Transactional(rollbackFor = Exception.class)
public void pushData(CbQuantitySummaryActual bo) {
//数据记录
if(ObjectUtils.isEmpty(bo.getId())) throw new BeanException("id不能为空!");
if(ObjectUtils.isEmpty(bo.getPushQuantities())) throw new BeanException("推送工程量不能为空!");
if(ObjectUtils.isEmpty(bo.getIpmProjectCode())) throw new BeanException("IPM项目编码不能为空!");
if(ObjectUtils.isEmpty(bo.getIpmContractCode())) throw new BeanException("IPM合同编码不能为空!");
if(ObjectUtils.isEmpty(bo.getIpmJobCode())) throw new BeanException("IPM作业编码不能为空!");
boolean update = actualService.updateById(bo);
if(!update){
if (ObjectUtils.isEmpty(bo.getId())) throw new BeanException("id不能为空!");
if (ObjectUtils.isEmpty(bo.getPushQuantities())) throw new BeanException("推送工程量不能为空!");
if (ObjectUtils.isEmpty(bo.getIpmProjectCode())) throw new BeanException("IPM项目编码不能为空!");
if (ObjectUtils.isEmpty(bo.getIpmContractCode())) throw new BeanException("IPM合同编码不能为空!");
if (ObjectUtils.isEmpty(bo.getIpmBizCode())) throw new BeanException("IPM作业编码不能为空!");
boolean update = baseActualService.updateById(bo);
if (!update) {
log.error("CbQuantitySummaryServiceImpl.pushData() data update error! data:" + JSONUtil.toJsonStr(bo));
throw new ServiceException("数据添加错误!");
}
//TODO 推送数据
}
@Override
public void dataDealWith(CbProjectBaseBo bo) {
//识别Excel内容
List<CbQuantitySummary> importList = new ArrayList<>();
try {
importList = new ExcelUtils<>(CbQuantitySummary.class).importExcelAllSheet(new FileInputStream(""), 1);
} catch (Exception e) {
e.printStackTrace();
}
if (importList.isEmpty()) {
throw new ServiceException("表格中不存在待导入数据!");
}
importList = importList.stream().parallel()
.filter(item -> !ObjectUtils.isEmpty(item.getCbName()))
.peek(item -> {
item.setProjectId(1L);
item.setCbStage(0);
item.setCbProjectFileId(1L);
}).collect(Collectors.toList());
if (importList.isEmpty()) {
throw new ServiceException("表格中不存在有效数据数据!");
}
}
}
......@@ -8,7 +8,7 @@
from cb_subject cs1
join cb_subject cs2 on (cs2.cb_subject_no like concat(cs1.cb_subject_no,'%') and cs2.`level` = 2 )
join cb_subject cs3 on (cs3.cb_subject_no like concat(cs2.cb_subject_no,'%') and cs3.`level` = 3 )
join cb_quantity_summary cqs on (cqs.cb_subject_name = cs3.cb_subject_name and cqs.project_id = #{projectId} and cqs.cb_stage = #{cbStage})
join cb_quantity_summary cqs on (cqs.cb_subject_name = cs3.cb_subject_name and cqs.del_falg = 0 and cqs.project_id = #{projectId} and cqs.cb_stage = #{cbStage} )
where cs1.`level` = 1
group by cs1.cb_subject_name,cs2.cb_subject_name,cs3.cb_subject_name
</select>
......@@ -18,7 +18,7 @@
count(cqs.id)
from cb_quantity_summary cqs
left join cb_subject cs1 on cqs.cb_subject_name = cs1.cb_subject_name
where cqs.project_id = #{projectId} and cqs.cb_stage = #{cbStage} and cs1.id is null
where cqs.del_falg = 0 and cqs.project_id = #{projectId} and cqs.cb_stage = #{cbStage} and cs1.id is null
</select>
<select id="selectMonthList" resultType="java.lang.String">
......@@ -26,7 +26,7 @@
cqsa.record_date
from cb_quantity_summary cqs
join cb_quantity_summary_actual cqsa on cqs.id = cqsa.cb_quantity_summary_id
where cqs.project_id = #{projectId} and cqs.cb_stage = #{cbStage} and cqs.cb_subject_name = #{cbSubjectName}
where cqs.del_falg = 0 and cqs.project_id = #{projectId} and cqs.cb_stage = #{cbStage} and cqs.cb_subject_name = #{cbSubjectName}
group by cqsa.record_date
order by cqsa.record_date
</select>
......@@ -41,7 +41,7 @@
cqsa.id actualId, cqsa.ipm_project_code, cqsa.ipm_contract_code, cqsa.ipm_job_code, cqsa.push_quantities
from cb_quantity_summary cqs
left join cb_quantity_summary_actual cqsa on cqs.id = cqsa.cb_quantity_summary_id
where cqs.project_id = #{projectId} and cqs.cb_stage = #{cbStage} and cqs.cb_subject_name = #{cbSubjectName}
where cqs.del_falg = 0 and cqs.project_id = #{projectId} and cqs.cb_stage = #{cbStage} and cqs.cb_subject_name = #{cbSubjectName}
<if test="recordDate != null and recordDate != ''"> and cqsa.record_date &lt;= #{recordDate} </if>
order by cqsa.record_date desc
) a
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment