com.founder.core.service.impl.UdiDocServiceImpl Maven / Gradle / Ivy
package com.founder.core.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.founder.core.base.BaseResult;
import com.founder.core.domain.GsUdi;
import com.founder.core.domain.GsUdiDoc;
import com.founder.core.domain.GsUdiDoclistUse;
import com.founder.core.exception.BizException;
import com.founder.core.mapper.GsUdiDocMapper;
import com.founder.core.service.UdiDocService;
import com.founder.core.service.UdiDoclistUseService;
import com.founder.core.service.UdiService;
import com.founder.core.valid.ValidList;
import com.founder.core.vopackage.*;
import org.apache.commons.lang3.StringUtils;
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.List;
import java.util.stream.Collectors;
@Service
public class UdiDocServiceImpl extends ServiceImpl implements UdiDocService {
@Autowired
UdiDoclistUseService udiDoclistUseService;
@Autowired
UdiDocService udiDocService;
@Autowired
UdiService udiService;
/**
* 查询所有通用档案
*
* @return
*/
@Override
public VoBusinessResult listUdiDoc(VoGs4101Req req) {
VoBusinessResult result = new VoBusinessResult();
String udiId = req.getId_udi();
if (StringUtils.isEmpty(udiId)){
result.setCode("0");
result.setMsg("档案产品主键不允许空");
return result;
}
String udidoclistId = req.getId_udidoclist();
if (StringUtils.isEmpty(udidoclistId)){
result.setCode("0");
result.setMsg("档案类型主键不允许空");
return result;
}
QueryWrapper queryWrapper = new QueryWrapper<>();
queryWrapper.eq("id_udi",udiId);
queryWrapper.eq("id_udidoclist",udidoclistId);
List gsUdiDocList = udiDocService.list(queryWrapper);
result.setCode("1");
result.setMsg("ok");
result.setObject(gsUdiDocList);
return result;
}
/**
* 保存通用字典
*
* @param list
* @return
*/
@Override
public VoBusinessResult saveUdiDoc(ValidList list) {
VoBusinessResult result = new VoBusinessResult();
if (CollectionUtils.isEmpty(list)) {
result.setCode("0");
result.setMsg("没有需要保存的数据");
return result;
}
List gsUdiDocList = new ArrayList<>();
list.stream().forEach(x->{
GsUdiDoc gsUdiDoc = new GsUdiDoc();
BeanUtils.copyProperties(x,gsUdiDoc);
gsUdiDocList.add(gsUdiDoc);
});
if (!udiDocService.saveBatch(gsUdiDocList)){
result.setCode("0");
result.setMsg("保存通用字典失败了");
return result;
}
result.setCode("1");
result.setMsg("ok");
result.setObject(gsUdiDocList);
return result;
}
/**
* 删除通用字典
*
* @param list
* @return
*/
@Override
public VoBusinessResult deleteUdiDoc(ValidList list) {
VoBusinessResult result = new VoBusinessResult();
if (CollectionUtils.isEmpty(list)) {
result.setCode("0");
result.setMsg("没有需要删除的数据");
return result;
}
List ids = new ArrayList<>();
list.stream().forEach(x->{
if (StringUtils.isEmpty(x.getId_udidoc())){
throw new BizException("请传入删除主键");
}
ids.add(x.getId_udidoc());
});
udiDocService.removeByIds(ids);
result.setCode("1");
result.setMsg("ok");
return result;
}
/**
* 查询通用字典树
*
* @return
*/
@Override
public VoBusinessResult listUdiDocTree() {
VoBusinessResult result = new VoBusinessResult();
List repList = new ArrayList<>();
List gsUdiList = udiService.list();
List udiIdList = new ArrayList<>();
gsUdiList.stream().forEach(x->{
udiIdList.add(x.getId_udi());
VoGs4104Rep rep = new VoGs4104Rep();
rep.setId_udi(x.getId_udi());
rep.setName_udi(x.getName());
repList.add(rep);
});
QueryWrapper queryWrapper = new QueryWrapper<>();
if (CollectionUtils.isEmpty(udiIdList)){
result.setCode(BaseResult.FAIL);
result.setMsg("无记录");
return result;
}
queryWrapper.in("id_udi",udiIdList);
List list = udiDoclistUseService.list(queryWrapper);
list.stream().collect(Collectors.groupingBy(GsUdiDoclistUse::getId_udi,Collectors.toList()))
.forEach((k,v)->{
List doclistUseList = v;
for (GsUdiDoclistUse doc:doclistUseList) {
VoGs4104Rep rep = new VoGs4104Rep();
rep.setId_udidoclist(doc.getId_udidoclist());
rep.setName_udidoclist(doc.getName_udidoclist());
rep.setPreant_id_udidoclist(k);
repList.add(rep);
}
});
result.setCode(BaseResult.SUCCESS);
result.setMsg("ok");
result.setObject(repList);
return result;
}
}