Browse Source

综合展示接口调整

wangli 4 years ago
parent
commit
87154ae875

+ 4 - 2
sms_water/src/main/java/com/huaxu/client/UserCenterClient.java

@@ -1,13 +1,12 @@
 package com.huaxu.client;
 
 import com.huaxu.config.FeignConfig;
+import com.huaxu.dto.OrgBaseTreeInfoDto;
 import com.huaxu.entity.OperateLogEntity;
 import com.huaxu.entity.Org;
 import com.huaxu.model.AjaxMessage;
 import org.springframework.cloud.openfeign.FeignClient;
 import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
 
 import java.util.List;
@@ -35,4 +34,7 @@ public interface UserCenterClient {
 
     @PostMapping(value = "/org/countCompanyByUser")
     Integer countCompanyByUser();
+
+    @PostMapping(value = "/org/getCompanyByUser")
+    List<OrgBaseTreeInfoDto> getCompanyByUser(@RequestParam("condition") String condition,@RequestParam("companyIds") List<Integer> companyIds);
 }

+ 81 - 0
sms_water/src/main/java/com/huaxu/controller/AppReportMonitorController.java

@@ -0,0 +1,81 @@
+package com.huaxu.controller;
+
+import com.huaxu.client.UserCenterClient;
+import com.huaxu.dto.CompanySceneInfoDto;
+import com.huaxu.dto.OrgBaseTreeInfoDto;
+import com.huaxu.dto.homePage.WaterQualityRate;
+import com.huaxu.entity.SceneEntity;
+import com.huaxu.model.AjaxMessage;
+import com.huaxu.model.ResultStatus;
+import com.huaxu.service.AppReportMonitorService;
+import com.huaxu.service.HomePageReportService;
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import io.swagger.annotations.ApiParam;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2021/2/24 9:09
+ */
+@RestController
+@RequestMapping("/AppReportMonitorController")
+@Api(tags = "App报表展示")
+public class AppReportMonitorController {
+
+    @Autowired
+    private HomePageReportService homePageReportService;
+    @Autowired
+    private AppReportMonitorService appReportMonitorService;
+
+
+
+    @RequestMapping(value = "getSceneByCompany",method = RequestMethod.GET)
+    @ApiOperation(value = "App报表展示————公司查询(点击公司查询水厂)")
+    public AjaxMessage<List<SceneEntity>> getSceneByCompany(
+            @ApiParam(value = "场景类型名称:水源、水厂、泵站、管网") @RequestParam String sceneTypeName,
+            @ApiParam(value = "公司id") @RequestParam Integer companyOrgId){
+        return new AjaxMessage<>(ResultStatus.OK,appReportMonitorService.getSceneByCompany(sceneTypeName,companyOrgId));
+    }
+
+    @RequestMapping(value = "getSceneByCompanyBySearch",method = RequestMethod.GET)
+    @ApiOperation(value = "App报表展示————公司查询(条件查询)")
+    public AjaxMessage<CompanySceneInfoDto> getSceneByCompanyBySearch(
+            @ApiParam(value = "场景类型名称:水源、水厂、泵站、管网") @RequestParam String sceneTypeName,
+            @ApiParam(value = "查询条件") @RequestParam String condition){
+        return new AjaxMessage<>(ResultStatus.OK,appReportMonitorService.getSceneByCompanyBySearch(sceneTypeName,condition));
+    }
+
+
+
+
+
+
+
+
+
+
+    @RequestMapping(value = "getWaterQualification",method = RequestMethod.GET)
+    @ApiOperation(value = "综合展示——水质安全")
+    public AjaxMessage<WaterQualityRate> getWaterQualification(
+            @ApiParam(value = "公司id,总公司传空值") @RequestParam(required = false) Integer companyOrgId){
+        return new AjaxMessage<>(ResultStatus.OK,homePageReportService.getWaterQualification(companyOrgId));
+    }
+
+
+
+
+
+
+
+
+
+
+}

