|
@@ -1,35 +1,47 @@
|
|
|
package cn.cslg.pas.service.business;
|
|
|
|
|
|
+import cn.cslg.pas.common.dto.business.GetAllCompanyAndAreaDTO;
|
|
|
import cn.cslg.pas.common.dto.business.ProductMarketDataDTO;
|
|
|
import cn.cslg.pas.common.dto.business.UpdateProductMarketDataDTO;
|
|
|
-import cn.cslg.pas.common.model.cronModel.Personnel;
|
|
|
-import cn.cslg.pas.common.model.cronModel.PersonnelVO;
|
|
|
-import cn.cslg.pas.common.model.cronModel.Records;
|
|
|
+import cn.cslg.pas.common.model.cronModel.*;
|
|
|
import cn.cslg.pas.common.model.request.GroupRequest;
|
|
|
import cn.cslg.pas.common.model.request.QueryRequest;
|
|
|
+import cn.cslg.pas.common.model.request.StringRequest;
|
|
|
import cn.cslg.pas.common.utils.CacheUtils;
|
|
|
import cn.cslg.pas.common.utils.LoginUtils;
|
|
|
+import cn.cslg.pas.common.vo.business.AllCompanyAndAreaVO;
|
|
|
import cn.cslg.pas.common.vo.business.ProductMarketDataVO;
|
|
|
+import cn.cslg.pas.domain.business.Product;
|
|
|
import cn.cslg.pas.domain.business.ProductMarketData;
|
|
|
import cn.cslg.pas.exception.UnLoginException;
|
|
|
import cn.cslg.pas.exception.XiaoShiException;
|
|
|
import cn.cslg.pas.factorys.businessFactory.Business;
|
|
|
+import cn.cslg.pas.factorys.reGroupFactory.QueryGroupFactory;
|
|
|
+import cn.cslg.pas.factorys.reGroupFactory.QueryGroupImp;
|
|
|
import cn.cslg.pas.mapper.ProductMarketDataMapper;
|
|
|
import cn.cslg.pas.service.permissions.PermissionService;
|
|
|
import cn.cslg.pas.service.query.FormatQueryService;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
+ * 产品营销数据的Service层
|
|
|
* @Author xiexiang
|
|
|
* @Date 2023/11/16
|
|
|
*/
|
|
@@ -49,14 +61,20 @@ public class ProductMarketDataService extends ServiceImpl<ProductMarketDataMappe
|
|
|
private LoginUtils loginUtils;
|
|
|
|
|
|
@Autowired
|
|
|
+ private QueryGroupFactory queryGroupFactory;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
private PermissionService permissionService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ProductService productService;
|
|
|
+
|
|
|
@Override
|
|
|
public Object queryMessage(QueryRequest queryRequest) throws Exception {
|
|
|
List<String> sqls = formatQueryService.reSqls(queryRequest,"productMarketData");
|
|
|
List<ProductMarketDataVO> productMarketDataVOS = productMarketDataMapper.getProductMarketData(sqls.get(0),sqls.get(1),sqls.get(2));
|
|
|
//查询总数
|
|
|
- Long total = productMarketDataMapper.getProductCategoryCount(sqls.get(0));
|
|
|
+ Long total = productMarketDataMapper.getProductMarketDataCount(sqls.get(0));
|
|
|
this.loadProductMarketData(productMarketDataVOS);
|
|
|
Records records = new Records();
|
|
|
records.setCurrent(queryRequest.getCurrent());
|
|
@@ -86,10 +104,6 @@ public class ProductMarketDataService extends ServiceImpl<ProductMarketDataMappe
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public Object getGroup(GroupRequest groupRequest, String tableName) throws Exception {
|
|
|
- return null;
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public Object addMessage(Object object) {
|
|
@@ -162,6 +176,16 @@ public class ProductMarketDataService extends ServiceImpl<ProductMarketDataMappe
|
|
|
personnels = JSONObject.parseArray(jsonObject.getString("data"), Personnel.class);
|
|
|
}
|
|
|
for (ProductMarketDataVO productMarketDataVO : productMarketDataVOS) {
|
|
|
+ String saleTime = productMarketDataVO.getSaleTime();
|
|
|
+ SimpleDateFormat sdfOutput = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ SimpleDateFormat sdfString = new SimpleDateFormat("yyyy-MM");
|
|
|
+ try {
|
|
|
+ Date finalDate = sdfOutput.parse(saleTime);
|
|
|
+ String saleTimeString = sdfString.format(finalDate);
|
|
|
+ productMarketDataVO.setSaleTime(saleTimeString);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
//装载人员信息
|
|
|
Personnel personnel = personnels.stream().filter(item -> item.getId().equals(productMarketDataVO.getCreateId())).findFirst().orElse(null);
|
|
|
if (personnel != null) {
|
|
@@ -171,4 +195,91 @@ public class ProductMarketDataService extends ServiceImpl<ProductMarketDataMappe
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询营销数据分组信息
|
|
|
+ *
|
|
|
+ * @param groupRequest
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Object getGroup(GroupRequest groupRequest, String tableName) throws Exception {
|
|
|
+ StringRequest stringRequest = new StringRequest();
|
|
|
+ BeanUtils.copyProperties(groupRequest, stringRequest);
|
|
|
+ List<String> sqls = formatQueryService.reSqls(stringRequest, tableName);
|
|
|
+ //格式化 分组
|
|
|
+ GroupConfig groupConfig = null;
|
|
|
+ if (groupRequest.getGroupBy() != null) {
|
|
|
+ String json = CommonService.readJsonFile(tableName + ".json");
|
|
|
+ List<GroupConfig> groupConfigs = JSON.parseArray(json, GroupConfig.class);
|
|
|
+ groupConfig = groupConfigs.stream().filter(item -> groupRequest.getGroupBy().equals(item.getField())).findFirst().orElse(null);
|
|
|
+ if (groupConfig == null) {
|
|
|
+ throw new XiaoShiException("未找到配置");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //返回分组数据
|
|
|
+ tableName = "product_market_data as pmd left join product as p on pmd.product_id = p.id";
|
|
|
+ QueryGroupImp queryGroupImp = queryGroupFactory.getClass(groupConfig.getGroupClass());
|
|
|
+ ReGroupDataVO reGroupDataVO = queryGroupImp.getGroup(sqls, tableName, groupConfig.getSqlField());
|
|
|
+ //装载数据
|
|
|
+ GroupVO groupVO = new GroupVO();
|
|
|
+ groupVO.setField(groupRequest.getGroupBy());
|
|
|
+ groupVO.setValues(reGroupDataVO.getValues());
|
|
|
+ Records records = new Records();
|
|
|
+ records.setData(groupVO);
|
|
|
+ return records;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询所有公司和地区
|
|
|
+ * @param getAllCompanyAndAreaDTO
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public AllCompanyAndAreaVO getAllCompanyAndArea(GetAllCompanyAndAreaDTO getAllCompanyAndAreaDTO){
|
|
|
+ AllCompanyAndAreaVO allCompanyAndAreaVO = new AllCompanyAndAreaVO();
|
|
|
+ Integer productId = getAllCompanyAndAreaDTO.getProductId();
|
|
|
+ Integer categoryId = getAllCompanyAndAreaDTO.getCategoryId();
|
|
|
+ //如果产品id为空 则必须有类别id
|
|
|
+ if (productId == null) {
|
|
|
+ if (categoryId != null) {
|
|
|
+ allCompanyAndAreaVO.setCategoryId(categoryId);
|
|
|
+ //根据类别id查询公司名
|
|
|
+ LambdaQueryWrapper<Product> categoryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ categoryWrapper.eq(Product::getCategoryId, categoryId);
|
|
|
+ List<Product> products = productService.list(categoryWrapper);
|
|
|
+ List<String> companyNames = products.stream().map(Product::getCompanyName).distinct().collect(Collectors.toList());
|
|
|
+ allCompanyAndAreaVO.setCompanyNames(companyNames);
|
|
|
+ //根据查出来的产品ids查询地区名
|
|
|
+ List<Integer> productIds = products.stream().map(Product::getId).collect(Collectors.toList());
|
|
|
+ LambdaQueryWrapper<ProductMarketData> areaWrapper = new LambdaQueryWrapper<>();
|
|
|
+ areaWrapper.in(ProductMarketData::getProductId, productIds);
|
|
|
+ List<ProductMarketData> productMarketDatas = this.list(areaWrapper);
|
|
|
+ List<String> areas = productMarketDatas.stream().map(ProductMarketData::getSaleArea).distinct().collect(Collectors.toList());
|
|
|
+ allCompanyAndAreaVO.setSaleAreas(areas);
|
|
|
+ return allCompanyAndAreaVO;
|
|
|
+ } else {
|
|
|
+ throw new XiaoShiException("必须传一个参数");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (categoryId != null) {
|
|
|
+ throw new XiaoShiException("只能传一个参数");
|
|
|
+ } else {
|
|
|
+ //根据产品id查询
|
|
|
+ allCompanyAndAreaVO.setProductId(productId);
|
|
|
+ List<String> companyNames = new ArrayList<>();
|
|
|
+ Product product = productService.getById(productId);
|
|
|
+ companyNames.add(product.getCompanyName());
|
|
|
+ companyNames.stream().distinct();
|
|
|
+ allCompanyAndAreaVO.setCompanyNames(companyNames);
|
|
|
+ LambdaQueryWrapper<ProductMarketData> areaWrapper = new LambdaQueryWrapper<>();
|
|
|
+ areaWrapper.eq(ProductMarketData::getProductId, productId);
|
|
|
+ List<ProductMarketData> productMarketDatas = this.list(areaWrapper);
|
|
|
+ List<String> saleAreas = productMarketDatas.stream().map(ProductMarketData::getSaleArea).distinct().collect(Collectors.toList());
|
|
|
+ allCompanyAndAreaVO.setSaleAreas(saleAreas);
|
|
|
+ return allCompanyAndAreaVO;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|