|
@@ -0,0 +1,306 @@
|
|
|
|
|
+package cn.iocoder.yudao.module.pms.controller.admin.stat;
|
|
|
|
|
+
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
|
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
|
|
+import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
|
|
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDevicePageReqVO;
|
|
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDeviceRespVO;
|
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
|
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.dataobject.IotProductClassifyDO;
|
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.IotDeviceMapper;
|
|
|
|
|
+import cn.iocoder.yudao.module.pms.dal.mysql.IotProductClassifyMapper;
|
|
|
|
|
+import cn.iocoder.yudao.module.pms.service.IotProductClassifyService;
|
|
|
|
|
+import cn.iocoder.yudao.module.pms.util.IotDeviceConvert;
|
|
|
|
|
+import cn.iocoder.yudao.module.supplier.dal.dataobject.product.SupplierDO;
|
|
|
|
|
+import cn.iocoder.yudao.module.supplier.service.product.SupplierService;
|
|
|
|
|
+import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
|
|
|
|
+import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
|
|
|
|
+import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
|
|
|
|
+import cn.iocoder.yudao.module.system.dal.dataobject.dict.DictDataDO;
|
|
|
|
|
+import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
|
|
|
|
+import cn.iocoder.yudao.module.system.service.dict.DictDataService;
|
|
|
|
|
+import com.google.common.collect.ImmutableList;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
+import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
+import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
+
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
|
+import javax.annotation.security.PermitAll;
|
|
|
|
|
+import javax.validation.Valid;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
+
|
|
|
|
|
+import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
|
|
|
|
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
|
|
|
|
+
|
|
|
|
|
+@Tag(name = "报表接口")
|
|
|
|
|
+@RestController
|
|
|
|
|
+@RequestMapping("/rq/report")
|
|
|
|
|
+@Validated
|
|
|
|
|
+@PermitAll
|
|
|
|
|
+public class IotReportDeviceController {
|
|
|
|
|
+ private static final ImmutableList<String> jt = ImmutableList.<String>builder()
|
|
|
|
|
+ .add("电驱增压机", "柴驱增压机", "液驱增压机", "电驱空压机", "柴驱空压机") // 第一批5个
|
|
|
|
|
+ .add("提纯撬", "空气处理撬", "膜组", "注水泵", "绞车") // 第二批5个
|
|
|
|
|
+ .add("井架", "底座", "发动机", "泥浆泵", "连油主车") // 第三批5个
|
|
|
|
|
+ .build();
|
|
|
|
|
+ private static final ImmutableList<String> rh = ImmutableList.<String>builder()
|
|
|
|
|
+ .add("电驱增压机", "柴驱增压机", "液驱增压机", "电驱空压机", "柴驱空压机") // 第一批5个
|
|
|
|
|
+ .add("提纯撬", "空气处理撬", "膜组", "注水泵").build();
|
|
|
|
|
+ private static final ImmutableList<String> ry = ImmutableList.<String>builder()
|
|
|
|
|
+ .add("井架", "底座", "发动机", "泥浆泵","绞车").build();
|
|
|
|
|
+ private static final ImmutableList<String> rd = ImmutableList.<String>builder()
|
|
|
|
|
+ .add("连油主车","混砂车","仪表车","小车").build();
|
|
|
|
|
+ private final DeptApi deptApi;
|
|
|
|
|
+ private final IotDeviceMapper iotDeviceMapper;
|
|
|
|
|
+ private final IotProductClassifyMapper iotProductClassifyMapper;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private DeptService deptService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private IotProductClassifyService iotProductClassifyService;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private SupplierService supplierService;
|
|
|
|
|
+
|
|
|
|
|
+ public IotReportDeviceController(DeptApi deptApi, IotDeviceMapper iotDeviceMapper, IotProductClassifyMapper iotProductClassifyMapper) {
|
|
|
|
|
+ this.deptApi = deptApi;
|
|
|
|
|
+ this.iotDeviceMapper = iotDeviceMapper;
|
|
|
|
|
+ this.iotProductClassifyMapper = iotProductClassifyMapper;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "类别统计")
|
|
|
|
|
+ @GetMapping("/device/type")
|
|
|
|
|
+ public CommonResult<List<Map<String, Object>>> getDeviceTypeStat(@Valid IotDevicePageReqVO iotDevicePageReqVO) {
|
|
|
|
|
+ Set<Long> ids;
|
|
|
|
|
+ String companyCode;
|
|
|
|
|
+ if (Objects.isNull(iotDevicePageReqVO.getDeptId())){
|
|
|
|
|
+ Long loginUserDeptId = SecurityFrameworkUtils.getLoginUserDeptId();
|
|
|
|
|
+ companyCode = getCompanyCode(loginUserDeptId);
|
|
|
|
|
+ ids = getDeptIds(companyCode);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ companyCode = getCompanyCode(iotDevicePageReqVO.getDeptId());
|
|
|
|
|
+ ids = deptService.getChildDeptIdListFromCache(iotDevicePageReqVO.getDeptId());
|
|
|
|
|
+ ids.add(iotDevicePageReqVO.getDeptId());
|
|
|
|
|
+ }
|
|
|
|
|
+ IotDevicePageReqVO pageReqVO = new IotDevicePageReqVO();
|
|
|
|
|
+ pageReqVO.setDeptIds(new ArrayList<>(ids));
|
|
|
|
|
+ List<IotDeviceDO> iotDeviceDOS = iotDeviceMapper.selectList(pageReqVO);
|
|
|
|
|
+ LinkedList<Map<String, Object>> results = new LinkedList<>();
|
|
|
|
|
+ List<Map.Entry<Long, Long>> collect = iotDeviceDOS.stream().collect(Collectors.groupingBy(IotDeviceDO::getAssetClass, Collectors.counting())).entrySet().stream().sorted(Map.Entry.<Long, Long>comparingByValue().reversed()).collect(Collectors.toList());
|
|
|
|
|
+ collect.forEach(e->{
|
|
|
|
|
+ IotProductClassifyDO iotProductClassifyDO = iotProductClassifyMapper.selectById(e.getKey());
|
|
|
|
|
+ if ("jt".equals(companyCode)) {
|
|
|
|
|
+ if (jt.contains(iotProductClassifyDO.getName())){
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>(4);
|
|
|
|
|
+ map.put("category", iotProductClassifyDO.getName());
|
|
|
|
|
+ map.put("value", e.getValue());
|
|
|
|
|
+ results.add(map);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("rh".equals(companyCode)) {
|
|
|
|
|
+ if (rh.contains(iotProductClassifyDO.getName())){
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>(4);
|
|
|
|
|
+ map.put("category", iotProductClassifyDO.getName());
|
|
|
|
|
+ map.put("value", e.getValue());
|
|
|
|
|
+ results.add(map);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("ry".equals(companyCode)) {
|
|
|
|
|
+ if (ry.contains(iotProductClassifyDO.getName())){
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>(4);
|
|
|
|
|
+ map.put("category", iotProductClassifyDO.getName());
|
|
|
|
|
+ map.put("value", e.getValue());
|
|
|
|
|
+ results.add(map);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("rd".equals(companyCode)) {
|
|
|
|
|
+ if (rd.contains(iotProductClassifyDO.getName())||iotProductClassifyDO.getName().contains("压裂泵车")){
|
|
|
|
|
+ Map<String, Object> map = new HashMap<>(4);
|
|
|
|
|
+ map.put("category", iotProductClassifyDO.getName());
|
|
|
|
|
+ map.put("value", e.getValue());
|
|
|
|
|
+ results.add(map);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ return CommonResult.success(results);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ @Operation(summary = "获取设备数量")
|
|
|
|
|
+ @GetMapping("/device/count")
|
|
|
|
|
+ public CommonResult<Long> getDeviceCount(@Valid IotDevicePageReqVO iotDevicePageReqVO) {
|
|
|
|
|
+ Set<Long> ids;
|
|
|
|
|
+ if (Objects.isNull(iotDevicePageReqVO.getDeptId())){
|
|
|
|
|
+ Long loginUserDeptId = SecurityFrameworkUtils.getLoginUserDeptId();
|
|
|
|
|
+ String companyCode = getCompanyCode(loginUserDeptId);
|
|
|
|
|
+ ids = getDeptIds(companyCode);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ids = deptService.getChildDeptIdListFromCache(iotDevicePageReqVO.getDeptId());
|
|
|
|
|
+ ids.add(iotDevicePageReqVO.getDeptId());
|
|
|
|
|
+ }
|
|
|
|
|
+ Long l = iotDeviceMapper.selectCountByParam(ids,iotDevicePageReqVO);
|
|
|
|
|
+ return CommonResult.success(l);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private DictDataService dictDataService;
|
|
|
|
|
+ @GetMapping("/device/status")
|
|
|
|
|
+ public CommonResult<List<Map<String, Object>>> getDeviceStatusStat(@Valid IotDevicePageReqVO iotDevicePageReqVO) {
|
|
|
|
|
+ Set<Long> ids;
|
|
|
|
|
+ if (Objects.isNull(iotDevicePageReqVO.getDeptId())){
|
|
|
|
|
+ Long loginUserDeptId = SecurityFrameworkUtils.getLoginUserDeptId();
|
|
|
|
|
+ String companyCode = getCompanyCode(loginUserDeptId);
|
|
|
|
|
+ ids = getDeptIds(companyCode);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ids = deptService.getChildDeptIdListFromCache(iotDevicePageReqVO.getDeptId());
|
|
|
|
|
+ ids.add(iotDevicePageReqVO.getDeptId());
|
|
|
|
|
+ }
|
|
|
|
|
+ IotDevicePageReqVO pageReqVO = new IotDevicePageReqVO();
|
|
|
|
|
+ pageReqVO.setDeptIds(new ArrayList<>(ids));
|
|
|
|
|
+ List<IotDeviceDO> iotDeviceDOS = iotDeviceMapper.selectList(pageReqVO);
|
|
|
|
|
+ Map<String, Long> order = iotDeviceDOS.stream().collect(Collectors.groupingBy(IotDeviceDO::getDeviceStatus, Collectors.counting()));
|
|
|
|
|
+ List<Map<String, Object>> results = new ArrayList<>();
|
|
|
|
|
+ List<DictDataDO> pmsDeviceStatus = dictDataService.getDictDataListByDictType("pms_device_status");
|
|
|
|
|
+ order.forEach((k,v)->{
|
|
|
|
|
+ pmsDeviceStatus.stream().filter(e -> e.getValue().equals(k)).findFirst().ifPresent(e -> {
|
|
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
|
|
+ resultMap.put("name", e.getLabel());
|
|
|
|
|
+ resultMap.put("value", v);
|
|
|
|
|
+ results.add(resultMap);
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+ return CommonResult.success(results);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @GetMapping("/device/page")
|
|
|
|
|
+ @Operation(summary = "获得设备报表分页")
|
|
|
|
|
+ @PreAuthorize("@ss.hasPermission('rq:iot-device:query')")
|
|
|
|
|
+ public CommonResult<PageResult<IotDeviceRespVO>> getIotDevicePage(@Valid IotDevicePageReqVO pageReqVO) {
|
|
|
|
|
+ Set<Long> ids;
|
|
|
|
|
+ if (Objects.isNull(pageReqVO.getDeptId())){
|
|
|
|
|
+ Long loginUserDeptId = SecurityFrameworkUtils.getLoginUserDeptId();
|
|
|
|
|
+ String companyCode = getCompanyCode(loginUserDeptId);
|
|
|
|
|
+ ids = getDeptIds(companyCode);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ids = deptService.getChildDeptIdListFromCache(pageReqVO.getDeptId());
|
|
|
|
|
+ ids.add(pageReqVO.getDeptId());
|
|
|
|
|
+ }
|
|
|
|
|
+ PageResult<IotDeviceDO> pageResult = iotDeviceMapper.selectPageReport(pageReqVO, ids);
|
|
|
|
|
+ if (CollUtil.isEmpty(pageResult.getList())) {
|
|
|
|
|
+ return success(new PageResult<>(pageResult.getTotal()));
|
|
|
|
|
+ }
|
|
|
|
|
+ Map<Long, DeptDO> deptMap = deptService.getDeptMap(
|
|
|
|
|
+ convertList(pageResult.getList(), IotDeviceDO::getDeptId));
|
|
|
|
|
+ List<IotDeviceRespVO> iotDeviceRespVOS = IotDeviceConvert.INSTANCE.convertList(pageResult.getList(), deptMap);
|
|
|
|
|
+ iotDeviceRespVOS.forEach(e ->{
|
|
|
|
|
+ if (Objects.nonNull(e.getAssetClass())) {
|
|
|
|
|
+ IotProductClassifyDO iotProductClassify = iotProductClassifyService.getIotProductClassify(e.getAssetClass());
|
|
|
|
|
+ e.setAssetClassName(Objects.nonNull(iotProductClassify)?iotProductClassify.getName():"");
|
|
|
|
|
+ }
|
|
|
|
|
+ SupplierDO supplierDO = supplierService.get(e.getManufacturerId());
|
|
|
|
|
+ if (Objects.nonNull(supplierDO)) {
|
|
|
|
|
+ e.setManufacturer(supplierDO.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+ DeptRespDTO dept = deptApi.getDept(e.getDeptId());
|
|
|
|
|
+ if (Objects.nonNull(dept)) {
|
|
|
|
|
+ if ("1".equals(dept.getType())) {
|
|
|
|
|
+ e.setCompany(dept.getName());
|
|
|
|
|
+ } else if ("2".equals(dept.getType())) {
|
|
|
|
|
+ e.setProject(dept.getName());
|
|
|
|
|
+ DeptRespDTO dept1 = deptApi.getDept(dept.getParentId());
|
|
|
|
|
+ if (Objects.nonNull(dept1)) {
|
|
|
|
|
+ e.setCompany(dept1.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if ("3".equals(dept.getName())) {
|
|
|
|
|
+ e.setDeptName(dept.getName());
|
|
|
|
|
+ DeptRespDTO dept1 = deptApi.getDept(dept.getParentId());
|
|
|
|
|
+ if (Objects.nonNull(dept1)) {
|
|
|
|
|
+ e.setProject(dept1.getName());
|
|
|
|
|
+ DeptRespDTO dept2 = deptApi.getDept(dept1.getParentId());
|
|
|
|
|
+ if (Objects.nonNull(dept2)) {
|
|
|
|
|
+ e.setCompany(dept2.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ return success(new PageResult<>(iotDeviceRespVOS, pageResult.getTotal()));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ private String getCompanyCode(Long deptId) {
|
|
|
|
|
+ DeptRespDTO dept = deptApi.getDeptNoPermission(deptId);
|
|
|
|
|
+ String name = dept.getName();
|
|
|
|
|
+ String companyCode = "";
|
|
|
|
|
+ if (name.contains("瑞恒")) {
|
|
|
|
|
+ companyCode = "rh";
|
|
|
|
|
+ } else if (name.contains("瑞都")) {
|
|
|
|
|
+ companyCode = "rd";
|
|
|
|
|
+ } else if (name.contains("瑞鹰")) {
|
|
|
|
|
+ companyCode = "ry";
|
|
|
|
|
+ } else if (name.contains("科瑞石油技术")) {
|
|
|
|
|
+ companyCode = "jt";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Long parentId = dept.getParentId();
|
|
|
|
|
+ DeptRespDTO dept1 = deptApi.getDeptNoPermission(parentId);
|
|
|
|
|
+ String name1 = dept1.getName();
|
|
|
|
|
+ if (name1.contains("瑞恒")) {
|
|
|
|
|
+ companyCode = "rh";
|
|
|
|
|
+ } else if (name1.contains("瑞都")) {
|
|
|
|
|
+ companyCode = "rd";
|
|
|
|
|
+ } else if (name1.contains("瑞鹰")) {
|
|
|
|
|
+ companyCode = "ry";
|
|
|
|
|
+ } else if (name1.contains("科瑞石油技术")) {
|
|
|
|
|
+ companyCode = "jt";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ DeptRespDTO dept2 = deptApi.getDeptNoPermission(dept1.getParentId());
|
|
|
|
|
+ String name2 = dept2.getName();
|
|
|
|
|
+ if (name2.contains("瑞恒")) {
|
|
|
|
|
+ companyCode = "rh";
|
|
|
|
|
+ } else if (name2.contains("瑞都")) {
|
|
|
|
|
+ companyCode = "rd";
|
|
|
|
|
+ } else if (name2.contains("瑞鹰")) {
|
|
|
|
|
+ companyCode = "ry";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ DeptRespDTO dept3= deptApi.getDeptNoPermission(dept2.getParentId());
|
|
|
|
|
+ String name3 = dept3.getName();
|
|
|
|
|
+ if (name3.contains("瑞恒")) {
|
|
|
|
|
+ companyCode = "rh";
|
|
|
|
|
+ } else if (name3.contains("瑞都")) {
|
|
|
|
|
+ companyCode = "rd";
|
|
|
|
|
+ } else if (name3.contains("瑞鹰")) {
|
|
|
|
|
+ companyCode = "ry";
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return companyCode;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public Set<Long> getDeptIds(String dept) {
|
|
|
|
|
+ Set<Long> ids = new HashSet<>();
|
|
|
|
|
+ List<DeptRespDTO> depts = new ArrayList<>();
|
|
|
|
|
+ if ("rd".equals(dept)) {
|
|
|
|
|
+ depts = deptApi.getDeptByName("四川瑞都");
|
|
|
|
|
+ } else if ("rh".equals(dept)) {
|
|
|
|
|
+ depts = deptApi.getDeptByName("瑞恒兴域");
|
|
|
|
|
+ } else if ("ry".equals(dept)) {
|
|
|
|
|
+ depts = deptApi.getDeptByName("瑞鹰国际");
|
|
|
|
|
+ } else if ("jt".equals(dept)) {
|
|
|
|
|
+ depts = deptApi.getDeptByName("科瑞石油技术");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ Long loginUserDeptId = SecurityFrameworkUtils.getLoginUserDeptId();
|
|
|
|
|
+ DeptRespDTO dto = deptApi.getDept(loginUserDeptId);
|
|
|
|
|
+ depts = deptApi.getDeptByName(dto.getName());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (CollUtil.isNotEmpty(depts)) {
|
|
|
|
|
+ Long deptId = depts.get(0).getId();
|
|
|
|
|
+ if (Objects.nonNull(depts.get(0).getId())) {
|
|
|
|
|
+ ids = deptService.getChildDeptIdListFromCache(depts.get(0).getId());
|
|
|
|
|
+ ids.add(deptId);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return ids;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|