Преглед изворни кода

Merge branch 'dev' of http://git.echepei.com/lazhaoqian/bladex into dev

1021934019@qq.com пре 4 година
родитељ
комит
5a1b2b8e25

+ 10 - 0
blade-service-api/blade-client-api/src/main/java/org/springblade/client/feign/IGoodsDescClient.java

@@ -25,6 +25,7 @@ public interface IGoodsDescClient {
 	String GET_SPECIFICATION = API_PREFIX + "/get_Specification" ;
 	String GET_GOOD_ID = API_PREFIX +"/getGoodId";
 	String GOOD_TYPE_ID = API_PREFIX + "/goodTypeId";
+	String GET_GOOD_Name = API_PREFIX +"/getGoodName";
 
 	/**
 	 * 获取商品信息
@@ -83,6 +84,15 @@ public interface IGoodsDescClient {
 	 */
 	@GetMapping(GOOD_TYPE_ID)
 	GoodsType goodTypeId(@RequestParam("goodId") Long goodId);
+	/**
+	 * 获取商品信息
+	 * @param cname 商品名
+	 * @param corpId 供应商
+	 * @return
+	 */
+	@GetMapping(GET_GOOD_Name)
+	GoodsDesc getGoodName(@RequestParam("cname") String cname,
+						  @RequestParam("corpId") Long corpId);
 
 
 }

+ 10 - 0
blade-service-api/blade-mocha-item-api/src/main/java/org/springblade/mocha/entity/PriceBank.java

@@ -234,6 +234,16 @@ public class PriceBank implements Serializable {
 	 */
 		@ApiModelProperty(value = "采购金额")
 		private BigDecimal purchaseAmount;
+	/**
+	 * 是否重点推荐 0 否 1 是
+	 */
+		@ApiModelProperty(value = "是否重点推荐 0 否 1 是")
+		private Integer priorityReferrer;
+	/**
+	 * 推荐理由
+	 */
+		@ApiModelProperty(value = "推荐理由")
+		private String referrerReason;
 
 
 }

+ 6 - 0
blade-service/blade-client/src/main/java/org/springblade/client/goods/feign/GoodsDescClient.java

@@ -113,4 +113,10 @@ public class GoodsDescClient implements IGoodsDescClient {
 		}
 		return goodsType;
 	}
+
+	@Override
+	public GoodsDesc getGoodName(String cname,Long corpId) {
+		return goodsDescService.getOne(new QueryWrapper<GoodsDesc>().eq("cname",cname).eq("corp_id",corpId)
+		.eq("tenant_id",SecureUtil.getTenantId()).eq("is_deleted",0));
+	}
 }

+ 30 - 0
blade-service/blade-mocha-item/src/main/java/org/springblade/mocha/controller/PriceBankController.java

@@ -23,23 +23,31 @@ import io.swagger.annotations.ApiOperation;
 import io.swagger.annotations.ApiParam;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
 import lombok.AllArgsConstructor;
+
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
 
 import org.springblade.client.entity.GoodsType;
 import org.springblade.client.feign.IGoodsDescClient;
+import org.springblade.core.excel.util.ExcelUtil;
 import org.springblade.core.mp.support.Condition;
 import org.springblade.core.mp.support.Query;
 import org.springblade.core.secure.utils.SecureUtil;
 import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.Func;
+import org.springblade.mocha.excel.PriceBankExcel;
+import org.springblade.mocha.excel.PriceBankImport;
+import org.springblade.mocha.excel.PriceImport;
 import org.springframework.web.bind.annotation.*;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import org.springblade.mocha.entity.PriceBank;
 import org.springblade.mocha.vo.PriceBankVO;
 import org.springblade.mocha.service.IPriceBankService;
 import org.springblade.core.boot.ctrl.BladeController;
+import org.springframework.web.multipart.MultipartFile;
 
 import java.time.Period;
+import java.util.ArrayList;
 import java.util.List;
 
 /**
@@ -176,6 +184,28 @@ public class PriceBankController extends BladeController {
 		List<PriceBank> list = priceBankService.list(lambdaQueryWrapper);
 		return R.data(priceBankService.list(lambdaQueryWrapper));
 	}
+	/**
+	 * 导出模板
+	 */
+	@GetMapping("/exportPrice")
+	@ApiOperationSupport(order = 9)
+	@ApiOperation(value = "导出模板")
+	public void exportPrice(HttpServletResponse response) {
+		List<PriceBankExcel> list = new ArrayList<>();
+		ExcelUtil.export(response, "价格库", "价格管理数据表", list, PriceBankExcel.class);
+	}
+	/**
+	 * 导入价格
+	 */
+	@PostMapping("/importPrice")
+	@ApiOperationSupport(order = 12)
+	@ApiOperation(value = "导入价格", notes = "传入excel")
+	public R importUser(MultipartFile file) {
+		Integer isCovered = 0;
+		PriceBankImport priceBankImport = new PriceBankImport(priceBankService, isCovered == 1);
+		ExcelUtil.save(file, priceBankImport, PriceBankExcel.class);
+		return R.success("操作成功");
+	}
 
 
 }

+ 2 - 2
blade-service/blade-mocha-item/src/main/java/org/springblade/mocha/controller/PriceItemController.java

