Parcourir la source

2023/3/13 查询

lwhhszx il y a 2 ans
Parent
commit
7724422100

+ 4 - 0
PAS/src/main/java/cn/cslg/pas/common/model/dto/StructureQueryPageDTO.java

@@ -20,5 +20,9 @@ public class StructureQueryPageDTO {
      * 架构id
      */
     private Integer structureId;
+    /**
+     * 架构名称
+     */
+    private String structureName;
 
 }

+ 5 - 2
PAS/src/main/java/cn/cslg/pas/mapper/StructureMapper.java

@@ -2,6 +2,7 @@ package cn.cslg.pas.mapper;
 
 import cn.cslg.pas.common.model.vo.StructureVO;
 import cn.cslg.pas.domain.Structure;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import org.springframework.stereotype.Repository;
 
 import java.util.List;
@@ -13,7 +14,7 @@ import java.util.List;
  * @Date 2023/3/10
  */
 @Repository
-public interface StructureMapper {
+public interface StructureMapper extends BaseMapper<Structure> {
     /**
      * 插入数据
      *
@@ -63,7 +64,7 @@ public interface StructureMapper {
      * @param productId 产品id
      * @return 返回查询到的数据
      */
-    List<StructureVO> selectByParentIdAndProductId(Integer parentId, Integer productId);
+    List<StructureVO> selectByParentIdAndProductId(Integer parentId, Integer productId,List<Integer> ids);
 
     /**
      * 根据模糊路径查询数据
@@ -73,6 +74,8 @@ public interface StructureMapper {
      */
     List<StructureVO> selectByFindInSetPath(String findInSetPath);
 
+    List<StructureVO> selectByName(String name);
+
     //List<StructureVO>
 
 }

+ 40 - 6
PAS/src/main/java/cn/cslg/pas/service/impl/ProductCategoryServiceImpl.java

@@ -260,9 +260,16 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
         List<ProductCategoryTrendVO> trendVOS = new ArrayList<>();
         //存储所有产品的营销数据
         List<ProductMarketData> marketData = new ArrayList<>();
+        //存储所有
+        ProductCategoryTrendVO trendAllVO = new ProductCategoryTrendVO();
+        trendAllVO.setProductId(0);
+        trendAllVO.setProductName("总产品");
+        Map<String, Object> allMarketDataMap = new HashMap<>();
         //根据产品类别ID获得产品id和产品名称
         LambdaQueryWrapper<Product> productWrapper = new LambdaQueryWrapper<>();
         productWrapper.eq(Product::getProductCategoryId, dto.getCategoryId());
+        if(dto.getCompanyName()!=null&&dto.getCompanyName()!=""){
+        productWrapper.eq(Product::getCompanyName,dto.getCompanyName());}
         List<Product> products = productService.list(productWrapper);
         if (products.size() != 0) {
             List<Integer> productIds = products.stream().map(Product::getId).collect(Collectors.toList());
@@ -290,23 +297,42 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
             temMarketData.forEach(item -> {
                         //获得营销数据的时间
                         String date = item.getSaleTime();
-                        double saleCount = item.getSaleCount() * item.getSaleMoney();
+                        double saleCount = item.getSaleMoney();
                         if (dto.getTimeUnit() == 1) {
                             try {
                                 Date dateForm = new SimpleDateFormat("yyyy-MM").parse(date);
-                                int month = dateForm.getMonth();
-                                int year = dateForm.getYear();
-                                int season = (month - 1) / 3;
+                                Calendar ca = Calendar.getInstance();
+                                ca.setTime(dateForm);
+                                int month = ca.get(Calendar.MONTH);//第几个月
+                                int year = ca.get(Calendar.YEAR);//年份数值
+                                int season = (month - 1) / 3+1;
                                 date = year + "-" + season;
                             } catch (ParseException e) {
                                 e.printStackTrace();
                             }
                         }
+                        else if(dto.getTimeUnit() == 2){
+                            try {
+                                Date dateForm = new SimpleDateFormat("yyyy-MM").parse(date);
+                                Calendar ca = Calendar.getInstance();
+                                ca.setTime(dateForm);
+                                int year = ca.get(Calendar.YEAR);//年份数值
+                                date = year+"";
+                            } catch (ParseException e) {
+                                e.printStackTrace();
+                            }
+                        }
                         //计算销售额
                         if (marketDataMap.get(date) != null) {
                             saleCount += Double.parseDouble(marketDataMap.get(date).toString());
                         }
                         marketDataMap.put(date, saleCount);
+
+                        //产品总体部分
+                if (allMarketDataMap.get(date) != null) {
+                    saleCount += Double.parseDouble(allMarketDataMap.get(date).toString());
+                }
+                allMarketDataMap.put(date, saleCount);
                     }
             );
             Set keyset = marketDataMap.keySet();
@@ -320,7 +346,16 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
             trendVO.setSaleVOS(saleVOS);
             trendVOS.add(trendVO);
         }
-
+        Set keyset = allMarketDataMap.keySet();
+        List<ProductCategoryTrendVO.saleVO> saleVOS = new ArrayList<>();
+        for (Object key : keyset) {
+            ProductCategoryTrendVO.saleVO saleVO = new ProductCategoryTrendVO.saleVO();
+            saleVO.setMarketData(key.toString());
+            saleVO.setSaleTotalMoney(Double.parseDouble(allMarketDataMap.get(key).toString()));
+            saleVOS.add(saleVO);
+        }
+        trendAllVO.setSaleVOS(saleVOS);
+        trendVOS.add(trendAllVO);
         return trendVOS;
     }
 