+ 20 - 0
sms_water/src/main/java/com/huaxu/dao/AppReportMonitorMapper.java

@@ -0,0 +1,20 @@
+package com.huaxu.dao;
+
+import com.huaxu.entity.SceneEntity;
+import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2021/3/19 11:43
+ */
+@Mapper
+public interface AppReportMonitorMapper {
+
+    List<SceneEntity> getSceneByCompany(@Param("sceneType") String sceneType,@Param("companyOrgId") Integer companyOrgId );
+
+    List<Integer> getCompanyBySceneCondition(@Param("sceneType") String sceneType,@Param("condition") String condition );
+}

+ 29 - 0
sms_water/src/main/java/com/huaxu/dto/CompanySceneInfoDto.java

@@ -0,0 +1,29 @@
+package com.huaxu.dto;
+
+import com.huaxu.entity.SceneEntity;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.util.List;
+
+/**
+ * @description 公司————场景信息
+ * @auto wangli
+ * @data 2021/3/19 14:28
+ */
+@Data
+public class CompanySceneInfoDto implements Serializable {
+
+    @ApiModelProperty("公司信息")
+    private List<OrgBaseTreeInfoDto> orgBaseTreeInfoDtos;
+    @ApiModelProperty("第一个公司的场景信息")
+    private List<SceneEntity> sceneEntities;
+
+    public CompanySceneInfoDto(){}
+
+    public CompanySceneInfoDto(List<OrgBaseTreeInfoDto> orgBaseTreeInfoDtos,List<SceneEntity> sceneEntities){
+        this.orgBaseTreeInfoDtos =orgBaseTreeInfoDtos;
+        this.sceneEntities =sceneEntities;
+    }
+}

+ 32 - 0
sms_water/src/main/java/com/huaxu/dto/OrgBaseTreeInfoDto.java

@@ -0,0 +1,32 @@
+package com.huaxu.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2021/3/18 17:33
+ */
+@Data
+public class OrgBaseTreeInfoDto implements Serializable {
+
+    private static final long serialVersionUID = -6468389729094977765L;
+
+    private Integer id ;
+    @ApiModelProperty(value = "父机构id")
+    private Integer parentOrgId ;
+    @ApiModelProperty(value = "父机构ids")
+    private String parentOrgIds ;
+
+    @ApiModelProperty(value = "子机构ids")
+    private String childOrgIds ;
+
+    @ApiModelProperty(value = "机构名称")
+    private String orgName;
+    @ApiModelProperty(value = "机构类型")
+    private String orgType;
+
+}

+ 28 - 0
sms_water/src/main/java/com/huaxu/service/AppReportMonitorService.java

@@ -0,0 +1,28 @@
+package com.huaxu.service;
+
+import com.huaxu.dto.CompanySceneInfoDto;
+import com.huaxu.entity.SceneEntity;
+
+import java.util.List;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2021/3/19 11:28
+ */
+public interface AppReportMonitorService {
+
+    /**
+     * 根据场景类型和公司id查询场景
+     * @param sceneTypeName
+     * @param companyOrgId
+     * @return
+     */
+    List<SceneEntity> getSceneByCompany( String sceneTypeName,Integer companyOrgId);
+
+    CompanySceneInfoDto getSceneByCompanyBySearch(String sceneTypeName, String condition);
+
+
+
+
+}

+ 61 - 0
sms_water/src/main/java/com/huaxu/service/impl/AppReportMonitorServiceImpl.java

