| | |
| | | package com.ruoyi.web.controller.api; |
| | | |
| | | |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.baomidou.mybatisplus.annotation.TableField; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.basic.PageInfo; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.domain.entity.SysUser; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.framework.web.service.TokenService; |
| | | import com.ruoyi.system.dto.AddAssetHouseInspection; |
| | | import com.ruoyi.system.dto.AddAssetRepairRequestDTO; |
| | | import com.ruoyi.system.model.*; |
| | | import com.ruoyi.system.query.AssetHouseInspectionRecordListQuery; |
| | | import com.ruoyi.system.query.AssetRepairRequestListQuery; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.system.vo.AssetHouseInspectionVO; |
| | | import com.ruoyi.system.vo.AssetRepairRequestVO; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.checkerframework.checker.units.qual.A; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/asset-house-inspection-item") |
| | | @Api(tags = {"房屋巡检"}) |
| | | public class AssetHouseInspectionItemController { |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | @Autowired |
| | | private ISysUserService sysUserService; |
| | | @Autowired |
| | | private TDeptService deptService; |
| | | @Autowired |
| | | private AssetMainService assetMainService; |
| | | @Autowired |
| | | private AssetHouseInspectionItemService assetHouseInspectionItemService; |
| | | @Autowired |
| | | private AssetHouseInspectionDetailService assetHouseInspectionDetailService; |
| | | @Autowired |
| | | private AssetHouseInspectionRecordService assetHouseInspectionRecordService; |
| | | |
| | | @ApiOperation("房屋巡检不分页列表") |
| | | @PostMapping("/listAll") |
| | | public R<PageInfo<AssetHouseInspectionVO>> listAll(@RequestBody AssetHouseInspectionRecordListQuery query) { |
| | | String deptId = tokenService.getLoginUser().getDeptId(); |
| | | List<Integer> deptIds = deptService.getAllSubDeptIds(deptId); |
| | | List<SysUser> sysUsers = sysUserService.selectAllList(); |
| | | if (deptIds.isEmpty()) { |
| | | return R.ok(new PageInfo<>()); |
| | | } else { |
| | | List<Long> userIds = sysUsers.stream().filter(e -> deptIds.contains(Integer.valueOf(e.getDeptId()))) |
| | | .map(SysUser::getUserId).collect(Collectors.toList()); |
| | | if (userIds.isEmpty()) { |
| | | return R.ok(new PageInfo<>()); |
| | | } |
| | | if (StringUtils.hasLength(query.getNickName())) { |
| | | List<SysUser> users = sysUsers.stream().filter(e -> e.getNickName().contains(query.getNickName())).collect(Collectors.toList()); |
| | | List<Long> queryUserIds = users.stream().map(SysUser::getUserId).collect(Collectors.toList()); |
| | | // userIds和queryUserIds取交集 |
| | | userIds = userIds.stream().filter(queryUserIds::contains).collect(Collectors.toList()); |
| | | if (userIds.isEmpty()) { |
| | | return R.ok(new PageInfo<>()); |
| | | } |
| | | } |
| | | query.setUserIds(userIds); |
| | | } |
| | | PageInfo<AssetHouseInspectionVO> res = assetHouseInspectionRecordService.pageList(query); |
| | | return R.ok(res); |
| | | } |
| | | |
| | | @ApiOperation(value = "巡检子项树状结构") |
| | | @PostMapping(value = "/listItem") |
| | | public R<List<AssetHouseInspectionItem>> listItem() { |
| | | // 查询所有未被禁用的巡检项 |
| | | List<AssetHouseInspectionItem> allItems = assetHouseInspectionItemService.list( |
| | | new LambdaQueryWrapper<AssetHouseInspectionItem>() |
| | | .eq(AssetHouseInspectionItem::getDisabled, 0) |
| | | ); |
| | | // 构建树形结构 |
| | | List<AssetHouseInspectionItem> tree = buildTree(allItems, 0); |
| | | |
| | | return R.ok(tree); |
| | | } |
| | | |
| | | /** |
| | | * 构建树形结构 |
| | | * |
| | | * @param items 所有巡检项 |
| | | * @param parentId 父级ID |
| | | * @return 树形结构列表 |
| | | */ |
| | | private List<AssetHouseInspectionItem> buildTree(List<AssetHouseInspectionItem> items, int parentId) { |
| | | List<AssetHouseInspectionItem> children = new ArrayList<>(); |
| | | |
| | | for (AssetHouseInspectionItem item : items) { |
| | | if (item.getParentId() != null && item.getParentId() == parentId) { |
| | | // 递归设置子节点 |
| | | List<AssetHouseInspectionItem> childItems = buildTree(items, item.getId()); |
| | | item.setChildren(childItems); |
| | | children.add(item); |
| | | } |
| | | } |
| | | |
| | | return children; |
| | | } |
| | | |
| | | @Log(title = "房屋巡检-新增", businessType = BusinessType.INSERT) |
| | | @ApiOperation(value = "房屋巡检新增") |
| | | @PostMapping(value = "/add") |
| | | @Transactional |
| | | public R add(@RequestBody AddAssetHouseInspection dto) { |
| | | assetHouseInspectionRecordService.save(dto); |
| | | StringBuilder houseCloseStatus = new StringBuilder(); |
| | | StringBuilder waterElectronicGasCloseStatus = new StringBuilder(); |
| | | StringBuilder innerStatus = new StringBuilder(); |
| | | for (AssetHouseInspectionDetail assetHouseInspectionDetail : dto.getList()) { |
| | | assetHouseInspectionDetail.setInspectionRecordId(dto.getId()); |
| | | if (assetHouseInspectionDetail.getInspectionResult()) { |
| | | if (assetHouseInspectionDetail.getSubItemName().contains("门窗")) { |
| | | houseCloseStatus.append(assetHouseInspectionDetail.getRemark()); |
| | | } else if (assetHouseInspectionDetail.getSubItemName().contains("电表")) { |
| | | waterElectronicGasCloseStatus.append(assetHouseInspectionDetail.getRemark()).append("|"); |
| | | } else if (assetHouseInspectionDetail.getSubItemName().contains("气表")) { |
| | | waterElectronicGasCloseStatus.append(assetHouseInspectionDetail.getRemark()).append("|"); |
| | | } else if (assetHouseInspectionDetail.getSubItemName().contains("水表")) { |
| | | waterElectronicGasCloseStatus.append(assetHouseInspectionDetail.getRemark()).append("|"); |
| | | } else if (assetHouseInspectionDetail.getSubItemName().contains("瓷砖")) { |
| | | innerStatus.append(assetHouseInspectionDetail.getRemark()).append("|"); |
| | | } else if (assetHouseInspectionDetail.getSubItemName().contains("墙壁")) { |
| | | innerStatus.append(assetHouseInspectionDetail.getRemark()).append("|"); |
| | | } else if (assetHouseInspectionDetail.getSubItemName().contains("设备")) { |
| | | innerStatus.append(assetHouseInspectionDetail.getRemark()).append("|"); |
| | | } else if (assetHouseInspectionDetail.getSubItemName().contains("漏水")) { |
| | | innerStatus.append(assetHouseInspectionDetail.getRemark()).append("|"); |
| | | } |
| | | } |
| | | } |
| | | if (StringUtils.hasLength(waterElectronicGasCloseStatus)){ |
| | | waterElectronicGasCloseStatus.deleteCharAt(waterElectronicGasCloseStatus.length() - 1); |
| | | } |
| | | if (StringUtils.hasLength(innerStatus)){ |
| | | innerStatus.deleteCharAt(innerStatus.length() - 1); |
| | | } |
| | | if (StringUtils.hasLength(houseCloseStatus)){ |
| | | dto.setHouseCloseStatus(houseCloseStatus.toString()); |
| | | }else{ |
| | | dto.setInnerStatus("正常"); |
| | | } |
| | | if (StringUtils.hasLength(waterElectronicGasCloseStatus)){ |
| | | dto.setWaterElectronicGasCloseStatus(waterElectronicGasCloseStatus.toString()); |
| | | }else{ |
| | | dto.setInnerStatus("正常"); |
| | | } |
| | | if (StringUtils.hasLength(innerStatus)){ |
| | | dto.setInnerStatus(innerStatus.toString()); |
| | | }else{ |
| | | dto.setInnerStatus("正常"); |
| | | } |
| | | assetHouseInspectionRecordService.updateById(dto); |
| | | assetHouseInspectionDetailService.saveBatch(dto.getList()); |
| | | return R.ok(); |
| | | } |
| | | |
| | | @Log(title = "房屋巡检-删除", businessType = BusinessType.DELETE) |
| | | @ApiOperation(value = "房屋巡检-删除") |
| | | @DeleteMapping(value = "/delete") |
| | | public R delete(@RequestParam String ids) { |
| | | assetHouseInspectionDetailService.remove(new LambdaQueryWrapper<AssetHouseInspectionDetail>() |
| | | .in(AssetHouseInspectionDetail::getInspectionRecordId, Arrays.asList(ids.split(",")))); |
| | | assetHouseInspectionRecordService.removeBatchByIds(Arrays.asList(ids.split(","))); |
| | | return R.ok(); |
| | | } |
| | | } |
| | | |