|
|
@@ -18,8 +18,11 @@ 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.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springblade.client.entity.CorpsDesc;
|
|
|
import org.springblade.client.entity.GoodsDesc;
|
|
|
@@ -30,13 +33,11 @@ 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.mocha.vo.PriceBankVO;
|
|
|
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;
|
|
|
@@ -56,6 +57,7 @@ public class PriceBankServiceImpl extends ServiceImpl<PriceBankMapper, PriceBank
|
|
|
private final ICorpsDescClient corpsDescClient;//获取客户信息
|
|
|
private final IGoodsDescClient goodsDescClient;//商品信息
|
|
|
private IUserClient userClient;//用户信息
|
|
|
+
|
|
|
@Override
|
|
|
public IPage<PriceBankVO> selectPriceBankPage(IPage<PriceBankVO> page, PriceBankVO priceBank) {
|
|
|
return page.setRecords(baseMapper.selectPriceBankPage(page, priceBank));
|
|
|
@@ -65,24 +67,24 @@ public class PriceBankServiceImpl extends ServiceImpl<PriceBankMapper, PriceBank
|
|
|
@Transactional
|
|
|
public PriceBank savePrice(PriceBank priceBank) {
|
|
|
PriceBank price = baseMapper.selectOne(new QueryWrapper<PriceBank>().eq("item_id", priceBank.getItemId()).eq("corp_id", priceBank.getCorpId())
|
|
|
- .eq("specs", priceBank.getSpecs()).eq("is_deleted", 0).eq("tenant_id",SecureUtil.getTenantId())
|
|
|
- .eq("bill_type",priceBank.getBillType()).eq("trade_type",priceBank.getTradeType()));
|
|
|
- if (price != null && priceBank.getId() == null){
|
|
|
- throw new RuntimeException("商品:"+priceBank.getCname()+"供应商:"+priceBank.getCorpName()+"规格:"+priceBank.getSpecs()+"的数据已存在");
|
|
|
- }else if (price != null && priceBank.getId() != null && price.getId().longValue() != priceBank.getId().longValue()){
|
|
|
- throw new RuntimeException("商品:"+priceBank.getCname()+"供应商:"+priceBank.getCorpName()+"规格:"+priceBank.getSpecs()+"的数据已存在");
|
|
|
+ .eq("specs", priceBank.getSpecs()).eq("is_deleted", 0).eq("tenant_id", SecureUtil.getTenantId())
|
|
|
+ .eq("bill_type", priceBank.getBillType()).eq("trade_type", priceBank.getTradeType()));
|
|
|
+ if (price != null && priceBank.getId() == null) {
|
|
|
+ throw new RuntimeException("商品:" + priceBank.getCname() + "供应商:" + priceBank.getCorpName() + "规格:" + priceBank.getSpecs() + "的数据已存在");
|
|
|
+ } else if (price != null && priceBank.getId() != null && price.getId().longValue() != priceBank.getId().longValue()) {
|
|
|
+ throw new RuntimeException("商品:" + priceBank.getCname() + "供应商:" + priceBank.getCorpName() + "规格:" + priceBank.getSpecs() + "的数据已存在");
|
|
|
}
|
|
|
- if (priceBank.getId() == null){
|
|
|
+ if (priceBank.getId() == null) {
|
|
|
priceBank.setCreateTime(new Date());
|
|
|
priceBank.setCreateUser(SecureUtil.getUserId());
|
|
|
- if (StringUtils.isBlank(priceBank.getPerson())){
|
|
|
+ if (StringUtils.isBlank(priceBank.getPerson())) {
|
|
|
priceBank.setPerson(SecureUtil.getUserName());
|
|
|
}
|
|
|
priceBank.setTenantId(SecureUtil.getTenantId());
|
|
|
priceBank.setPriceTime(new Date());
|
|
|
baseMapper.insert(priceBank);
|
|
|
- }else {
|
|
|
- if (priceBank.getPriceTime().compareTo(price.getPriceTime()) >0){
|
|
|
+ } else {
|
|
|
+ if (priceBank.getPriceTime().compareTo(price.getPriceTime()) > 0) {
|
|
|
baseMapper.updatePrice(price.getId());//更新历史价格
|
|
|
}
|
|
|
baseMapper.updatePrice(priceBank.getId());//更新历史价格
|
|
|
@@ -105,7 +107,7 @@ public class PriceBankServiceImpl extends ServiceImpl<PriceBankMapper, PriceBank
|
|
|
public R importUser(List<PriceBankExcel> data, Boolean isCovered) {
|
|
|
List<String> corpList = new ArrayList<>();//供应商不存在的集合
|
|
|
List<String> goodList = new ArrayList<>();//商品不存在的
|
|
|
- data.stream().forEach(item ->{
|
|
|
+ data.stream().forEach(item -> {
|
|
|
//先查供应商 看供应商是否存在
|
|
|
PriceBank priceBank = new PriceBank();
|
|
|
priceBank.setPrice(item.getPrice());//单价
|
|
|
@@ -115,50 +117,50 @@ public class PriceBankServiceImpl extends ServiceImpl<PriceBankMapper, PriceBank
|
|
|
priceBank.setEndTime(item.getEndTime());
|
|
|
priceBank.setPriceTime(new Date());
|
|
|
priceBank.setTradeType("CK");
|
|
|
- if (item.getCoefficient() == null){
|
|
|
+ if (item.getCoefficient() == null) {
|
|
|
priceBank.setCoefficient(BigDecimal.ZERO);//FOB系数默认0
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
priceBank.setCoefficient(item.getCoefficient());//FOB系数
|
|
|
}
|
|
|
- if (StringUtils.isBlank(item.getCurrency())){
|
|
|
+ if (StringUtils.isBlank(item.getCurrency())) {
|
|
|
priceBank.setCurrency("CNY");//币别
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
priceBank.setCurrency(item.getCurrency());//币别
|
|
|
}
|
|
|
- if (item.getTaxRate() == null){
|
|
|
+ if (item.getTaxRate() == null) {
|
|
|
priceBank.setTaxRate(new BigDecimal(13));//税率默认13
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
priceBank.setTaxRate(item.getTaxRate());//税率
|
|
|
}
|
|
|
- if (StringUtils.isNotBlank(item.getPriorityReferrer()) && item.getPriorityReferrer().equals("是")){
|
|
|
+ if (StringUtils.isNotBlank(item.getPriorityReferrer()) && item.getPriorityReferrer().equals("是")) {
|
|
|
priceBank.setPriorityReferrer(1);
|
|
|
- }else if (StringUtils.isNotBlank(item.getPriorityReferrer()) && item.getPriorityReferrer().equals("否")){
|
|
|
+ } else if (StringUtils.isNotBlank(item.getPriorityReferrer()) && item.getPriorityReferrer().equals("否")) {
|
|
|
priceBank.setPriorityReferrer(0);
|
|
|
}
|
|
|
//价格类型
|
|
|
- if (StringUtils.isBlank(item.getBillType())){
|
|
|
+ if (StringUtils.isBlank(item.getBillType())) {
|
|
|
priceBank.setBillType("CG");
|
|
|
- }else {
|
|
|
+ } 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))))),4).multiply(new BigDecimal(1).add((priceBank.getCoefficient().divide(new BigDecimal(100))))));
|
|
|
- if (StringUtils.isNotBlank(item.getCorpName())){
|
|
|
+ priceBank.setPurchaseAmount(priceBank.getPrice().divide((new BigDecimal(1).add((priceBank.getTaxRate().divide(new BigDecimal(100))))), 4).multiply(new BigDecimal(1).add((priceBank.getCoefficient().divide(new BigDecimal(100))))));
|
|
|
+ if (StringUtils.isNotBlank(item.getCorpName())) {
|
|
|
/*CorpsDesc corpsDesc = new CorpsDesc();
|
|
|
corpsDesc.setCname(item.getCorpName());
|
|
|
corpsDesc.setCorpType("GYS");*/
|
|
|
- CorpsDesc corpByName = corpsDescClient.getCorpsDesc(item.getCorpName(),"GYS");
|
|
|
- if (corpByName != null){
|
|
|
+ CorpsDesc corpByName = corpsDescClient.getCorpsDesc(item.getCorpName(), "GYS");
|
|
|
+ if (corpByName != null) {
|
|
|
priceBank.setCorpName(item.getCorpName());//供应商
|
|
|
priceBank.setCorpId(corpByName.getId());//供应商id
|
|
|
//查商品id
|
|
|
GoodsType goodsType = goodsDescClient.goodTypeCname(item.getGoodsTypeName());
|
|
|
- if (goodsType != null){
|
|
|
+ if (goodsType != null) {
|
|
|
priceBank.setGoodTypeId(goodsType.getId());
|
|
|
}
|
|
|
//查商品看商品是否存在
|
|
|
GoodsDesc goodName = goodsDescClient.getGoodName(item.getCname(), null);
|
|
|
- if (goodName != null){
|
|
|
+ if (goodName != null) {
|
|
|
priceBank.setCname(item.getCname());//商品名
|
|
|
priceBank.setEname(goodName.getEname());
|
|
|
priceBank.setItemId(goodName.getId());//商品id
|
|
|
@@ -167,19 +169,19 @@ public class PriceBankServiceImpl extends ServiceImpl<PriceBankMapper, PriceBank
|
|
|
priceBank.setCnameDescription(goodName.getCnameDescription());//英文描述
|
|
|
//查询是否存在
|
|
|
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());
|
|
|
+ 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){
|
|
|
+ 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){
|
|
|
+ } else {
|
|
|
+ if (priceBank.getPriceTime().compareTo(bank.getPriceTime()) > 0) {
|
|
|
baseMapper.updatePrice(bank.getId());//更新历史价格
|
|
|
}
|
|
|
priceBank.setId(bank.getId());
|
|
|
@@ -188,22 +190,22 @@ public class PriceBankServiceImpl extends ServiceImpl<PriceBankMapper, PriceBank
|
|
|
baseMapper.updateById(priceBank);
|
|
|
}
|
|
|
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
goodList.add(item.getCname());
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
corpList.add(item.getCorpName());
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- if (CollectionUtils.isNotEmpty(corpList) || CollectionUtils.isNotEmpty(goodList)){
|
|
|
+ if (CollectionUtils.isNotEmpty(corpList) || CollectionUtils.isNotEmpty(goodList)) {
|
|
|
String message = new String();
|
|
|
- if (CollectionUtils.isNotEmpty(corpList)){
|
|
|
+ if (CollectionUtils.isNotEmpty(corpList)) {
|
|
|
StringBuffer stringBuffer = new StringBuffer("未找到供应商的有:");
|
|
|
stringBuffer.append(org.apache.commons.lang.StringUtils.join(corpList.toArray(), ","));
|
|
|
message = message + stringBuffer.toString();
|
|
|
}
|
|
|
- if (CollectionUtils.isNotEmpty(goodList)){
|
|
|
+ if (CollectionUtils.isNotEmpty(goodList)) {
|
|
|
StringBuffer stringBuffer = new StringBuffer("根据供应商和商品名未找到商品的有:");
|
|
|
stringBuffer.append(org.apache.commons.lang.StringUtils.join(goodList.toArray(), ","));
|
|
|
message = message + stringBuffer.toString();
|
|
|
@@ -213,4 +215,34 @@ public class PriceBankServiceImpl extends ServiceImpl<PriceBankMapper, PriceBank
|
|
|
return R.data("导入成功");
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新产品价格商品类别
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public R updateParts(String ids) {
|
|
|
+ if (ObjectUtils.isNotNull(ids)) {
|
|
|
+ String[] arrs = ids.split(",");
|
|
|
+ for (String arr : arrs) {
|
|
|
+ PriceBank priceBank = baseMapper.selectById(Long.parseLong(arr));
|
|
|
+ if (ObjectUtils.isNotNull(priceBank)) {
|
|
|
+ GoodsType goodsType = goodsDescClient.goodTypeId(priceBank.getItemId());
|
|
|
+ if (ObjectUtils.isNotNull(goodsType)) {
|
|
|
+ priceBank.setGoodTypeId(goodsType.getId());
|
|
|
+ priceBank.setGoodsTypeName(goodsType.getCname());
|
|
|
+ baseMapper.updateById(priceBank);
|
|
|
+ } else {
|
|
|
+ return R.fail("未找到商品类别");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return R.fail("未找到价格数据");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return R.success("更新成功");
|
|
|
+ } else {
|
|
|
+ return R.fail("缺少参数");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|