| | |
| | | package com.lf.server.service.all; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.lf.server.controller.all.BaseController; |
| | | import com.lf.server.entity.all.HttpStatus; |
| | | import com.lf.server.entity.all.ResponseMsg; |
| | | import com.lf.server.entity.all.SettingData; |
| | | import com.lf.server.entity.all.StaticData; |
| | | import com.lf.server.entity.all.*; |
| | | import com.lf.server.entity.ctrl.KeyValueEntity; |
| | | import com.lf.server.entity.data.MetaEntity; |
| | | import com.lf.server.entity.data.MetaFileEntity; |
| | | import com.lf.server.entity.sys.AttachEntity; |
| | | import com.lf.server.entity.sys.UserEntity; |
| | | import com.lf.server.helper.*; |
| | | import com.lf.server.mapper.all.BasicMapper; |
| | | import com.lf.server.service.sys.AttachService; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.File; |
| | | import java.lang.reflect.Field; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | |
| | | |
| | | private static String tabs = "''"; |
| | | |
| | | private static Map<String, String> attachTabs = new HashMap<>(); |
| | | private final static Map<String, String> ATTACH_TABS = new HashMap<>(); |
| | | |
| | | private final static Log log = LogFactory.getLog(UploadAttachService.class); |
| | | |
| | |
| | | |
| | | List<String> keys = new ArrayList<>(); |
| | | for (String str : strs) { |
| | | if (attachTabs.containsKey(str)) { |
| | | if (ATTACH_TABS.containsKey(str)) { |
| | | continue; |
| | | } |
| | | |
| | | attachTabs.put(str, str.contains("bd.") ? "materiname" : "photono"); |
| | | ATTACH_TABS.put(str, str.contains("bd.") ? "materiname" : "photono"); |
| | | keys.add("'" + str + "'"); |
| | | } |
| | | tabs = StringHelper.join(keys, ","); |
| | |
| | | } |
| | | |
| | | List<KeyValueEntity> rs = new ArrayList<>(); |
| | | for (MetaEntity me : ms) { |
| | | int rows = uploadXlsAnnex(me, files); |
| | | rs.add(new KeyValueEntity(me.getName(), String.valueOf(rows))); |
| | | for (MetaEntity meta : ms) { |
| | | int rows = uploadXlsAnnex(meta, files); |
| | | rs.add(new KeyValueEntity(meta.getName(), String.valueOf(rows))); |
| | | } |
| | | |
| | | return rs; |
| | |
| | | /** |
| | | * 上传Excel附件 |
| | | */ |
| | | private int uploadXlsAnnex(MetaEntity me, List<String> files) { |
| | | private int uploadXlsAnnex(MetaEntity meta, List<String> files) { |
| | | List<?> list = queryXlsData(meta); |
| | | if (null == list || list.size() == 0) { |
| | | return 0; |
| | | } |
| | | |
| | | Field field = getAnnexField(list.get(0), meta); |
| | | |
| | | |
| | | return 0; |
| | | int rows = 0; |
| | | for (Object obj : list) { |
| | | BaseEntity be = (BaseEntity) obj; |
| | | rows += insertXlsAnnex(be, files); |
| | | } |
| | | |
| | | return rows; |
| | | } |
| | | |
| | | /** |
| | | * 查询Excel数据 |
| | | */ |
| | | private List<?> queryXlsData(MetaEntity meta) { |
| | | String entity = meta.getTab().substring(meta.getTab().indexOf(".") + 1).replace("_", "").toLowerCase(); |
| | | BasicMapper basicMapper = ClassHelper.getBasicMapper(entity); |
| | | if (null == basicMapper) { |
| | | return null; |
| | | } |
| | | |
| | | QueryWrapper wrapper = new QueryWrapper(); |
| | | wrapper.eq("parentid", meta.getEventid()); |
| | | |
| | | List<?> list = basicMapper.selectList(wrapper); |
| | | if (null == list || list.size() == 0) { |
| | | return null; |
| | | } |
| | | if (!(list.get(0) instanceof BaseEntity)) { |
| | | return null; |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 获取附件字段 |
| | | */ |
| | | private Field getAnnexField(Object obj, MetaEntity meta) { |
| | | try { |
| | | String str = ATTACH_TABS.get(meta.getTab()); |
| | | Field field = obj.getClass().getDeclaredField(str); |
| | | field.setAccessible(true); |
| | | |
| | | return field; |
| | | } catch (Exception ex) { |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 查找Excel附件 |
| | | */ |
| | | private String findXlsAnnex(Object obj) { |
| | | |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 插入Excel附件 |
| | | */ |
| | | private int insertXlsAnnex(BaseEntity be, List<String> files) { |
| | | |
| | | return 1; |
| | | } |
| | | } |