|
@@ -5,18 +5,27 @@ import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.bsentity.domin.ComCustomerDo;
|
|
import com.bsentity.domin.ComMetalFinanceItemDo;
|
|
import com.bsentity.domin.ComMetalFinanceItemDo;
|
|
import com.bsentity.domin.ComMetalFinanceRecheckItemDo;
|
|
import com.bsentity.domin.ComMetalFinanceRecheckItemDo;
|
|
|
|
+import com.bsentity.dto.MetalProductDto;
|
|
import com.bsentity.vo.CopyFinanceRequest;
|
|
import com.bsentity.vo.CopyFinanceRequest;
|
|
import com.bsentity.vo.CopyFinanceVo;
|
|
import com.bsentity.vo.CopyFinanceVo;
|
|
|
|
+import com.bsentity.vo.GetFinalWeightRequest;
|
|
|
|
+import com.bsentity.vo.GetFinalWeightVo;
|
|
import com.rongwei.bscommon.sys.dao.ComMetalFinanceItemDao;
|
|
import com.rongwei.bscommon.sys.dao.ComMetalFinanceItemDao;
|
|
import com.rongwei.bscommon.sys.dao.ComMetalFinanceRecheckItemDao;
|
|
import com.rongwei.bscommon.sys.dao.ComMetalFinanceRecheckItemDao;
|
|
|
|
+import com.rongwei.bscommon.sys.service.ComCustomerService;
|
|
import com.rongwei.bscommon.sys.service.ComMetalFinanceItemService;
|
|
import com.rongwei.bscommon.sys.service.ComMetalFinanceItemService;
|
|
import com.rongwei.bscommon.sys.service.ComMetalFinanceRecheckItemService;
|
|
import com.rongwei.bscommon.sys.service.ComMetalFinanceRecheckItemService;
|
|
|
|
+import com.rongwei.bscommon.sys.service.ComMetalProductService;
|
|
import com.rongwei.rwcommon.base.R;
|
|
import com.rongwei.rwcommon.base.R;
|
|
|
|
+import com.rongwei.rwcommon.base.exception.CustomException;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
|
+import java.math.RoundingMode;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -39,19 +48,25 @@ public class ComMetalFinanceItemServiceImpl extends ServiceImpl<ComMetalFinanceI
|
|
ComMetalFinanceRecheckItemDao financeRecheckItemDao;
|
|
ComMetalFinanceRecheckItemDao financeRecheckItemDao;
|
|
@Autowired
|
|
@Autowired
|
|
ComMetalFinanceRecheckItemService financeRecheckItemService;
|
|
ComMetalFinanceRecheckItemService financeRecheckItemService;
|
|
|
|
+ @Autowired
|
|
|
|
+ ComCustomerService customerService;
|
|
|
|
+ @Autowired
|
|
|
|
+ ComMetalProductService comMetalProductService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public R copyFinance(CopyFinanceRequest request) {
|
|
public R copyFinance(CopyFinanceRequest request) {
|
|
|
|
|
|
- if (StrUtil.isEmpty(request.getCustomerId()) && ArrayUtil.isEmpty(request.getCopyFinanceVos())){
|
|
|
|
|
|
+ if (StrUtil.isEmpty(request.getCustomerId()) && ArrayUtil.isEmpty(request.getCopyFinanceVos())) {
|
|
return R.error("数据不存在");
|
|
return R.error("数据不存在");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+ // 获取客诉产品信息
|
|
// 获取复核信息
|
|
// 获取复核信息
|
|
List<ComMetalFinanceRecheckItemDo> comMetalFinanceRecheckItemDos = financeRecheckItemDao.selectList(
|
|
List<ComMetalFinanceRecheckItemDo> comMetalFinanceRecheckItemDos = financeRecheckItemDao.selectList(
|
|
new LambdaQueryWrapper<ComMetalFinanceRecheckItemDo>()
|
|
new LambdaQueryWrapper<ComMetalFinanceRecheckItemDo>()
|
|
- .eq(ComMetalFinanceRecheckItemDo::getCustomerid, request.getCustomerId())
|
|
|
|
- .eq(ComMetalFinanceRecheckItemDo::getDeleted, "0"));
|
|
|
|
|
|
+ .eq(ComMetalFinanceRecheckItemDo::getCustomerid, request.getCustomerId())
|
|
|
|
+ .eq(ComMetalFinanceRecheckItemDo::getDeleted, "0"));
|
|
|
|
|
|
// 预估信息转成Map
|
|
// 预估信息转成Map
|
|
Map<String, CopyFinanceVo> copyFinVOMap = Optional.of(request.getCopyFinanceVos()).orElse(new ArrayList<>())
|
|
Map<String, CopyFinanceVo> copyFinVOMap = Optional.of(request.getCopyFinanceVos()).orElse(new ArrayList<>())
|
|
@@ -61,8 +76,8 @@ public class ComMetalFinanceItemServiceImpl extends ServiceImpl<ComMetalFinanceI
|
|
|
|
|
|
for (ComMetalFinanceRecheckItemDo cmfrItemDo : comMetalFinanceRecheckItemDos) {
|
|
for (ComMetalFinanceRecheckItemDo cmfrItemDo : comMetalFinanceRecheckItemDos) {
|
|
CopyFinanceVo copyFinanceVo = copyFinVOMap.get(cmfrItemDo.getProductid());
|
|
CopyFinanceVo copyFinanceVo = copyFinVOMap.get(cmfrItemDo.getProductid());
|
|
- if (ObjectUtil.isEmpty(copyFinanceVo)){
|
|
|
|
- break;
|
|
|
|
|
|
+ if (ObjectUtil.isEmpty(copyFinanceVo)) {
|
|
|
|
+ throw new CustomException("客诉产品在表找那个不存在,请检查。");
|
|
}
|
|
}
|
|
// 赋值
|
|
// 赋值
|
|
cmfrItemDo.setEstimatedlossdate(copyFinanceVo.getEstimatedlossdate());
|
|
cmfrItemDo.setEstimatedlossdate(copyFinanceVo.getEstimatedlossdate());
|
|
@@ -71,11 +86,155 @@ public class ComMetalFinanceItemServiceImpl extends ServiceImpl<ComMetalFinanceI
|
|
cmfrItemDo.setFreightunitprice(copyFinanceVo.getFreightunitprice());
|
|
cmfrItemDo.setFreightunitprice(copyFinanceVo.getFreightunitprice());
|
|
cmfrItemDo.setExchangerate(copyFinanceVo.getExchangerate());
|
|
cmfrItemDo.setExchangerate(copyFinanceVo.getExchangerate());
|
|
cmfrItemDo.setOthercostrmb(copyFinanceVo.getOthercostrmb());
|
|
cmfrItemDo.setOthercostrmb(copyFinanceVo.getOthercostrmb());
|
|
- cmfrItemDo.setUnitkgpricelossusd(copyFinanceVo.getUnitkgpricelossusd());
|
|
|
|
cmfrItemDo.setMetalconfigid(copyFinanceVo.getMetalconfigid());
|
|
cmfrItemDo.setMetalconfigid(copyFinanceVo.getMetalconfigid());
|
|
|
|
+ cmfrItemDo.setRemark(copyFinanceVo.getRemark() == null ? "" : copyFinanceVo.getRemark());
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
financeRecheckItemService.saveOrUpdateBatch(comMetalFinanceRecheckItemDos);
|
|
financeRecheckItemService.saveOrUpdateBatch(comMetalFinanceRecheckItemDos);
|
|
return R.ok();
|
|
return R.ok();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public R getFinalWeight(GetFinalWeightRequest request) {
|
|
|
|
+ if (StrUtil.isEmpty(request.getCustomerId()) && ArrayUtil.isEmpty(request.getFinalWeightVos())) {
|
|
|
|
+ return R.error("数据不存在");
|
|
|
|
+ }
|
|
|
|
+ //获取客诉单信息
|
|
|
|
+ ComCustomerDo customer = customerService.getById(request.getCustomerId());
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ List<String> productIds = request.getFinalWeightVos().stream().map(GetFinalWeightVo::getProductId).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ // 通过 商品ID ,金属配置ID 查询 客诉产品信息 和 金属价格信息
|
|
|
|
+ Map< String , MetalProductDto> metalProductIdMap = comMetalProductService.getMetalProduct(productIds , request.getCustomerId());
|
|
|
|
+
|
|
|
|
+ // 获取客诉产品信息财务复核信息
|
|
|
|
+ List<ComMetalFinanceRecheckItemDo> comMetalFinanceRecheckItemDos = financeRecheckItemDao.selectList(
|
|
|
|
+ new LambdaQueryWrapper<ComMetalFinanceRecheckItemDo>()
|
|
|
|
+ .eq(ComMetalFinanceRecheckItemDo::getCustomerid, request.getCustomerId())
|
|
|
|
+ .eq(ComMetalFinanceRecheckItemDo::getDeleted, "0"));
|
|
|
|
+
|
|
|
|
+ // 预估信息转成Map
|
|
|
|
+ Map<String, GetFinalWeightVo> finalWeightVoMap = Optional.of(request.getFinalWeightVos()).orElse(new ArrayList<>())
|
|
|
|
+ .stream()
|
|
|
|
+ .collect(Collectors.toMap(GetFinalWeightVo::getProductId, Function.identity()));
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ for (ComMetalFinanceRecheckItemDo cmfrItemDo : comMetalFinanceRecheckItemDos) {
|
|
|
|
+ GetFinalWeightVo finalWeightVo = finalWeightVoMap.get(cmfrItemDo.getProductid());
|
|
|
|
+ MetalProductDto metalProductDto = metalProductIdMap.get(cmfrItemDo.getProductid() + "#" + cmfrItemDo.getMetalconfigid());
|
|
|
|
+ if (ObjectUtil.isEmpty(finalWeightVo) && ObjectUtil.isEmpty(metalProductDto)) {
|
|
|
|
+ throw new CustomException("当前客诉产品客诉产品表中不存在,请检查。 -> "+cmfrItemDo.getProductid() +" ;金属配置ID ->"+cmfrItemDo.getMetalconfigid());
|
|
|
|
+ }
|
|
|
|
+ // 财务复核字段计算
|
|
|
|
+ ComputationalReview(cmfrItemDo, finalWeightVo ,metalProductDto);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 获取合计数据
|
|
|
|
+ ComputationalReviewTotal(comMetalFinanceRecheckItemDos, customer);
|
|
|
|
+
|
|
|
|
+ customerService.saveOrUpdate(customer);
|
|
|
|
+
|
|
|
|
+ financeRecheckItemService.saveOrUpdateBatch(comMetalFinanceRecheckItemDos);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return R.ok();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 计算财务复核合计数据
|
|
|
|
+ *
|
|
|
|
+ * @param comMetalFinanceRecheckItemDos
|
|
|
|
+ * @param customer
|
|
|
|
+ */
|
|
|
|
+ private void ComputationalReviewTotal(List<ComMetalFinanceRecheckItemDo> comMetalFinanceRecheckItemDos, ComCustomerDo customer) {
|
|
|
|
+
|
|
|
|
+ // 计算合计(人民币) = 所有计算合计数据总和
|
|
|
|
+ BigDecimal totalcostrmb = comMetalFinanceRecheckItemDos.stream()
|
|
|
|
+ .map(ComMetalFinanceRecheckItemDo::getTotalcostrmb)
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
+
|
|
|
|
+ // 计算合计(美元) = 所有计算合计(美元)总和
|
|
|
|
+ BigDecimal pricetotalusd = comMetalFinanceRecheckItemDos.stream()
|
|
|
|
+ .map(ComMetalFinanceRecheckItemDo::getPricetotalusd)
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
+
|
|
|
|
+ // 其他费用(人民币)
|
|
|
|
+ BigDecimal othercostrmb = comMetalFinanceRecheckItemDos.stream()
|
|
|
|
+ .map(ComMetalFinanceRecheckItemDo::getOthercostrmb)
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 其他费用 (美元)
|
|
|
|
+ BigDecimal othercostusd = comMetalFinanceRecheckItemDos.stream()
|
|
|
|
+ .map(ComMetalFinanceRecheckItemDo::getOthercostusd)
|
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ // 金额总计 (人民币) = 计算合计(人民币) + 其他费用(人民币)
|
|
|
|
+ BigDecimal rechecktotalcostrmb = totalcostrmb.add(othercostrmb);
|
|
|
|
+
|
|
|
|
+ // 金额总计 (美元) = 计算合计(美元) + 其他费用(美元)
|
|
|
|
+ BigDecimal recheckpricetotalusd = pricetotalusd.add(othercostusd);
|
|
|
|
+
|
|
|
|
+ customer.setRecheckcomputecostrmb(totalcostrmb);
|
|
|
|
+ customer.setRecheckcomputecostusd(pricetotalusd);
|
|
|
|
+ customer.setRecheckothercostrmb(othercostrmb);
|
|
|
|
+ customer.setRecheckothercostusd(othercostusd);
|
|
|
|
+ customer.setRechecktotalcostrmb(rechecktotalcostrmb);
|
|
|
|
+ customer.setRecheckpricetotalusd(recheckpricetotalusd);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 计算复核
|
|
|
|
+ *
|
|
|
|
+ * @param cmfrItemDo 财务复核实体
|
|
|
|
+ * @param requestVo 前端请求信息
|
|
|
|
+ * @param metalProductDto 客诉产品金属价格信息
|
|
|
|
+ */
|
|
|
|
+ private void ComputationalReview(ComMetalFinanceRecheckItemDo cmfrItemDo, GetFinalWeightVo requestVo, MetalProductDto metalProductDto) {
|
|
|
|
+
|
|
|
|
+ // 金属损失金额=金属价格/1.13/1000*报废损失率*最终重量
|
|
|
|
+ BigDecimal metalpriceloss = metalProductDto.getMetakprice()
|
|
|
|
+ .divide(new BigDecimal("1.13"),4,RoundingMode.HALF_UP)
|
|
|
|
+ .divide(new BigDecimal("1000"),4,RoundingMode.HALF_UP)
|
|
|
|
+ .multiply(metalProductDto.getLossrate().divide(new BigDecimal("100.00"),2,RoundingMode.HALF_UP))
|
|
|
|
+ .multiply(requestVo.getFinalweight());
|
|
|
|
+
|
|
|
|
+ // 运费损失=运费单价*2/1.09/1000*最终重量
|
|
|
|
+ BigDecimal freightloss = cmfrItemDo.getFreightunitprice()
|
|
|
|
+ .multiply(new BigDecimal("2"))
|
|
|
|
+ .divide(new BigDecimal("1.09"),4, RoundingMode.HALF_UP)
|
|
|
|
+ .divide(new BigDecimal("1000"), 4,RoundingMode.HALF_UP)
|
|
|
|
+ .multiply(requestVo.getFinalweight());
|
|
|
|
+
|
|
|
|
+ // 计算合计 (人民币)=加工收入单价/1.13*最终重量+加工成本单价*最终重量+金属损失金额+运费损失
|
|
|
|
+ BigDecimal totalcostrmb = cmfrItemDo.getProcessunitprice()
|
|
|
|
+ .divide(new BigDecimal("1.13"),4, RoundingMode.HALF_UP)
|
|
|
|
+ .multiply(metalProductDto.getFinalweight())
|
|
|
|
+ .add(cmfrItemDo.getCostunitprice())
|
|
|
|
+ .multiply(requestVo.getFinalweight())
|
|
|
|
+ .add(metalpriceloss)
|
|
|
|
+ .add(freightloss);
|
|
|
|
+
|
|
|
|
+ //计算合计美元 = 计算合计(人民币)/外汇税率
|
|
|
|
+ BigDecimal pricetotalusd = totalcostrmb.divide(cmfrItemDo.getExchangerate(), 2, RoundingMode.HALF_UP);
|
|
|
|
+
|
|
|
|
+ //单kg损失金额(美元) = 计算合计美元 / 最终重量
|
|
|
|
+ BigDecimal unitkgpricelossusd = pricetotalusd.divide(requestVo.getFinalweight(),2, RoundingMode.HALF_UP);
|
|
|
|
+
|
|
|
|
+ BigDecimal othercostusd = cmfrItemDo.getOthercostrmb().divide(cmfrItemDo.getExchangerate(), 2, RoundingMode.HALF_UP);
|
|
|
|
+
|
|
|
|
+ // 赋值
|
|
|
|
+ cmfrItemDo.setMetalpriceloss(metalpriceloss);
|
|
|
|
+ cmfrItemDo.setFreightloss(freightloss);
|
|
|
|
+ cmfrItemDo.setTotalcostrmb(totalcostrmb);
|
|
|
|
+ cmfrItemDo.setPricetotalusd(pricetotalusd);
|
|
|
|
+ cmfrItemDo.setUnitkgpricelossusd(unitkgpricelossusd);
|
|
|
|
+ cmfrItemDo.setOthercostusd(othercostusd);
|
|
|
|
+ }
|
|
}
|
|
}
|