|
|
@@ -16,19 +16,30 @@
|
|
|
*/
|
|
|
package org.springblade.mocha.service.impl;
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import lombok.AllArgsConstructor;
|
|
|
+import org.springblade.client.entity.CorpsDesc;
|
|
|
+import org.springblade.client.entity.GoodsDesc;
|
|
|
+import org.springblade.client.feign.ICorpsDescClient;
|
|
|
+import org.springblade.client.feign.IGoodsDescClient;
|
|
|
import org.springblade.core.secure.utils.SecureUtil;
|
|
|
+import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.mocha.entity.PriceBank;
|
|
|
+import org.springblade.mocha.excel.PriceBankExcel;
|
|
|
import org.springblade.mocha.vo.PriceBankVO;
|
|
|
import org.springblade.mocha.mapper.PriceBankMapper;
|
|
|
import org.springblade.mocha.service.IPriceBankService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.springblade.system.user.feign.IUserClient;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 出口价格库 服务实现类
|
|
|
@@ -37,8 +48,11 @@ import java.util.Date;
|
|
|
* @since 2021-12-06
|
|
|
*/
|
|
|
@Service
|
|
|
+@AllArgsConstructor
|
|
|
public class PriceBankServiceImpl extends ServiceImpl<PriceBankMapper, PriceBank> implements IPriceBankService {
|
|
|
-
|
|
|
+ private ICorpsDescClient corpsDescClient;//获取客户信息
|
|
|
+ private IGoodsDescClient goodsDescClient;//商品信息
|
|
|
+ private IUserClient userClient;//用户信息
|
|
|
@Override
|
|
|
public IPage<PriceBankVO> selectPriceBankPage(IPage<PriceBankVO> page, PriceBankVO priceBank) {
|
|
|
return page.setRecords(baseMapper.selectPriceBankPage(page, priceBank));
|
|
|
@@ -81,4 +95,85 @@ public class PriceBankServiceImpl extends ServiceImpl<PriceBankMapper, PriceBank
|
|
|
return priceBank;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void importUser(List<PriceBankExcel> data, Boolean isCovered) {
|
|
|
+ data.stream().forEach(item ->{
|
|
|
+ //先查供应商 看供应商是否存在
|
|
|
+ PriceBank priceBank = new PriceBank();
|
|
|
+ priceBank.setPrice(item.getPrice());//单价
|
|
|
+ priceBank.setPerson(item.getCreateUserName());//录入人
|
|
|
+ priceBank.setGoodsTypeName(item.getGoodsTypeName());//商品类别名称
|
|
|
+ priceBank.setReferrerReason(item.getReferrerReason());//推荐理由
|
|
|
+ priceBank.setEndTime(item.getEndTime());
|
|
|
+ priceBank.setPriceTime(new Date());
|
|
|
+ priceBank.setTradeType("CK");
|
|
|
+ if (item.getCoefficient() == null){
|
|
|
+ priceBank.setCoefficient(BigDecimal.ZERO);//FOB系数默认0
|
|
|
+ }else {
|
|
|
+ priceBank.setCoefficient(item.getCoefficient());//FOB系数
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(item.getCurrency())){
|
|
|
+ priceBank.setCurrency("CNY");//币别
|
|
|
+ }else {
|
|
|
+ priceBank.setCurrency(item.getCurrency());//币别
|
|
|
+ }
|
|
|
+ if (item.getTaxRate() == null){
|
|
|
+ priceBank.setTaxRate(new BigDecimal(13));//税率默认13
|
|
|
+ }else {
|
|
|
+ priceBank.setTaxRate(item.getTaxRate());//税率
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(item.getPriorityReferrer()) && item.getPriorityReferrer().equals("是")){
|
|
|
+ priceBank.setPriorityReferrer(1);
|
|
|
+ }else if (StringUtils.isNotBlank(item.getPriorityReferrer()) && item.getPriorityReferrer().equals("否")){
|
|
|
+ priceBank.setPriorityReferrer(0);
|
|
|
+ }
|
|
|
+ //价格类型
|
|
|
+ if (StringUtils.isBlank(item.getBillType())){
|
|
|
+ priceBank.setBillType("CG");
|
|
|
+ }else {
|
|
|
+ priceBank.setBillType(item.getBillType());
|
|
|
+ }
|
|
|
+ //采购报价=单价 / (1+税率/100) *(1+FOB系数/100)
|
|
|
+ priceBank.setPurchaseAmount(priceBank.getPrice().divide((new BigDecimal(1).add((priceBank.getTaxRate().divide(new BigDecimal(100),2)))).multiply(new BigDecimal(1).add((priceBank.getCoefficient().divide(new BigDecimal(100),2)))),2));
|
|
|
+ if (StringUtils.isNotBlank(item.getCorpName())){
|
|
|
+ R<CorpsDesc> corpByName = corpsDescClient.getCorpByName(item.getCorpName(), SecureUtil.getTenantId());
|
|
|
+ if (corpByName.isSuccess() && corpByName.getData() != null){
|
|
|
+ priceBank.setCorpName(item.getCorpName());//供应商
|
|
|
+ priceBank.setCorpId(corpByName.getData().getId());//供应商id
|
|
|
+ //查商品看商品是否存在
|
|
|
+ GoodsDesc goodName = goodsDescClient.getGoodName(item.getCname(), priceBank.getCorpId());
|
|
|
+ if (goodName != null){
|
|
|
+ priceBank.setCname(item.getCname());//商品名
|
|
|
+ priceBank.setItemId(goodName.getId());//商品id
|
|
|
+ priceBank.setCode(goodName.getCode());//商品编码
|
|
|
+ priceBank.setSpecs(goodName.getTypeno());//商品中文规格
|
|
|
+ //查询是否存在
|
|
|
+ LambdaQueryWrapper<PriceBank> lambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lambdaQueryWrapper.eq(PriceBank::getCorpId,priceBank.getCorpId());
|
|
|
+ lambdaQueryWrapper.eq(PriceBank::getItemId,priceBank.getItemId());
|
|
|
+ lambdaQueryWrapper.eq(PriceBank::getBillType,priceBank.getBillType());
|
|
|
+ lambdaQueryWrapper.eq(PriceBank::getIsDeleted,0);
|
|
|
+ lambdaQueryWrapper.eq(PriceBank::getTenantId,SecureUtil.getTenantId());
|
|
|
+ PriceBank bank = baseMapper.selectOne(lambdaQueryWrapper);
|
|
|
+ if (bank == null){
|
|
|
+ priceBank.setTenantId(SecureUtil.getTenantId());
|
|
|
+ priceBank.setCreateUser(SecureUtil.getUserId());
|
|
|
+ priceBank.setCreateTime(new Date());
|
|
|
+ baseMapper.insert(priceBank);
|
|
|
+ }else {
|
|
|
+ if (priceBank.getPriceTime().compareTo(bank.getPriceTime()) >0){
|
|
|
+ baseMapper.updatePrice(bank.getId());//更新历史价格
|
|
|
+ }
|
|
|
+ priceBank.setId(bank.getId());
|
|
|
+ priceBank.setUpdateTime(new Date());
|
|
|
+ priceBank.setUpdateUser(SecureUtil.getUserId());
|
|
|
+ baseMapper.updateById(priceBank);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
}
|