package com.zzg.web.controller.state; import cn.hutool.core.date.DateUtil; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.github.pagehelper.PageInfo; import com.zzg.common.constant.state.UrlConstants; import com.zzg.common.core.domain.AjaxResult; import com.zzg.common.core.domain.entity.state.StateHousehold; import com.zzg.common.core.domain.entity.state.StateProject; import com.zzg.common.core.domain.entity.state.StateProjectCollectionFile; import com.zzg.common.core.domain.entity.state.StateProjectNotice; import com.zzg.common.enums.HouseSearchStatusEnum; import com.zzg.common.enums.StateProjectStatusEnum; import com.zzg.common.exception.GlobalException; import com.zzg.common.utils.DateUtils; import com.zzg.system.convert.StateProjectConvert; import com.zzg.system.domain.bo.*; import com.zzg.system.domain.vo.CalculateCompensationVO; import com.zzg.system.domain.vo.ParentCollectionFileVO; import com.zzg.system.domain.vo.ProjectImplPageVO; import com.zzg.system.domain.vo.StateProjectNoticeVO; import com.zzg.system.service.state.*; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.util.CollectionUtils; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import java.util.List; import java.util.Objects; @Slf4j @RestController @RequiredArgsConstructor public class StateProjectController { private final StateProjectService stateProjectService; private final StateProjectCollectionFileService stateProjectCollectionFileService; private final StateProjectNoticeService stateProjectNoticeService; private final StateHouseholdService stateHouseholdService; // 查询所有项目 @GetMapping(UrlConstants.STATE_PROJECT_LIST) public AjaxResult> list() { return AjaxResult.success(stateProjectService.list()); } // 分页查询 @PostMapping(UrlConstants.STATE_PROJECT_PAGE) @ApiOperation(value = "分页查询项目列表", notes = "分页查询项目列表") public AjaxResult page(@RequestBody GetProjectPageBO getProjectPageBO) { return AjaxResult.success(stateProjectService.getPage(getProjectPageBO)); } // 分页查询 @PostMapping(UrlConstants.STATE_PROJECT_PAGE_APPLY_RECORD) @ApiOperation(value = "分页查询项目列表 仅针对住宅临时安置费处进行查询", notes = "分页查询项目列表") public AjaxResult pageForApplyRecord(@RequestBody GetProjectPageBO getProjectPageBO) { return AjaxResult.success(stateProjectService.getPageForApplyRecord(getProjectPageBO)); } // 根据ID查询项目 @GetMapping(UrlConstants.STATE_PROJECT_GET_BY_ID) public AjaxResult getById(@PathVariable String id) { return AjaxResult.success(stateProjectService.getProjectInfoById(id)); } //获取当前项目的所有街道 @GetMapping(UrlConstants.STATE_PROJECT_GET_STREET_BY_ID) public AjaxResult getProjectBelongingStreetTownById(@PathVariable String id) { return AjaxResult.success(stateProjectService.getProjectBelongingStreetTownById(id)); } // 创建项目 @PostMapping(UrlConstants.STATE_PROJECT_SAVE) @ApiOperation(value = "新建或更新项目", notes = "新建或更新项目") public AjaxResult create(@RequestBody StateProjectBO stateProject) { return AjaxResult.success(stateProjectService.saveProjectAndInfo(stateProject)); } // 更新项目 @PutMapping(UrlConstants.STATE_PROJECT_UPDATE) public AjaxResult update(@RequestBody StateProject stateProject) { return AjaxResult.success(stateProjectService.updateById(stateProject)); } @PostMapping(UrlConstants.STATE_PROJECT_UPDATE_STATUS) @ApiOperation(value = "修改项目状态,例如转征收,并发布公告", notes = "修改项目状态,例如转征收,并发布公告") public AjaxResult update(@RequestBody UpdateProjectAndAddNoticeBO updateProjectAndAddNoticeBO) { if (StateProjectStatusEnum.LEVY.getKey().equals(updateProjectAndAddNoticeBO.getProjectStatus()) || StateProjectStatusEnum.SIMULATE.getKey().equals(updateProjectAndAddNoticeBO.getProjectStatus())) { HouseAgreeMoveRateBO houseAgreeMoveRateBO = stateHouseholdService.currentProjectRate(updateProjectAndAddNoticeBO.getProjectId()); if (Objects.isNull(houseAgreeMoveRateBO)) { throw new GlobalException("当前项目未添加任何房产信息数据"); } if (houseAgreeMoveRateBO.getAreaAgreeMoveRate() <= 66.66) { throw new GlobalException("房产同意面积未超过2/3"); } if (houseAgreeMoveRateBO.getPersonAgreeMoveRate() <= 95.00) { throw new GlobalException("房产同意率未超过95%"); } } StateProject projectById = stateProjectService.getProjectById(updateProjectAndAddNoticeBO.getProjectId()); projectById.setStatus(updateProjectAndAddNoticeBO.getProjectStatus()); projectById.setIsNeedEvaluate(updateProjectAndAddNoticeBO.getIsNeedEvaluate()); if (updateProjectAndAddNoticeBO.getProjectStatus().equals(StateProjectStatusEnum.SIMULATE.getKey())) { projectById.setSimulatedTime(DateUtil.parseDate(com.zzg.common.utils.DateUtil.formatDate(com.zzg.common.utils.DateUtil.getNewDate(), DateUtils.YYYY_MM_DD))); projectById.setStage(StateProjectStatusEnum.SIMULATE.getKey()); } else if (updateProjectAndAddNoticeBO.getProjectStatus().equals(StateProjectStatusEnum.LEVY.getKey())) { projectById.setLevyTime(DateUtil.parseDate(com.zzg.common.utils.DateUtil.formatDate(com.zzg.common.utils.DateUtil.getNewDate(), DateUtils.YYYY_MM_DD))); projectById.setStage(StateProjectStatusEnum.LEVY.getKey()); if (projectById.getIsNeedEvaluate() == 1) { LambdaQueryWrapper queryWrapper = new LambdaQueryWrapper<>(); queryWrapper.eq(StateHousehold::getStateProjectId, projectById.getId()); List householdList = stateHouseholdService.list(queryWrapper); if (!CollectionUtils.isEmpty(householdList)) { householdList.forEach(e -> { //协议状态、调查评估签订状态重置 e.setAgreementStatus(null); if (StringUtils.isNotBlank(e.getAppendData())) { String appendData = e.getAppendData(); CalculateCompensationVO calculateCompensationVO = JSON.parseObject(appendData, CalculateCompensationVO.class); if (Objects.nonNull(calculateCompensationVO.getSurveyResultRegistrationBO())) { calculateCompensationVO.getSurveyResultRegistrationBO().setIsSignedVirtualAgreement(null); } e.setAppendData(JSON.toJSONString(calculateCompensationVO)); } }); stateHouseholdService.saveOrUpdateBatch(householdList); } } } stateProjectService.saveProject(projectById); StateProjectNotice stateProjectNotice = StateProjectConvert.INSTANCE.updateProjectAndAddNoticeBOToEntity(updateProjectAndAddNoticeBO); if (Objects.nonNull(updateProjectAndAddNoticeBO.getFileBOList()) && !CollectionUtils.isEmpty(updateProjectAndAddNoticeBO.getFileBOList())) { stateProjectNotice.setFileUrl(JSON.toJSONString(updateProjectAndAddNoticeBO.getFileBOList())); } if (Objects.nonNull(updateProjectAndAddNoticeBO.getImgBOList()) && !CollectionUtils.isEmpty(updateProjectAndAddNoticeBO.getImgBOList())) { stateProjectNotice.setImgUrl(JSON.toJSONString(updateProjectAndAddNoticeBO.getImgBOList())); } //1 正常公告 2转征收的公告 stateProjectNotice.setType(2); stateProjectNoticeService.saveOrUpdate(stateProjectNotice); //转征收后,将房产调查状态改为调查过 用于app端展示对应数据 LambdaUpdateWrapper updateWrapper = new LambdaUpdateWrapper<>(); updateWrapper.eq(StateHousehold::getStateProjectId, updateProjectAndAddNoticeBO.getProjectId()); if (updateProjectAndAddNoticeBO.getProjectStatus().equals(StateProjectStatusEnum.LEVY.getKey())) { updateWrapper.set(StateHousehold::getSearchStatus, HouseSearchStatusEnum.SEARCHED.getValue()); } updateWrapper.set(StateHousehold::getStage, StateProjectStatusEnum.LEVY.getKey()); //对于转征收的数据 协议的审核状态挂在房产上的 房产的对应状态需要置空 updateWrapper.set(StateHousehold::getAgreementStatus, null); stateHouseholdService.update(updateWrapper); return AjaxResult.success(); } // 删除项目 @DeleteMapping(UrlConstants.STATE_PROJECT_DELETE) @ApiOperation(value = "删除项目", notes = "删除项目") public AjaxResult delete(@PathVariable String id) { return AjaxResult.success(stateProjectService.removeById(id)); } // 删除项目 @PostMapping(UrlConstants.STATE_PROJECT_SUCCESS) @ApiOperation(value = "将项目改为已完成", notes = "将项目改为已完成") public AjaxResult successProject(@RequestBody GetProjectPageBO getProjectPageBO) { //todo接workflow 并计算金额 stateProjectService.updateProjectAppStage(getProjectPageBO.getProjectId(), StateProjectStatusEnum.SUCCESS.getKey()); return AjaxResult.success(stateProjectService.updateProjectStatus(getProjectPageBO.getProjectId(), StateProjectStatusEnum.SUCCESS.getKey())); } @PostMapping(UrlConstants.STATE_PROJECT_APP_SUCCESS) @ApiOperation(value = "app将项目改为已完成", notes = "app将项目改为已完成") public AjaxResult appSuccessProject(@RequestBody GetProjectPageBO getProjectPageBO) { return AjaxResult.success(stateProjectService.updateProjectAppStage(getProjectPageBO.getProjectId(), StateProjectStatusEnum.SUCCESS.getKey())); } @PostMapping(UrlConstants.STATE_PROJECT_NOTICE_SIMULATE) @ApiOperation(value = "将项目改为模拟", notes = "将项目改为模拟") public AjaxResult simulatedProject(@RequestBody GetProjectPageBO getProjectPageBO) { stateProjectService.updateProjectAppStage(getProjectPageBO.getProjectId(), StateProjectStatusEnum.SIMULATE.getKey()); return AjaxResult.success(stateProjectService.updateProjectStatus(getProjectPageBO.getProjectId(), StateProjectStatusEnum.SIMULATE.getKey())); } @DeleteMapping(UrlConstants.STATE_PROJECT_CANCELLATION) @ApiOperation(value = "作废项目", notes = "作废项目") public AjaxResult cancellationStateProject(@PathVariable String id) { return AjaxResult.success(stateProjectService.cancellationStateProject(id)); } //查询所有征集文件 @GetMapping(UrlConstants.STATE_PROJECT_COLLECTION_FILE_LIST) @ApiOperation(value = "查询所有征集文件", notes = "查询所有征集文件") public AjaxResult> listCollectionFile(@RequestParam String projectId, @RequestParam Integer fileType, @RequestParam Boolean isBefore) { return AjaxResult.success(stateProjectCollectionFileService.getByProjectIdAndType(projectId, fileType, isBefore)); } @GetMapping(UrlConstants.STATE_PROJECT_COLLECTION_FILE_PARENT) @ApiOperation(value = "查询所有父亲文件", notes = "查询所有父亲文件") public AjaxResult> listCollectionFileParent(@RequestParam Boolean isBefore) { return AjaxResult.success(stateProjectCollectionFileService.getParentCollectionFile(isBefore)); } @GetMapping(UrlConstants.STATE_PROJECT_REMOVE_COLLECTION_FILE) @ApiOperation(value = "删除征收文件", notes = "删除征收文件") public AjaxResult removeCollectionFile(@RequestParam String fileId) { return AjaxResult.success(stateProjectCollectionFileService.removeById(fileId)); } @PostMapping(UrlConstants.STATE_PROJECT_ADD_COLLECTION_FILE) @ApiOperation(value = "添加征收文件", notes = "添加征收文件") public AjaxResult addCollectionFile(@RequestBody @Validated UploadFileBO uploadFileBO) { return AjaxResult.success(stateProjectCollectionFileService.addCollectionFile(uploadFileBO)); } @PostMapping(UrlConstants.STATE_PROJECT_NOTICE_PAGE) @ApiOperation(value = "分页查询公告", notes = "分页查询公告") public AjaxResult> pageNotice(@RequestBody GetProjectPageBO getProjectPageBO) { return AjaxResult.success(stateProjectNoticeService.page(new Page<>(getProjectPageBO.getPageNum(), getProjectPageBO.getPageSize()))); } @PostMapping(UrlConstants.STATE_PROJECT_NOTICE_PAGE_AFTER_UPDATE_PROJECT) @ApiOperation(value = "分页查询公告", notes = "分页查询公告在更新项目之后") public AjaxResult> pageNoticeAfterUpdateProject(@RequestBody GetProjectPageBO getProjectPageBO) { LambdaQueryWrapper stateProjectNoticeLambdaQueryWrapper = new LambdaQueryWrapper<>(); //对于新建项目而言 此处没有公告 if (Objects.isNull(getProjectPageBO.getProjectId())) { return AjaxResult.success(); } stateProjectNoticeLambdaQueryWrapper.eq(StateProjectNotice::getProjectId, getProjectPageBO.getProjectId()); return AjaxResult.success(stateProjectNoticeService.page(new Page<>(getProjectPageBO.getPageNum(), getProjectPageBO.getPageSize()), stateProjectNoticeLambdaQueryWrapper)); } @GetMapping(UrlConstants.STATE_PROJECT_NOTICE_GET) @ApiOperation(value = "查询公告详情", notes = "查询公告详情") public AjaxResult getNoticeInfo(@RequestParam String noticeId) { StateProjectNoticeVO stateProjectNoticeVO = stateProjectNoticeService.getStateProjectNoticeVO(noticeId); return AjaxResult.success(stateProjectNoticeVO); } @DeleteMapping(UrlConstants.STATE_PROJECT_NOTICE_DELETE) @ApiOperation(value = "删除公告", notes = "删除公告") public AjaxResult deleteNotice(@PathVariable String id) { return AjaxResult.success(stateProjectNoticeService.removeById(id)); } @PostMapping(UrlConstants.STATE_PROJECT_NOTICE_ADD) @ApiOperation(value = "新增公告", notes = "新增公告") public AjaxResult addNotice(@RequestBody UpdateProjectAndAddNoticeBO updateProjectAndAddNoticeBO) { StateProjectNotice stateProjectNotice = StateProjectConvert.INSTANCE.updateProjectAndAddNoticeBOToEntity(updateProjectAndAddNoticeBO); if (Objects.nonNull(updateProjectAndAddNoticeBO.getFileBOList()) && !CollectionUtils.isEmpty(updateProjectAndAddNoticeBO.getFileBOList())) { stateProjectNotice.setFileUrl(JSON.toJSONString(updateProjectAndAddNoticeBO.getFileBOList())); } if (Objects.nonNull(updateProjectAndAddNoticeBO.getImgBOList()) && !CollectionUtils.isEmpty(updateProjectAndAddNoticeBO.getImgBOList())) { stateProjectNotice.setImgUrl(JSON.toJSONString(updateProjectAndAddNoticeBO.getImgBOList())); } //1 正常公告 2转征收的公告 stateProjectNotice.setType(1); return AjaxResult.success(stateProjectNoticeService.saveOrUpdate(stateProjectNotice)); } @PostMapping(UrlConstants.STATE_PROJECT_IMPL_PAGE) @ApiOperation(value = "项目实施查询", notes = "项目实施查询") public AjaxResult> projectImplPage(@RequestBody GetProjectPageBO getProjectPageBO) { return AjaxResult.success(stateProjectService.getProjectImplPage(getProjectPageBO)); } }