Commit 4935d753 authored by tianbo's avatar tianbo

优化代码

parent 0f52741f
...@@ -19,7 +19,7 @@ public interface IKeySiteService { ...@@ -19,7 +19,7 @@ public interface IKeySiteService {
* @param id * @param id
* @return * @return
*/ */
public boolean deletebyId(Long id); public boolean deleteById(Long id);
/** /**
* 保存 * 保存
* @param model * @param model
...@@ -36,7 +36,7 @@ public boolean update (KeySite keySite); ...@@ -36,7 +36,7 @@ public boolean update (KeySite keySite);
* 获取机场单位组织结构树,包含单位下部门数量的统计 * 获取机场单位组织结构树,包含单位下部门数量的统计
* @return * @return
*/ */
public List<OrgUsrTreeDto> getOrguserTree(); public List<OrgUsrTreeDto> getOrgUserTree();
/** /**
* *
* @return * @return
...@@ -51,5 +51,5 @@ public KeySiteDto getSequenceNbr(Long sequenceNbr); ...@@ -51,5 +51,5 @@ public KeySiteDto getSequenceNbr(Long sequenceNbr);
public List<KeySiteExcleDto> exportToExcel(); public List<KeySiteExcleDto> exportToExcel();
public boolean saveExcle(List<KeySiteExcleDto> excelDtoList); public boolean saveExcel(List<KeySiteExcleDto> excelDtoList);
} }
...@@ -94,7 +94,7 @@ public class KeySiteController extends BaseController { ...@@ -94,7 +94,7 @@ public class KeySiteController extends BaseController {
@DeleteMapping(value = "delete/{sequenceNbr}") @DeleteMapping(value = "delete/{sequenceNbr}")
@ApiOperation(httpMethod = "DELETE", value = "根据sequenceNbr删除重点部位", notes = "根据sequenceNbr删除重点部位") @ApiOperation(httpMethod = "DELETE", value = "根据sequenceNbr删除重点部位", notes = "根据sequenceNbr删除重点部位")
public ResponseModel<Boolean> deleteBySequenceNbr(HttpServletRequest request, @PathVariable(value = "sequenceNbr") Long sequenceNbr){ public ResponseModel<Boolean> deleteBySequenceNbr(HttpServletRequest request, @PathVariable(value = "sequenceNbr") Long sequenceNbr){
return ResponseHelper.buildResponse(keySiteService.deletebyId(sequenceNbr)); return ResponseHelper.buildResponse(keySiteService.deleteById(sequenceNbr));
} }
/** /**
...@@ -151,7 +151,7 @@ public class KeySiteController extends BaseController { ...@@ -151,7 +151,7 @@ public class KeySiteController extends BaseController {
@GetMapping(value = "/getOrguserTree") @GetMapping(value = "/getOrguserTree")
public ResponseModel<List<OrgMenuDto>> getOrguserTree() throws Exception{ public ResponseModel<List<OrgMenuDto>> getOrguserTree() throws Exception{
List<OrgMenuDto> menus = iOrgUsrService.getTree(null, List<OrgMenuDto> menus = iOrgUsrService.getTree(null,
keySiteService.getOrguserTree(), OrgUsrTreeDto.class.getName(), keySiteService.getOrgUserTree(), OrgUsrTreeDto.class.getName(),
"getSequenceNbr", 2, "getBizOrgName", "getParentId", "getNum"); "getSequenceNbr", 2, "getBizOrgName", "getParentId", "getNum");
return ResponseHelper.buildResponse(menus); return ResponseHelper.buildResponse(menus);
} }
......
...@@ -49,8 +49,6 @@ public class MaintenanceCompanyController extends BaseController { ...@@ -49,8 +49,6 @@ public class MaintenanceCompanyController extends BaseController {
@Autowired @Autowired
MaintenanceCompanyServiceImpl maintenanceCompanyServiceImpl; MaintenanceCompanyServiceImpl maintenanceCompanyServiceImpl;
SourceFileServiceImpl sourceFileService;
@Autowired @Autowired
IMaintenanceCompanyService maintenanceCompanyService; IMaintenanceCompanyService maintenanceCompanyService;
......
...@@ -56,17 +56,19 @@ public class KeySiteServiceImpl extends BaseService<KeySiteDto, KeySite, KeySite ...@@ -56,17 +56,19 @@ public class KeySiteServiceImpl extends BaseService<KeySiteDto, KeySite, KeySite
/** /**
* 列表查询 示例 * 列表查询 示例
*/ */
@Override
public List<KeySiteDto> queryForKeySiteList() { public List<KeySiteDto> queryForKeySiteList() {
return keySiteMapper.getKeySiteList(); return keySiteMapper.getKeySiteList();
} }
@Override
public List<KeySiteExcleDto> exportToExcel() { public List<KeySiteExcleDto> exportToExcel() {
List<KeySiteDto> list = this.queryForKeySiteList(); List<KeySiteDto> list = this.queryForKeySiteList();
return JSONArray.parseArray(JSONArray.toJSONString(list), KeySiteExcleDto.class); return JSONArray.parseArray(JSONArray.toJSONString(list), KeySiteExcleDto.class);
} }
@Override @Override
public boolean deletebyId(Long id) { public boolean deleteById(Long id) {
KeySite keySite = keySiteMapper.selectById(id); KeySite keySite = keySiteMapper.selectById(id);
if (keySite == null) { if (keySite == null) {
return false; return false;
...@@ -85,37 +87,12 @@ public class KeySiteServiceImpl extends BaseService<KeySiteDto, KeySite, KeySite ...@@ -85,37 +87,12 @@ public class KeySiteServiceImpl extends BaseService<KeySiteDto, KeySite, KeySite
KeySite keySite = new KeySite(); KeySite keySite = new KeySite();
Bean.copyExistPropertis(model, keySite); Bean.copyExistPropertis(model, keySite);
this.save(keySite); this.save(keySite);
this.saveAttachments(model); sourceFileService.saveAttachments(model.getSequenceNbr(), model.getAttachments());
// TODO Auto-generated method stub // TODO Auto-generated method stub
return model; return model;
} }
public void saveAttachments(KeySiteDto keySiteDto) { @Override
if (!ValidationUtil.isEmpty(keySiteDto.getAttachments())) {
List<SourceFile> sourceFiles = Lists.newArrayList();
Map<String, List<AttachmentDto>> attachmentMap = keySiteDto.getAttachments();
attachmentMap.entrySet().forEach(entry -> {
List<AttachmentDto> atts = entry.getValue();
sourceFiles.addAll(attachment2SourceFile(entry.getKey(), atts));
});
sourceFileService.saveSourceFile(keySiteDto.getSequenceNbr(), sourceFiles);
}
}
private List<SourceFile> attachment2SourceFile(String type, List<AttachmentDto> attachmentDtoList) {
List<SourceFile> sourceFiles = Lists.newArrayList();
if (!ValidationUtil.isEmpty(attachmentDtoList)) {
attachmentDtoList.forEach(a -> {
SourceFile s = new SourceFile();
s.setFilePath(a.getUrl());
s.setFileName(a.getName());
s.setFileCategory(type);
sourceFiles.add(s);
});
}
return sourceFiles;
}
public boolean update(KeySite keySite) { public boolean update(KeySite keySite) {
keySite.setIsDelete(false); keySite.setIsDelete(false);
int num = keySiteMapper.updateById(keySite); int num = keySiteMapper.updateById(keySite);
...@@ -126,7 +103,7 @@ public class KeySiteServiceImpl extends BaseService<KeySiteDto, KeySite, KeySite ...@@ -126,7 +103,7 @@ public class KeySiteServiceImpl extends BaseService<KeySiteDto, KeySite, KeySite
} }
@Override @Override
public List<OrgUsrTreeDto> getOrguserTree() { public List<OrgUsrTreeDto> getOrgUserTree() {
return orgUsrMapper.getCompanyAndCountDepartment(); return orgUsrMapper.getCompanyAndCountDepartment();
} }
...@@ -136,7 +113,7 @@ public class KeySiteServiceImpl extends BaseService<KeySiteDto, KeySite, KeySite ...@@ -136,7 +113,7 @@ public class KeySiteServiceImpl extends BaseService<KeySiteDto, KeySite, KeySite
} }
@Override @Override
public boolean saveExcle(List<KeySiteExcleDto> excelDtoList) { public boolean saveExcel(List<KeySiteExcleDto> excelDtoList) {
List<KeySite> excelList = new ArrayList<KeySite>(); List<KeySite> excelList = new ArrayList<KeySite>();
for (KeySiteExcleDto keySiteExcleDto : excelDtoList) { for (KeySiteExcleDto keySiteExcleDto : excelDtoList) {
KeySite keySiteDto = new KeySite(); KeySite keySiteDto = new KeySite();
......
...@@ -116,7 +116,7 @@ public class MaintenanceCompanyServiceImpl ...@@ -116,7 +116,7 @@ public class MaintenanceCompanyServiceImpl
try { try {
this.save(maintenanceCompany); this.save(maintenanceCompany);
saveAttachments(maintenanceCompany); sourceFileService.saveAttachments(maintenanceCompany.getSequenceNbr(), maintenanceCompany.getAttachments());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;
...@@ -144,7 +144,7 @@ public class MaintenanceCompanyServiceImpl ...@@ -144,7 +144,7 @@ public class MaintenanceCompanyServiceImpl
try { try {
this.save(maintenanceCompany); this.save(maintenanceCompany);
saveAttachments(maintenanceCompany); sourceFileService.saveAttachments(maintenanceCompany.getSequenceNbr(), maintenanceCompany.getAttachments());
} catch (Exception e) { } catch (Exception e) {
return false; return false;
} }
...@@ -152,35 +152,6 @@ public class MaintenanceCompanyServiceImpl ...@@ -152,35 +152,6 @@ public class MaintenanceCompanyServiceImpl
} }
/** /**
* 保存附件
*/
public void saveAttachments(MaintenanceCompany maintenanceCompany) {
if (!ValidationUtil.isEmpty(maintenanceCompany.getAttachments())) {
List<SourceFile> sourceFiles = Lists.newArrayList();
Map<String, List<AttachmentDto>> attachmentMap = maintenanceCompany.getAttachments();
attachmentMap.entrySet().forEach(entry -> {
List<AttachmentDto> atts = entry.getValue();
sourceFiles.addAll(attachment2SourceFile(entry.getKey(), atts));
});
sourceFileService.saveSourceFile(maintenanceCompany.getSequenceNbr(), sourceFiles);
}
}
private List<SourceFile> attachment2SourceFile(String type, List<AttachmentDto> attachmentDtoList) {
List<SourceFile> sourceFiles = Lists.newArrayList();
if (!ValidationUtil.isEmpty(attachmentDtoList)) {
attachmentDtoList.forEach(a -> {
SourceFile s = new SourceFile();
s.setFilePath(a.getUrl());
s.setFileName(a.getName());
s.setFileCategory(type);
sourceFiles.add(s);
});
}
return sourceFiles;
}
/**
* 添加动态表单信息 * 添加动态表单信息
* *
* @param maintenanceCompany * @param maintenanceCompany
...@@ -212,7 +183,7 @@ public class MaintenanceCompanyServiceImpl ...@@ -212,7 +183,7 @@ public class MaintenanceCompanyServiceImpl
try { try {
this.save(maintenanceCompany); this.save(maintenanceCompany);
saveAttachments(maintenanceCompany); sourceFileService.saveAttachments(maintenanceCompany.getSequenceNbr(), maintenanceCompany.getAttachments());
} catch (Exception e) { } catch (Exception e) {
return false; return false;
} }
...@@ -488,7 +459,7 @@ public class MaintenanceCompanyServiceImpl ...@@ -488,7 +459,7 @@ public class MaintenanceCompanyServiceImpl
this.updateById(model); this.updateById(model);
// 更新附件 // 更新附件
saveAttachments(model); sourceFileService.saveAttachments(model.getSequenceNbr(), model.getAttachments());
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return false; return false;
......
...@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Sequence; import com.baomidou.mybatisplus.core.toolkit.Sequence;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import com.yeejoin.amos.boot.module.common.api.dto.AttachmentDto;
import com.yeejoin.amos.boot.module.common.api.dto.SourceFileDto; import com.yeejoin.amos.boot.module.common.api.dto.SourceFileDto;
import com.yeejoin.amos.boot.module.common.api.entity.SourceFile; import com.yeejoin.amos.boot.module.common.api.entity.SourceFile;
import com.yeejoin.amos.boot.module.common.api.mapper.SourceFileMapper; import com.yeejoin.amos.boot.module.common.api.mapper.SourceFileMapper;
...@@ -11,12 +13,14 @@ import com.yeejoin.amos.boot.module.common.api.service.ISourceFileService; ...@@ -11,12 +13,14 @@ import com.yeejoin.amos.boot.module.common.api.service.ISourceFileService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService; import org.typroject.tyboot.core.rdbms.service.BaseService;
import org.typroject.tyboot.core.restful.exception.instance.BadRequest; import org.typroject.tyboot.core.restful.exception.instance.BadRequest;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional; import java.util.Optional;
/** /**
...@@ -76,4 +80,32 @@ public class SourceFileServiceImpl extends BaseService<SourceFileDto, SourceFile ...@@ -76,4 +80,32 @@ public class SourceFileServiceImpl extends BaseService<SourceFileDto, SourceFile
boolean flag = this.saveOrUpdateBatch(sourceFiles); boolean flag = this.saveOrUpdateBatch(sourceFiles);
return flag ? sourceFiles : Collections.EMPTY_LIST; return flag ? sourceFiles : Collections.EMPTY_LIST;
} }
/**
* 保存附件
*/
public void saveAttachments(Long sequenceNbr, Map<String, List<AttachmentDto>> attachmentMap) {
if (!ValidationUtil.isEmpty(attachmentMap)) {
List<SourceFile> sourceFiles = Lists.newArrayList();
attachmentMap.entrySet().forEach(entry -> {
List<AttachmentDto> attachments = entry.getValue();
sourceFiles.addAll(attachment2SourceFile(entry.getKey(), attachments));
});
saveSourceFile(sequenceNbr, sourceFiles);
}
}
private List<SourceFile> attachment2SourceFile(String type, List<AttachmentDto> attachmentDtoList) {
List<SourceFile> sourceFiles = Lists.newArrayList();
if (!ValidationUtil.isEmpty(attachmentDtoList)) {
attachmentDtoList.forEach(a -> {
SourceFile s = new SourceFile();
s.setFilePath(a.getUrl());
s.setFileName(a.getName());
s.setFileCategory(type);
sourceFiles.add(s);
});
}
return sourceFiles;
}
} }
\ No newline at end of file
...@@ -285,7 +285,7 @@ public class ExcelController extends BaseController { ...@@ -285,7 +285,7 @@ public class ExcelController extends BaseController {
private void excelImportkeySite(MultipartFile multipartFile, String wbry) throws Exception { private void excelImportkeySite(MultipartFile multipartFile, String wbry) throws Exception {
List<KeySiteExcleDto> excelDtoList = ExcelUtil.readFirstSheetExcel(multipartFile, List<KeySiteExcleDto> excelDtoList = ExcelUtil.readFirstSheetExcel(multipartFile,
KeySiteExcleDto.class, 1); KeySiteExcleDto.class, 1);
keySiteService.saveExcle(excelDtoList); keySiteService.saveExcel(excelDtoList);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment