diff --git a/zfipc-server/zfipc-admin/src/main/java/com/inspur/web/controller/bigscreen/CompanyDashboardController.java b/zfipc-server/zfipc-admin/src/main/java/com/inspur/web/controller/bigscreen/CompanyDashboardController.java new file mode 100644 index 0000000..5fa84f9 --- /dev/null +++ b/zfipc-server/zfipc-admin/src/main/java/com/inspur/web/controller/bigscreen/CompanyDashboardController.java @@ -0,0 +1,33 @@ +package com.inspur.web.controller.bigscreen; + +import com.inspur.bigscreen.service.ICompanyDashboardService; +import com.inspur.common.core.domain.AjaxResult; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * 公司级控制层 + * @Author zhangjunwen + * @create 2024/7/15 + */ +@RestController +@RequestMapping("/bigscreen/company") +public class CompanyDashboardController { + + @Autowired + private ICompanyDashboardService factoryDashboardService; + + @GetMapping("/countEquipNumByCompany/{deptId}") + public AjaxResult countEquipNumByCompany(@PathVariable Long deptId) { + return AjaxResult.success(factoryDashboardService.countEquipNumByStatus(deptId)); + } + + + @GetMapping("/countEquipNumByDiffCompany/{deptId}") + public AjaxResult countEquipNumByDiffCompany(@PathVariable Long deptId) { + return AjaxResult.success(factoryDashboardService.countEquipNumByCompanyId(deptId)); + } +} diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/constant/EquipInfoStatus.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/constant/EquipInfoStatus.java new file mode 100644 index 0000000..854d174 --- /dev/null +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/constant/EquipInfoStatus.java @@ -0,0 +1,29 @@ +package com.inspur.bigscreen.constant; + +/** + * @Author zhangjunwen + * @create 2024/7/15 + */ +public class EquipInfoStatus { + + /** + * 运行 + */ + public static final Integer RUNNING = 0; + + /** + * 维修保养 + */ + public static final Integer MAINTENANCE = 1; + + /** + * 停机 + */ + public static final Integer STOP = 2; + + /** + * 报废 + */ + public static final Integer SCRAP = 3; + +} diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/dto/CompanyDashboardDTO.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/dto/CompanyDashboardDTO.java new file mode 100644 index 0000000..1f6fad8 --- /dev/null +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/dto/CompanyDashboardDTO.java @@ -0,0 +1,29 @@ +package com.inspur.bigscreen.dto; + +import lombok.Data; + +import java.util.List; + +/** + * 公司级产线 + * @Author zhangjunwen + * @create 2024/7/15 + */ +@Data +public class CompanyDashboardDTO { + + private Long deptId; + + private String deptName; + + private Integer data; + + private Integer status; + + private String time; + + private List x; + + private List y; + +} diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/mapper/CompanyDashboardMapper.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/mapper/CompanyDashboardMapper.java new file mode 100644 index 0000000..3fec898 --- /dev/null +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/mapper/CompanyDashboardMapper.java @@ -0,0 +1,27 @@ +package com.inspur.bigscreen.mapper; + +import com.inspur.bigscreen.dto.CompanyDashboardDTO; +import com.inspur.bigscreen.dto.FactoryDashboardDTO; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +/** + * @Author zhangjunwen + * @create 2024/7/15 + */ +public interface CompanyDashboardMapper { + + /** + * 查询公司的各个状态设备数量 + * @param deptId + */ + public CompanyDashboardDTO countDiffStatusCompanyEquipNumByDeptId(@Param("deptId")Long deptId, + @Param("status")Integer status); + + /** + * 根据厂区部门id查询设备总数 + */ + public CompanyDashboardDTO countEquipNumByCompany(@Param("deptId")Long deptId); + +} diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/mapper/FactoryDashboardMapper.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/mapper/FactoryDashboardMapper.java index 62e093e..a9f0b73 100644 --- a/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/mapper/FactoryDashboardMapper.java +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/mapper/FactoryDashboardMapper.java @@ -23,7 +23,8 @@ public interface FactoryDashboardMapper { /** * 根据厂区部门id查询各个产线不同状态设备数 */ - public List countEquipNumByStatusandProductionLine(Long deptId); + public List countEquipNumByStatusandProductionLine(@Param("deptId")Long deptId, + @Param("status")Integer status); /** * 根据厂区部门id查询各个产线传感器数量 diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/service/ICompanyDashboardService.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/service/ICompanyDashboardService.java new file mode 100644 index 0000000..2f59fa7 --- /dev/null +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/service/ICompanyDashboardService.java @@ -0,0 +1,24 @@ +package com.inspur.bigscreen.service; + +import com.inspur.bigscreen.dto.CompanyDashboardDTO; +import com.inspur.bigscreen.dto.FactoryDashboardDTO; + +import java.util.List; + +/** + * 公司级业务层接口 + * @Author zhangjunwen + * @create 2024/7/15 + */ +public interface ICompanyDashboardService { + + /** + * 统计不同状态公司设备数 + */ + public List countEquipNumByStatus(Long deptId); + + /** + * 根据公司id统计公司设备数 + */ + public List countEquipNumByCompanyId(Long deptId); +} diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/service/impl/CompanyDashboardService.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/service/impl/CompanyDashboardService.java new file mode 100644 index 0000000..60413da --- /dev/null +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/service/impl/CompanyDashboardService.java @@ -0,0 +1,63 @@ +package com.inspur.bigscreen.service.impl; + +import com.inspur.bigscreen.constant.EquipInfoStatus; +import com.inspur.bigscreen.dto.CompanyDashboardDTO; +import com.inspur.bigscreen.dto.FactoryDashboardDTO; +import com.inspur.bigscreen.mapper.CompanyDashboardMapper; +import com.inspur.bigscreen.service.ICompanyDashboardService; +import com.inspur.bigscreen.service.IFactoryDashboardService; +import com.inspur.common.core.domain.entity.SysDept; +import com.inspur.system.mapper.SysDeptMapper; +import com.inspur.system.service.ISysDeptService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 公司级业务层 + * @Author zhangjunwen + * @create 2024/7/15 + */ +@Service +public class CompanyDashboardService implements ICompanyDashboardService { + + @Autowired + private CompanyDashboardMapper companyDashboardMapper; + + @Autowired + private SysDeptMapper sysDeptMapper; + + /** + * 统计不同状态公司设备数 + */ + public List countEquipNumByStatus(Long deptId){ + List resultList = new ArrayList<>(); + CompanyDashboardDTO runData = companyDashboardMapper.countDiffStatusCompanyEquipNumByDeptId(deptId, EquipInfoStatus.RUNNING); + CompanyDashboardDTO stopData = companyDashboardMapper.countDiffStatusCompanyEquipNumByDeptId(deptId, EquipInfoStatus.STOP); + CompanyDashboardDTO maintainData = companyDashboardMapper.countDiffStatusCompanyEquipNumByDeptId(deptId, EquipInfoStatus.MAINTENANCE); + resultList.add(runData); + resultList.add(stopData); + resultList.add(maintainData); + return resultList; + } + + /** + * 根据公司id统计公司设备数 + */ + @Override + public List countEquipNumByCompanyId(Long deptId){ + //查询给定公司id的厂区id + List childDeptList = sysDeptMapper.selectChildrenDeptById(deptId); + List factoryDeptList = childDeptList.stream().filter(dept -> dept.getAncestors().split(",").length == 3 ).collect(Collectors.toList()); + List resultList = new ArrayList<>(); + factoryDeptList.forEach(factoryDept -> { + CompanyDashboardDTO companyDashboardDTO = companyDashboardMapper.countEquipNumByCompany(factoryDept.getDeptId()); + resultList.add(companyDashboardDTO); + }); + return resultList; + } + +} diff --git a/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/service/impl/FactoryDashboardService.java b/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/service/impl/FactoryDashboardService.java index d9dd48a..137d9a2 100644 --- a/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/service/impl/FactoryDashboardService.java +++ b/zfipc-server/zfipc-system/src/main/java/com/inspur/bigscreen/service/impl/FactoryDashboardService.java @@ -1,5 +1,6 @@ package com.inspur.bigscreen.service.impl; +import com.inspur.bigscreen.constant.EquipInfoStatus; import com.inspur.bigscreen.dto.FactoryDashboardDTO; import com.inspur.bigscreen.mapper.FactoryDashboardMapper; import com.inspur.bigscreen.service.IFactoryDashboardService; @@ -31,6 +32,7 @@ public class FactoryDashboardService implements IFactoryDashboardService { @Autowired private IIpcAlarmRecordService ipcAlarmRecordService; + /** * @param deptId 厂区的部门id *根据厂区id查询厂区下所有产线设备数量 @@ -55,7 +57,14 @@ public class FactoryDashboardService implements IFactoryDashboardService { */ @Override public List countEquipNumByStatusandProductionLine(Long deptId){ - return factoryDashboardMapper.countEquipNumByStatusandProductionLine(deptId); + List runningDataList = factoryDashboardMapper.countEquipNumByStatusandProductionLine(deptId,EquipInfoStatus.RUNNING); + List matenanceDataList = factoryDashboardMapper.countEquipNumByStatusandProductionLine(deptId,EquipInfoStatus.MAINTENANCE); + List stopDataList = factoryDashboardMapper.countEquipNumByStatusandProductionLine(deptId,EquipInfoStatus.STOP); + List resultList = new ArrayList<>(); + resultList.addAll(runningDataList); + resultList.addAll(matenanceDataList); + resultList.addAll(stopDataList); + return resultList; } /** diff --git a/zfipc-server/zfipc-system/src/main/resources/mapper/bigscreen/CompanyDashboardMapper.xml b/zfipc-server/zfipc-system/src/main/resources/mapper/bigscreen/CompanyDashboardMapper.xml new file mode 100644 index 0000000..c2ab1fb --- /dev/null +++ b/zfipc-server/zfipc-system/src/main/resources/mapper/bigscreen/CompanyDashboardMapper.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + select curdate() as click_date + union all + select date_sub(curdate(), interval 1 day) as click_date + union all + select date_sub(curdate(), interval 2 day) as click_date + union all + select date_sub(curdate(), interval 3 day) as click_date + union all + select date_sub(curdate(), interval 4 day) as click_date + union all + select date_sub(curdate(), interval 5 day) as click_date + union all + select date_sub(curdate(), interval 6 day) as click_date + + + + + + + + + \ No newline at end of file diff --git a/zfipc-server/zfipc-system/src/main/resources/mapper/bigscreen/FactoryDashboardMapper.xml b/zfipc-server/zfipc-system/src/main/resources/mapper/bigscreen/FactoryDashboardMapper.xml index 927fd6f..47036cc 100644 --- a/zfipc-server/zfipc-system/src/main/resources/mapper/bigscreen/FactoryDashboardMapper.xml +++ b/zfipc-server/zfipc-system/src/main/resources/mapper/bigscreen/FactoryDashboardMapper.xml @@ -33,16 +33,31 @@ select dept_id,count(1) as data from ipc_equip_info where dept_id in (select dept_id from sys_dept where parent_id = #{deptId}) + and status != 3 GROUP BY dept_id; - + SELECT + d.dept_id, + d.dept_name, + COALESCE(ei.data, 0) AS data, + #{status} AS status + FROM + (SELECT dept_id,dept_name FROM sys_dept WHERE FIND_IN_SET(#{deptId}, ancestors)) d -- 生成所有可能的dept_id和dept_name + LEFT JOIN + (SELECT + a.dept_id, + COUNT(1) AS data + FROM + ipc_equip_info a + WHERE + a.status = #{status} + GROUP BY + a.dept_id) ei -- 子查询来计数满足条件的记录 + ON + d.dept_id = ei.dept_id;