Commit 4935d753 authored by tianbo's avatar tianbo

优化代码

parent 0f52741f
......@@ -19,7 +19,7 @@ public interface IKeySiteService {
* @param id
* @return
*/
public boolean deletebyId(Long id);
public boolean deleteById(Long id);
/**
* 保存
* @param model
......@@ -36,7 +36,7 @@ public boolean update (KeySite keySite);
* 获取机场单位组织结构树,包含单位下部门数量的统计
* @return
*/
public List<OrgUsrTreeDto> getOrguserTree();
public List<OrgUsrTreeDto> getOrgUserTree();
/**
*
* @return
......@@ -51,5 +51,5 @@ public KeySiteDto getSequenceNbr(Long sequenceNbr);
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 {
@DeleteMapping(value = "delete/{sequenceNbr}")
@ApiOperation(httpMethod = "DELETE", value = "根据sequenceNbr删除重点部位", notes = "根据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 {
@GetMapping(value = "/getOrguserTree")
public ResponseModel<List<OrgMenuDto>> getOrguserTree() throws Exception{
List<OrgMenuDto> menus = iOrgUsrService.getTree(null,
keySiteService.getOrguserTree(), OrgUsrTreeDto.class.getName(),
keySiteService.getOrgUserTree(), OrgUsrTreeDto.class.getName(),
"getSequenceNbr", 2, "getBizOrgName", "getParentId", "getNum");
return ResponseHelper.buildResponse(menus);
}
......
......@@ -49,8 +49,6 @@ public class MaintenanceCompanyController extends BaseController {
@Autowired
MaintenanceCompanyServiceImpl maintenanceCompanyServiceImpl;
SourceFileServiceImpl sourceFileService;
@Autowired
IMaintenanceCompanyService maintenanceCompanyService;
......
......@@ -56,17 +56,19 @@ public class KeySiteServiceImpl extends BaseService<KeySiteDto, KeySite, KeySite
/**
* 列表查询 示例
*/
@Override
public List<KeySiteDto> queryForKeySiteList() {
return keySiteMapper.getKeySiteList();
}
@Override
public List<KeySiteExcleDto> exportToExcel() {
List<KeySiteDto> list = this.queryForKeySiteList();
return JSONArray.parseArray(JSONArray.toJSONString(list), KeySiteExcleDto.class);
}
@Override
public boolean deletebyId(Long id) {
public boolean deleteById(Long id) {
KeySite keySite = keySiteMapper.selectById(id);
if (keySite == null) {
return false;
......@@ -85,37 +87,12 @@ public class KeySiteServiceImpl extends BaseService<KeySiteDto, KeySite, KeySite
KeySite keySite = new KeySite();
Bean.copyExistPropertis(model, keySite);
this.save(keySite);
this.saveAttachments(model);
sourceFileService.saveAttachments(model.getSequenceNbr(), model.getAttachments());
// TODO Auto-generated method stub
return model;
}
public void saveAttachments(KeySiteDto keySiteDto) {
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;
}
@Override
public boolean update(KeySite keySite) {
keySite.setIsDelete(false);
int num = keySiteMapper.updateById(keySite);
......@@ -126,7 +103,7 @@ public class KeySiteServiceImpl extends BaseService<KeySiteDto, KeySite, KeySite
}
@Override
public List<OrgUsrTreeDto> getOrguserTree() {
public List<OrgUsrTreeDto> getOrgUserTree() {
return orgUsrMapper.getCompanyAndCountDepartment();
}
......@@ -136,7 +113,7 @@ public class KeySiteServiceImpl extends BaseService<KeySiteDto, KeySite, KeySite
}
@Override
public boolean saveExcle(List<KeySiteExcleDto> excelDtoList) {
public boolean saveExcel(List<KeySiteExcleDto> excelDtoList) {
List<KeySite> excelList = new ArrayList<KeySite>();
for (KeySiteExcleDto keySiteExcleDto : excelDtoList) {
KeySite keySiteDto = new KeySite();
......
......@@ -116,7 +116,7 @@ public class MaintenanceCompanyServiceImpl
try {
this.save(maintenanceCompany);
saveAttachments(maintenanceCompany);
sourceFileService.saveAttachments(maintenanceCompany.getSequenceNbr(), maintenanceCompany.getAttachments());
} catch (Exception e) {
e.printStackTrace();
return false;
......@@ -144,7 +144,7 @@ public class MaintenanceCompanyServiceImpl
try {
this.save(maintenanceCompany);
saveAttachments(maintenanceCompany);
sourceFileService.saveAttachments(maintenanceCompany.getSequenceNbr(), maintenanceCompany.getAttachments());
} catch (Exception e) {
return false;
}
......@@ -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
......@@ -212,7 +183,7 @@ public class MaintenanceCompanyServiceImpl
try {
this.save(maintenanceCompany);
saveAttachments(maintenanceCompany);
sourceFileService.saveAttachments(maintenanceCompany.getSequenceNbr(), maintenanceCompany.getAttachments());
} catch (Exception e) {
return false;
}
......@@ -488,7 +459,7 @@ public class MaintenanceCompanyServiceImpl
this.updateById(model);
// 更新附件
saveAttachments(model);
sourceFileService.saveAttachments(model.getSequenceNbr(), model.getAttachments());
} catch (Exception e) {
e.printStackTrace();
return false;
......
......@@ -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.Sequence;
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.entity.SourceFile;
import com.yeejoin.amos.boot.module.common.api.mapper.SourceFileMapper;
......@@ -11,12 +13,14 @@ import com.yeejoin.amos.boot.module.common.api.service.ISourceFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
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.restful.exception.instance.BadRequest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
......@@ -76,4 +80,32 @@ public class SourceFileServiceImpl extends BaseService<SourceFileDto, SourceFile
boolean flag = this.saveOrUpdateBatch(sourceFiles);
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 {
private void excelImportkeySite(MultipartFile multipartFile, String wbry) throws Exception {
List<KeySiteExcleDto> excelDtoList = ExcelUtil.readFirstSheetExcel(multipartFile,
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