diff --git a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java index f7b664de4b..f25fd4269a 100644 --- a/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java +++ b/epmet-module/epmet-common-service/common-service-client/src/main/java/com/epmet/constants/ImportTaskConstants.java @@ -88,4 +88,9 @@ public interface ImportTaskConstants { * 物业表:ic_property_management */ String IC_PROPERTY_MANAGEMENT="ic_property_management"; + + /** + * 楼长单元长 + */ + String COMMUNITY_BUILDING_MANAGER="community_building_manager"; } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/CommunityBuildingManagerController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/CommunityBuildingManagerController.java index 4378e9bf8b..7c4f1fef3c 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/CommunityBuildingManagerController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/CommunityBuildingManagerController.java @@ -12,6 +12,7 @@ import com.epmet.commons.tools.aop.NoRepeatSubmit; import com.epmet.commons.tools.constant.NumConstant; import com.epmet.commons.tools.exception.EpmetErrorCode; import com.epmet.commons.tools.exception.EpmetException; +import com.epmet.commons.tools.feign.ResultDataResolver; import com.epmet.commons.tools.page.PageData; import com.epmet.commons.tools.security.dto.TokenDto; import com.epmet.commons.tools.utils.DateUtils; @@ -31,6 +32,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpHeaders; import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; @@ -51,7 +53,7 @@ import java.util.List; @Slf4j @RestController @RequestMapping("communityBuildingManager") -public class CommunityBuildingManagerController { +public class CommunityBuildingManagerController implements ResultDataResolver { @Autowired private CommunityBuildingManagerService communityBuildingManagerService; @@ -207,6 +209,54 @@ public class CommunityBuildingManagerController { } } + /** + * 导入excel + * + * @return + */ + @PostMapping("import") + public Result importExcel(@RequestPart("file") MultipartFile file) { + return new Result(); + /*// 1.暂存文件 + String originalFilename = file.getOriginalFilename(); + String extName = originalFilename.substring(originalFilename.lastIndexOf(".")); + + Path fileSavePath; + try { + Path importPath = FileUtils.getAndCreateDirUnderEpmetFilesDir(ImportTaskConstants.COMMUNITY_BUILDING_MANAGER, "import"); + fileSavePath = importPath.resolve(UUID.randomUUID().toString().concat(extName)); + } catch (IOException e) { + String errorMsg = ExceptionUtils.getErrorStackTrace(e); + log.error("【楼长单元长导入】创建临时存储文件失败:{}", errorMsg); + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "文件上传失败", "文件上传失败"); + } + + InputStream is = null; + FileOutputStream os = null; + + try { + is = file.getInputStream(); + os = new FileOutputStream(fileSavePath.toString()); + IOUtils.copy(is, os); + } catch (Exception e) { + log.error(ImportTaskConstants.COMMUNITY_BUILDING_MANAGER + "表 importExcel exception", e); + } finally { + org.apache.poi.util.IOUtils.closeQuietly(is); + org.apache.poi.util.IOUtils.closeQuietly(os); + } + + // 2.生成导入任务记录 + ImportTaskCommonResultDTO rstData = getResultDataOrThrowsException( + ImportTaskUtils.createImportTask(originalFilename, ImportTaskConstants.COMMUNITY_BUILDING_MANAGER), + ServiceConstant.EPMET_COMMON_SERVICE, + EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), + "楼长单元长导入excel错误", + "楼长单元长导入excel错误"); + + // 3.执行导入 + communityBuildingManagerService.execAsyncExcelImport(fileSavePath, rstData.getTaskId()); + return new Result();*/ + } diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/PropertyManagementController.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/PropertyManagementController.java index c3bff703b0..50767693ed 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/PropertyManagementController.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/controller/PropertyManagementController.java @@ -139,7 +139,25 @@ public class PropertyManagementController implements ResultDataResolver { public Result delete(@RequestBody IcPropertyManagementFormDTO formDTO){ //效验数据 ValidatorUtils.validateEntity(formDTO, IcPropertyManagementFormDTO.DeleteGroup.class); - propertyManagementService.delete(formDTO); + propertyManagementService.delete(formDTO.getId()); + return new Result(); + } + + /** + * 物业管理-批量删除 + * + * @param ids + * @return 返回失败的id列表 + */ + @PostMapping("delete-batch") + public Result> deleteBatch(@RequestBody List ids) { + if (CollectionUtils.isNotEmpty(ids)) { + List failedIdList = propertyManagementService.deleteBatch(ids); + Result result = new Result>().ok(failedIdList); + result.setMsg("部门物业删除失败"); + result.setCode(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode()); + return result; + } return new Result(); } @@ -239,7 +257,7 @@ public class PropertyManagementController implements ResultDataResolver { * @return */ @PostMapping("import") - public Result importExcel(MultipartFile file) { + public Result importExcel(@RequestPart("file") MultipartFile file) { // 1.暂存文件 String originalFilename = file.getOriginalFilename(); String extName = originalFilename.substring(originalFilename.lastIndexOf(".")); diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/yt/IcPropertyManagementImportExcelData.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/yt/IcPropertyManagementImportExcelData.java index 55196ffa18..cf9ad9d66b 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/yt/IcPropertyManagementImportExcelData.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/excel/yt/IcPropertyManagementImportExcelData.java @@ -4,6 +4,8 @@ import com.alibaba.excel.annotation.ExcelProperty; import com.alibaba.excel.annotation.write.style.ColumnWidth; import lombok.Data; +import javax.validation.constraints.NotBlank; + /** * @Description * @Author yzm @@ -14,6 +16,7 @@ public class IcPropertyManagementImportExcelData { /** * 物业名称 */ + @NotBlank(message = "物业名称必填") @ExcelProperty(value = "*物业名称") private String name; diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/CommunityBuildingManagerService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/CommunityBuildingManagerService.java index b67d4d0d35..eb32743443 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/CommunityBuildingManagerService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/CommunityBuildingManagerService.java @@ -7,6 +7,7 @@ import com.epmet.dto.result.CommunityBuildingManagerDTO; import com.epmet.dto.result.yt.CommunityBuildingManagerResultDTO; import com.epmet.entity.CommunityBuildingManagerEntity; +import java.nio.file.Path; import java.util.List; /** @@ -63,4 +64,6 @@ public interface CommunityBuildingManagerService extends BaseService ids); + + void execAsyncExcelImport(Path fileSavePath, String taskId); } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/PropertyManagementService.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/PropertyManagementService.java index 301b730072..3f50a0658c 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/PropertyManagementService.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/PropertyManagementService.java @@ -38,7 +38,11 @@ public interface PropertyManagementService { String add(IcPropertyManagementFormDTO formDTO); void update(IcPropertyManagementFormDTO formDTO); - void delete(IcPropertyManagementFormDTO formDTO); + /** + * 物业管理批量删除 + * @param id + */ + Boolean delete(String id); /** * 物业管理-列表查询 @@ -68,4 +72,12 @@ public interface PropertyManagementService { * @param taskId */ void execAsyncExcelImport(Path fileSavePath, String taskId); + + /** + * 物业管理批量删除 + * + * @param ids + * @return 返回失败的id列表 + */ + List deleteBatch(List ids); } \ No newline at end of file diff --git a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CommunityBuildingManagerServiceImpl.java b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CommunityBuildingManagerServiceImpl.java index 9f8e9bbf09..817d435c9b 100644 --- a/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CommunityBuildingManagerServiceImpl.java +++ b/epmet-module/gov-org/gov-org-server/src/main/java/com/epmet/service/impl/CommunityBuildingManagerServiceImpl.java @@ -22,11 +22,14 @@ import com.epmet.service.CommunityBuildingManagerService; import com.epmet.service.CustomerGridService; import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; +import java.nio.file.Path; import java.util.List; /** @@ -35,6 +38,7 @@ import java.util.List; * @author generator generator@elink-cn.com * @since v1.0.0 2023-05-06 */ +@Slf4j @Service public class CommunityBuildingManagerServiceImpl extends BaseServiceImpl implements CommunityBuildingManagerService { @@ -67,7 +71,7 @@ public class CommunityBuildingManagerServiceImpl extends BaseServiceImpl pageInfo = new PageInfo<>(resList); - return new PageData<>(resList, pageInfo.getTotal(),formDTO.getPageSize()); + return new PageData<>(resList, pageInfo.getTotal(), formDTO.getPageSize()); } /** @@ -108,7 +112,7 @@ public class CommunityBuildingManagerServiceImpl extends BaseServiceImpl countQuery=new LambdaQueryWrapper<>(); - countQuery.eq(CommunityBuildingManagerEntity::getType,type) - .eq(CommunityBuildingManagerEntity::getBuildingId,buildingId) - .eq(StringUtils.isNotBlank(unitId),CommunityBuildingManagerEntity::getUnitId,unitId) - .ne(StringUtils.isNotBlank(id),CommunityBuildingManagerEntity::getId,id); - if(baseDao.selectCount(countQuery)>NumConstant.ZERO){ - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"所选楼栋(单元)已存在楼长(单元长)","所选楼栋(单元)已存在楼长(单元长)"); + LambdaQueryWrapper countQuery = new LambdaQueryWrapper<>(); + countQuery.eq(CommunityBuildingManagerEntity::getType, type) + .eq(CommunityBuildingManagerEntity::getBuildingId, buildingId) + .eq(StringUtils.isNotBlank(unitId), CommunityBuildingManagerEntity::getUnitId, unitId) + .ne(StringUtils.isNotBlank(id), CommunityBuildingManagerEntity::getId, id); + if (baseDao.selectCount(countQuery) > NumConstant.ZERO) { + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "所选楼栋(单元)已存在楼长(单元长)", "所选楼栋(单元)已存在楼长(单元长)"); } } @@ -138,7 +142,7 @@ public class CommunityBuildingManagerServiceImpl extends BaseServiceImpl queryWrapper=new LambdaQueryWrapper<>(); - queryWrapper.eq(IcNeighborHoodPropertyEntity::getPropertyId,formDTO.getId()); + public Boolean delete(String id) { + Boolean delResFlag=true; + CustomerStaffInfoCacheResult staffInfoCacheResult = CustomerStaffRedis.getStaffInfo(EpmetRequestHolder.getLoginUserCustomerId(), EpmetRequestHolder.getLoginUserId()); + // 查询当前物业,在本组织及下级范围内,管理的小区 + List originNeighborHoodList = icNeighborHoodPropertyDao.getNeighborHoodList(id, staffInfoCacheResult.getAgencyId()); + // 如果存在记录,则解除物业与小区关联关系 + originNeighborHoodList.forEach(origin -> { + LambdaUpdateWrapper updateWrapper1 = new LambdaUpdateWrapper<>(); + updateWrapper1.eq(IcNeighborHoodPropertyEntity::getPropertyId, id) + .eq(IcNeighborHoodPropertyEntity::getNeighborHoodId, origin.getId()) + .set(IcNeighborHoodPropertyEntity::getDelFlag, NumConstant.ONE_STR) + .set(IcNeighborHoodPropertyEntity::getUpdatedTime, new Date()) + .set(IcNeighborHoodPropertyEntity::getUpdatedBy, EpmetRequestHolder.getLoginUserId()); + icNeighborHoodPropertyDao.update(null, updateWrapper1); + }); + // 再查询是否存在其他组织下的小区,与该物业有关联,存在则不允许删除 + LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(IcNeighborHoodPropertyEntity::getPropertyId, id); if (icNeighborHoodPropertyDao.selectCount(queryWrapper) > 0) { - throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(),"物业存在与小区关联,无法删除","已与小区关联,无法删除"); + delResFlag=false; + throw new EpmetException(EpmetErrorCode.EPMET_COMMON_OPERATION_FAIL.getCode(), "当前物业已与其他组织下的小区关联,无法删除", "当前物业已与其他组织下的小区关联,无法删除"); } - icPropertyManagementDao.deleteById(formDTO.getId()); + // 删除物业表 + icPropertyManagementDao.deleteById(id); + return delResFlag; } + + /** + * 物业管理批量删除 + * + * @param ids + * @return 返回失败的id列表 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public List deleteBatch(List ids) { + if (CollectionUtils.isEmpty(ids)) { + return new ArrayList<>(); + } + List failedIdList = new ArrayList<>(); + for (String id : ids) { + Boolean res = delete(id); + if (!res) { + failedIdList.add(id); + } + } + return failedIdList; + } + + /** * 物业管理-列表查询 *