|  |  |  | 
|---|
|  |  |  | package com.doumee.service.business.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.doumee.core.model.LoginUserInfo; | 
|---|
|  |  |  | import com.doumee.core.model.PageData; | 
|---|
|  |  |  | import com.doumee.core.model.PageWrap; | 
|---|
|  |  |  | import com.doumee.core.utils.Constants; | 
|---|
|  |  |  | import com.doumee.core.utils.Utils; | 
|---|
|  |  |  | import com.doumee.dao.business.YwBuildingMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.YwFloorMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.YwProjectMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.model.YwProject; | 
|---|
|  |  |  | import com.doumee.dao.business.YwRoomMapper; | 
|---|
|  |  |  | import com.doumee.dao.business.model.*; | 
|---|
|  |  |  | import com.doumee.dao.business.vo.CompanyTree; | 
|---|
|  |  |  | import com.doumee.dao.business.vo.ProjectDataVO; | 
|---|
|  |  |  | import com.doumee.dao.business.vo.ProjectTree; | 
|---|
|  |  |  | import com.doumee.service.business.AreasService; | 
|---|
|  |  |  | import com.doumee.service.business.YwProjectService; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.core.metadata.IPage; | 
|---|
|  |  |  | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | 
|---|
|  |  |  | import org.checkerframework.checker.units.qual.A; | 
|---|
|  |  |  | import org.springframework.beans.BeanUtils; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.stereotype.Service; | 
|---|
|  |  |  | import org.springframework.util.CollectionUtils; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.util.ArrayList; | 
|---|
|  |  |  | import java.util.Date; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private YwProjectMapper ywProjectMapper; | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private AreasService areasService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private YwFloorMapper ywFloorMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private YwRoomMapper ywRoomMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private YwBuildingMapper ywBuildingMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Integer create(YwProject ywProject) { | 
|---|
|  |  |  | ywProjectMapper.insert(ywProject); | 
|---|
|  |  |  | return ywProject.getId(); | 
|---|
|  |  |  | public Integer create(YwProject  model) { | 
|---|
|  |  |  | model.setCreator(model.getLoginUserInfo().getId()); | 
|---|
|  |  |  | model.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | model.setCreateDate(new Date()); | 
|---|
|  |  |  | model.setStatus(Constants.ZERO); | 
|---|
|  |  |  | model.setEditDate(model.getCreateDate()); | 
|---|
|  |  |  | model.setEditor(model.getCreator()); | 
|---|
|  |  |  | ywProjectMapper.insert(model); | 
|---|
|  |  |  | return model.getId(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void deleteById(Integer id) { | 
|---|
|  |  |  | ywProjectMapper.deleteById(id); | 
|---|
|  |  |  | public void deleteById(Integer id, LoginUserInfo user) { | 
|---|
|  |  |  | YwProject model = new YwProject(); | 
|---|
|  |  |  | model.setId(id); | 
|---|
|  |  |  | model.setEditDate(new Date()); | 
|---|
|  |  |  | model.setEditor(user.getId()); | 
|---|
|  |  |  | model.setIsdeleted(Constants.ONE); | 
|---|
|  |  |  | ywProjectMapper.updateById(model); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void deleteByIdInBatch(List<Integer> ids) { | 
|---|
|  |  |  | public void deleteByIdInBatch(List<Integer> ids, LoginUserInfo user) { | 
|---|
|  |  |  | if (CollectionUtils.isEmpty(ids)) { | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | ywProjectMapper.deleteBatchIds(ids); | 
|---|
|  |  |  | for(Integer id : ids){ | 
|---|
|  |  |  | this.deleteById(id,user); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void updateById(YwProject ywProject) { | 
|---|
|  |  |  | ywProjectMapper.updateById(ywProject); | 
|---|
|  |  |  | public void updateById(YwProject model) { | 
|---|
|  |  |  | model.setEditDate(new Date()); | 
|---|
|  |  |  | model.setEditor(model.getLoginUserInfo().getId()); | 
|---|
|  |  |  | ywProjectMapper.updateById(model); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<YwProject> findList(YwProject ywProject) { | 
|---|
|  |  |  | ywProject.setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | QueryWrapper<YwProject> wrapper = new QueryWrapper<>(ywProject); | 
|---|
|  |  |  | return ywProjectMapper.selectList(wrapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | IPage<YwProject> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); | 
|---|
|  |  |  | QueryWrapper<YwProject> queryWrapper = new QueryWrapper<>(); | 
|---|
|  |  |  | Utils.MP.blankToNull(pageWrap.getModel()); | 
|---|
|  |  |  | pageWrap.getModel().setIsdeleted(Constants.ZERO); | 
|---|
|  |  |  | queryWrapper.select("*,(select count(1) from yw_room a where a.isdeleted=0 and a.PROJECT_ID=yw_project.id) as roomNum"+ | 
|---|
|  |  |  | ",(select count(1) from yw_room a where a.isdeleted=0 and a.PROJECT_ID=yw_project.id and a.IS_INVESTMENT=1) as roomRentNum"); | 
|---|
|  |  |  | if (pageWrap.getModel().getId() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwProject::getId, pageWrap.getModel().getId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | if (pageWrap.getModel().getAddr() != null) { | 
|---|
|  |  |  | queryWrapper.lambda().eq(YwProject::getAddr, pageWrap.getModel().getAddr()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for(PageWrap.SortData sortData: pageWrap.getSorts()) { | 
|---|
|  |  |  | if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) { | 
|---|
|  |  |  | queryWrapper.orderByDesc(sortData.getProperty()); | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | queryWrapper.orderByAsc(sortData.getProperty()); | 
|---|
|  |  |  | queryWrapper.lambda().orderByDesc(YwProject::getCreateDate); | 
|---|
|  |  |  | PageData<YwProject> data = PageData.from(ywProjectMapper.selectPage(page, queryWrapper)); | 
|---|
|  |  |  | if(data!=null && data.getRecords()!=null){ | 
|---|
|  |  |  | for(YwProject model :data.getRecords()){ | 
|---|
|  |  |  | if(model.getAreaId()!=null){ | 
|---|
|  |  |  | Areas a = areasService.findById(model.getAreaId(),Constants.TWO); | 
|---|
|  |  |  | if(a != null){ | 
|---|
|  |  |  | model.setAreaName(a.getName()); | 
|---|
|  |  |  | model.setCityId(a.getCityId()); | 
|---|
|  |  |  | model.setCityName(a.getCityName()); | 
|---|
|  |  |  | model.setProvinceId(a.getProvinceId()); | 
|---|
|  |  |  | model.setProvinceName(a.getProvinceName()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return PageData.from(ywProjectMapper.selectPage(page, queryWrapper)); | 
|---|
|  |  |  | return data; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | QueryWrapper<YwProject> wrapper = new QueryWrapper<>(ywProject); | 
|---|
|  |  |  | return ywProjectMapper.selectCount(wrapper); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<ProjectDataVO> projectTree(){ | 
|---|
|  |  |  | List<ProjectDataVO> projectDataVOList = new ArrayList<>(); | 
|---|
|  |  |  | List<YwProject>  ywProjectList = ywProjectMapper.selectList(new QueryWrapper<YwProject>().lambda() | 
|---|
|  |  |  | .eq(YwProject::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(YwProject::getStatus,Constants.ZERO) | 
|---|
|  |  |  | .orderByAsc(YwProject::getSortnum) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | for (YwProject ywProject:ywProjectList) { | 
|---|
|  |  |  | ProjectDataVO projectDataVO = new ProjectDataVO(); | 
|---|
|  |  |  | BeanUtils.copyProperties(ywProject,projectDataVO); | 
|---|
|  |  |  | projectDataVO.setLv(Constants.ZERO); | 
|---|
|  |  |  | projectDataVOList.add(projectDataVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<YwBuilding>  ywBuildingList = ywBuildingMapper.selectList(new QueryWrapper<YwBuilding>().lambda() | 
|---|
|  |  |  | .eq(YwBuilding::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(YwBuilding::getStatus,Constants.ZERO) | 
|---|
|  |  |  | .orderByAsc(YwBuilding::getSortnum) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (YwBuilding data:ywBuildingList) { | 
|---|
|  |  |  | ProjectDataVO projectDataVO = new ProjectDataVO(); | 
|---|
|  |  |  | BeanUtils.copyProperties(data,projectDataVO); | 
|---|
|  |  |  | projectDataVO.setPId(data.getProjectId()); | 
|---|
|  |  |  | projectDataVO.setLv(Constants.ONE); | 
|---|
|  |  |  | projectDataVOList.add(projectDataVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<YwFloor>  ywFloorList = ywFloorMapper.selectList(new QueryWrapper<YwFloor>().lambda() | 
|---|
|  |  |  | .eq(YwFloor::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(YwFloor::getStatus,Constants.ZERO) | 
|---|
|  |  |  | .orderByAsc(YwFloor::getSortnum) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (YwFloor data:ywFloorList) { | 
|---|
|  |  |  | ProjectDataVO projectDataVO = new ProjectDataVO(); | 
|---|
|  |  |  | BeanUtils.copyProperties(data,projectDataVO); | 
|---|
|  |  |  | projectDataVO.setPId(data.getBuildingId()); | 
|---|
|  |  |  | projectDataVO.setLv(Constants.TWO); | 
|---|
|  |  |  | projectDataVOList.add(projectDataVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<YwRoom>  ywRoomList = ywRoomMapper.selectList(new QueryWrapper<YwRoom>().lambda() | 
|---|
|  |  |  | .eq(YwRoom::getIsdeleted,Constants.ZERO) | 
|---|
|  |  |  | .eq(YwRoom::getStatus,Constants.ZERO) | 
|---|
|  |  |  | .orderByAsc(YwRoom::getSortnum) | 
|---|
|  |  |  | ); | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | for (YwRoom data:ywRoomList) { | 
|---|
|  |  |  | ProjectDataVO projectDataVO = new ProjectDataVO(); | 
|---|
|  |  |  | BeanUtils.copyProperties(data,projectDataVO); | 
|---|
|  |  |  | projectDataVO.setName(data.getCode()); | 
|---|
|  |  |  | projectDataVO.setPId(data.getFloor()); | 
|---|
|  |  |  | projectDataVO.setLv(Constants.THREE); | 
|---|
|  |  |  | projectDataVOList.add(projectDataVO); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | ProjectTree treeBuild = new ProjectTree(projectDataVOList); | 
|---|
|  |  |  | projectDataVOList = treeBuild.buildTree(); | 
|---|
|  |  |  | return  projectDataVOList; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|