package com.terra.system.service.sys;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.terra.system.entity.all.BaseEntity;
|
import com.terra.system.entity.data.FmeLogEntity;
|
import com.terra.system.entity.sys.AttachEntity;
|
import com.terra.system.helper.ClassHelper;
|
import com.terra.system.helper.StringHelper;
|
import com.terra.system.mapper.all.BasicMapper;
|
import com.terra.system.mapper.sys.AttachMapper;
|
import com.terra.system.service.all.UploadAttachService;
|
import javax.annotation.Resource;
|
import org.springframework.stereotype.Service;
|
|
import java.lang.reflect.Field;
|
import java.util.List;
|
|
/**
|
* 附件
|
* @author WWW
|
*/
|
@Service
|
public class AttachService implements AttachMapper {
|
@Resource
|
AttachMapper attachMapper;
|
|
private static String tabs;
|
|
@Override
|
public Integer selectCount(String name) {
|
name = StringHelper.getLikeUpperStr(name);
|
|
return attachMapper.selectCount(name);
|
}
|
|
@Override
|
public List<AttachEntity> selectByPage(String name, Integer limit, Integer offset) {
|
name = StringHelper.getLikeUpperStr(name);
|
|
return attachMapper.selectByPage(name, limit, offset);
|
}
|
|
@Override
|
public List<AttachEntity> selectAll() {
|
return attachMapper.selectAll();
|
}
|
|
@Override
|
public AttachEntity selectById(int id) {
|
return attachMapper.selectById(id);
|
}
|
|
@Override
|
public AttachEntity selectByGuid(String guid) {
|
return attachMapper.selectByGuid(guid);
|
}
|
|
@Override
|
public List<AttachEntity> selectByGuids(List<String> guids) {
|
return attachMapper.selectByGuids(guids);
|
}
|
|
@Override
|
public AttachEntity selectByTabAndGuid(String tab, String tabGuid, String guid) {
|
return attachMapper.selectByTabAndGuid(tab, tabGuid, guid);
|
}
|
|
@Override
|
public List<AttachEntity> selectByTabGuids(String tab, List<String> guids) {
|
return attachMapper.selectByTabGuids(tab, guids);
|
}
|
|
@Override
|
public List<AttachEntity> selectByTab(String tab, String guid) {
|
return attachMapper.selectByTab(tab, guid);
|
}
|
|
@Override
|
public Integer insert(AttachEntity entity) {
|
return attachMapper.insert(entity);
|
}
|
|
@Override
|
public Integer inserts(List<AttachEntity> list) {
|
return attachMapper.inserts(list);
|
}
|
|
@Override
|
public Integer delete(int id) {
|
return attachMapper.delete(id);
|
}
|
|
@Override
|
public Integer deletes(List<Integer> ids) {
|
return attachMapper.deletes(ids);
|
}
|
|
@Override
|
public Integer update(AttachEntity entity) {
|
return attachMapper.update(entity);
|
}
|
|
@Override
|
public Integer updates(List<AttachEntity> list) {
|
return attachMapper.updates(list);
|
}
|
|
@Override
|
public Integer insertAttachByMeta(String tab, String tabGuid, String metaName, String dirid) {
|
return attachMapper.insertAttachByMeta(tab, tabGuid, metaName, dirid);
|
}
|
|
/**
|
* 同步附件
|
*/
|
public void syncAttaches(FmeLogEntity entity) {
|
String tab = entity.getPgNs() + "." + entity.getTcdm();
|
String fieldName = UploadAttachService.ATTACH_TABS.get(tab);
|
|
List<?> list = selectRowsByParentid(entity.getTcdm().replace("_", ""), entity.getParentid(), fieldName);
|
if (null == list || list.isEmpty()) {
|
return;
|
}
|
|
Field field = UploadAttachService.getAnnexField(list.get(0), tab);
|
if (null == field) {
|
return;
|
}
|
|
for (Object obj : list) {
|
String[] names = UploadAttachService.getNames(UploadAttachService.getAnnexName(obj, field));
|
if (null == names || names.length == 0) {
|
continue;
|
}
|
|
BaseEntity be = (BaseEntity) obj;
|
String dirid = getDirid(be);
|
for (String name : names) {
|
if (StringHelper.isEmpty(name)) {
|
continue;
|
}
|
insertAttachByMeta(tab, be.getEventid(), name.trim(), dirid);
|
}
|
}
|
}
|
|
/**
|
* 获取目录编码
|
*/
|
private String getDirid(BaseEntity be) {
|
if (StringHelper.isEmpty(be.getDirid())) {
|
return null;
|
}
|
|
String dirid = be.getDirid().substring(0, 2);
|
|
return StringHelper.getRightLike(dirid);
|
}
|
|
/**
|
* 根据父ID查询记录
|
*/
|
private List<?> selectRowsByParentid(String entity, String parentid, String field) {
|
BasicMapper baseMapper = ClassHelper.getBasicMapper(entity);
|
if (null == baseMapper) {
|
return null;
|
}
|
|
QueryWrapper wrapper = new QueryWrapper();
|
wrapper.eq("parentid", parentid);
|
wrapper.apply(field + " is not null");
|
|
return baseMapper.selectList(wrapper);
|
}
|
}
|