@@ -0,0 +1,61 @@
+package com.huaxu.service.impl;
+
+import com.huaxu.client.UserCenterClient;
+import com.huaxu.dao.AppReportMonitorMapper;
+import com.huaxu.dto.CompanySceneInfoDto;
+import com.huaxu.dto.OrgBaseTreeInfoDto;
+import com.huaxu.entity.SceneEntity;
+import com.huaxu.service.AppReportMonitorService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2021/3/19 11:29
+ */
+@Service
+public class AppReportMonitorServiceImpl  implements AppReportMonitorService {
+
+    @Resource
+    private AppReportMonitorMapper appReportMonitorMapper;
+
+    @Autowired
+    private UserCenterClient userCenterClient;
+
+
+    @Override
+    public List<SceneEntity> getSceneByCompany(String sceneTypeName,Integer companyOrgId) {
+
+        return appReportMonitorMapper.getSceneByCompany(sceneTypeName,companyOrgId);
+    }
+
+    @Override
+    public CompanySceneInfoDto getSceneByCompanyBySearch(String sceneTypeName, String condition) {
+        //先查询公司
+        List<OrgBaseTreeInfoDto> orgBaseTreeInfoDtos = userCenterClient.getCompanyByUser(condition,null);
+        //有公司的展示第一个公司信息
+        if(orgBaseTreeInfoDtos.size() > 0){
+            List<SceneEntity> sceneEntities = appReportMonitorMapper.getSceneByCompany(sceneTypeName,orgBaseTreeInfoDtos.get(0).getId());
+            return new CompanySceneInfoDto(orgBaseTreeInfoDtos,sceneEntities);
+        }
+        //模糊查询场景所属公司id
+        List<Integer> companyIds = appReportMonitorMapper.getCompanyBySceneCondition(sceneTypeName,condition);
+        if(companyIds.size() > 0){
+            //根据场景的公司id查询公司
+            orgBaseTreeInfoDtos = userCenterClient.getCompanyByUser(null,companyIds);
+            //有公司的展示第一个公司信息
+            if(orgBaseTreeInfoDtos.size() > 0){
+                List<SceneEntity> sceneEntities = appReportMonitorMapper.getSceneByCompany(sceneTypeName,orgBaseTreeInfoDtos.get(0).getId());
+                return new CompanySceneInfoDto(orgBaseTreeInfoDtos,sceneEntities);
+            }
+        }
+
+        return new CompanySceneInfoDto();
+    }
+}

+ 10 - 11
sms_water/src/main/java/com/huaxu/service/impl/HomePageReportServiceImpl.java

@@ -14,7 +14,6 @@ import com.huaxu.model.LoginUser;
 import com.huaxu.service.HomePageReportService;
 import com.huaxu.service.MonitorDataReportService;
 import com.huaxu.util.UserUtil;
