|  |  |  | 
|---|
|  |  |  | package com.ruoyi.web.controller.api; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import cn.afterturn.easypoi.excel.ExcelExportUtil; | 
|---|
|  |  |  | import cn.afterturn.easypoi.excel.ExcelImportUtil; | 
|---|
|  |  |  | import cn.afterturn.easypoi.excel.entity.ExportParams; | 
|---|
|  |  |  | import cn.afterturn.easypoi.excel.entity.ImportParams; | 
|---|
|  |  |  | import cn.hutool.json.JSONObject; | 
|---|
|  |  |  | 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.core.domain.entity.TDept; | 
|---|
|  |  |  | import com.ruoyi.common.core.exception.ServiceException; | 
|---|
|  |  |  | import com.ruoyi.common.enums.BusinessType; | 
|---|
|  |  |  | import com.ruoyi.common.utils.SecurityUtils; | 
|---|
|  |  |  | import com.ruoyi.common.utils.WebUtils; | 
|---|
|  |  |  | import com.ruoyi.framework.web.service.TokenService; | 
|---|
|  |  |  | import com.ruoyi.system.dto.AddAssetHouseInspection; | 
|---|
|  |  |  | import com.ruoyi.system.export.AssetHouseInspectionImport; | 
|---|
|  |  |  | import com.ruoyi.system.model.AssetHouseInspectionDetail; | 
|---|
|  |  |  | import com.ruoyi.system.model.AssetHouseInspectionItem; | 
|---|
|  |  |  | import com.ruoyi.system.model.AssetHouseInspectionRecord; | 
|---|
|  |  |  | import com.ruoyi.system.model.AssetMain; | 
|---|
|  |  |  | import com.ruoyi.system.model.AssetPropertyExt; | 
|---|
|  |  |  | import com.ruoyi.system.model.AssetType; | 
|---|
|  |  |  | import com.ruoyi.system.query.AssetHouseInspectionRecordListQuery; | 
|---|
|  |  |  | import com.ruoyi.system.service.AssetHouseInspectionDetailService; | 
|---|
|  |  |  | import com.ruoyi.system.service.AssetHouseInspectionItemService; | 
|---|
|  |  |  | import com.ruoyi.system.service.AssetHouseInspectionRecordService; | 
|---|
|  |  |  | import com.ruoyi.system.service.AssetMainService; | 
|---|
|  |  |  | import com.ruoyi.system.service.AssetPropertyExtService; | 
|---|
|  |  |  | import com.ruoyi.system.service.AssetTypeService; | 
|---|
|  |  |  | import com.ruoyi.system.service.ISysUserService; | 
|---|
|  |  |  | import com.ruoyi.system.service.TDeptService; | 
|---|
|  |  |  | import com.ruoyi.system.vo.AssetHouseInspectionVO; | 
|---|
|  |  |  | import io.swagger.annotations.Api; | 
|---|
|  |  |  | import io.swagger.annotations.ApiOperation; | 
|---|
|  |  |  | import lombok.extern.slf4j.Slf4j; | 
|---|
|  |  |  | import org.apache.poi.ss.usermodel.Workbook; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Propagation; | 
|---|
|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
|---|
|  |  |  | import org.springframework.util.CollectionUtils; | 
|---|
|  |  |  | import org.springframework.util.StringUtils; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.DeleteMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.GetMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.PostMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestBody; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestMapping; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestParam; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RequestPart; | 
|---|
|  |  |  | import org.springframework.web.bind.annotation.RestController; | 
|---|
|  |  |  | import org.springframework.web.multipart.MultipartFile; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.servlet.ServletOutputStream; | 
|---|
|  |  |  | import javax.servlet.http.HttpServletResponse; | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | import java.io.InputStream; | 
|---|
|  |  |  | import java.net.URLEncoder; | 
|---|
|  |  |  | import java.time.LocalDate; | 
|---|
|  |  |  | import java.time.format.DateTimeFormatter; | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Arrays; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  | import java.util.Map; | 
|---|
|  |  |  | import java.util.stream.Collectors; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * <p> | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @RestController | 
|---|
|  |  |  | @RequestMapping("/asset-house-inspection-item") | 
|---|
|  |  |  | @Api(tags = {"房屋巡检"}) | 
|---|
|  |  |  | @Slf4j | 
|---|
|  |  |  | public class AssetHouseInspectionItemController { | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TokenService tokenService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ISysUserService sysUserService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private TDeptService deptService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AssetMainService assetMainService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AssetTypeService assetTypeService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AssetHouseInspectionItemService assetHouseInspectionItemService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AssetHouseInspectionDetailService assetHouseInspectionDetailService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AssetHouseInspectionRecordService assetHouseInspectionRecordService; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AssetPropertyExtService assetPropertyExtService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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 = "/listAssetMain") | 
|---|
|  |  |  | public R<List<AssetMain>> listAssetMain() { | 
|---|
|  |  |  | String deptId = tokenService.getLoginUser().getDeptId(); | 
|---|
|  |  |  | TDept dept = deptService.getById(tokenService.getLoginUser().getDeptId()); | 
|---|
|  |  |  | List<Integer> deptIds = deptService.getAllSubDeptIds(deptId); | 
|---|
|  |  |  | AssetType assetType = assetTypeService.lambdaQuery().like(AssetType::getTypeName, "房屋"). | 
|---|
|  |  |  | last("limit 1").one(); | 
|---|
|  |  |  | Map<Integer, String> map = assetPropertyExtService.lambdaQuery().isNotNull(AssetPropertyExt::getRoomNumber).list() | 
|---|
|  |  |  | .stream().collect(Collectors.toMap(AssetPropertyExt::getAssetMainId, AssetPropertyExt::getRoomNumber)); | 
|---|
|  |  |  | Long userId = tokenService.getLoginUser().getUserId(); | 
|---|
|  |  |  | if (!SecurityUtils.isAdmin(userId)) { | 
|---|
|  |  |  | if (dept.getDeptName().contains("资产管理") || dept.getDeptName().contains("董事长") || dept.getDeptName().contains("总经理")) { | 
|---|
|  |  |  | List<AssetMain> list = assetMainService.lambdaQuery() | 
|---|
|  |  |  | .eq(AssetMain::getAssetTypeId, assetType.getId()) | 
|---|
|  |  |  | .list(); | 
|---|
|  |  |  | for (AssetMain assetMain : list) { | 
|---|
|  |  |  | assetMain.setRoomNumber(map.get(assetMain.getId())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(list); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | if (deptIds.isEmpty()) { | 
|---|
|  |  |  | return R.ok(new ArrayList<>()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | List<AssetMain> list = assetMainService.lambdaQuery() | 
|---|
|  |  |  | .eq(AssetMain::getAssetTypeId, assetType.getId()) | 
|---|
|  |  |  | .in(AssetMain::getOwnershipDeptId, deptIds).list(); | 
|---|
|  |  |  | for (AssetMain assetMain : list) { | 
|---|
|  |  |  | assetMain.setRoomNumber(map.get(assetMain.getId())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | List<AssetMain> list = assetMainService.lambdaQuery() | 
|---|
|  |  |  | .eq(AssetMain::getAssetTypeId, assetType.getId()) | 
|---|
|  |  |  | .list(); | 
|---|
|  |  |  | for (AssetMain assetMain : list) { | 
|---|
|  |  |  | assetMain.setRoomNumber(map.get(assetMain.getId())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return R.ok(list); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @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) { | 
|---|
|  |  |  | AssetMain assetMain = assetMainService.getById(dto.getAssetMainId()); | 
|---|
|  |  |  | AssetPropertyExt assetPropertyExt = assetPropertyExtService.lambdaQuery().eq(AssetPropertyExt::getAssetMainId, assetMain.getId()) | 
|---|
|  |  |  | .last("limit 1").one(); | 
|---|
|  |  |  | dto.setAssetCode(assetMain.getAssetCode()); | 
|---|
|  |  |  | dto.setAssetName(assetMain.getAssetName()); | 
|---|
|  |  |  | dto.setRoomNumber(assetPropertyExt.getRoomNumber()); | 
|---|
|  |  |  | dto.setInspectionDate(LocalDate.now()); | 
|---|
|  |  |  | int userId = tokenService.getLoginUser().getUserId().intValue(); | 
|---|
|  |  |  | dto.setInspectionId(userId); | 
|---|
|  |  |  | 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.setHouseCloseStatus("正常"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (StringUtils.hasLength(waterElectronicGasCloseStatus)) { | 
|---|
|  |  |  | dto.setWaterElectronicGasCloseStatus(waterElectronicGasCloseStatus.toString()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | dto.setWaterElectronicGasCloseStatus("正常"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (StringUtils.hasLength(innerStatus)) { | 
|---|
|  |  |  | dto.setInnerStatus(innerStatus.toString()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | dto.setInnerStatus("正常"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | assetHouseInspectionRecordService.updateById(dto); | 
|---|
|  |  |  | assetHouseInspectionDetailService.saveBatch(dto.getList()); | 
|---|
|  |  |  | return R.ok(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @ApiOperation(value = "房屋巡检导入模板下载") | 
|---|
|  |  |  | @GetMapping("/import-template") | 
|---|
|  |  |  | public void importTemplate() { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<AssetHouseInspectionImport> assetHouseInspectionImports = new ArrayList<>(); | 
|---|
|  |  |  | AssetHouseInspectionImport temp = new AssetHouseInspectionImport(); | 
|---|
|  |  |  | assetHouseInspectionImports.add(temp); | 
|---|
|  |  |  | Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), AssetHouseInspectionImport.class, assetHouseInspectionImports); | 
|---|
|  |  |  | HttpServletResponse response = WebUtils.response(); | 
|---|
|  |  |  | ServletOutputStream outputStream = null; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | String fileName = URLEncoder.encode("房屋巡检导入模板.xls", "utf-8"); | 
|---|
|  |  |  | response.setHeader("Content-Disposition", "attachment;filename=" + fileName); | 
|---|
|  |  |  | response.setHeader("content-Type", "application/vnd.ms-excel"); | 
|---|
|  |  |  | response.setHeader("Pragma", "no-cache"); | 
|---|
|  |  |  | response.setHeader("Cache-Control", "no-cache"); | 
|---|
|  |  |  | outputStream = response.getOutputStream(); | 
|---|
|  |  |  | workbook.write(outputStream); | 
|---|
|  |  |  | } catch (IOException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | System.out.println("房屋巡检导入模板下载失败!"); | 
|---|
|  |  |  | } finally { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | outputStream.close(); | 
|---|
|  |  |  | } catch (IOException e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Log(title = "房屋巡检导入", businessType = BusinessType.INSERT) | 
|---|
|  |  |  | @ApiOperation(value = "房屋巡检导入") | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW) | 
|---|
|  |  |  | @PostMapping("/import") | 
|---|
|  |  |  | public R<String> importLocation(@RequestPart("file") MultipartFile file) { | 
|---|
|  |  |  | Map<String, AssetMain> assetMainMap = assetMainService.list().stream().collect(Collectors.toMap(AssetMain::getAssetCode, assetMain -> assetMain)); | 
|---|
|  |  |  | Map<String, SysUser> sysUserMap = sysUserService.selectAllList().stream().collect(Collectors.toMap(SysUser::getNickName, sysUser -> sysUser)); | 
|---|
|  |  |  | Map<Integer, AssetPropertyExt> assetPropertyExtMap = assetPropertyExtService.list().stream().collect(Collectors.toMap(AssetPropertyExt::getAssetMainId, assetPropertyExt -> assetPropertyExt)); | 
|---|
|  |  |  | List<AssetHouseInspectionItem> allItems = assetHouseInspectionItemService.list( | 
|---|
|  |  |  | new LambdaQueryWrapper<AssetHouseInspectionItem>() | 
|---|
|  |  |  | .eq(AssetHouseInspectionItem::getDisabled, 0) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | List<AssetHouseInspectionDetail> assetHouseInspectionDetails = new ArrayList<>(); | 
|---|
|  |  |  | ImportParams params = new ImportParams(); | 
|---|
|  |  |  | params.setHeadRows(1); //表头行数 | 
|---|
|  |  |  | InputStream inputStream = null; | 
|---|
|  |  |  | List<AssetHouseInspectionImport> assetHouseInspectionImports; | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | inputStream = file.getInputStream(); | 
|---|
|  |  |  | assetHouseInspectionImports = ExcelImportUtil.importExcel(inputStream, | 
|---|
|  |  |  | AssetHouseInspectionImport.class, params); | 
|---|
|  |  |  | } catch (Exception e) { | 
|---|
|  |  |  | e.printStackTrace(); | 
|---|
|  |  |  | log.error("房屋巡检导入失败:{}", e.getMessage()); | 
|---|
|  |  |  | throw new ServiceException("房屋巡检导入失败!"); | 
|---|
|  |  |  | } finally { | 
|---|
|  |  |  | try { | 
|---|
|  |  |  | inputStream.close(); | 
|---|
|  |  |  | } catch (IOException e) { | 
|---|
|  |  |  | throw new ServiceException(e.getMessage()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (CollectionUtils.isEmpty(assetHouseInspectionImports)) { | 
|---|
|  |  |  | throw new ServiceException("房屋巡检数据为空!"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | JSONObject result = new JSONObject(); | 
|---|
|  |  |  | for (AssetHouseInspectionImport assetHouseInspectionImport : assetHouseInspectionImports) { | 
|---|
|  |  |  | AssetHouseInspectionRecord assetHouseInspectionRecord = new AssetHouseInspectionRecord(); | 
|---|
|  |  |  | AssetMain assetMain = assetMainMap.get(assetHouseInspectionImport.getAssetCode()); | 
|---|
|  |  |  | if (assetMain==null){ | 
|---|
|  |  |  | result.append("根据资产编码:[", assetHouseInspectionImport.getAssetCode()+"]未查询到资产"); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | assetHouseInspectionRecord.setAssetMainId(assetMain.getId()); | 
|---|
|  |  |  | SysUser sysUser = sysUserMap.get(assetHouseInspectionImport.getNickName()); | 
|---|
|  |  |  | if (sysUser==null){ | 
|---|
|  |  |  | result.append("根据巡检人名称:[", assetHouseInspectionImport.getNickName()+"]未查询到巡检人"); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | assetHouseInspectionRecord.setInspectionId(sysUser.getUserId().intValue()); | 
|---|
|  |  |  | assetHouseInspectionRecord.setAssetCode(assetMain.getAssetCode()); | 
|---|
|  |  |  | assetHouseInspectionRecord.setAssetName(assetMain.getAssetName()); | 
|---|
|  |  |  | AssetPropertyExt assetPropertyExt = assetPropertyExtMap.get(assetMain.getId()); | 
|---|
|  |  |  | if (assetPropertyExt!=null){ | 
|---|
|  |  |  | assetHouseInspectionRecord.setRoomNumber(assetPropertyExt.getRoomNumber()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (StringUtils.hasLength(assetHouseInspectionImport.getInspectionDate())){ | 
|---|
|  |  |  | String s = assetHouseInspectionImport.getInspectionDate().replaceAll("\\.", "-"); | 
|---|
|  |  |  | String s1 = assetHouseInspectionImport.getInspectionDate().replaceAll("/", "-"); | 
|---|
|  |  |  | LocalDate parse = LocalDate.parse(s1, DateTimeFormatter.ofPattern("yyyy-MM-dd")); | 
|---|
|  |  |  | assetHouseInspectionRecord.setInspectionDate(parse); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | result.append("未填写巡检日期:[", "未填写巡检日期"+"]"); | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | assetHouseInspectionRecord.setHouseCloseStatus(assetHouseInspectionImport.getHouseCloseStatus()); | 
|---|
|  |  |  | AssetHouseInspectionDetail assetHouseInspectionDetail = new AssetHouseInspectionDetail(); | 
|---|
|  |  |  | assetHouseInspectionDetail.setInspectionItemId(1); | 
|---|
|  |  |  | assetHouseInspectionDetail.setItemName("房屋关闭情况"); | 
|---|
|  |  |  | assetHouseInspectionDetail.setSubItemId(2); | 
|---|
|  |  |  | assetHouseInspectionDetail.setSubItemName("门窗关闭情况"); | 
|---|
|  |  |  | assetHouseInspectionDetail.setRemark(assetHouseInspectionImport.getHouseCloseStatus()); | 
|---|
|  |  |  | if (assetHouseInspectionImport.getHouseCloseStatus().equals("正常")){ | 
|---|
|  |  |  | assetHouseInspectionDetail.setInspectionResult(true); | 
|---|
|  |  |  | assetHouseInspectionRecord.setHouseCloseStatus("正常"); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | assetHouseInspectionDetail.setInspectionResult(false); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | assetHouseInspectionDetails.add(assetHouseInspectionDetail); | 
|---|
|  |  |  | String waterStatus1 = assetHouseInspectionImport.getWaterStatus1(); | 
|---|
|  |  |  | String waterStatus2 = assetHouseInspectionImport.getWaterStatus2(); | 
|---|
|  |  |  | String waterStatus3 = assetHouseInspectionImport.getWaterStatus3(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AssetHouseInspectionDetail assetHouseInspectionDetailWatter1 = new AssetHouseInspectionDetail(); | 
|---|
|  |  |  | assetHouseInspectionDetailWatter1.setInspectionItemId(3); | 
|---|
|  |  |  | assetHouseInspectionDetailWatter1.setItemName("水电气表关闭情况"); | 
|---|
|  |  |  | assetHouseInspectionDetailWatter1.setSubItemId(4); | 
|---|
|  |  |  | assetHouseInspectionDetailWatter1.setSubItemName("水表关闭情况"); | 
|---|
|  |  |  | assetHouseInspectionDetailWatter1.setRemark(assetHouseInspectionImport.getWaterStatus1()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AssetHouseInspectionDetail assetHouseInspectionDetailWatter2 = new AssetHouseInspectionDetail(); | 
|---|
|  |  |  | assetHouseInspectionDetailWatter2.setInspectionItemId(3); | 
|---|
|  |  |  | assetHouseInspectionDetailWatter2.setItemName("水电气表关闭情况"); | 
|---|
|  |  |  | assetHouseInspectionDetailWatter2.setSubItemId(5); | 
|---|
|  |  |  | assetHouseInspectionDetailWatter2.setSubItemName("气表关闭情况"); | 
|---|
|  |  |  | assetHouseInspectionDetailWatter2.setRemark(assetHouseInspectionImport.getWaterStatus2()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AssetHouseInspectionDetail assetHouseInspectionDetailWatter3 = new AssetHouseInspectionDetail(); | 
|---|
|  |  |  | assetHouseInspectionDetailWatter3.setInspectionItemId(3); | 
|---|
|  |  |  | assetHouseInspectionDetailWatter3.setItemName("水电气表关闭情况"); | 
|---|
|  |  |  | assetHouseInspectionDetailWatter3.setSubItemId(6); | 
|---|
|  |  |  | assetHouseInspectionDetailWatter3.setSubItemName("电表关闭情况"); | 
|---|
|  |  |  | assetHouseInspectionDetailWatter3.setRemark(assetHouseInspectionImport.getWaterStatus3()); | 
|---|
|  |  |  | if (waterStatus1.equals("正常")&&waterStatus2.equals("正常")&&waterStatus3.equals("正常")){ | 
|---|
|  |  |  | assetHouseInspectionDetailWatter1.setInspectionResult(true); | 
|---|
|  |  |  | assetHouseInspectionDetailWatter2.setInspectionResult(true); | 
|---|
|  |  |  | assetHouseInspectionDetailWatter3.setInspectionResult(true); | 
|---|
|  |  |  | assetHouseInspectionRecord.setWaterElectronicGasCloseStatus("正常"); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | StringBuilder stringBuilder = new StringBuilder(); | 
|---|
|  |  |  | if (!waterStatus1.equals("正常")){ | 
|---|
|  |  |  | stringBuilder.append(waterStatus1).append("|"); | 
|---|
|  |  |  | assetHouseInspectionDetailWatter1.setInspectionResult(false); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | assetHouseInspectionDetailWatter1.setInspectionResult(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!waterStatus2.equals("正常")){ | 
|---|
|  |  |  | stringBuilder.append(waterStatus2).append("|"); | 
|---|
|  |  |  | assetHouseInspectionDetailWatter2.setInspectionResult(false); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | assetHouseInspectionDetailWatter2.setInspectionResult(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!waterStatus3.equals("正常")){ | 
|---|
|  |  |  | stringBuilder.append(waterStatus3).append("|"); | 
|---|
|  |  |  | assetHouseInspectionDetailWatter3.setInspectionResult(false); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | assetHouseInspectionDetailWatter3.setInspectionResult(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (stringBuilder.length()>0){ | 
|---|
|  |  |  | stringBuilder.deleteCharAt(stringBuilder.length()-1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | assetHouseInspectionRecord.setInnerStatus(stringBuilder.toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | assetHouseInspectionDetails.add(assetHouseInspectionDetailWatter1); | 
|---|
|  |  |  | assetHouseInspectionDetails.add(assetHouseInspectionDetailWatter2); | 
|---|
|  |  |  | assetHouseInspectionDetails.add(assetHouseInspectionDetailWatter3); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | String innerStatus1 = assetHouseInspectionImport.getInnerStatus1(); | 
|---|
|  |  |  | String innerStatus2 = assetHouseInspectionImport.getInnerStatus2(); | 
|---|
|  |  |  | String innerStatus3 = assetHouseInspectionImport.getInnerStatus3(); | 
|---|
|  |  |  | String innerStatus4 = assetHouseInspectionImport.getInnerStatus4(); | 
|---|
|  |  |  | AssetHouseInspectionDetail assetHouseInspectionDetailInner1 = new AssetHouseInspectionDetail(); | 
|---|
|  |  |  | assetHouseInspectionDetailInner1.setInspectionItemId(7); | 
|---|
|  |  |  | assetHouseInspectionDetailInner1.setItemName("房屋内部情况"); | 
|---|
|  |  |  | assetHouseInspectionDetailInner1.setSubItemId(8); | 
|---|
|  |  |  | assetHouseInspectionDetailInner1.setSubItemName("墙壁漏水情况"); | 
|---|
|  |  |  | assetHouseInspectionDetailInner1.setRemark(assetHouseInspectionImport.getWaterStatus1()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AssetHouseInspectionDetail assetHouseInspectionDetailInner2 = new AssetHouseInspectionDetail(); | 
|---|
|  |  |  | assetHouseInspectionDetailInner2.setInspectionItemId(7); | 
|---|
|  |  |  | assetHouseInspectionDetailInner2.setItemName("房屋内部情况"); | 
|---|
|  |  |  | assetHouseInspectionDetailInner2.setSubItemId(9); | 
|---|
|  |  |  | assetHouseInspectionDetailInner2.setSubItemName("设备损坏情况"); | 
|---|
|  |  |  | assetHouseInspectionDetailInner2.setRemark(assetHouseInspectionImport.getWaterStatus2()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AssetHouseInspectionDetail assetHouseInspectionDetailInner3 = new AssetHouseInspectionDetail(); | 
|---|
|  |  |  | assetHouseInspectionDetailInner3.setInspectionItemId(7); | 
|---|
|  |  |  | assetHouseInspectionDetailInner3.setItemName("房屋内部情况"); | 
|---|
|  |  |  | assetHouseInspectionDetailInner3.setSubItemId(10); | 
|---|
|  |  |  | assetHouseInspectionDetailInner3.setSubItemName("墙壁掉灰情况"); | 
|---|
|  |  |  | assetHouseInspectionDetailInner3.setRemark(assetHouseInspectionImport.getWaterStatus3()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | AssetHouseInspectionDetail assetHouseInspectionDetailInner4 = new AssetHouseInspectionDetail(); | 
|---|
|  |  |  | assetHouseInspectionDetailInner4.setInspectionItemId(7); | 
|---|
|  |  |  | assetHouseInspectionDetailInner4.setItemName("房屋内部情况"); | 
|---|
|  |  |  | assetHouseInspectionDetailInner4.setSubItemId(11); | 
|---|
|  |  |  | assetHouseInspectionDetailInner4.setSubItemName("地瓷砖开裂情况"); | 
|---|
|  |  |  | assetHouseInspectionDetailInner4.setRemark(assetHouseInspectionImport.getWaterStatus3()); | 
|---|
|  |  |  | if (innerStatus1.equals("正常")&&innerStatus2.equals("正常")&&innerStatus3.equals("正常")&&innerStatus4.equals("正常")){ | 
|---|
|  |  |  | assetHouseInspectionRecord.setInnerStatus("正常"); | 
|---|
|  |  |  | assetHouseInspectionDetailInner4.setInspectionResult(true); | 
|---|
|  |  |  | assetHouseInspectionDetailInner3.setInspectionResult(true); | 
|---|
|  |  |  | assetHouseInspectionDetailInner2.setInspectionResult(true); | 
|---|
|  |  |  | assetHouseInspectionDetailInner1.setInspectionResult(true); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | StringBuilder stringBuilder = new StringBuilder(); | 
|---|
|  |  |  | if (!innerStatus1.equals("正常")){ | 
|---|
|  |  |  | stringBuilder.append(innerStatus1).append("|"); | 
|---|
|  |  |  | assetHouseInspectionDetailInner1.setInspectionResult(false); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | assetHouseInspectionDetailInner1.setInspectionResult(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!innerStatus2.equals("正常")){ | 
|---|
|  |  |  | stringBuilder.append(innerStatus2).append("|"); | 
|---|
|  |  |  | assetHouseInspectionDetailInner2.setInspectionResult(false); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | assetHouseInspectionDetailInner2.setInspectionResult(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!innerStatus3.equals("正常")){ | 
|---|
|  |  |  | stringBuilder.append(innerStatus3).append("|"); | 
|---|
|  |  |  | assetHouseInspectionDetailInner3.setInspectionResult(false); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | assetHouseInspectionDetailInner3.setInspectionResult(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (!innerStatus4.equals("正常")){ | 
|---|
|  |  |  | stringBuilder.append(innerStatus4).append("|"); | 
|---|
|  |  |  | assetHouseInspectionDetailInner4.setInspectionResult(false); | 
|---|
|  |  |  | }else{ | 
|---|
|  |  |  | assetHouseInspectionDetailInner4.setInspectionResult(true); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (stringBuilder.length()>0){ | 
|---|
|  |  |  | stringBuilder.deleteCharAt(stringBuilder.length()-1); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | assetHouseInspectionRecord.setInnerStatus(stringBuilder.toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | assetHouseInspectionDetails.add(assetHouseInspectionDetailInner4); | 
|---|
|  |  |  | assetHouseInspectionDetails.add(assetHouseInspectionDetailInner3); | 
|---|
|  |  |  | assetHouseInspectionDetails.add(assetHouseInspectionDetailInner2); | 
|---|
|  |  |  | assetHouseInspectionDetails.add(assetHouseInspectionDetailInner1); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | assetHouseInspectionRecord.setRemarks(assetHouseInspectionImport.getRemark()); | 
|---|
|  |  |  | assetHouseInspectionRecordService.save(assetHouseInspectionRecord); | 
|---|
|  |  |  | assetHouseInspectionDetails.add(assetHouseInspectionDetail); | 
|---|
|  |  |  | for (AssetHouseInspectionDetail houseInspectionDetail : assetHouseInspectionDetails) { | 
|---|
|  |  |  | houseInspectionDetail.setInspectionRecordId(assetHouseInspectionRecord.getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | assetHouseInspectionDetailService.saveBatch(assetHouseInspectionDetails); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if(!result.isEmpty()){ | 
|---|
|  |  |  | return R.fail(result.toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 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(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|