From 4ee9e6833f738e22390c4e875fe140c2b96cfcc2 Mon Sep 17 00:00:00 2001 From: fuliqi <fuliqi@qq.com> Date: 星期五, 29 十一月 2024 04:03:37 +0800 Subject: [PATCH] 项目库分页查询 --- business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java | 158 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 151 insertions(+), 7 deletions(-) diff --git a/business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java b/business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java index eeca686..39d69d4 100644 --- a/business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java +++ b/business/src/main/java/com/ycl/service/impl/ProjectInfoServiceImpl.java @@ -1,21 +1,34 @@ package com.ycl.service.impl; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.ycl.common.base.Result; +import com.ycl.common.enums.business.FileTypeEnum; +import com.ycl.common.utils.CopyUtils; +import com.ycl.common.utils.DateUtils; +import com.ycl.common.utils.SecurityUtils; +import com.ycl.domain.entity.File; import com.ycl.domain.entity.ProjectInfo; +import com.ycl.domain.form.DocumentInfoForm; import com.ycl.domain.form.ProjectInfoForm; import com.ycl.domain.query.ProjectInfoQuery; -import com.ycl.domain.vo.ProjectInfoVO; +import com.ycl.domain.vo.*; import com.ycl.framework.utils.PageUtil; +import com.ycl.mapper.FileMapper; import com.ycl.mapper.ProjectInfoMapper; +import com.ycl.service.FileService; import com.ycl.service.ProjectInfoService; import lombok.RequiredArgsConstructor; import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.Assert; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** @@ -29,41 +42,75 @@ public class ProjectInfoServiceImpl extends ServiceImpl<ProjectInfoMapper, ProjectInfo> implements ProjectInfoService { private final ProjectInfoMapper projectInfoMapper; + private final FileService fileService; + private final FileMapper fileMapper; /** * 娣诲姞 + * * @param form * @return */ @Override + @Transactional(rollbackFor = Exception.class) public Result add(ProjectInfoForm form) { + //娣诲姞鍩烘湰淇℃伅 ProjectInfo entity = ProjectInfoForm.getEntityByForm(form, null); + Long userId = SecurityUtils.getUserId(); + entity.setCreateBy(userId); + entity.setUpdateBy(userId); baseMapper.insert(entity); - return Result.ok("娣诲姞鎴愬姛"); + //娣诲姞鏂囦欢 + List<File> fileList = form.getFileList(); + fileList.forEach(item -> { + item.setBusId(entity.getId()); + item.setType(FileTypeEnum.PROJECT_INFO); + }); + fileService.saveBatch(fileList); + return Result.ok("娣诲姞鎴愬姛").data(entity.getId()); } /** * 淇敼 + * * @param form * @return */ @Override + @Transactional(rollbackFor = Exception.class) public Result update(ProjectInfoForm form) { ProjectInfo entity = baseMapper.selectById(form.getId()); - // 涓虹┖鎶汭llegalArgumentException锛屽仛鍏ㄥ眬寮傚父澶勭悊 Assert.notNull(entity, "璁板綍涓嶅瓨鍦�"); - BeanUtils.copyProperties(form, entity); + ProjectInfoForm.getEntityByForm(form, entity); + Long userId = SecurityUtils.getUserId(); + entity.setUpdateBy(userId); + //鏇存柊椤圭洰淇℃伅 baseMapper.updateById(entity); + List<File> fileList = form.getFileList(); + fileList.forEach(item -> { + item.setId(null); + item.setBusId(entity.getId()); + item.setType(FileTypeEnum.PROJECT_INFO); + }); + //鍒犻櫎鍘熸湁鏂囦欢 + QueryWrapper<File> fileQueryWrapper = new QueryWrapper<>(); + fileQueryWrapper.eq("type", FileTypeEnum.PROJECT_INFO.getType()); + fileQueryWrapper.eq("bus_id", entity.getId()); + fileMapper.delete(fileQueryWrapper); + //鏇挎崲鎴愮幇鏈� + fileService.saveBatch(fileList); return Result.ok("淇敼鎴愬姛"); } /** * 鎵归噺鍒犻櫎 + * * @param ids * @return */ @Override + //TODO:寰呭畬鍠� public Result remove(List<String> ids) { baseMapper.deleteBatchIds(ids); return Result.ok("鍒犻櫎鎴愬姛"); @@ -71,10 +118,12 @@ /** * id鍒犻櫎 + * * @param id * @return */ @Override + //TODO:寰呭畬鍠� public Result removeById(String id) { baseMapper.deleteById(id); return Result.ok("鍒犻櫎鎴愬姛"); @@ -82,30 +131,63 @@ /** * 鍒嗛〉鏌ヨ + * * @param query * @return */ @Override public Result page(ProjectInfoQuery query) { + if (query.getProjectStartTime() != null) { + query.setProjectStartTime(DateUtils.getDayStart(query.getProjectStartTime())); + } + if (query.getProjectEndTime() != null) { + query.setProjectEndTime(DateUtils.getDayEnd(query.getProjectEndTime())); + } IPage<ProjectInfoVO> page = PageUtil.getPage(query, ProjectInfoVO.class); baseMapper.getPage(page, query); - return Result.ok().data(page.getRecords()).total(page.getTotal()); + List<ProjectInfoVO> records = page.getRecords(); + List<ProjectVO> list = new ArrayList<>(); + records.forEach(vo -> { + ProjectInfoVO.transform(vo); + vo.setProjectColorCode("green"); + ProjectVO projectVO = new ProjectVO(); + copyToProjectVO(vo,projectVO); + list.add(projectVO); + }); + return Result.ok().data(list).total(page.getTotal()); + } + + private void copyToProjectVO(ProjectInfoVO vo,ProjectVO projectVO) { + //蹇界暐null鍊肩殑澶嶅埗 + CopyUtils.copyNoNullProperties(vo, projectVO); + if(vo.getProjectInvestmentFunding()!=null) CopyUtils.copyNoNullProperties(vo.getProjectInvestmentFunding(),projectVO); + if(vo.getProjectInvestmentInfo()!=null) CopyUtils.copyNoNullProperties(vo.getProjectInvestmentInfo(),projectVO); + if(vo.getProjectUnitRegistrationInfo()!=null) CopyUtils.copyNoNullProperties(vo.getProjectUnitRegistrationInfo(),projectVO); + if(vo.getProjectInvestmentPolicyCompliance()!=null) CopyUtils.copyNoNullProperties(vo.getProjectInvestmentPolicyCompliance(),projectVO); } /** * 鏍规嵁id鏌ユ壘 + * * @param id * @return */ @Override public Result detail(Integer id) { - ProjectInfoVO vo = baseMapper.getById(id); - Assert.notNull(vo, "璁板綍涓嶅瓨鍦�"); + ProjectInfo entity = baseMapper.getById(id); + Assert.notNull(entity, "璁板綍涓嶅瓨鍦�"); + ProjectInfoVO vo = ProjectInfoVO.getVoByEntity(entity, null); + QueryWrapper<File> fileQueryWrapper = new QueryWrapper<>(); + fileQueryWrapper.eq("type", FileTypeEnum.PROJECT_INFO.getType()); + fileQueryWrapper.eq("bus_id", vo.getId()); + List<File> files = fileMapper.selectList(fileQueryWrapper); + vo.setFileList(files); return Result.ok().data(vo); } /** * 鍒楄〃 + * * @return */ @Override @@ -116,4 +198,66 @@ .collect(Collectors.toList()); return Result.ok().data(vos); } + + @Override + public IndexCountVO getIndexCount(IndexDTO indexDTO) { + // {"proPhaseCountVO":[{"type":"鍌ㄥ瑙勫垝闃舵","count":0,"amount":"0.00","text":"鍌�"}, + // {"type":"椤圭洰鍓嶆湡闃舵","count":0,"amount":"0.00","text":"鏂�"}, + // {"type":"瀹炴柦闃舵","count":0,"amount":"0.00","text":"寤�"},{"type":"绔e伐鎶曠敤闃舵","count":0,"amount":"0.00","text":"绔�"}], + // "impTypeCountVO":[{"type":"涓�鑸」鐩�","count":0,"amount":"0.00","text":"鏅�"}, + // {"type":"鍘块噸鐐归」鐩�","count":0,"amount":"0.00","text":"鍘�"},{"type":"甯傞噸鐐归」鐩�","count":0,"amount":"0.00","text":"甯�"}, + // {"type":"鐪侀噸鐐归」鐩�","count":0,"amount":"0.00","text":"鐪�"}]}} + IndexCountVO indexCountVO = new IndexCountVO(); + List<IndexProPhaseCountVO> proPhaseCountVO = new ArrayList<>(); + proPhaseCountVO.add(new IndexProPhaseCountVO("鍌ㄥ瑙勫垝闃舵", 0, "0.00", "鍌�")); + proPhaseCountVO.add(new IndexProPhaseCountVO("椤圭洰鍓嶆湡闃舵", 0, "0.00", "鏂�")); + proPhaseCountVO.add(new IndexProPhaseCountVO("瀹炴柦闃舵", 0, "0.00", "寤�")); + proPhaseCountVO.add(new IndexProPhaseCountVO("绔e伐鎶曠敤闃舵", 0, "0.00", "绔�")); + List<IndexImpTypeCountVO> impTypeCountVO = new ArrayList<>(); + impTypeCountVO.add(new IndexImpTypeCountVO("涓�鑸」鐩�", 0, "0.00", "鏅�")); + impTypeCountVO.add(new IndexImpTypeCountVO("鍘块噸鐐归」鐩�", 0, "0.00", "鍘�")); + impTypeCountVO.add(new IndexImpTypeCountVO("甯傞噸鐐归」鐩�", 0, "0.00", "甯�")); + impTypeCountVO.add(new IndexImpTypeCountVO("鐪侀噸鐐归」鐩�", 0, "0.00", "鐪�")); + indexCountVO.setImpTypeCountVO(impTypeCountVO); + indexCountVO.setProPhaseCountVO(proPhaseCountVO); + + + return indexCountVO; + } + + @Override + public Map<String, Integer> countExceptionProject(IndexDTO indexDTO) { + Map<String, Integer> map = new HashMap<>(); + map.put("processExceptionProject", 0); + return map; + } + + @Override + public Result docDetail(Integer id) { + DocumentInfoForm documentInfoForm = new DocumentInfoForm(); + QueryWrapper<File> fileQueryWrapper = new QueryWrapper<>(); + fileQueryWrapper.eq("type", FileTypeEnum.DOCUMENT_INFO.getType()); + fileQueryWrapper.eq("bus_id", id); + List<File> files = fileMapper.selectList(fileQueryWrapper); + documentInfoForm.setFileList(files); + return Result.ok().data(documentInfoForm); + } + + @Override + public Result addDoc(DocumentInfoForm form) { + List<File> fileList = form.getFileList(); + fileList.forEach(item -> { + item.setId(null); + item.setBusId(form.getProjectId()); + item.setType(FileTypeEnum.DOCUMENT_INFO); + }); + //鍒犻櫎鍘熸湁鏂囦欢 + QueryWrapper<File> fileQueryWrapper = new QueryWrapper<>(); + fileQueryWrapper.eq("type", FileTypeEnum.DOCUMENT_INFO.getType()); + fileQueryWrapper.eq("bus_id", form.getProjectId()); + fileMapper.delete(fileQueryWrapper); + //鏇挎崲鎴愮幇鏈� + fileService.saveBatch(fileList); + return Result.ok(); + } } -- Gitblit v1.8.0