-import org.apache.commons.lang3.Conversion;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
@@ -45,7 +44,7 @@ public class HomePageReportServiceImpl implements HomePageReportService {
     private MonitorDataReportMapper monitorDataReportMapper;
 
     @Autowired
-    private MonitorDataReportService MonitorDataReportService;
+    private MonitorDataReportService monitorDataReportService;
 
     @Override
     public List<DeviceWaterSupply> deviceWaterReportForSixMonth(Integer companyOrgId,String sceneType, Integer parmType) {
@@ -56,11 +55,11 @@ public class HomePageReportServiceImpl implements HomePageReportService {
 
         List<DeviceWaterSupply> deviceWaterSupplies = homePageReportMapper.getDeviceWaterForSixMonth(companyOrgId,sceneType,parmType ,tenantId,loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
 
-        BigDecimal AmountCountMonth = MonitorDataReportService.getAmountCount(companyOrgId,null, sceneType, parmType,2 );
+        BigDecimal amountCount = monitorDataReportService.getAmountCount(companyOrgId,null, sceneType, parmType,2 );
 
         DeviceWaterSupply deviceWaterSupplyMonth = new DeviceWaterSupply();
         deviceWaterSupplyMonth.setOrderNo(1);
-        deviceWaterSupplyMonth.setAmount(AmountCountMonth!=null?AmountCountMonth.divide(new BigDecimal("10000")):BigDecimal.ZERO);
+        deviceWaterSupplyMonth.setAmount(amountCount!=null?amountCount.divide(new BigDecimal("10000")):BigDecimal.ZERO);
         deviceWaterSupplyMonth.setYear(localDate.getYear());
         deviceWaterSupplyMonth.setMonth(localDate.getMonthValue());
         deviceWaterSupplyMonth.setDate(localDate);
@@ -102,7 +101,7 @@ public class HomePageReportServiceImpl implements HomePageReportService {
 
         List<DeviceWaterSupply> deviceWaterSupplies = homePageReportMapper.getDeviceWaterForMonth(companyOrgId,sceneType,parmType ,tenantId,loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList(),month);
 
-        BigDecimal AmountCountMonth = MonitorDataReportService.getAmountCount(companyOrgId,null, sceneType, parmType,2 );
+        BigDecimal AmountCountMonth = monitorDataReportService.getAmountCount(companyOrgId,null, sceneType, parmType,2 );
 
         DeviceWaterSupply deviceWaterSupplyMonth = new DeviceWaterSupply();
         deviceWaterSupplyMonth.setOrderNo(1);
@@ -154,7 +153,7 @@ public class HomePageReportServiceImpl implements HomePageReportService {
     public CompanyProduce deviceWaterAmount(Integer companyOrgId) {
         LoginUser loginUser = UserUtil.getCurrentUser();
         String tenantId = loginUser.getTenantId();
-        Map<Integer, MonitorDataEntity> MonitorDataMap = MonitorDataReportService.getIntegerMonitorDataEntityMap(loginUser);
+        Map<Integer, MonitorDataEntity> MonitorDataMap = monitorDataReportService.getIntegerMonitorDataEntityMap(loginUser);
 
         LocalDate localDate = LocalDate.now();
 
@@ -272,7 +271,7 @@ public class HomePageReportServiceImpl implements HomePageReportService {
 
         LocalDate localDate = LocalDate.now();
         //当天数据
-        BigDecimal amountCount = MonitorDataReportService.getAmountCount(null,sceneId, sceneType, parmType,1 );
+        BigDecimal amountCount = monitorDataReportService.getAmountCount(null,sceneId, sceneType, parmType,1 );
         DeviceWaterSupply deviceWaterSupplyToday = new DeviceWaterSupply();
         deviceWaterSupplyToday.setOrderNo(1);
         deviceWaterSupplyToday.setAmount(amountCount != null?amountCount:BigDecimal.ZERO);
@@ -399,13 +398,13 @@ public class HomePageReportServiceImpl implements HomePageReportService {
 
         LocalDate localDate = LocalDate.now();
         //当天数据
-        BigDecimal waterDataCountDay = MonitorDataReportService.getAmountCount(null,sceneId, sceneType, 3,1 );
-        BigDecimal powerDataCountDay = MonitorDataReportService.getAmountCount(null,sceneId, sceneType, 5,1 );
-        BigDecimal drugDataCountDay = MonitorDataReportService.getAmountCount(null,sceneId, sceneType, 6,1 );
+        BigDecimal waterDataCountDay = monitorDataReportService.getAmountCount(null,sceneId, sceneType, 3,1 );
+        BigDecimal powerDataCountDay = monitorDataReportService.getAmountCount(null,sceneId, sceneType, 5,1 );
+        BigDecimal drugDataCountDay = monitorDataReportService.getAmountCount(null,sceneId, sceneType, 6,1 );
         WaterSupplyChart waterSupplyChartToday = new WaterSupplyChart();
         waterSupplyChartToday.setSort(localDate.getDayOfMonth());
         waterSupplyChartToday.setDate(DateTimeFormatter.ofPattern("yyyy-MM-dd").format(localDate));
-        waterSupplyChartToday.setWaterData(waterDataCountDay);
+        waterSupplyChartToday.setWaterData(waterDataCountDay.divide(new BigDecimal("10000"),3,BigDecimal.ROUND_HALF_UP));
         waterSupplyChartToday.setPowerData(powerDataCountDay);
         waterSupplyChartToday.setDrugData(drugDataCountDay);
 

+ 18 - 19
sms_water/src/main/java/com/huaxu/service/impl/MonitorDataReportServiceImpl.java

@@ -15,6 +15,7 @@ import com.huaxu.util.ByteArrayUtils;
 import com.huaxu.util.OrgInfoUtil;
 import com.huaxu.util.RedisUtil;
 import com.huaxu.util.UserUtil;
+import io.swagger.annotations.ApiModelProperty;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
@@ -1011,21 +1012,13 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
     public List<WaterSupplyChart> waterSupplyChartsByMonth(String sceneTypeName, Integer companyOrgId) {
         LoginUser loginUser = UserUtil.getCurrentUser();
         String tenantId = loginUser.getTenantId();
+
         List<WaterSupplyData> waterSupplyDatas = monitorDataReportMapper.getWaterSupplyDataByMonth(tenantId,companyOrgId,sceneTypeName,loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
-        List<WaterSupplyData> waterSupplyDatasForCurrentMonth = monitorDataReportMapper.getWaterSupplyDataByMonthForCurrentMonth(tenantId,companyOrgId,sceneTypeName,loginUser.getType(),loginUser.getPermissonType(),loginUser.getProgramItemList());
-        if(waterSupplyDatasForCurrentMonth.size()>0) {
-            //获取当天数据
-            ComUsageDto comUsageDto = getYieldPowerUsage(companyOrgId!=null?Long.valueOf(companyOrgId):null);
-            if(comUsageDto!=null) {
-                for (WaterSupplyData item : waterSupplyDatasForCurrentMonth) {
-                    if (item.getParmType() == 3)
-                        item.setAmount(item.getAmount() != null ? item.getAmount().add(BigDecimal.valueOf(comUsageDto.getYieldWaterUsage())) : item.getAmount());
-                    if (item.getParmType() == 5)
-                        item.setAmount(item.getAmount() != null ? item.getAmount().add(BigDecimal.valueOf(comUsageDto.getPowerUsage())) : item.getAmount());
-                }
-            }
-            waterSupplyDatas.addAll(waterSupplyDatasForCurrentMonth);
-        }
+        //获取本月水量
+        BigDecimal waterDataAmountCountMonth = getAmountCount(companyOrgId,null, sceneTypeName, 3,2 );
+        //获取本月电耗
+        BigDecimal powerDataAmountCountMonth = getAmountCount(companyOrgId,null, sceneTypeName, 5,2 );
+
         List<WaterSupplyChart> waterSupplyCharts = new ArrayList<>();
         waterSupplyDatas.stream()
                 .collect(Collectors.groupingBy(item -> item.getYear() + "-" + item.getMonth()))
@@ -1034,21 +1027,27 @@ public class MonitorDataReportServiceImpl implements MonitorDataReportService {
                     waterSupplyChart.setDate(key);
                     value.stream().forEach(waterSupplyData -> {
                         Period period = Period.between(LocalDate.of(waterSupplyData.getYear(), waterSupplyData.getMonth(),1), LocalDate.now());
-                        waterSupplyChart.setSort(period.getMonths());
+                        waterSupplyChart.setSort(period.getMonths()+1);
                         if (waterSupplyData.getParmType() == 3) { //供水
                             waterSupplyChart.setWaterData(waterSupplyData.getAmount().divide(BigDecimal.valueOf(10000),2, RoundingMode.HALF_UP));
                         } else if (waterSupplyData.getParmType() == 5) {//电耗
-                            waterSupplyChart.setPowerData(waterSupplyData.getAmount().divide(BigDecimal.valueOf(10000),2, RoundingMode.HALF_UP));
+                            waterSupplyChart.setPowerData(waterSupplyData.getAmount());
                         }
                     });
                     waterSupplyCharts.add(waterSupplyChart);
                 });
+        WaterSupplyChart waterSupplyChart = new WaterSupplyChart();
+        waterSupplyChart.setSort(1);
+        waterSupplyChart.setDate(LocalDate.now().getYear()+"-"+LocalDate.now().getMonthValue());
+        waterSupplyChart.setPowerData(powerDataAmountCountMonth);
+        waterSupplyChart.setWaterData(waterDataAmountCountMonth);
+        waterSupplyCharts.add(waterSupplyChart);
 
         waterSupplyCharts.sort(Comparator.comparing(WaterSupplyChart::getSort));
         for(int i=0;i<6;i++){
-//            if(i == waterSupplyCharts.size() || !waterSupplyCharts.get(i).getSort().equals(i+1)){
-//               waterSupplyCharts.add(i,new WaterSupplyChart(i+1));
-//            }
+            if(i == waterSupplyCharts.size() || !waterSupplyCharts.get(i).getSort().equals(i+1)){
+                waterSupplyCharts.add(i,new WaterSupplyChart(i+1, LocalDate.now().getYear()+"-"+LocalDate.now().getMonthValue()));
+            }
         }
         waterSupplyCharts.sort(Comparator.comparing(WaterSupplyChart::getSort).reversed());
         return waterSupplyCharts;

+ 5 - 5
sms_water/src/main/java/com/huaxu/service/impl/TestDataServiceImpl.java

@@ -59,7 +59,7 @@ public class TestDataServiceImpl implements TestDataService {
         Double j =0d;
         List<DayReportEntity> dayReportEntities =new ArrayList<>();
         for(int i=0; beginDateTime.isBefore(endDateTime);i++,j++){
-            Double value = r.nextDouble() * 120000;
+            Double value = r.nextDouble() * 12000;
 
             if(i==24){
                 i=0;
@@ -87,13 +87,13 @@ public class TestDataServiceImpl implements TestDataService {
                 dayReport.setMinValue(j);
                 dayReport.setAvgValue(j+(value/2));
                 dayReport.setSumValue(value);
-                j+=value;
-                dayReport.setMaxValue(j);
-                dayReport.setLatestValue(j);
+
+                dayReport.setMaxValue(j+value);
+                dayReport.setLatestValue(j+value);
                 dayReport.setCollectDate(Date.from(beginDateTime.atZone(ZoneId.systemDefault()).toInstant()));
                 dayReportEntities.add(dayReport);
             }
-
+            j+=value;
         }
         if(dayReportEntities.size()>0){
             for(int i=0;500*i<dayReportEntities.size();i++){

+ 31 - 0
sms_water/src/main/resources/mapper/AppReportMonitorMapper.xml

@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.huaxu.dao.AppReportMonitorMapper">
+
+    <select id="getSceneByCompany" resultType="com.huaxu.entity.SceneEntity">
+        select
+            s.id,
+            s.SCENE_NAME as "sceneName",
+            s.PARENT_SCENE_ID as "parentSceneId"
+        from sms_scene_type st
+        left join sms_scene s on st.id=s.SCENE_TYPE_ID
+        where st.SCENE_TYPE_NAME =#{sceneType}
+        and  s.COMPANY_ORG_ID = #{companyOrgId}
+        order by s.SCENE_NAME
+
+    </select>
+
+    <select id="getCompanyBySceneCondition" resultType="java.lang.Integer">
+        select
+         s.COMPANY_ORG_ID
+        from sms_scene_type st
+        left join sms_scene s on st.id=s.SCENE_TYPE_ID
+        where
+        st.SCENE_TYPE_NAME =#{sceneType}
+        <if test="condition != null and condition !=''">
+            and s.SCENE_NAME like concat('%',#{condition},'%')
+        </if>
+
+    </select>
+
+</mapper>

+ 7 - 3
user_center/src/main/java/com/huaxu/controller/OrgController.java

@@ -1,13 +1,11 @@
 package com.huaxu.controller;
 
-import com.baomidou.mybatisplus.core.metadata.IPage;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.huaxu.dto.OrgBaseTreeInfoDto;
 import com.huaxu.dto.OrgTree;
 import com.huaxu.entity.Org;
 import com.huaxu.logAdvice.LogAnnotation;
 import com.huaxu.model.AjaxMessage;
 import com.huaxu.model.LoginUser;
-import com.huaxu.model.Pagination;
 import com.huaxu.model.ResultStatus;
 import com.huaxu.service.OrgService;
 import com.huaxu.util.UserUtil;
@@ -166,4 +164,10 @@ public class OrgController {
     public Integer countCompanyByUser() {
         return orgService.countCompanyByUser();
     }
+
+
+    @RequestMapping(value = "getCompanyByUser", method = RequestMethod.POST)
+    public List<OrgBaseTreeInfoDto> getCompanyByUser(@RequestParam("condition") String condition,@RequestParam("companyIds") List<Integer> companyIds ) {
+        return orgService.getCompanyByUser(condition,companyIds);
+    }
 }

+ 3 - 0
user_center/src/main/java/com/huaxu/dao/OrgMapper.java

@@ -1,6 +1,7 @@
 package com.huaxu.dao;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.huaxu.dto.OrgBaseTreeInfoDto;
 import com.huaxu.dto.OrgTree;
 import com.huaxu.entity.Org;
 import com.huaxu.model.ProgramItem;
@@ -94,5 +95,7 @@ public interface OrgMapper {
 
     Integer countCompanyByUser( @Param("tenantId")String tenantId, @Param("userType")String userType,
                                 @Param("programItems")List<ProgramItem> programItems);
+    List<OrgBaseTreeInfoDto> getCompanyByUser(@Param("condition")String condition,@Param("companyIds")List<Integer> companyIds, @Param("tenantId")String tenantId, @Param("userType")String userType,
+                                              @Param("programItems")List<ProgramItem> programItems);
 
 }

+ 30 - 0
user_center/src/main/java/com/huaxu/dto/OrgBaseTreeInfoDto.java

@@ -0,0 +1,30 @@
+package com.huaxu.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @description
+ * @auto wangli
+ * @data 2021/3/18 17:33
+ */
+@Data
+public class OrgBaseTreeInfoDto implements Serializable {
+
+    private static final long serialVersionUID = -6468389729094977765L;
+
+    private Integer id ;
+    @ApiModelProperty(value = "父机构id")
+    private Integer parentOrgId ;
+    @ApiModelProperty(value = "父机构ids")
+    private String parentOrgIds ;
+    @ApiModelProperty(value = "子机构ids")
+    private String childOrgIds ;
+    @ApiModelProperty(value = "机构名称")
+    private String orgName;
+    @ApiModelProperty(value = "机构类型")
+    private String orgType;
+
+}

+ 2 - 1
user_center/src/main/java/com/huaxu/service/OrgService.java

@@ -1,9 +1,9 @@
 package com.huaxu.service;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.huaxu.dto.OrgBaseTreeInfoDto;
 import com.huaxu.dto.OrgTree;
 import com.huaxu.entity.Org;
-import com.huaxu.model.ProgramItem;
 
 import java.util.List;
 
@@ -92,4 +92,5 @@ public interface OrgService {
     String findParentOrgByChildId(Integer childId);
 
     Integer countCompanyByUser();
+    List<OrgBaseTreeInfoDto> getCompanyByUser(String condition,List<Integer> companyIds);
 }

+ 44 - 3
user_center/src/main/java/com/huaxu/service/impl/OrgServiceImpl.java

@@ -2,6 +2,7 @@ package com.huaxu.service.impl;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.huaxu.dao.OrgMapper;
+import com.huaxu.dto.OrgBaseTreeInfoDto;
 import com.huaxu.dto.OrgTree;
 import com.huaxu.entity.Org;
 import com.huaxu.model.LoginUser;
@@ -10,12 +11,11 @@ import com.huaxu.service.OrgService;
 import com.huaxu.util.ByteArrayUtils;
 import com.huaxu.util.RedisUtil;
 import com.huaxu.util.UserUtil;
-import io.swagger.models.auth.In;
-import org.apache.ibatis.annotations.Param;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.Resource;
 import java.util.*;
 
 import static com.google.common.collect.Lists.newArrayList;
@@ -28,7 +28,7 @@ import static com.google.common.collect.Lists.newArrayList;
  */
 @Service("orgService")
 public class OrgServiceImpl implements OrgService {
-    @Autowired
+    @Resource
     private OrgMapper orgMapper;
     @Autowired
     private RedisUtil redisUtil;
@@ -337,4 +337,45 @@ public class OrgServiceImpl implements OrgService {
         LoginUser loginUser = UserUtil.getCurrentUser();
         return orgMapper.countCompanyByUser(loginUser.getTenantId(),loginUser.getType(),loginUser.getProgramItemList());
     }
+
+    @Override
+    public List<OrgBaseTreeInfoDto> getCompanyByUser(String condition,List<Integer> companyIds) {
+        LoginUser loginUser = UserUtil.getCurrentUser();
+        List<OrgBaseTreeInfoDto> list = orgMapper.getCompanyByUser(condition,companyIds,loginUser.getTenantId(),loginUser.getType(),loginUser.getProgramItemList());
+        //获取每个节点的父id集合
+//        getOrgPids(null,0,list);
+//        getOrgchildIds(new OrgBaseTreeInfoDto(),0,list);
+        return list;
+    }
+
+    //获取每个节点的父id集合
+    private void getOrgPids(OrgBaseTreeInfoDto pOrg, Integer pid, List<OrgBaseTreeInfoDto> orgs){
+
+        for(OrgBaseTreeInfoDto org :orgs){
+            if(org.getParentOrgId() != null  && org.getParentOrgId().equals( pid)){
+                if(pid == 0){
+                    org.setParentOrgIds( org.getId()+"");
+                }else{
+                    org.setParentOrgIds( pOrg.getParentOrgIds()+","+org.getId());
+                }
+                getOrgPids(org ,org.getId() , orgs);
+            }
+        }
+    }
+
+    //获取每个节点的子id集合
+    private String getOrgchildIds(OrgBaseTreeInfoDto pOrg, Integer pid, List<OrgBaseTreeInfoDto> orgs){
+        String childIds="";
+        for(OrgBaseTreeInfoDto org :orgs){
+            if(org.getParentOrgId() != null  && org.getParentOrgId().equals( pid)){
+                childIds = childIds +","+getOrgchildIds(org ,org.getId() , orgs);
+            }
+        }
+        if(pOrg == null){
+            return childIds;
+        }
+        pOrg.setChildOrgIds(pOrg.getId()+childIds);
+        return pOrg.getChildOrgIds();
+    }
+
 }

+ 29 - 0
user_center/src/main/resources/mapper/OrgMapper.xml

@@ -317,4 +317,33 @@
         </if>
     </select>
 
+    <select id="getCompanyByUser" resultType="com.huaxu.dto.OrgBaseTreeInfoDto">
+        select
+            p.id as "id",
+            p.org_name as "orgName",
+            p.PARENT_ORG_ID as "parentOrgId",
+            p.ORG_TYPE as "orgType"
+        from uims_org p
+        where p.`STATUS` = 1
+        and p.PARENT_ORG_ID != 0 and p.ORG_TYPE = 'company'
+        and p.TENANT_ID = #{tenantId}
+        <if test="condition != null and condition != ''">
+            and p.org_name like concat('%', #{condition},'%')
+        </if>
+        <if test="companyIds != null and companyIds.size() > 0">
+            and p.id in
+            <foreach collection="companyIds" item="item" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+        </if>
+        <if test="userType!=null and userType!=-999 and userType!=-9999 and  programItems != null and programItems.size() > 0">
+            and p.id in
+            <foreach collection="programItems" item="item" open="(" close=")" separator=",">
+                #{item.orgId}
+            </foreach>
+        </if>
+        order by p.org_name asc
+    </select>
+
+
 </mapper>