|
@@ -19,13 +19,16 @@ import com.fjhx.item.entity.product.dto.ProductInfoDto;
|
|
|
import com.fjhx.item.entity.product.dto.ProductInfoSelectDto;
|
|
|
import com.fjhx.item.entity.product.po.ProductClassify;
|
|
|
import com.fjhx.item.entity.product.po.ProductInfo;
|
|
|
+import com.fjhx.item.entity.product.po.ProductInfoEhsdExcel;
|
|
|
import com.fjhx.item.entity.product.po.ProductInfoEhsdJson;
|
|
|
import com.fjhx.item.entity.product.vo.ProductInfoVo;
|
|
|
import com.fjhx.item.mapper.product.ProductInfoMapper;
|
|
|
import com.fjhx.item.service.product.ProductClassifyService;
|
|
|
import com.fjhx.item.service.product.ProductInfoService;
|
|
|
import com.fjhx.item.util.CodeEnum;
|
|
|
+import com.fjhx.item.util.excel.util.ExcelUtil;
|
|
|
import com.fjhx.tenant.entity.dict.dto.DictTenantDataSelectDto;
|
|
|
+import com.fjhx.tenant.entity.dict.po.DictTenantData;
|
|
|
import com.fjhx.tenant.entity.dict.vo.DictTenantDataVo;
|
|
|
import com.fjhx.tenant.service.dict.DictTenantDataService;
|
|
|
import com.obs.services.internal.ServiceException;
|
|
@@ -302,6 +305,75 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
|
|
|
@DSTransactional
|
|
|
@Override
|
|
|
+ public void excelImportByEhsd(MultipartFile file) {
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.BASE);
|
|
|
+ Map<String, String> unitMap = dictTenantDataService.mapKV(DictTenantData::getDictValue,
|
|
|
+ DictTenantData::getDictKey, q -> q.eq(DictTenantData::getDictCode, "unit"));
|
|
|
+ Map<String, String> innerPackMethodMap = dictTenantDataService.mapKV(DictTenantData::getDictValue,
|
|
|
+ DictTenantData::getDictKey, q -> q.eq(DictTenantData::getDictCode, "inner_packaging_method_ehsd"));
|
|
|
+ Map<String, String> outsidePackMethodMap = dictTenantDataService.mapKV(DictTenantData::getDictValue,
|
|
|
+ DictTenantData::getDictKey, q -> q.eq(DictTenantData::getDictCode, "outside_packaging_method_ehsd"));
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+
|
|
|
+ List<ProductInfoEhsdExcel> read = ExcelUtil.read(file, ProductInfoEhsdExcel.class);
|
|
|
+ List<ProductInfo> productInfoList = new ArrayList<>();
|
|
|
+ for (ProductInfoEhsdExcel productInfoEhsdExcel : read) {
|
|
|
+ ProductInfo productInfo = BeanUtil.copyProperties(productInfoEhsdExcel, ProductInfo.class);
|
|
|
+ // 赋值产品编号
|
|
|
+ productInfo.setCode(CodeEnum.PRODUCT.getCode());
|
|
|
+ // 排除名称重复
|
|
|
+ this.nameDuplication(ProductInfo::getName, productInfo.getName(), "产品名称重复");
|
|
|
+
|
|
|
+ //产品分类名称转id
|
|
|
+ ProductClassify productClassify = productClassifyService.getOne(q -> q.eq(ProductClassify::getName, productInfoEhsdExcel.getProductClassifyName()));
|
|
|
+ if (ObjectUtil.isEmpty(productClassify)) {
|
|
|
+ throw new ServiceException("未知产品分类"+ productInfoEhsdExcel.getProductClassifyName());
|
|
|
+ }
|
|
|
+ productInfo.setProductClassifyId(productClassify.getId());
|
|
|
+ //单位名称转字典key
|
|
|
+ if (ObjectUtil.isNotEmpty(productInfo.getUnit())) {
|
|
|
+ String unit = unitMap.get(productInfo.getUnit());
|
|
|
+ if (ObjectUtil.isEmpty(unit)) {
|
|
|
+ throw new ServiceException("未知单位" + productInfo.getUnit());
|
|
|
+ }
|
|
|
+ productInfo.setUnit(unit);
|
|
|
+ }
|
|
|
+ ProductInfoEhsdJson productInfoEhsdJson = BeanUtil.copyProperties(productInfoEhsdExcel, ProductInfoEhsdJson.class);
|
|
|
+ productInfoEhsdJson.setType("1");//公司产品
|
|
|
+ productInfoEhsdJson.setCustomerId(0l);//客户id为0 公司产品
|
|
|
+ //内外包装方式名称转字典key
|
|
|
+ String innerPackMethod = productInfoEhsdJson.getInnerPackMethod();
|
|
|
+ if (ObjectUtil.isNotEmpty(innerPackMethod)) {
|
|
|
+ String[] split = innerPackMethod.split(",");
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ String key = innerPackMethodMap.get(split[i]);
|
|
|
+ if (ObjectUtil.isEmpty(key)) {
|
|
|
+ throw new ServiceException("未知内包装方式" + split[i]);
|
|
|
+ }
|
|
|
+ split[i] = key;
|
|
|
+ }
|
|
|
+ productInfoEhsdJson.setInnerPackMethod(String.join(",", split));
|
|
|
+ }
|
|
|
+ String outerPackMethod = productInfoEhsdJson.getOuterPackMethod();
|
|
|
+ if (ObjectUtil.isNotEmpty(outerPackMethod)) {
|
|
|
+ String[] split = outerPackMethod.split(",");
|
|
|
+ for (int i = 0; i < split.length; i++) {
|
|
|
+ String key = outsidePackMethodMap.get(split[i]);
|
|
|
+ if (ObjectUtil.isEmpty(key)) {
|
|
|
+ throw new ServiceException("未知外包装方式" + split[i]);
|
|
|
+ }
|
|
|
+ split[i] = key;
|
|
|
+ }
|
|
|
+ productInfoEhsdJson.setOuterPackMethod(String.join(",", split));
|
|
|
+ }
|
|
|
+ productInfo.setEhsdJson(JSONObject.toJSONString(productInfoEhsdJson));
|
|
|
+ productInfoList.add(productInfo);
|
|
|
+ }
|
|
|
+ saveBatch(productInfoList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @DSTransactional
|
|
|
+ @Override
|
|
|
public void addByWdly(ProductInfoDto productInfoDto) {
|
|
|
//处理维多利亚扩展
|
|
|
String victoriatouristJson = productInfoDto.getVictoriatouristJson();
|
|
@@ -444,13 +516,13 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
* @param productInfoDto
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<Map<String,Object>> productDistribution(ProductInfoDto productInfoDto) {
|
|
|
+ public List<Map<String, Object>> productDistribution(ProductInfoDto productInfoDto) {
|
|
|
if (ObjectUtil.isEmpty(productInfoDto) && ObjectUtil.isEmpty(productInfoDto.getBeginTime())
|
|
|
- && StringUtils.isNotEmpty(productInfoDto.getEndTime())){
|
|
|
- throw new ServiceException("参数缺失:开始时间,结束时间不能为null");
|
|
|
+ && StringUtils.isNotEmpty(productInfoDto.getEndTime())) {
|
|
|
+ throw new ServiceException("参数缺失:开始时间,结束时间不能为null");
|
|
|
}
|
|
|
//存放产品分布列表
|
|
|
- List<Map<String,Object>> list = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> list = new ArrayList<>();
|
|
|
|
|
|
QueryWrapper<ProductInfo> query = Wrappers.<ProductInfo>query();
|
|
|
query.select("count(*) count,ifnull(type,999) type");
|
|
@@ -459,30 +531,30 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
query.le("DATE_FORMAT(create_time,'%Y-%m-%d')", productInfoDto.getEndTime());
|
|
|
//查询每个类型的总计
|
|
|
List<ProductInfo> productInfos = baseMapper.selectList(query);
|
|
|
- if (productInfos.size()==0){
|
|
|
+ if (productInfos.size() == 0) {
|
|
|
new ArrayList<>();
|
|
|
}
|
|
|
- Map<String, List<ProductInfo>> productInfoMap= productInfos.stream().collect(Collectors.groupingBy(ProductInfo::getType));
|
|
|
+ Map<String, List<ProductInfo>> productInfoMap = productInfos.stream().collect(Collectors.groupingBy(ProductInfo::getType));
|
|
|
//获取产品类型的字典数据
|
|
|
DynamicDataSourceContextHolder.push(SourceConstant.BASE);
|
|
|
List<DictTenantDataVo> dictTenantDataVoList = getDict("product_type");
|
|
|
DynamicDataSourceContextHolder.poll();
|
|
|
|
|
|
- if (dictTenantDataVoList.size()==0){
|
|
|
+ if (dictTenantDataVoList.size() == 0) {
|
|
|
new ArrayList<>();
|
|
|
}
|
|
|
|
|
|
//赋值
|
|
|
for (DictTenantDataVo dictTenantDataVo : dictTenantDataVoList) {
|
|
|
- Map<String,Object> map = new HashMap<>();
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
//初始化
|
|
|
- map.put("type",dictTenantDataVo.getDictKey());
|
|
|
- map.put("name",dictTenantDataVo.getDictValue());
|
|
|
- map.put("count",0);
|
|
|
+ map.put("type", dictTenantDataVo.getDictKey());
|
|
|
+ map.put("name", dictTenantDataVo.getDictValue());
|
|
|
+ map.put("count", 0);
|
|
|
|
|
|
List<ProductInfo> productInfoList = productInfoMap.get(dictTenantDataVo.getDictKey());
|
|
|
- if (ObjectUtil.isNotEmpty(productInfoList)){
|
|
|
- map.put("count",productInfoList.get(0).getCount());
|
|
|
+ if (ObjectUtil.isNotEmpty(productInfoList)) {
|
|
|
+ map.put("count", productInfoList.get(0).getCount());
|
|
|
}
|
|
|
list.add(map);
|
|
|
}
|
|
@@ -495,21 +567,21 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
* @param productInfoDto
|
|
|
*/
|
|
|
@Override
|
|
|
- public List<Map<String,Object>> productTypeRanking(ProductInfoSelectDto productInfoDto) {
|
|
|
+ public List<Map<String, Object>> productTypeRanking(ProductInfoSelectDto productInfoDto) {
|
|
|
//存放产品类型排行数据
|
|
|
- List<Map<String,Object>> list = new ArrayList<>();
|
|
|
+ List<Map<String, Object>> list = new ArrayList<>();
|
|
|
|
|
|
QueryWrapper<Object> query = Wrappers.query();
|
|
|
String beginTime = DateUtil.format(productInfoDto.getBeginTime(), "yyyy-MM-dd");
|
|
|
String endTime = DateUtil.format(productInfoDto.getEndTime(), "yyyy-MM-dd");
|
|
|
- query.ge("DATE_FORMAT(pc.create_time,'%Y-%m-%d')",beginTime);
|
|
|
- query.le("DATE_FORMAT(pc.create_time,'%Y-%m-%d')",endTime);
|
|
|
- query.eq(ObjectUtil.isNotEmpty(productInfoDto.getCountryId()),"bc.buy_country_id",productInfoDto.getCountryId());
|
|
|
+ query.ge("DATE_FORMAT(pc.create_time,'%Y-%m-%d')", beginTime);
|
|
|
+ query.le("DATE_FORMAT(pc.create_time,'%Y-%m-%d')", endTime);
|
|
|
+ query.eq(ObjectUtil.isNotEmpty(productInfoDto.getCountryId()), "bc.buy_country_id", productInfoDto.getCountryId());
|
|
|
// sort(query,productInfoDto);
|
|
|
query.groupBy("pi.type");
|
|
|
//查询产品类型排行数据
|
|
|
List<ProductInfoVo> productInfoVos = baseMapper.productTypeRanking(query);
|
|
|
- if (productInfoVos.size()==0){
|
|
|
+ if (productInfoVos.size() == 0) {
|
|
|
return list;
|
|
|
}
|
|
|
Map<String, List<ProductInfoVo>> productInfoVoMap = productInfoVos.stream().collect(Collectors.groupingBy(ProductInfoVo::getType));
|
|
@@ -521,26 +593,26 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
//赋值
|
|
|
for (DictTenantDataVo dictTenantDataVo : dictTenantDataVoList) {
|
|
|
//初始化
|
|
|
- Map<String,Object> map = new HashMap<>();
|
|
|
- map.put("type",dictTenantDataVo.getDictKey());
|
|
|
- map.put("name",dictTenantDataVo.getDictValue());
|
|
|
- map.put("contractAmount",new BigDecimal(0));
|
|
|
- map.put("contractQuantity",new BigDecimal(0));
|
|
|
- map.put("purchaseAmount",new BigDecimal(0));
|
|
|
- map.put("purchaseQuantity",new BigDecimal(0));
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ map.put("type", dictTenantDataVo.getDictKey());
|
|
|
+ map.put("name", dictTenantDataVo.getDictValue());
|
|
|
+ map.put("contractAmount", new BigDecimal(0));
|
|
|
+ map.put("contractQuantity", new BigDecimal(0));
|
|
|
+ map.put("purchaseAmount", new BigDecimal(0));
|
|
|
+ map.put("purchaseQuantity", new BigDecimal(0));
|
|
|
//赋值
|
|
|
List<ProductInfoVo> productInfoVos1 = productInfoVoMap.get(dictTenantDataVo.getDictKey());
|
|
|
- if (ObjectUtil.isNotEmpty(productInfoVos1)){
|
|
|
- map.put("contractAmount",productInfoVos1.get(0).getContractAmount());
|
|
|
- map.put("contractQuantity",productInfoVos1.get(0).getContractQuantity());
|
|
|
- map.put("purchaseAmount",productInfoVos1.get(0).getPurchaseAmount());
|
|
|
- map.put("purchaseQuantity",productInfoVos1.get(0).getPurchaseQuantity());
|
|
|
+ if (ObjectUtil.isNotEmpty(productInfoVos1)) {
|
|
|
+ map.put("contractAmount", productInfoVos1.get(0).getContractAmount());
|
|
|
+ map.put("contractQuantity", productInfoVos1.get(0).getContractQuantity());
|
|
|
+ map.put("purchaseAmount", productInfoVos1.get(0).getPurchaseAmount());
|
|
|
+ map.put("purchaseQuantity", productInfoVos1.get(0).getPurchaseQuantity());
|
|
|
}
|
|
|
list.add(map);
|
|
|
}
|
|
|
- if (ObjectUtil.isNotEmpty(list)){
|
|
|
+ if (ObjectUtil.isNotEmpty(list)) {
|
|
|
//排序
|
|
|
- list= typeSort(list,productInfoDto);
|
|
|
+ list = typeSort(list, productInfoDto);
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
@@ -590,49 +662,49 @@ public class ProductInfoServiceImpl extends ServiceImpl<ProductInfoMapper, Produ
|
|
|
}
|
|
|
|
|
|
//产品类型排序
|
|
|
- private List<Map<String,Object>> typeSort(List<Map<String,Object>> list,ProductInfoSelectDto productInfoSelectDto){
|
|
|
- if (productInfoSelectDto.getOrderBy() ==10){
|
|
|
- if (productInfoSelectDto.getSort() ==10){
|
|
|
+ private List<Map<String, Object>> typeSort(List<Map<String, Object>> list, ProductInfoSelectDto productInfoSelectDto) {
|
|
|
+ if (productInfoSelectDto.getOrderBy() == 10) {
|
|
|
+ if (productInfoSelectDto.getSort() == 10) {
|
|
|
list = list.stream()
|
|
|
.sorted(Comparator.comparing(m -> new BigDecimal(m.get("contractQuantity").toString())))
|
|
|
.collect(Collectors.toList());
|
|
|
return list;
|
|
|
- }else if (productInfoSelectDto.getSort() ==20){
|
|
|
+ } else if (productInfoSelectDto.getSort() == 20) {
|
|
|
list = list.stream()
|
|
|
.sorted(Comparator.comparing(m -> new BigDecimal(m.get("contractAmount").toString())))
|
|
|
.collect(Collectors.toList());
|
|
|
return list;
|
|
|
- }else if (productInfoSelectDto.getSort() ==30){
|
|
|
+ } else if (productInfoSelectDto.getSort() == 30) {
|
|
|
list = list.stream()
|
|
|
.sorted(Comparator.comparing(m -> new BigDecimal(m.get("purchaseQuantity").toString())))
|
|
|
.collect(Collectors.toList());
|
|
|
return list;
|
|
|
- }else if (productInfoSelectDto.getSort() ==40){
|
|
|
+ } else if (productInfoSelectDto.getSort() == 40) {
|
|
|
list = list.stream()
|
|
|
.sorted(Comparator.comparing(m -> new BigDecimal(m.get("purchaseAmount").toString())))
|
|
|
.collect(Collectors.toList());
|
|
|
return list;
|
|
|
}
|
|
|
- }else {
|
|
|
- if (productInfoSelectDto.getSort() ==10){
|
|
|
+ } else {
|
|
|
+ if (productInfoSelectDto.getSort() == 10) {
|
|
|
list = list.stream()
|
|
|
.sorted(Comparator.comparing(m -> new BigDecimal(m.get("contractQuantity").toString())))
|
|
|
.collect(Collectors.toList());
|
|
|
Collections.reverse(list);
|
|
|
return list;
|
|
|
- }else if (productInfoSelectDto.getSort() ==20){
|
|
|
+ } else if (productInfoSelectDto.getSort() == 20) {
|
|
|
list = list.stream()
|
|
|
.sorted(Comparator.comparing(m -> new BigDecimal(m.get("contractAmount").toString())))
|
|
|
.collect(Collectors.toList());
|
|
|
Collections.reverse(list);
|
|
|
return list;
|
|
|
- }else if (productInfoSelectDto.getSort() ==30){
|
|
|
+ } else if (productInfoSelectDto.getSort() == 30) {
|
|
|
list = list.stream()
|
|
|
.sorted(Comparator.comparing(m -> new BigDecimal(m.get("purchaseQuantity").toString())))
|
|
|
.collect(Collectors.toList());
|
|
|
Collections.reverse(list);
|
|
|
return list;
|
|
|
- }else if (productInfoSelectDto.getSort() ==40){
|
|
|
+ } else if (productInfoSelectDto.getSort() == 40) {
|
|
|
list = list.stream()
|
|
|
.sorted(Comparator.comparing(m -> new BigDecimal(m.get("purchaseAmount").toString())))
|
|
|
.collect(Collectors.toList());
|