|
@@ -20,27 +20,31 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
+import org.springblade.core.excel.util.ExcelUtil;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
import org.springblade.core.mp.support.Query;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
+import org.springblade.core.tool.utils.BeanUtil;
|
|
|
+import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
import org.springblade.meter.dto.MaterialMeterFormDTO;
|
|
|
-import org.springblade.meter.entity.AttachmentForm;
|
|
|
-import org.springblade.meter.entity.ContractMeterPeriod;
|
|
|
-import org.springblade.meter.entity.MaterialMeterForm;
|
|
|
-import org.springblade.meter.entity.MeterPeriod;
|
|
|
+import org.springblade.meter.entity.*;
|
|
|
+import org.springblade.meter.excel.MaterialMeterFormExcel;
|
|
|
import org.springblade.meter.mapper.MaterialMeterFormMapper;
|
|
|
-import org.springblade.meter.service.IAttachmentFormService;
|
|
|
-import org.springblade.meter.service.IMaterialMeterFormService;
|
|
|
+import org.springblade.meter.service.*;
|
|
|
import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
-import org.springblade.meter.service.IMeterPeriodService;
|
|
|
import org.springblade.meter.vo.MaterialMeterFormVO;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 材料计量单 服务实现类
|
|
@@ -56,6 +60,10 @@ public class MaterialMeterFormServiceImpl extends BaseServiceImpl<MaterialMeterF
|
|
|
|
|
|
private final IMeterPeriodService meterPeriodService;
|
|
|
|
|
|
+ private final IContractMaterialService contractMaterialService;
|
|
|
+
|
|
|
+ private final MeterContractInfoService meterContractInfoService;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 新增 材料计量单
|
|
@@ -159,4 +167,93 @@ public class MaterialMeterFormServiceImpl extends BaseServiceImpl<MaterialMeterF
|
|
|
this.removeById(id);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R<String> importExcel(MultipartFile file, Long projectId, Long contractId,Long meterPeriodId) {
|
|
|
+ //获取计量期信息
|
|
|
+ MeterPeriod period = meterPeriodService.getById(meterPeriodId);
|
|
|
+ if (ObjectUtil.isEmpty(period)){
|
|
|
+ throw new ServiceException("未获取到计量期相关信息");
|
|
|
+ }
|
|
|
+ if (period.getApproveStatus() != 0){
|
|
|
+ throw new ServiceException("当前材料计量期不是未上报状态,不能导入材料计量单");
|
|
|
+ }
|
|
|
+ //获取当前合同段所有材料
|
|
|
+ List<ContractMaterial> materials = contractMaterialService.list(new LambdaQueryWrapper<ContractMaterial>()
|
|
|
+ .eq(ContractMaterial::getContractId, contractId));
|
|
|
+ if (ObjectUtil.isEmpty(materials)){
|
|
|
+ throw new ServiceException("当前合同段没有材料");
|
|
|
+ }
|
|
|
+ Map<String, ContractMaterial> materialMap = materials.stream().collect(Collectors.toMap(l -> l.getMaterialName(), l -> l));
|
|
|
+ //获取后管合同段材料支付比例
|
|
|
+ MeterContractInfo one = meterContractInfoService.getOne(new LambdaQueryWrapper<MeterContractInfo>()
|
|
|
+ .eq(MeterContractInfo::getContractId, contractId));
|
|
|
+ if (ObjectUtil.isEmpty(one) || ObjectUtil.isEmpty(one.getClPrepaymentRatio())){
|
|
|
+ throw new ServiceException("当前合同段未设置材料预付款比例");
|
|
|
+ }
|
|
|
+ //校验文件类型
|
|
|
+ String filename = file.getOriginalFilename();
|
|
|
+ String fileSuffix = filename.substring(filename.lastIndexOf(".")+1);
|
|
|
+ try {
|
|
|
+ if (!"xlsx".contains(fileSuffix)) {
|
|
|
+ throw new ServiceException("请传入excel文件,或者先转换为xlsx");
|
|
|
+ }
|
|
|
+ List<MaterialMeterFormExcel> excels = ExcelUtil.read(file, MaterialMeterFormExcel.class);
|
|
|
+ excels = excels.stream()
|
|
|
+ .filter(l -> (StringUtils.isNotBlank(l.getContractMaterialName())))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (excels == null || excels.size() == 0) {
|
|
|
+ throw new ServiceException("未检测到excel中材料计量单数据,请检查格式后后重新导入");
|
|
|
+ }
|
|
|
+ excels.forEach(l->{
|
|
|
+ if (StringUtils.isBlank(l.getMaterialConformName()) || l.getMaterialConformName().equals("否")){
|
|
|
+ l.setMaterialConform(0);
|
|
|
+ }else {
|
|
|
+ l.setMaterialConform(1);
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(l.getStorageConformName()) || l.getStorageConformName().equals("否")){
|
|
|
+ l.setStorageConform(0);
|
|
|
+ }else {
|
|
|
+ l.setStorageConform(1);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //复制数据
|
|
|
+ List<MaterialMeterForm> forms = BeanUtil.copy(excels, MaterialMeterForm.class);
|
|
|
+ //循环数据
|
|
|
+ forms.stream().forEach(l -> {
|
|
|
+ /** 校验字段 */
|
|
|
+ if (StringUtils.isBlank(l.getMaterialArriveNumber()) || StringUtils.isBlank(l.getContractMaterialName()) || ObjectUtil.isEmpty(l.getBusinessDate())) {
|
|
|
+ throw new ServiceException("excel中有必填项未填写,请检查(材料到场编号,合同材料,业务日期)后重新导入");
|
|
|
+ }
|
|
|
+ if (l.getPrice() == null || l.getMeterAmount() == null) {
|
|
|
+ throw new ServiceException("请填写单价和数量");
|
|
|
+ }
|
|
|
+ ContractMaterial material = materialMap.get(l.getContractMaterialName());
|
|
|
+ if (ObjectUtil.isEmpty(material)){
|
|
|
+ throw new ServiceException("当前合同段没有材料:"+l.getContractMaterialName());
|
|
|
+ }
|
|
|
+ /** 补充字段 */
|
|
|
+ l.setProjectId(projectId);
|
|
|
+ l.setContractId(contractId);
|
|
|
+ l.setMeterPeriodId(period.getId());
|
|
|
+ l.setPeriodNumber(period.getPeriodNumber());
|
|
|
+ l.setPeriodName(period.getPeriodName());
|
|
|
+ l.setContractMaterialId(material.getId());
|
|
|
+ l.setMeterMoney(l.getPrice().multiply(l.getMeterAmount()).setScale(0,RoundingMode.HALF_UP));
|
|
|
+ l.setContractStatedMoney(l.getMeterMoney()
|
|
|
+ .multiply(one.getClPrepaymentRatio())
|
|
|
+ .multiply(new BigDecimal("0.01"))
|
|
|
+ .setScale(0,RoundingMode.HALF_UP));
|
|
|
+ });
|
|
|
+ this.saveBatch(forms);
|
|
|
+ return R.data("成功新增" + forms.size() + "条数据");
|
|
|
+ }catch (Exception e){
|
|
|
+ if (e.getMessage().contains("java.time.LocalDate")){
|
|
|
+ throw new ServiceException("导入失败:" + "业务日期格式错误,正确格式:2024-01-10");
|
|
|
+ }else {
|
|
|
+ throw new ServiceException("导入失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|