@@ -142,10 +142,10 @@ public class PriceItemController extends BladeController {
 	@ApiOperation(value = "导出模板")
 	public void exportPrice(HttpServletResponse response) {
 		List<PriceItemExcel> list = new ArrayList<>();
-		ExcelUtil.export(response, "价格管理模板", "价格管理数据表", list, PriceItemExcel.class);
+		ExcelUtil.export(response, "价格", "价格管理数据表", list, PriceItemExcel.class);
 	}
 	/**
-	 * 导入用户
+	 * 导入价格
 	 */
 	@PostMapping("import-price")
 	@ApiOperationSupport(order = 12)

+ 90 - 0
blade-service/blade-mocha-item/src/main/java/org/springblade/mocha/excel/PriceBankExcel.java

@@ -0,0 +1,90 @@
+package org.springblade.mocha.excel;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.write.style.ColumnWidth;
+import com.alibaba.excel.annotation.write.style.ContentRowHeight;
+import com.alibaba.excel.annotation.write.style.HeadRowHeight;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * 出口价格库导入模板
+ */
+@Data
+@ColumnWidth(25)
+@HeadRowHeight(20)
+@ContentRowHeight(18)
+public class PriceBankExcel  implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * 供应商名称
+	 */
+	@ExcelProperty(value = "供应商名称")
+	private String corpName;
+	/**
+	 * 商品类别中文名
+	 */
+	@ExcelProperty(value = "商品类别名称")
+	private String goodsTypeName;
+	/**
+	 * 商品名称
+	 */
+	@ExcelProperty(value = "商品名称")
+	private String cname;
+	/**
+	 * 最新采购价或最新销售价
+	 */
+	@ExcelProperty(value = "最新采购价或最新销售价")
+	private BigDecimal price;
+	/**
+	 * FOB系数
+	 */
+	@ExcelProperty(value = "FOB系数")
+	private BigDecimal coefficient;
+	/**
+	 * 税率
+	 */
+	@ExcelProperty(value = "税率")
+	private BigDecimal taxRate;
+	/**
+	 * 币别
+	 */
+	@ExcelProperty(value = "币别")
+	private String currency;
+	/**
+	 * 有效期结束
+	 */
+	@ColumnWidth(50)
+	@ExcelProperty(value = "有效期结束时间 yyyy-MM-dd HH:mm:ss")
+	@DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss")
+	private Date endTime;
+	/**
+	 * 价格类型 销售价格 XS 采购价格 CG
+	 */
+	@ColumnWidth(50)
+	@ExcelProperty(value = "价格类型 销售 XS 采购 CG 默认采购")
+	private String billType;
+	/**
+	 * 是否重点推荐 0 否 1 是
+	 */
+	@ColumnWidth(50)
+	@ExcelProperty(value = "重点推荐 是/否")
+	private String priorityReferrer;
+	/**
+	 * 推荐理由
+	 */
+	@ExcelProperty(value = "推荐理由")
+	private String referrerReason;
+	/**
+	 * 录入人
+	 */
+	@ExcelProperty(value = "录入人")
+	private String createUserName;
+}

+ 24 - 0
blade-service/blade-mocha-item/src/main/java/org/springblade/mocha/excel/PriceBankImport.java

@@ -0,0 +1,24 @@
+package org.springblade.mocha.excel;
+
+import lombok.AllArgsConstructor;
+import lombok.RequiredArgsConstructor;
+import org.springblade.core.excel.support.ExcelImporter;
+import org.springblade.mocha.service.IPriceBankService;
+
+import java.util.List;
+
+/**
+ * 价格管理数据导入类
+ *
+ * @author Chill
+ */
+@RequiredArgsConstructor
+@AllArgsConstructor
+public class PriceBankImport implements ExcelImporter<PriceBankExcel> {
+	private IPriceBankService priceBankService;
+	private final Boolean isCovered;
+	@Override
+	public void save(List<PriceBankExcel> data) {
+		priceBankService.importUser(data,isCovered);
+	}
+}

+ 2 - 0
blade-service/blade-mocha-item/src/main/java/org/springblade/mocha/mapper/PriceBankMapper.xml

@@ -41,6 +41,8 @@
         <result column="goods_type_name" property="goodsTypeName"/>
         <result column="tax_rate" property="taxRate"/>
         <result column="purchase_amount" property="purchaseAmount"/>
+        <result column="priority_referrer" property="priorityReferrer"/>
+        <result column="referrer_reason" property="referrerReason"/>
     </resultMap>
 
 

+ 11 - 0
blade-service/blade-mocha-item/src/main/java/org/springblade/mocha/service/IPriceBankService.java

@@ -17,10 +17,13 @@
 package org.springblade.mocha.service;
 
 import org.springblade.mocha.entity.PriceBank;
+import org.springblade.mocha.excel.PriceBankExcel;
 import org.springblade.mocha.vo.PriceBankVO;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 
+import java.util.List;
+
 /**
  * 出口价格库 服务类
  *
@@ -44,5 +47,13 @@ public interface IPriceBankService extends IService<PriceBank> {
 	 * @return
 	 */
 	PriceBank savePrice(PriceBank priceBank);
+	/**
+	 * 导入价格管理数据
+	 *
+	 * @param data
+	 * @param isCovered
+	 * @return
+	 */
+	void importUser(List<PriceBankExcel> data, Boolean isCovered);
 
 }

+ 96 - 1
blade-service/blade-mocha-item/src/main/java/org/springblade/mocha/service/impl/PriceBankServiceImpl.java

@@ -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);
+						}
+
+					}
+				}
+			}
+		});
+	}
+
 }