@@ -354,7 +389,6 @@ public class ProductCategoryServiceImpl implements IProductCategoryService {
 
 
     public List<String> getCompanyList(Integer id) {
-
         List<String> areaList = new ArrayList<>();
         //根据架构id获得产品
         LambdaQueryWrapper<Product> productWrapper = new LambdaQueryWrapper<>();

+ 32 - 10
PAS/src/main/java/cn/cslg/pas/service/impl/StructureServiceImpl.java

@@ -5,12 +5,16 @@ import cn.cslg.pas.common.model.vo.PathStructureNameVO;
 import cn.cslg.pas.common.model.vo.StructurePictureVO;
 import cn.cslg.pas.common.model.vo.StructureVO;
 import cn.cslg.pas.common.utils.FileUtils;
+import cn.cslg.pas.domain.Project;
 import cn.cslg.pas.domain.Structure;
 import cn.cslg.pas.domain.asso.AssoStructurePicture;
 import cn.cslg.pas.exception.XiaoShiException;
 import cn.cslg.pas.mapper.AssoStructurePictureMapper;
+import cn.cslg.pas.mapper.ProjectMapper;
 import cn.cslg.pas.mapper.StructureMapper;
 import cn.cslg.pas.service.IStructureService;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.BeanUtils;
@@ -18,7 +22,9 @@ import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * 架构的Service层接口实现类
@@ -29,7 +35,7 @@ import java.util.List;
 @RequiredArgsConstructor
 @Slf4j
 @Service
-public class StructureServiceImpl implements IStructureService {
+public class StructureServiceImpl extends ServiceImpl<StructureMapper, Structure> implements IStructureService {
     private final StructureMapper structureMapper;
     private final AssoStructurePictureMapper assoStructurePictureMapper;
     private final FileUtils fileUtils;
@@ -253,13 +259,31 @@ public class StructureServiceImpl implements IStructureService {
     @Override
     public StructureVO query(StructureQueryPageDTO structureQueryPageDTO) {
         log.info("开始处理【查询架构树】的业务,参数为:{}", structureQueryPageDTO);
-
-        //从DTO中取出产品id、架构id、架构名称
+        StructureVO structureVO = new StructureVO();
+        //从DTO中取出产品id、架构id
         Integer productId = structureQueryPageDTO.getProductId();
         Integer structureId = structureQueryPageDTO.getStructureId();
+        LambdaQueryWrapper<Structure> wrapper = new LambdaQueryWrapper<>();
+        wrapper.like(Structure::getStructureName, structureQueryPageDTO.getStructureName());
+        List<Structure> structures = this.list(wrapper);
+        List<Integer> ids = structures.stream().map(Structure::getId).collect(Collectors.toList());
+        List<String> paths = structures.stream().map(Structure::getPath).collect(Collectors.toList());
+        paths.forEach(
+                item -> {
+                    String[] pathStrs = item.split(",");
+                    List<String> pathStr = new ArrayList<>(Arrays.asList(pathStrs));
+                    pathStr.forEach(
+                            tem -> {
+                                Integer paId = Integer.parseInt(tem);
+                                if (!ids.contains(paId)) {
+                                    ids.add(paId);
+                                }
+                            }
+                    );
+                }
+        );
 
-        StructureVO structureVO = new StructureVO();
-        diGui(structureVO, structureId, productId);
+        diGui(structureVO, structureId, productId, ids);
         return structureVO;
     }
 
@@ -304,18 +328,16 @@ public class StructureServiceImpl implements IStructureService {
         }
 
 
-
-
     }
 
     //递归组装架构树集合
-    private void diGui(StructureVO structureVO, Integer structureId, Integer productId) {
-        List<StructureVO> structureVOs = structureMapper.selectByParentIdAndProductId(structureId, productId);
+    private void diGui(StructureVO structureVO, Integer structureId, Integer productId, List<Integer> ids) {
+        List<StructureVO> structureVOs = structureMapper.selectByParentIdAndProductId(structureId, productId, ids);
         if (structureVOs != null) {
             structureVO.setChildren(structureVOs);
             for (StructureVO n : structureVOs) {
                 structureId = n.getId();
-                diGui(n, structureId, productId);
+                diGui(n, structureId, productId, ids);
             }
         }
     }

+ 14 - 1
PAS/src/main/resources/mapper/StructureMapper.xml

@@ -82,6 +82,10 @@
         from structure
         where parent_id = #{parentId}
           and product_id = #{productId}
+        and id in
+        <foreach collection="ids" item="item" separator="," open="(" close=")">
+            #{item}
+        </foreach>
         order by s_id
     </select>
 
@@ -127,7 +131,16 @@
         from structure
         where find_in_set(#{findInSetPath}, path)
     </select>
-
+    <select id="selectByName" resultMap="selectByFindInSetPathMap">
+        select id,
+               parent_id,
+               structure_name,
+               path,
+               remark,
+               product_id
+        from structure
+        where  structure_name like concat('%', #{name}, '%') order By LENGTH(path)
+    </select>
     <resultMap id="selectByFindInSetPathMap" type="cn.cslg.pas.common.model.vo.StructureVO">
         <id column="id" property="id"/>
         <result column="parent_id" property="parentId"/>