GeneraterSwapUtil.java 111 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665
  1. package jnpf.util;
  2. import cn.afterturn.easypoi.excel.ExcelExportUtil;
  3. import cn.afterturn.easypoi.excel.entity.ExportParams;
  4. import cn.afterturn.easypoi.excel.entity.enmus.ExcelType;
  5. import cn.afterturn.easypoi.excel.entity.params.ExcelExportEntity;
  6. import cn.hutool.core.util.ObjectUtil;
  7. import com.alibaba.fastjson.JSONArray;
  8. import com.alibaba.fastjson.JSONObject;
  9. import com.baomidou.dynamic.datasource.annotation.DS;
  10. import com.baomidou.mybatisplus.annotation.TableField;
  11. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  12. import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
  13. import com.github.yulichang.wrapper.MPJLambdaWrapper;
  14. import jnpf.annotation.JnpfField;
  15. import jnpf.base.ActionResult;
  16. import jnpf.base.UserInfo;
  17. import jnpf.base.entity.*;
  18. import jnpf.base.model.ColumnDataModel;
  19. import jnpf.base.model.OnlineImport.ExcelImportModel;
  20. import jnpf.base.model.OnlineImport.ImportDataModel;
  21. import jnpf.base.model.OnlineImport.ImportFormCheckUniqueModel;
  22. import jnpf.base.model.OnlineImport.VisualdevModelDataInfoVO;
  23. import jnpf.base.model.datainterface.DataInterfaceActionVo;
  24. import jnpf.base.model.datainterface.DataInterfaceModel;
  25. import jnpf.base.model.datainterface.DataInterfacePage;
  26. import jnpf.base.model.filter.RuleInfo;
  27. import jnpf.base.service.*;
  28. import jnpf.base.util.*;
  29. import jnpf.base.util.common.DataControlUtils;
  30. import jnpf.base.vo.DownloadVO;
  31. import jnpf.base.vo.PageListVO;
  32. import jnpf.base.vo.PaginationVO;
  33. import jnpf.constant.JnpfConst;
  34. import jnpf.constant.FileTypeConstant;
  35. import jnpf.constant.PermissionConst;
  36. import jnpf.database.model.entity.DbLinkEntity;
  37. import jnpf.database.model.superQuery.ConditionJsonModel;
  38. import jnpf.database.model.superQuery.SuperJsonModel;
  39. import jnpf.database.model.superQuery.SuperQueryConditionModel;
  40. import jnpf.database.model.superQuery.SuperQueryJsonModel;
  41. import jnpf.database.util.ConnUtil;
  42. import jnpf.database.util.DynamicDataSourceUtil;
  43. import jnpf.entity.FileParameter;
  44. import jnpf.excel.ExcelExportStyler;
  45. import jnpf.excel.ExcelHelper;
  46. import jnpf.exception.DataException;
  47. import jnpf.exception.WorkFlowException;
  48. import jnpf.flowable.entity.TaskEntity;
  49. import jnpf.flowable.entity.TemplateJsonEntity;
  50. import jnpf.model.ExcelModel;
  51. import jnpf.model.OnlineDevData;
  52. import jnpf.model.QueryAllModel;
  53. import jnpf.model.generater.GenerParamConst;
  54. import jnpf.model.generater.GenerViewConst;
  55. import jnpf.model.SystemParamModel;
  56. import jnpf.model.visualJson.FieLdsModel;
  57. import jnpf.model.visualJson.FormDataModel;
  58. import jnpf.model.visualJson.TableModel;
  59. import jnpf.model.visualJson.TemplateJsonModel;
  60. import jnpf.model.visualJson.config.ConfigModel;
  61. import jnpf.model.visualJson.config.HeaderModel;
  62. import jnpf.model.visualJson.config.RuleConfig;
  63. import jnpf.onlinedev.model.OnlineDevEnum.CacheKeyEnum;
  64. import jnpf.onlinedev.model.PaginationModelExport;
  65. import jnpf.onlinedev.model.VisualErrInfo;
  66. import jnpf.onlinedev.service.VisualDevInfoService;
  67. import jnpf.onlinedev.util.onlineDevUtil.OnlineDevListUtils;
  68. import jnpf.onlinedev.util.onlineDevUtil.OnlineProductSqlUtils;
  69. import jnpf.onlinedev.util.onlineDevUtil.OnlinePublicUtils;
  70. import jnpf.onlinedev.util.onlineDevUtil.OnlineSwapDataUtils;
  71. import jnpf.permission.entity.*;
  72. import jnpf.permission.service.*;
  73. import jnpf.util.context.RequestContext;
  74. import jnpf.util.visiual.JnpfKeyConsts;
  75. import jnpf.workflow.service.TaskApi;
  76. import jnpf.workflow.service.TemplateApi;
  77. import lombok.Cleanup;
  78. import lombok.extern.slf4j.Slf4j;
  79. import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  80. import org.apache.poi.ss.usermodel.Workbook;
  81. import org.dromara.x.file.storage.core.FileInfo;
  82. import org.springframework.beans.factory.annotation.Autowired;
  83. import org.springframework.stereotype.Component;
  84. import org.springframework.web.multipart.MultipartFile;
  85. import java.io.IOException;
  86. import java.lang.reflect.Field;
  87. import java.lang.reflect.Method;
  88. import java.lang.reflect.ParameterizedType;
  89. import java.lang.reflect.Type;
  90. import java.math.BigDecimal;
  91. import java.sql.Connection;
  92. import java.time.Instant;
  93. import java.time.LocalDateTime;
  94. import java.time.ZoneId;
  95. import java.time.format.DateTimeFormatter;
  96. import java.util.*;
  97. import java.util.stream.Collectors;
  98. import static jnpf.util.Constants.ADMIN_KEY;
  99. /**
  100. * 数据转换(代码生成器用)
  101. *
  102. * @author JNPF开发平台组
  103. * @version V3.1.0
  104. * @copyright 引迈信息技术有限公司(https://www.jnpfsoft.com)
  105. * @date 2021/3/16
  106. */
  107. @Slf4j
  108. @Component
  109. public class GeneraterSwapUtil {
  110. @Autowired
  111. private OrganizeService organizeService;
  112. @Autowired
  113. private FilterService filterService;
  114. @Autowired
  115. private PositionService positionService;
  116. @Autowired
  117. private UserService userService;
  118. @Autowired
  119. private VisualdevService visualdevService;
  120. @Autowired
  121. private VisualDevInfoService visualDevInfoService;
  122. @Autowired
  123. private DataInterfaceService dataInterfaceService;
  124. @Autowired
  125. private ProvinceService provinceService;
  126. @Autowired
  127. private DictionaryDataService dictionaryDataService;
  128. @Autowired
  129. private BillRuleService billRuleService;
  130. @Autowired
  131. private VisualBillUtil visualBillUtil;
  132. @Autowired
  133. private GroupService groupService;
  134. @Autowired
  135. private RoleService roleService;
  136. @Autowired
  137. private DbLinkService dbLinkService;
  138. @Autowired
  139. private UserRelationService userRelationService;
  140. @Autowired
  141. private FlowFormDataUtil flowFormDataUtil;
  142. @Autowired
  143. private DbLinkService dblinkService;
  144. @Autowired
  145. private OnlineSwapDataUtils swapDataUtils;
  146. @Autowired
  147. private RedisUtil redisUtil;
  148. @Autowired
  149. private AuthorizeService authorizeService;
  150. @Autowired
  151. private ModuleService moduleService;
  152. //以下新的流程api
  153. @Autowired
  154. private TaskApi taskApi;
  155. @Autowired
  156. private TemplateApi templateApi;
  157. @Autowired
  158. private FormCheckUtils formCheckUtils;
  159. @Autowired
  160. private UserService userApi;
  161. public final String regEx = "[\\[\\]\"]";
  162. private static long DEFAULT_CACHE_TIME = 60 * 5;
  163. /**
  164. * 日期时间戳字符串转换
  165. *
  166. * @param date
  167. * @param format
  168. * @return
  169. */
  170. public String dateSwap(String date, String format) {
  171. if (StringUtil.isNotEmpty(date)) {
  172. DateTimeFormatter ftf = DateTimeFormatter.ofPattern(format);
  173. if (date.contains(",")) {
  174. String[] dates = date.split(",");
  175. long time1 = Long.parseLong(dates[0]);
  176. long time2 = Long.parseLong(dates[1]);
  177. String value1 = ftf.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(time1), ZoneId.systemDefault()));
  178. String value2 = ftf.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(time2), ZoneId.systemDefault()));
  179. return value1 + "至" + value2;
  180. }
  181. long time = Long.parseLong(date);
  182. return ftf.format(LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault()));
  183. }
  184. return date;
  185. }
  186. /**
  187. * 行政区划转换
  188. *
  189. * @param data
  190. * @return
  191. */
  192. public String provinceData(String data, Map<String, Object> localCache) {
  193. Map<String, String> proMap = new HashMap<>();
  194. if (localCache != null && localCache.containsKey("__pro_map")) {
  195. proMap = (Map<String, String>) localCache.get("__pro_map");
  196. }
  197. if (StringUtil.isNotEmpty(data)) {
  198. try {
  199. if (data.contains("[[")) {
  200. List<String> addList = new ArrayList<>();
  201. String[][] provinceDataS = JsonUtil.getJsonToBean(data, String[][].class);
  202. for (String[] AddressData : provinceDataS) {
  203. List<String> provList = new ArrayList(Arrays.asList(AddressData));
  204. List<String> nameList = new ArrayList<>();
  205. if (localCache != null) {
  206. for (String info : provList) {
  207. nameList.add(proMap.get(info));
  208. }
  209. } else {
  210. List<ProvinceEntity> proList = provinceService.getProList(provList);
  211. for (ProvinceEntity info : proList) {
  212. nameList.add(info.getFullName());
  213. }
  214. }
  215. addList.add(String.join("/", nameList));
  216. }
  217. return String.join(";", addList);
  218. } else if (data.contains("[")) {
  219. List<String> provList = JsonUtil.getJsonToList(data, String.class);
  220. List<String> nameList = new ArrayList<>();
  221. if (localCache != null) {
  222. for (String info : provList) {
  223. nameList.add(proMap.get(info));
  224. }
  225. } else {
  226. List<ProvinceEntity> proList = provinceService.getProList(provList);
  227. for (ProvinceEntity info : proList) {
  228. nameList.add(info.getFullName());
  229. }
  230. }
  231. return String.join("/", nameList);
  232. } else {
  233. String[] strs = data.split(",");
  234. List<String> provList = new ArrayList(Arrays.asList(strs));
  235. List<String> proNameList = new ArrayList<>();
  236. if (localCache != null) {
  237. for (String info : provList) {
  238. proNameList.add(proMap.get(info));
  239. }
  240. } else {
  241. List<ProvinceEntity> proList = provinceService.getProList(provList);
  242. for (ProvinceEntity info : proList) {
  243. proNameList.add(info.getFullName());
  244. }
  245. }
  246. return String.join("/", proNameList);
  247. }
  248. } catch (Exception e) {
  249. e.printStackTrace();
  250. }
  251. }
  252. return "";
  253. }
  254. public Map<String, Object> localCache() {
  255. //公共数据
  256. String dsName = Optional.ofNullable(TenantHolder.getDatasourceId()).orElse("");
  257. Map<String, Object> localCache = new HashMap<>();
  258. //省市区
  259. Map<Object, Object> proMap = redisUtil.getMap(String.format("%s-%s-%d", dsName, "province", 1));
  260. List<Map<String, String>> proMapList = new ArrayList<>();
  261. if (CollectionUtils.isNotEmpty(proMap)) {
  262. //分级存储
  263. for (int i = 1; i <= 4; i++) {
  264. String redisKey = String.format("%s-%s-%d", dsName, "province", i);
  265. if (!redisUtil.exists(redisKey)) {
  266. List<ProvinceEntity> provinceEntityList = provinceService.getProListBytype(String.valueOf(i));
  267. Map<String, String> provinceMap = new HashMap<>(16);
  268. if (provinceEntityList != null) {
  269. provinceEntityList.forEach(p -> provinceMap.put(p.getId(), p.getFullName()));
  270. }
  271. proMapList.add(provinceMap);
  272. //区划基本不修改 不做是否缓存判断
  273. redisUtil.insert(redisKey, provinceMap, RedisUtil.CAHCEWEEK);
  274. }
  275. }
  276. } else {
  277. for (int i = 1; i <= 4; i++) {
  278. proMapList.add(redisUtil.getMap(String.format("%s-%s-%d", dsName, "province", i)));
  279. }
  280. }
  281. Map<String, String> proMapr = new HashMap<>();
  282. proMapList.forEach(proMapr::putAll);
  283. localCache.put("__pro_map", proMapr);
  284. return localCache;
  285. }
  286. /**
  287. * 公司部门id转名称
  288. *
  289. * @param value
  290. * @return
  291. */
  292. public String comSelectValue(String value, String showLevel) {
  293. if (StringUtil.isNotEmpty(String.valueOf(value))) {
  294. OrganizeEntity organizeEntity = organizeService.getInfo(String.valueOf(value));
  295. if ("all".equals(showLevel)) {
  296. List<OrganizeEntity> organizeListAll = organizeService.getList(false);
  297. String[] organizeTreeId = StringUtil.isNotEmpty(organizeEntity.getOrganizeIdTree()) ? organizeEntity.getOrganizeIdTree().split(",") : new String[]{};
  298. List<String> organizeTreeList = Arrays.stream(organizeTreeId).filter(t -> !t.isEmpty()).collect(Collectors.toList());
  299. StringJoiner joiner = new StringJoiner("/");
  300. for (String id : organizeTreeList) {
  301. OrganizeEntity entity = organizeListAll.stream().filter(t -> t.getId().equals(id)).findFirst().orElse(null);
  302. if (entity != null) {
  303. joiner.add(entity.getFullName());
  304. }
  305. }
  306. value = joiner.toString();
  307. } else {
  308. if (organizeEntity != null) {
  309. if (organizeEntity.getCategory().equals("company")) {
  310. return " ";
  311. }
  312. value = organizeEntity.getFullName();
  313. }
  314. }
  315. } else {
  316. value = " ";
  317. }
  318. return value;
  319. }
  320. /**
  321. * 公司部门id转名称(多选)
  322. *
  323. * @param ids
  324. * @return
  325. */
  326. public String comSelectValues(String ids, Boolean mul) {
  327. List<String> comValueList = new ArrayList<>();
  328. if (StringUtil.isEmpty(ids)) {
  329. return null;
  330. }
  331. String Separator = mul ? "," : "/";
  332. if (ids.contains("[[")) {
  333. String[][] idArrays = JsonUtil.getJsonToBean(ids, String[][].class);
  334. for (String[] array : idArrays) {
  335. List<String> idList = new ArrayList<>();
  336. for (String s : array) {
  337. OrganizeEntity info = organizeService.getInfo(s);
  338. idList.add(Objects.nonNull(info) ? info.getFullName() : s);
  339. }
  340. String orgCom = String.join("/", idList);
  341. comValueList.add(orgCom);
  342. }
  343. return String.join(";", comValueList);
  344. } else if (ids.contains("[")) {
  345. List<String> idList = JsonUtil.getJsonToList(ids, String.class);
  346. List<String> nameList = new ArrayList<>();
  347. for (String orgId : idList) {
  348. OrganizeEntity info = organizeService.getInfo(orgId);
  349. nameList.add(Objects.nonNull(info) ? info.getFullName() : orgId);
  350. }
  351. return String.join(Separator, nameList);
  352. } else {
  353. ids = ids.replaceAll("\"", "");
  354. String[] idList = ids.split(",");
  355. if (idList.length > 0) {
  356. List<String> comSelectList = new ArrayList<>();
  357. for (String id : idList) {
  358. OrganizeEntity organizeEntity = organizeService.getInfo(id);
  359. if (organizeEntity != null) {
  360. comSelectList.add(organizeEntity.getFullName());
  361. }
  362. }
  363. return String.join(",", comSelectList);
  364. }
  365. }
  366. return null;
  367. }
  368. /**
  369. * 岗位id转名称
  370. *
  371. * @param id
  372. * @return
  373. */
  374. public String posSelectValue(String id) {
  375. if (StringUtil.isNotEmpty(id)) {
  376. PositionEntity positionApiInfo = positionService.getInfo(id);
  377. if (ObjectUtil.isNotEmpty(positionApiInfo)) {
  378. return positionApiInfo.getFullName();
  379. }
  380. return id;
  381. }
  382. return " ";
  383. }
  384. /**
  385. * 岗位id转名称(多选)
  386. *
  387. * @param ids
  388. * @return
  389. */
  390. public String posSelectValues(String ids) {
  391. if (StringUtil.isEmpty(ids)) {
  392. return "";
  393. }
  394. List<String> posList = new ArrayList<>();
  395. if (ids.contains("[")) {
  396. List<String> idList = JsonUtil.getJsonToList(ids, String.class);
  397. List<String> nameList = new ArrayList<>();
  398. for (String orgId : idList) {
  399. PositionEntity info = positionService.getInfo(orgId);
  400. nameList.add(Objects.nonNull(info) ? info.getFullName() : orgId);
  401. }
  402. posList = nameList;
  403. } else {
  404. String[] idList = ids.split(",");
  405. for (String id : idList) {
  406. PositionEntity positionEntity = positionService.getInfo(id);
  407. if (ObjectUtil.isNotEmpty(positionEntity)) {
  408. posList.add(positionEntity.getFullName());
  409. }
  410. }
  411. }
  412. return String.join(",", posList);
  413. }
  414. /**
  415. * 用户id转名称
  416. *
  417. * @param id
  418. * @return
  419. */
  420. public String userSelectValue(String id) {
  421. if (StringUtil.isNotEmpty(id)) {
  422. UserEntity userEntity = userService.getInfo(id);
  423. if (ObjectUtil.isNotEmpty(userEntity)) {
  424. return userEntity.getRealName() + "/" + userEntity.getAccount();
  425. }
  426. return id;
  427. }
  428. return "";
  429. }
  430. /**
  431. * 用户id转名称(多选)
  432. *
  433. * @param ids
  434. * @return
  435. */
  436. public String userSelectValues(String ids) {
  437. //公共数据
  438. String dsName = Optional.ofNullable(TenantHolder.getDatasourceId()).orElse("");
  439. //人员
  440. String redisKey = dsName + CacheKeyEnum.USER.getName();
  441. Map<String, Object> userMap;
  442. if (redisUtil.exists(redisKey)) {
  443. userMap = redisUtil.getMap(redisKey);
  444. userMap = Optional.ofNullable(userMap).orElse(new HashMap<>(20));
  445. } else {
  446. userMap = userService.getUserMap();
  447. redisUtil.insert(redisKey, userMap, DEFAULT_CACHE_TIME);
  448. }
  449. if (StringUtil.isEmpty(ids)) {
  450. return ids;
  451. }
  452. if (ids.contains("[")) {
  453. List<String> nameList = new ArrayList<>();
  454. List<String> jsonToList = JsonUtil.getJsonToList(ids, String.class);
  455. for (String userId : jsonToList) {
  456. nameList.add(Objects.nonNull(userMap.get(userId)) ? userMap.get(userId).toString() : userId);
  457. }
  458. return String.join(";", nameList);
  459. } else {
  460. List<String> userInfoList = new ArrayList<>();
  461. String[] idList = ids.split(",");
  462. for (String userId : idList) {
  463. userInfoList.add(Objects.nonNull(userMap.get(userId)) ? userMap.get(userId).toString() : userId);
  464. }
  465. return String.join("-", userInfoList);
  466. }
  467. }
  468. /**
  469. * 用户组件id转名称(多选)
  470. *
  471. * @param ids
  472. * @return
  473. */
  474. public String usersSelectValues(String ids) {
  475. if (StringUtil.isEmpty(ids)) {
  476. return ids;
  477. }
  478. List<String> dataNoSwapInMethod = OnlinePublicUtils.getDataNoSwapInMethod(ids);
  479. StringJoiner valueJoin = new StringJoiner(",");
  480. for (String data : dataNoSwapInMethod) {
  481. String id = data.contains("--") ? data.substring(0, data.lastIndexOf("--")) : data;
  482. String type = data.contains("--") ? data.substring(data.lastIndexOf("--") + 2) : "";
  483. switch (type) {
  484. case "role":
  485. RoleEntity roleEntity = roleService.getInfo(id);
  486. if (roleEntity != null) {
  487. valueJoin.add(roleEntity.getFullName());
  488. } else {
  489. valueJoin.add(data);
  490. }
  491. break;
  492. case "position":
  493. PositionEntity positionEntity = positionService.getInfo(id);
  494. if (positionEntity != null) {
  495. valueJoin.add(positionEntity.getFullName());
  496. } else {
  497. valueJoin.add(data);
  498. }
  499. break;
  500. case "company":
  501. case "department":
  502. OrganizeEntity organizeEntity = organizeService.getInfo(id);
  503. if (organizeEntity != null) {
  504. valueJoin.add(organizeEntity.getFullName());
  505. } else {
  506. valueJoin.add(data);
  507. }
  508. break;
  509. case "group":
  510. GroupEntity groupEntity = groupService.getInfo(id);
  511. if (groupEntity != null) {
  512. valueJoin.add(groupEntity.getFullName());
  513. } else {
  514. valueJoin.add(data);
  515. }
  516. break;
  517. case "user":
  518. default:
  519. UserEntity userEntity = userService.getInfo(id);
  520. if (userEntity != null) {
  521. valueJoin.add(userEntity.getRealName() + "/" + userEntity.getAccount());
  522. } else {
  523. valueJoin.add(data);
  524. }
  525. break;
  526. }
  527. }
  528. return valueJoin.toString();
  529. }
  530. /**
  531. * 开关
  532. *
  533. * @param data
  534. * @return
  535. */
  536. public String switchSelectValue(String data, String activeTxt, String inactiveTxt) {
  537. if (StringUtil.isNotEmpty(data)) {
  538. if (data.equals("0") || data.equals("false")) {
  539. return inactiveTxt;
  540. } else if (data.equals("1") || data.equals("true")) {
  541. return activeTxt;
  542. } else {
  543. return data;
  544. }
  545. }
  546. return null;
  547. }
  548. public VisualdevEntity visualdevEntity(String id) {
  549. return visualdevService.getInfo(id);
  550. }
  551. /**
  552. * 关联表单数据转换
  553. *
  554. * @param vmodel
  555. * @param value
  556. * @param modelId
  557. * @return
  558. */
  559. public String swapRelationFormValue(String vmodel, String value, String modelId, Map<String, Object> formDataMaps) {
  560. if (StringUtil.isEmpty(value)) {
  561. return "";
  562. }
  563. try {
  564. VisualdevEntity entity = visualdevService.getInfo(modelId);
  565. VisualdevModelDataInfoVO infoVO = visualDevInfoService.getDetailsDataInfo(value, entity);
  566. if (infoVO != null) {
  567. Map<String, Object> formDataMap = infoVO.getData() != null ? JsonUtil.stringToMap(infoVO.getData()) : new HashMap<>();
  568. if (CollectionUtils.isNotEmpty(formDataMaps)) {
  569. formDataMaps.putAll(formDataMap);
  570. formDataMap = OnlinePublicUtils.mapKeyToLower(formDataMap);
  571. value = String.valueOf(formDataMap.get(vmodel.toLowerCase()));
  572. }
  573. }
  574. } catch (Exception e) {
  575. log.error(e.getMessage(), e);
  576. }
  577. return value;
  578. }
  579. /**
  580. * 弹窗
  581. *
  582. * @param interfaceId
  583. * @param propsValue
  584. * @param relationField
  585. * @param dataValue
  586. * @return
  587. */
  588. public String getPopupSelectValue(String interfaceId, String propsValue, String relationField, String dataValue, Map<String, Object> dataMaps, String json, int num, Map<String, Object> dataAll) {
  589. if (StringUtil.isEmpty(interfaceId)) {
  590. return null;
  591. }
  592. List<TemplateJsonModel> list = JsonUtil.getJsonToList(json, TemplateJsonModel.class);
  593. Map<String, String> infoMap = new HashMap<>();
  594. List<DataInterfaceModel> listParam = new ArrayList<>();
  595. for (TemplateJsonModel templateJsonModel : list) {
  596. DataInterfaceModel dataInterfaceModel = JsonUtil.getJsonToBean(templateJsonModel, DataInterfaceModel.class);
  597. String defaultV = "";
  598. if (StringUtil.isNotEmpty(templateJsonModel.getRelationField())) {
  599. String[] mastTable = templateJsonModel.getRelationField().split(JnpfConst.SIDE_MARK);
  600. String[] child = templateJsonModel.getRelationField().split("-");
  601. if (mastTable.length > 1) {
  602. if (dataAll.get(mastTable[0]) instanceof Map) {
  603. Map<String, Object> mastTableData = (Map<String, Object>) dataAll.get(mastTable[0]);
  604. infoMap.put(templateJsonModel.getField(), String.valueOf(mastTableData.get(mastTable[1])));
  605. defaultV = String.valueOf(mastTableData.get(mastTable[1]));
  606. }
  607. } else if (child.length > 1) {
  608. if (dataAll.get(child[0]) instanceof List) {
  609. List<Map<String, Object>> chidList = (List<Map<String, Object>>) dataAll.get(child[0]);
  610. for (int i = 0; i < chidList.size(); i++) {
  611. Map<String, Object> objectMap = chidList.get(i);
  612. if (i == num) {
  613. infoMap.put(templateJsonModel.getField(), String.valueOf(objectMap.get(child[1])));
  614. defaultV = String.valueOf(objectMap.get(child[1]));
  615. }
  616. }
  617. }
  618. } else {
  619. infoMap.put(templateJsonModel.getField(), String.valueOf(dataAll.get(templateJsonModel.getRelationField())));
  620. defaultV = String.valueOf(String.valueOf(dataAll.get(templateJsonModel.getRelationField())));
  621. }
  622. }
  623. dataInterfaceModel.setDefaultValue(defaultV);
  624. listParam.add(dataInterfaceModel);
  625. }
  626. if (StringUtil.isNotEmpty(dataValue)) {
  627. // Object data = dataInterfaceService.infoToId(interfaceId, null, infoMap).getData();
  628. // List<Map<String, Object>> dataInterfaceDataList;
  629. // if (data instanceof ActionResult) {
  630. // ActionResult actionVo = (ActionResult) data;
  631. // dataInterfaceDataList = (List<Map<String, Object>>) actionVo.getData();
  632. // } else {
  633. // dataInterfaceDataList = (List<Map<String, Object>>) data;
  634. // }
  635. DataInterfacePage dataInterfacePage = new DataInterfacePage();
  636. dataInterfacePage.setParamList(listParam);
  637. dataInterfacePage.setInterfaceId(interfaceId);
  638. List<String> ids = new ArrayList<>();
  639. if (dataValue.startsWith("[")) {
  640. ids = JsonUtil.getJsonToList(dataValue, String.class);
  641. } else {
  642. ids.add(dataValue);
  643. }
  644. dataInterfacePage.setIds(ids);
  645. dataInterfacePage.setPropsValue(propsValue);
  646. dataInterfacePage.setRelationField(relationField);
  647. List<Map<String, Object>> dataInterfaceDataList = dataInterfaceService.infoToInfo(interfaceId, dataInterfacePage);
  648. if (dataValue.contains("[")) {
  649. List<String> valueList = JsonUtil.getJsonToList(dataValue, String.class);
  650. List<String> swapValue = new ArrayList<>();
  651. for (String va : valueList) {
  652. dataInterfaceDataList.stream().filter(map ->
  653. map.get(propsValue).equals(va)
  654. ).forEach(
  655. modelMap -> swapValue.add(String.valueOf(modelMap.get(relationField)))
  656. );
  657. }
  658. return String.join(",", swapValue);
  659. }
  660. if (dataInterfaceDataList != null) {
  661. Map<String, Object> dataMap = dataInterfaceDataList.stream().filter(d -> d.get(propsValue).equals(dataValue)).findFirst().orElse(null);
  662. if (dataMap != null) {
  663. dataMaps.putAll(dataMap);
  664. return String.valueOf(dataMap.get(relationField));
  665. }
  666. }
  667. return null;
  668. } else {
  669. return null;
  670. }
  671. }
  672. /**
  673. * 弹窗
  674. *
  675. * @param interfaceId
  676. * @param propsValue
  677. * @param relationField
  678. * @param dataValue
  679. * @return
  680. */
  681. public String getPopupSelectValue(String interfaceId, String propsValue, String relationField, String dataValue, Map<String, Object> dataMaps) {
  682. if (StringUtil.isEmpty(interfaceId)) {
  683. return null;
  684. }
  685. if (StringUtil.isNotEmpty(dataValue)) {
  686. Object data = dataInterfaceService.infoToId(interfaceId, null, null).getData();
  687. List<Map<String, Object>> dataInterfaceDataList;
  688. if (data instanceof ActionResult) {
  689. ActionResult actionVo = (ActionResult) data;
  690. dataInterfaceDataList = (List<Map<String, Object>>) actionVo.getData();
  691. } else {
  692. dataInterfaceDataList = (List<Map<String, Object>>) data;
  693. }
  694. if (dataValue.contains("[")) {
  695. List<String> valueList = JsonUtil.getJsonToList(dataValue, String.class);
  696. List<String> swapValue = new ArrayList<>();
  697. for (String va : valueList) {
  698. dataInterfaceDataList.stream().filter(map ->
  699. map.get(propsValue).equals(va)
  700. ).forEach(
  701. modelMap -> swapValue.add(String.valueOf(modelMap.get(relationField)))
  702. );
  703. }
  704. return swapValue.stream().collect(Collectors.joining(","));
  705. }
  706. Map<String, Object> dataMap = dataInterfaceDataList.stream().filter(d -> d.get(propsValue).equals(dataValue)).findFirst().orElse(null);
  707. if (dataMap != null) {
  708. dataMaps.putAll(dataMap);
  709. return String.valueOf(dataMap.get(relationField));
  710. }
  711. return null;
  712. } else {
  713. return null;
  714. }
  715. }
  716. public String getFileNameInJson(String fileJson) {
  717. if (StringUtil.isNotEmpty(fileJson) && !"null".equals(fileJson)) {
  718. return fileJson;
  719. }
  720. return "";
  721. }
  722. /**
  723. * 获取数据字典数据
  724. *
  725. * @param feild
  726. * @return
  727. */
  728. public String getDicName(String feild, String dictionaryTypeId) {
  729. if (StringUtil.isNotEmpty(feild)) {
  730. //去除中括号以及双引号
  731. feild = feild.replaceAll(regEx, "");
  732. //判断多选框
  733. String[] feilds = feild.split(",");
  734. if (feilds.length > 1) {
  735. StringBuilder feildsValue = new StringBuilder();
  736. DictionaryDataEntity dictionaryDataEntity;
  737. for (String feil : feilds) {
  738. dictionaryDataEntity = dictionaryDataService.getSwapInfo(feil, dictionaryTypeId);
  739. if (dictionaryDataEntity != null) {
  740. feildsValue.append(dictionaryDataEntity.getFullName()).append(",");
  741. } else {
  742. feildsValue.append(feil).append(",");
  743. }
  744. }
  745. String finalValue;
  746. if (StringUtil.isEmpty(feildsValue) || feildsValue.equals("")) {
  747. finalValue = feildsValue.toString();
  748. } else {
  749. finalValue = feildsValue.substring(0, feildsValue.length() - 1);
  750. }
  751. return finalValue;
  752. }
  753. DictionaryDataEntity dictionaryDataentity = dictionaryDataService.getSwapInfo(feild, dictionaryTypeId);
  754. if (dictionaryDataentity != null) {
  755. return dictionaryDataentity.getFullName();
  756. }
  757. return feild;
  758. }
  759. if (StringUtil.isNotEmpty(feild)) {
  760. List<DictionaryDataEntity> dicList = dictionaryDataService.getDicList(dictionaryTypeId);
  761. }
  762. return feild;
  763. }
  764. /**
  765. * 获取数据字典数据-
  766. *
  767. * @param feild
  768. * @param keyName id或encode
  769. * @return
  770. */
  771. public String getDicName(String feild, String dictionaryTypeId, String keyName, boolean isMultiple, String separator) {
  772. Object dataConversion = "";
  773. String redisKey = dictionaryTypeId + "-" + feild + "-" + keyName;
  774. if (StringUtil.isNotEmpty(feild)) {
  775. List<DictionaryDataEntity> dicList;
  776. if (redisUtil.exists(redisKey)) {
  777. List<Object> tmpList = redisUtil.get(redisKey, 0, -1);
  778. dicList = JsonUtil.getJsonToList(tmpList, DictionaryDataEntity.class);
  779. } else {
  780. dicList = dictionaryDataService.getDicList(dictionaryTypeId);
  781. redisUtil.insert(redisKey, dicList, DEFAULT_CACHE_TIME);
  782. }
  783. Map<String, Object> idMap = new HashMap<>(dicList.size());
  784. Map<String, Object> enCodeMap = new HashMap<>(dicList.size());
  785. for (DictionaryDataEntity dd : dicList) {
  786. idMap.put(dd.getId(), dd.getFullName());
  787. enCodeMap.put(dd.getEnCode(), dd.getFullName());
  788. }
  789. if (StringUtil.isNotEmpty(separator)) {
  790. separator = "/";
  791. }
  792. if ("enCode".equals(keyName)) {
  793. dataConversion = FormPublicUtils.getDataConversion(enCodeMap, feild, isMultiple, separator);
  794. } else {
  795. dataConversion = FormPublicUtils.getDataConversion(idMap, feild, isMultiple, separator);
  796. }
  797. }
  798. return dataConversion.toString();
  799. }
  800. /**
  801. * 获取远端数据
  802. *
  803. * @param urlId
  804. * @param label
  805. * @param value
  806. * @param feildValue
  807. * @return
  808. * @throws IOException
  809. */
  810. public String getDynName(String urlId, String label, String value, String feildValue, String json, int num, Map<String, Object> dataAll) {
  811. List<TemplateJsonModel> list = JsonUtil.getJsonToList(json, TemplateJsonModel.class);
  812. Map<String, String> infoMap = list.size() > 0 ? new HashMap<>() : null;
  813. for (TemplateJsonModel templateJsonModel : list) {
  814. if (StringUtil.isNotEmpty(templateJsonModel.getRelationField())) {
  815. String[] mastTable = templateJsonModel.getRelationField().split(JnpfConst.SIDE_MARK);
  816. String[] child = templateJsonModel.getRelationField().split("-");
  817. if (mastTable.length > 1) {
  818. if (dataAll.get(mastTable[0]) instanceof Map) {
  819. Map<String, Object> mastTableData = (Map<String, Object>) dataAll.get(mastTable[0]);
  820. infoMap.put(templateJsonModel.getField(), String.valueOf(mastTableData.get(mastTable[1])));
  821. }
  822. } else if (child.length > 1) {
  823. if (dataAll.get(child[0]) instanceof List) {
  824. List<Map<String, Object>> chidList = (List<Map<String, Object>>) dataAll.get(child[0]);
  825. for (int i = 0; i < chidList.size(); i++) {
  826. Map<String, Object> objectMap = chidList.get(i);
  827. if (i == num) {
  828. infoMap.put(templateJsonModel.getField(), String.valueOf(objectMap.get(child[1])));
  829. }
  830. }
  831. }
  832. } else {
  833. infoMap.put(templateJsonModel.getField(), String.valueOf(dataAll.get(templateJsonModel.getRelationField())));
  834. }
  835. }
  836. }
  837. if (StringUtil.isNotEmpty(feildValue)) {
  838. //去除中括号以及双引号
  839. feildValue = feildValue.replaceAll(regEx, "");
  840. //获取远端数据
  841. Map<String, String> a = new HashMap<>();
  842. ActionResult object = dataInterfaceService.infoToId(urlId, null, infoMap);
  843. if (object.getData() != null && object.getData() instanceof DataInterfaceActionVo) {
  844. DataInterfaceActionVo vo = (DataInterfaceActionVo) object.getData();
  845. List<Map<String, Object>> dataList = (List<Map<String, Object>>) vo.getData();
  846. //判断是否多选
  847. String[] feildValues = feildValue.split(",");
  848. if (feildValues.length > 0) {
  849. //转换的真实值
  850. StringBuilder feildVa = new StringBuilder();
  851. for (String feild : feildValues) {
  852. for (Map<String, Object> data : dataList) {
  853. if (String.valueOf(data.get(value)).equals(feild)) {
  854. feildVa.append(data.get(label)).append(",");
  855. }
  856. }
  857. }
  858. String finalValue;
  859. if (StringUtil.isEmpty(feildVa) || feildVa.equals("")) {
  860. finalValue = feildVa.toString();
  861. } else {
  862. finalValue = feildVa.substring(0, feildVa.length() - 1);
  863. }
  864. return finalValue;
  865. }
  866. for (Map<String, Object> data : dataList) {
  867. if (feildValue.equals(String.valueOf(data.get(value)))) {
  868. return data.get(label).toString();
  869. }
  870. return feildValue;
  871. }
  872. }
  873. return feildValue;
  874. }
  875. return feildValue;
  876. }
  877. /**
  878. * 获取远端数据
  879. *
  880. * @param urlId
  881. * @param name
  882. * @param id
  883. * @param children
  884. * @param feildValue
  885. * @return
  886. */
  887. public String getDynName(String urlId, String name, String id, String children, String feildValue, boolean mul) {
  888. List<String> result = new ArrayList<>();
  889. String sep = ",";
  890. if (mul) {
  891. sep = "/";
  892. }
  893. if (StringUtil.isNotEmpty(feildValue)) {
  894. Map<String, String> a = new HashMap<>();
  895. ActionResult object = dataInterfaceService.infoToId(urlId, null, null);
  896. List<Map<String, Object>> dataList = (List<Map<String, Object>>) object.getData();
  897. // if (actionVo.getData() instanceof List) {
  898. // dataList = (List<Map<String, Object>>) actionVo.getData();
  899. // }
  900. JSONArray dataAll = JsonUtil.getListToJsonArray(dataList);
  901. List<Map<String, Object>> list = new ArrayList<>();
  902. treeToList(id, name, children, dataAll, list);
  903. String value = feildValue.replaceAll("\\[", "").replaceAll("\\]", "");
  904. Map<String, String> resultMap = new HashMap<>();
  905. list.stream().forEach(t -> {
  906. resultMap.put(String.valueOf(t.get(id)), String.valueOf(t.get(name)));
  907. });
  908. if (feildValue.startsWith("[[")) {
  909. String[][] fv = JsonUtil.getJsonToBean(feildValue, String[][].class);
  910. StringJoiner f1 = new StringJoiner(",");
  911. for (String[] f : fv) {
  912. StringJoiner v1 = new StringJoiner("/");
  913. for (String v : f) {
  914. v1.add(resultMap.get(v));
  915. }
  916. f1.add(v1.toString());
  917. }
  918. return f1.toString();
  919. } else if (feildValue.startsWith("[")) {
  920. List<String> fvs = JsonUtil.getJsonToList(feildValue, String.class);
  921. return fvs.stream().map(resultMap::get).collect(Collectors.joining(sep));
  922. } else {
  923. return resultMap.get(feildValue);
  924. }
  925. }
  926. return feildValue;
  927. }
  928. /**
  929. * 获取远端数据
  930. *
  931. * @param urlId
  932. * @param name
  933. * @param id
  934. * @param children
  935. * @param feildValue
  936. * @param mul 是否多选
  937. * @param isFullPath 全路径
  938. * @return
  939. */
  940. public String getDynName(String urlId, String name, String id, String children, String feildValue, boolean mul, boolean isFullPath, String json, int num, Map<String, Object> dataAll1) {
  941. List<TemplateJsonModel> list = JsonUtil.getJsonToList(json, TemplateJsonModel.class);
  942. Map<String, String> infoMap = CollectionUtils.isNotEmpty(list) ? new HashMap<>() : null;
  943. for (TemplateJsonModel templateJsonModel : list) {
  944. if (StringUtil.isNotEmpty(templateJsonModel.getRelationField())) {
  945. String[] mastTable = templateJsonModel.getRelationField().split(JnpfConst.SIDE_MARK);
  946. String[] child = templateJsonModel.getRelationField().split("-");
  947. if (mastTable.length > 1) {
  948. if (dataAll1.get(mastTable[0]) instanceof Map) {
  949. Map<String, Object> mastTableData = (Map<String, Object>) dataAll1.get(mastTable[0]);
  950. infoMap.put(templateJsonModel.getField(), String.valueOf(mastTableData.get(mastTable[1])));
  951. }
  952. } else if (child.length > 1) {
  953. if (dataAll1.get(child[0]) instanceof List) {
  954. List<Map<String, Object>> chidList = (List<Map<String, Object>>) dataAll1.get(child[0]);
  955. for (int i = 0; i < chidList.size(); i++) {
  956. Map<String, Object> objectMap = chidList.get(i);
  957. if (i == num) {
  958. infoMap.put(templateJsonModel.getField(), String.valueOf(objectMap.get(child[1])));
  959. }
  960. }
  961. }
  962. } else {
  963. infoMap.put(templateJsonModel.getField(), String.valueOf(dataAll1.get(templateJsonModel.getRelationField())));
  964. }
  965. }
  966. }
  967. if (StringUtil.isNotEmpty(feildValue)) {
  968. Map<String, String> a = new HashMap<>();
  969. ActionResult data = dataInterfaceService.infoToId(urlId, null, infoMap);
  970. List<Map<String, Object>> dataList = (List<Map<String, Object>>) data.getData();
  971. JSONArray dataAll = JsonUtil.getListToJsonArray(dataList);
  972. List<Map<String, Object>> datalist = new ArrayList<>();
  973. treeToList(id, name, children, dataAll, datalist);
  974. String value = feildValue.replaceAll("\\[", "").replaceAll("\\]", "");
  975. Map<String, Object> resultMap = new HashMap<>();
  976. datalist.forEach(t -> {
  977. resultMap.put(String.valueOf(t.get(id)), String.valueOf(t.get(name)));
  978. });
  979. Object dataConversion = FormPublicUtils.getDataConversion(resultMap, feildValue, mul, "/");
  980. feildValue = String.valueOf(dataConversion);
  981. }
  982. return feildValue;
  983. }
  984. /**
  985. * 树转成list
  986. **/
  987. private void treeToList(String id, String fullName, String children, JSONArray data, List<Map<String, Object>> result) {
  988. if (data != null) {
  989. for (int i = 0; i < data.size(); i++) {
  990. JSONObject ob = data.getJSONObject(i);
  991. Map<String, Object> tree = new HashMap<>(16);
  992. tree.put(id, String.valueOf(ob.get(id)));
  993. tree.put(fullName, String.valueOf(ob.get(fullName)));
  994. result.add(tree);
  995. if (ob.get(children) != null) {
  996. JSONArray childArray = ob.getJSONArray(children);
  997. treeToList(id, fullName, children, childArray, result);
  998. }
  999. }
  1000. }
  1001. }
  1002. /**
  1003. * 生成单据规则
  1004. *
  1005. * @param encode
  1006. * @param isCache
  1007. * @return
  1008. * @throws DataException
  1009. */
  1010. @DS("")
  1011. public String getBillNumber(String encode, Boolean isCache) throws DataException {
  1012. return billRuleService.getBillNumber(encode, isCache);
  1013. }
  1014. /**
  1015. * 生成单据规则方法2(表单内单据配置)
  1016. *
  1017. * @param visualId 功能id
  1018. * @param ruleId 规则id
  1019. * @param ruleJson 规则josn
  1020. * @param obj 表单数据(联动用)
  1021. * @return
  1022. * @throws DataException
  1023. */
  1024. @DS("")
  1025. public String getBillNumber2(String visualId, String ruleId, String ruleJson, Object obj) throws DataException {
  1026. Map<String, Object> dataMap = JsonUtil.entityToMap(obj);
  1027. FieLdsModel fieLdsModel = new FieLdsModel();
  1028. ConfigModel config = new ConfigModel();
  1029. config.setRuleType(2);
  1030. config.setJnpfKey(JnpfKeyConsts.BILLRULE);
  1031. config.setFormId(ruleId);
  1032. RuleConfig ruleConfig = JsonUtil.getJsonToBean(ruleJson, RuleConfig.class);
  1033. config.setRuleConfig(ruleConfig);
  1034. fieLdsModel.setConfig(config);
  1035. Object billNumber = visualBillUtil.getBillNumber(visualId, fieLdsModel, dataMap, null);
  1036. return billNumber.toString();
  1037. }
  1038. /**
  1039. * 功能流程 获取可视化实体
  1040. *
  1041. * @param visualId
  1042. * @return
  1043. */
  1044. public VisualdevEntity getVisualEntity(String visualId) {
  1045. VisualdevEntity info = visualdevService.getInfo(visualId);
  1046. if (info != null) {
  1047. return info;
  1048. }
  1049. return new VisualdevEntity();
  1050. }
  1051. @DS("")
  1052. public UserEntity getUser(String userId) {
  1053. return userService.getInfo(userId);
  1054. }
  1055. public String getGroupSelect(String groupIds) {
  1056. if (StringUtil.isEmpty(groupIds)) {
  1057. return groupIds;
  1058. }
  1059. List<String> swapList = new ArrayList<>();
  1060. if (groupIds.contains("[")) {
  1061. List<String> groups = JsonUtil.getJsonToList(groupIds, String.class);
  1062. for (String g : groups) {
  1063. GroupEntity info = groupService.getInfo(g);
  1064. String s = info != null ? info.getFullName() : "";
  1065. swapList.add(s);
  1066. }
  1067. } else {
  1068. GroupEntity info = groupService.getInfo(groupIds);
  1069. swapList.add(info != null ? info.getFullName() : "");
  1070. }
  1071. return String.join(",", swapList);
  1072. }
  1073. public String getRoleSelect(String roleIds) {
  1074. if (StringUtil.isEmpty(roleIds)) {
  1075. return roleIds;
  1076. }
  1077. List<String> swapList = new ArrayList<>();
  1078. if (roleIds.contains("[")) {
  1079. List<String> groups = JsonUtil.getJsonToList(roleIds, String.class);
  1080. for (String g : groups) {
  1081. RoleEntity info = roleService.getInfo(g);
  1082. String s = info != null ? info.getFullName() : "";
  1083. swapList.add(s);
  1084. }
  1085. } else {
  1086. RoleEntity info = roleService.getInfo(roleIds);
  1087. swapList.add(info != null ? info.getFullName() : "");
  1088. }
  1089. return String.join(",", swapList);
  1090. }
  1091. /**
  1092. * 高级查询
  1093. *
  1094. * @param conditionModel
  1095. * @param entity
  1096. * @param num
  1097. * @return
  1098. */
  1099. public Integer getCondition(SuperQueryConditionModel conditionModel, Object entity, int num) {
  1100. QueryWrapper<?> queryWrapper = conditionModel.getObj();
  1101. List<ConditionJsonModel> queryConditionModels = conditionModel.getConditionList();
  1102. String op = conditionModel.getMatchLogic();
  1103. String tableName = conditionModel.getTableName();
  1104. List<ConditionJsonModel> useCondition = new ArrayList<>();
  1105. for (ConditionJsonModel queryConditionModel : queryConditionModels) {
  1106. if (queryConditionModel.getTableName().equalsIgnoreCase(tableName)) {
  1107. if (queryConditionModel.getField().contains("jnpf")) {
  1108. String child = queryConditionModel.getField();
  1109. String s1 = child.substring(child.lastIndexOf(JnpfConst.SIDE_MARK_PRE)).replace(JnpfConst.SIDE_MARK_PRE, "");
  1110. queryConditionModel.setField(s1);
  1111. }
  1112. if (queryConditionModel.getField().startsWith("tableField")) {
  1113. String child = queryConditionModel.getField();
  1114. String s1 = child.substring(child.indexOf("-") + 1);
  1115. queryConditionModel.setField(s1);
  1116. }
  1117. useCondition.add(queryConditionModel);
  1118. }
  1119. }
  1120. if (queryConditionModels.isEmpty() || useCondition.size() < 1) {
  1121. return num;
  1122. }
  1123. if (!useCondition.isEmpty()) {
  1124. num += 1;
  1125. }
  1126. //处理控件 转换为有效值
  1127. for (ConditionJsonModel queryConditionModel : useCondition) {
  1128. String jnpfKey = queryConditionModel.getJnpfKey();
  1129. String fieldValue = queryConditionModel.getFieldValue();
  1130. if (StringUtil.isEmpty(fieldValue)) {
  1131. if (jnpfKey.equals(JnpfKeyConsts.CASCADER) || jnpfKey.equals(JnpfKeyConsts.CHECKBOX) || jnpfKey.equals(JnpfKeyConsts.ADDRESS)) {
  1132. queryConditionModel.setFieldValue("[]");
  1133. } else {
  1134. queryConditionModel.setFieldValue("");
  1135. }
  1136. if (queryConditionModel.getSymbol().equals("like")) {
  1137. queryConditionModel.setSymbol("==");
  1138. } else if (queryConditionModel.getSymbol().equals("notLike")) {
  1139. queryConditionModel.setSymbol("<>");
  1140. }
  1141. }
  1142. if (jnpfKey.equals(JnpfKeyConsts.DATE)) {
  1143. String startTime = "";
  1144. if (StringUtil.isNotEmpty(fieldValue)) {
  1145. Long o1 = Long.valueOf(fieldValue);
  1146. startTime = DateUtil.daFormatHHMMSS(o1);
  1147. }
  1148. queryConditionModel.setFieldValue(startTime);
  1149. } else if (jnpfKey.equals(JnpfKeyConsts.CREATETIME) || jnpfKey.equals(JnpfKeyConsts.MODIFYTIME)) {
  1150. String startTime = "";
  1151. if (StringUtil.isNotEmpty(fieldValue)) {
  1152. Long o1 = Long.valueOf(fieldValue);
  1153. startTime = DateUtil.daFormatHHMMSS(o1);
  1154. }
  1155. queryConditionModel.setFieldValue(startTime);
  1156. }
  1157. }
  1158. //反射获取数据库实际字段
  1159. Class<?> aClass = entity.getClass();
  1160. queryWrapper.and(tw -> {
  1161. for (ConditionJsonModel conditionJsonModel : useCondition) {
  1162. String conditionField = conditionJsonModel.getField();
  1163. String jnpfKey = conditionJsonModel.getJnpfKey();
  1164. Field declaredField = null;
  1165. try {
  1166. declaredField = aClass.getDeclaredField(conditionField);
  1167. } catch (NoSuchFieldException e) {
  1168. e.printStackTrace();
  1169. }
  1170. declaredField.setAccessible(true);
  1171. String field = declaredField.getAnnotation(TableField.class).value();
  1172. String fieldValue = conditionJsonModel.getFieldValue();
  1173. String symbol = conditionJsonModel.getSymbol();
  1174. if ("AND".equalsIgnoreCase(op)) {
  1175. if (symbol.equals("==")) {
  1176. tw.and(qw -> {
  1177. List<String> multJnpf = new ArrayList() {{
  1178. add(JnpfKeyConsts.CASCADER);
  1179. add(JnpfKeyConsts.COMSELECT);
  1180. add(JnpfKeyConsts.ADDRESS);
  1181. add(JnpfKeyConsts.SELECT);
  1182. add(JnpfKeyConsts.TREESELECT);
  1183. }};
  1184. if (JnpfKeyConsts.CHECKBOX.equals(jnpfKey) || (multJnpf.contains(jnpfKey) && conditionJsonModel.isFormMultiple())) {
  1185. //todo 多选,高级查询只选一个,需要拼成数组查询,其他控件目前没发现,后续添加至此
  1186. String eavalue = "";
  1187. if (fieldValue.contains("[")) {
  1188. eavalue = "[" + fieldValue + "]";
  1189. } else {
  1190. JSONArray jarr = new JSONArray();
  1191. jarr.add(fieldValue);
  1192. eavalue = jarr.toJSONString();
  1193. }
  1194. qw.eq(field, eavalue);
  1195. } else if (!jnpfKey.equals(JnpfKeyConsts.NUM_INPUT) && !jnpfKey.equals(JnpfKeyConsts.CALCULATE)) {
  1196. qw.eq(field, fieldValue);
  1197. } else {
  1198. if (StringUtil.isNotEmpty(fieldValue)) {
  1199. qw.eq(field, fieldValue);
  1200. }
  1201. }
  1202. if (StringUtil.isEmpty(fieldValue)) {
  1203. qw.or(
  1204. ew -> ew.isNull(field)
  1205. );
  1206. }
  1207. }
  1208. );
  1209. } else if (symbol.equals(">=")) {
  1210. tw.ge(field, fieldValue);
  1211. } else if (symbol.equals("<=")) {
  1212. tw.and(ew -> {
  1213. ew.le(field, fieldValue);
  1214. ew.and(
  1215. qw -> qw.ne(field, "")
  1216. );
  1217. });
  1218. } else if (symbol.equals(">")) {
  1219. tw.gt(field, fieldValue);
  1220. } else if (symbol.equals("<")) {
  1221. tw.and(ew -> {
  1222. ew.lt(field, fieldValue);
  1223. ew.and(
  1224. qw -> qw.ne(field, "")
  1225. );
  1226. });
  1227. } else if (symbol.equals("<>")) {
  1228. tw.and(ew -> {
  1229. ew.ne(field, fieldValue);
  1230. if (StringUtil.isNotEmpty(fieldValue)) {
  1231. ew.or(
  1232. qw -> qw.isNull(field)
  1233. );
  1234. } else {
  1235. ew.and(
  1236. qw -> qw.isNotNull(field)
  1237. );
  1238. }
  1239. });
  1240. } else if (symbol.equals("like")) {
  1241. tw.and(ew -> {
  1242. if (StringUtil.isNotEmpty(fieldValue)) {
  1243. ew.like(field, fieldValue);
  1244. } else {
  1245. ew.isNull(field);
  1246. }
  1247. });
  1248. } else if (symbol.equals("notLike")) {
  1249. tw.and(ew -> {
  1250. if (StringUtil.isNotEmpty(fieldValue)) {
  1251. ew.notLike(field, fieldValue);
  1252. ew.or(
  1253. qw -> qw.isNull(field)
  1254. );
  1255. } else {
  1256. ew.isNotNull(field);
  1257. }
  1258. });
  1259. }
  1260. } else {
  1261. if (symbol.equals("==")) {
  1262. tw.or(
  1263. qw -> qw.eq(field, fieldValue)
  1264. );
  1265. } else if (symbol.equals(">=")) {
  1266. tw.or(
  1267. qw -> qw.ge(field, fieldValue)
  1268. );
  1269. } else if (symbol.equals("<=")) {
  1270. tw.or(
  1271. qw -> qw.le(field, fieldValue)
  1272. );
  1273. } else if (symbol.equals(">")) {
  1274. tw.or(
  1275. qw -> qw.gt(field, fieldValue)
  1276. );
  1277. } else if (symbol.equals("<")) {
  1278. tw.or(
  1279. qw -> qw.lt(field, fieldValue)
  1280. );
  1281. } else if (symbol.equals("<>")) {
  1282. tw.or(
  1283. qw -> qw.ne(field, fieldValue)
  1284. );
  1285. if (StringUtil.isNotEmpty(fieldValue)) {
  1286. tw.or(
  1287. qw -> qw.isNull(field)
  1288. );
  1289. }
  1290. } else if (symbol.equals("like")) {
  1291. if (StringUtil.isNotEmpty(fieldValue)) {
  1292. tw.or(
  1293. qw -> qw.like(field, fieldValue)
  1294. );
  1295. } else {
  1296. tw.or(
  1297. qw -> qw.isNull(field)
  1298. );
  1299. }
  1300. } else if (symbol.equals("notLike")) {
  1301. if (StringUtil.isNotEmpty(fieldValue)) {
  1302. tw.or(
  1303. qw -> qw.notLike(field, fieldValue)
  1304. );
  1305. tw.or(
  1306. qw -> qw.isNull(field)
  1307. );
  1308. } else {
  1309. tw.or(
  1310. qw -> qw.isNotNull(field)
  1311. );
  1312. }
  1313. }
  1314. }
  1315. }
  1316. });
  1317. return num;
  1318. }
  1319. /**
  1320. * 取主表交集
  1321. *
  1322. * @param lists
  1323. * @return
  1324. */
  1325. public List<String> getIntersection(List<List<String>> lists) {
  1326. if (lists == null || lists.isEmpty()) {
  1327. return new ArrayList<>();
  1328. }
  1329. ArrayList<List<String>> arrayList = new ArrayList<>(lists);
  1330. for (List<String> list : arrayList) {
  1331. if (list == null || list.isEmpty()) {
  1332. return new ArrayList<>();
  1333. }
  1334. }
  1335. List<String> intersection = arrayList.get(0);
  1336. for (List<String> list : arrayList) {
  1337. intersection.retainAll(list);
  1338. }
  1339. return intersection;
  1340. }
  1341. public Map<String, Object> putCache(Map<String, Object> localCache) {
  1342. //读取系统控件 所需编码 id
  1343. Map<String, Object> depMap = organizeService.getOrgEncodeAndName("department");
  1344. localCache.put("_dep_map", depMap);
  1345. Map<String, Object> comMap = organizeService.getOrgNameAndId("");
  1346. localCache.put("_com_map", comMap);
  1347. Map<String, Object> posMap = positionService.getPosEncodeAndName();
  1348. localCache.put("_pos_map", posMap);
  1349. Map<String, Object> userMap = userService.getUserNameAndIdMap();
  1350. localCache.put("_user_map", userMap);
  1351. Map<String, Object> roleMap = roleService.getRoleNameAndIdMap();
  1352. localCache.put("_role_map", roleMap);
  1353. Map<String, Object> groupMap = groupService.getGroupEncodeMap();
  1354. localCache.put("_group_map", groupMap);
  1355. return localCache;
  1356. }
  1357. /**
  1358. * 时间是否在范围内
  1359. *
  1360. * @param jnpfField
  1361. * @param parse
  1362. * @return
  1363. */
  1364. private boolean timeInRange(JnpfField jnpfField, Date parse) {
  1365. boolean flag = true;
  1366. if (StringUtil.isNotEmpty(jnpfField.startTime())) {
  1367. long startTime = Long.parseLong(jnpfField.startTime());
  1368. flag = parse.after(new Date(startTime));
  1369. }
  1370. if (flag && StringUtil.isNotEmpty(jnpfField.endTime())) {
  1371. long endTime = Long.parseLong(jnpfField.endTime());
  1372. flag = parse.before(new Date(endTime));
  1373. }
  1374. return flag;
  1375. }
  1376. private List<String> checkOptionsControl(boolean multiple, Map<String, Object> insMap, String vModel, String label, Map<String, Object> cacheMap, List<String> valueList, StringJoiner errInfo) {
  1377. boolean error = false;
  1378. if (!multiple) {
  1379. //非多选填入多选值
  1380. if (valueList.size() > 1) {
  1381. error = true;
  1382. errInfo.add(label + "非多选");
  1383. }
  1384. }
  1385. List<String> dataList = new ArrayList<>();
  1386. if (!error) {
  1387. boolean errorHapen = false;
  1388. for (String va : valueList) {
  1389. Object vo = cacheMap.get(va);
  1390. if (vo == null) {
  1391. errorHapen = true;
  1392. } else {
  1393. dataList.add(vo.toString());
  1394. }
  1395. }
  1396. if (errorHapen) {
  1397. errInfo.add(label + "值不正确");
  1398. } else {
  1399. insMap.put(vModel, !multiple ? dataList.get(0) : JsonUtil.getObjectToString(dataList));
  1400. }
  1401. }
  1402. return dataList;
  1403. }
  1404. /**
  1405. * 递归查询
  1406. *
  1407. * @param label
  1408. * @param value
  1409. * @param Children
  1410. * @param data
  1411. * @param options
  1412. */
  1413. public static void getOptions(String label, String value, String Children, JSONArray data, List<Map<String, Object>> options) {
  1414. for (int i = 0; i < data.size(); i++) {
  1415. JSONObject ob = data.getJSONObject(i);
  1416. Map<String, Object> tree = new HashMap<>(16);
  1417. tree.put(value, String.valueOf(ob.get(value)));
  1418. tree.put(label, String.valueOf(ob.get(label)));
  1419. options.add(tree);
  1420. if (ob.get(Children) != null) {
  1421. JSONArray childrenArray = ob.getJSONArray(Children);
  1422. getOptions(label, value, Children, childrenArray, options);
  1423. }
  1424. }
  1425. }
  1426. /**
  1427. * 获取用户主件查询条件
  1428. *
  1429. * @param value
  1430. * @return
  1431. */
  1432. public List<String> usersSelectQuery(String value) {
  1433. List<String> userSList = new ArrayList<>();
  1434. String userValue = value.substring(0, value.indexOf("--"));
  1435. UserEntity userEntity = userService.getInfo(userValue);
  1436. if (userEntity != null) {
  1437. //在用户关系表中取出
  1438. List<UserRelationEntity> groupRel = Optional.ofNullable(userRelationService.getListByObjectType(userValue, PermissionConst.GROUP)).orElse(new ArrayList<>());
  1439. List<UserRelationEntity> orgRel = Optional.ofNullable(userRelationService.getListByObjectType(userValue, PermissionConst.ORGANIZE)).orElse(new ArrayList<>());
  1440. List<UserRelationEntity> posRel = Optional.ofNullable(userRelationService.getListByObjectType(userValue, PermissionConst.POSITION)).orElse(new ArrayList<>());
  1441. List<UserRelationEntity> roleRel = Optional.ofNullable(userRelationService.getListByObjectType(userValue, PermissionConst.ROLE)).orElse(new ArrayList<>());
  1442. if (!groupRel.isEmpty()) {
  1443. for (UserRelationEntity split : groupRel) {
  1444. userSList.add(split.getObjectId());
  1445. }
  1446. }
  1447. if (StringUtil.isNotEmpty(userEntity.getOrganizeId())) {
  1448. //向上递归 查出所有上级组织
  1449. List<String> allUpOrgIDs = new ArrayList<>();
  1450. organizeService.upWardRecursion(allUpOrgIDs, userEntity.getOrganizeId());
  1451. userSList.addAll(allUpOrgIDs);
  1452. }
  1453. if (!posRel.isEmpty()) {
  1454. for (UserRelationEntity split : posRel) {
  1455. userSList.add(split.getObjectId());
  1456. }
  1457. }
  1458. if (!roleRel.isEmpty()) {
  1459. for (UserRelationEntity split : roleRel) {
  1460. userSList.add(split.getObjectId());
  1461. }
  1462. }
  1463. return userSList;
  1464. } else {
  1465. return null;
  1466. }
  1467. }
  1468. /**
  1469. * 获取用户主件查询条件(多选)
  1470. *
  1471. * @param values
  1472. * @return
  1473. */
  1474. public List<String> usersSelectQuery(List<String> values) {
  1475. List<String> userSList = new ArrayList<>();
  1476. for (String value : values) {
  1477. String userValue = value.substring(0, value.indexOf("--"));
  1478. UserEntity userEntity = userService.getInfo(userValue);
  1479. if (userEntity != null) {
  1480. //在用户关系表中取出
  1481. List<UserRelationEntity> groupRel = Optional.ofNullable(userRelationService.getListByObjectType(userValue, PermissionConst.GROUP)).orElse(new ArrayList<>());
  1482. List<UserRelationEntity> orgRel = Optional.ofNullable(userRelationService.getListByObjectType(userValue, PermissionConst.ORGANIZE)).orElse(new ArrayList<>());
  1483. List<UserRelationEntity> posRel = Optional.ofNullable(userRelationService.getListByObjectType(userValue, PermissionConst.POSITION)).orElse(new ArrayList<>());
  1484. List<UserRelationEntity> roleRel = Optional.ofNullable(userRelationService.getListByObjectType(userValue, PermissionConst.ROLE)).orElse(new ArrayList<>());
  1485. if (!groupRel.isEmpty()) {
  1486. for (UserRelationEntity split : groupRel) {
  1487. userSList.add(split.getObjectId());
  1488. }
  1489. }
  1490. if (StringUtil.isNotEmpty(userEntity.getOrganizeId())) {
  1491. //向上递归 查出所有上级组织
  1492. List<String> allUpOrgIDs = new ArrayList<>();
  1493. organizeService.upWardRecursion(allUpOrgIDs, userEntity.getOrganizeId());
  1494. userSList.addAll(allUpOrgIDs);
  1495. }
  1496. if (!posRel.isEmpty()) {
  1497. for (UserRelationEntity split : posRel) {
  1498. userSList.add(split.getObjectId());
  1499. }
  1500. }
  1501. if (!roleRel.isEmpty()) {
  1502. for (UserRelationEntity split : roleRel) {
  1503. userSList.add(split.getObjectId());
  1504. }
  1505. }
  1506. }
  1507. }
  1508. return userSList;
  1509. }
  1510. @DS("")
  1511. public List<RuleInfo> getFilterCondition(String id) {
  1512. return filterService.getCondition(id);
  1513. }
  1514. public static List convertToList(Object obj) {
  1515. return OnlineSwapDataUtils.convertToList(obj);
  1516. }
  1517. public static String convertValueToString(String obj, boolean mult, boolean isOrg) {
  1518. return OnlineSwapDataUtils.convertValueToString(obj, mult, isOrg);
  1519. }
  1520. /**
  1521. * 获取数据连接
  1522. *
  1523. * @param dbLink
  1524. * @return
  1525. */
  1526. public DbLinkEntity getDataSource(String dbLink) {
  1527. QueryWrapper<DbLinkEntity> queryWrapper = new QueryWrapper<>();
  1528. queryWrapper.lambda().eq(DbLinkEntity::getFullName, dbLink);
  1529. return dblinkService.getOne(queryWrapper);
  1530. }
  1531. /**
  1532. * 静态数据转换
  1533. *
  1534. * @param param 需要转换的值
  1535. * @param options 静态数据模型
  1536. * @param key label key-value编码对应
  1537. * @param multiple 是否多选
  1538. * @return 转换后的值
  1539. */
  1540. public static String selectStaitcSwap(String param, String options, String key, String label, boolean multiple) {
  1541. List<String> textList = new ArrayList<>();
  1542. List<Map> optionsList = JsonUtil.getJsonToList(options, Map.class);
  1543. if (multiple) {
  1544. List<String> jsonToList = JsonUtil.getJsonToList(param, String.class);
  1545. for (String list1 : jsonToList) {
  1546. if (list1.contains("[")) {
  1547. List<String> textList2 = new ArrayList<>();
  1548. List<String> jsonToList2 = JsonUtil.getJsonToList(list1, String.class);
  1549. for (String str : jsonToList2) {
  1550. textList2.add(loop(optionsList, str, key, label));
  1551. }
  1552. textList.add(String.join("/", textList2));
  1553. } else {
  1554. textList.add(loop(optionsList, list1, key, label));
  1555. }
  1556. }
  1557. } else {
  1558. if (param.contains("[")) {
  1559. List<String> textList2 = new ArrayList<>();
  1560. List<String> jsonToList = JsonUtil.getJsonToList(param, String.class);
  1561. for (String str : jsonToList) {
  1562. textList2.add(loop(optionsList, str, key, label));
  1563. }
  1564. textList.add(String.join("/", textList2));
  1565. } else {
  1566. textList.add(loop(optionsList, param, key, label));
  1567. }
  1568. }
  1569. return String.join(",", textList);
  1570. }
  1571. public static String loop(List<Map> options, String oneData, String key, String label) {
  1572. for (int i = 0; i < options.size(); i++) {
  1573. if (options.get(i).get(key).equals(oneData)) {
  1574. return options.get(i).get(label).toString();
  1575. } else if (options.get(i).get("children") != null) {
  1576. List<Map> children = JsonUtil.getJsonToList(options.get(i).get("children"), Map.class);
  1577. String loop = loop(children, oneData, key, label);
  1578. if (loop != null) {
  1579. return loop;
  1580. }
  1581. }
  1582. }
  1583. return null;
  1584. }
  1585. /**
  1586. * 功能表单获取流程信息-导入绑定多流程的第一个
  1587. *
  1588. * @param formId
  1589. * @return
  1590. * @throws WorkFlowException
  1591. */
  1592. public String getFlowTempJsonId(String formId) throws WorkFlowException {
  1593. String flowTemjsonId = "";
  1594. //todo 功能表单获取流程信息调整取流程id位置变化
  1595. // if (form == null || StringUtil.isEmpty(form.getFlowId())) {
  1596. // throw new WorkFlowException("该功能未配置流程不可用");
  1597. // }
  1598. // FlowTemplateInfoVO vo = flowTemplateService.info(form.getFlowId());
  1599. // if (vo == null || StringUtil.isEmpty(vo.getFlowTemplateJson()) || "[]".equals(vo.getFlowTemplateJson())) {
  1600. // throw new WorkFlowException("流程未设计!");
  1601. // }
  1602. // List<FlowJsonModel> collect = JsonUtil.getJsonToList(vo.getFlowTemplateJson(), FlowJsonModel.class);
  1603. // flowTemjsonId = collect.get(0).getId();
  1604. return flowTemjsonId;
  1605. }
  1606. /**
  1607. * 输入时表单时间字段根据格式转换去尾巴
  1608. *
  1609. * @param form
  1610. */
  1611. public static void swapDatetime(Object form) {
  1612. Field[] declaredFields = form.getClass().getDeclaredFields();
  1613. for (Field f : declaredFields) {
  1614. try {
  1615. //副表处理
  1616. if (f.getType().getName().startsWith("jnpf.model")) {
  1617. if (!f.isAccessible()) {
  1618. f.setAccessible(true);
  1619. }
  1620. Object o = f.get(form);
  1621. if (o == null) {
  1622. continue;
  1623. }
  1624. swapDatetime(o);
  1625. f.set(form, o);
  1626. continue;
  1627. }
  1628. //子表处理
  1629. if (List.class.isAssignableFrom(f.getType())) {
  1630. Type type = f.getGenericType();
  1631. if (type instanceof ParameterizedType) {
  1632. if (!f.isAccessible()) {
  1633. f.setAccessible(true);
  1634. }
  1635. List list = getList(f, f.get(form));
  1636. for (Object o : list) {
  1637. swapDatetime(o);
  1638. }
  1639. if (list.size() > 0) {
  1640. f.set(form, list);
  1641. }
  1642. }
  1643. continue;
  1644. }
  1645. //主表处理
  1646. if (f.getAnnotation(JnpfField.class) == null) continue;
  1647. JnpfField annotation = f.getAnnotation(JnpfField.class);
  1648. if (!"date".equals(annotation.jnpfKey()) || StringUtil.isEmpty(annotation.format())) continue;
  1649. String format = annotation.format();
  1650. f.setAccessible(true);
  1651. if (f.get(form) != null && Long.parseLong(String.valueOf(f.get(form))) > 0) {
  1652. Date date = new Date(Long.parseLong(String.valueOf(f.get(form))));
  1653. String completionStr = "";
  1654. switch (format) {
  1655. case "yyyy":
  1656. completionStr = "-01-01 00:00:00";
  1657. break;
  1658. case "yyyy-MM":
  1659. completionStr = "-01 00:00:00";
  1660. break;
  1661. case "yyyy-MM-dd":
  1662. completionStr = " 00:00:00";
  1663. break;
  1664. case "yyyy-MM-dd HH":
  1665. completionStr = ":00:00";
  1666. break;
  1667. case "yyyy-MM-dd HH:mm":
  1668. completionStr = ":00";
  1669. break;
  1670. default:
  1671. break;
  1672. }
  1673. String datestr = DateUtil.dateToString(date, format);
  1674. long time = DateUtil.stringToDate(datestr + completionStr).getTime();
  1675. f.set(form, String.valueOf(time));
  1676. }
  1677. } catch (Exception e) {
  1678. e.printStackTrace();
  1679. }
  1680. }
  1681. }
  1682. public static List getList(Field field, Object object) {
  1683. List resultList = new ArrayList<>();
  1684. if (object != null) {
  1685. try {
  1686. Class clzz = object.getClass();
  1687. //反射调用获取到list的size方法来获取到集合的大小
  1688. Method sizeMethod = clzz.getDeclaredMethod("size");
  1689. if (!sizeMethod.isAccessible()) {
  1690. sizeMethod.setAccessible(true);
  1691. }
  1692. //集合长度
  1693. int size = (int) sizeMethod.invoke(object);
  1694. //循环遍历获取到数据
  1695. for (int i = 0; i < size; i++) {
  1696. //反射获取到list的get方法
  1697. Method getMethod = clzz.getDeclaredMethod("get", int.class);
  1698. //调用get方法获取数据
  1699. if (!getMethod.isAccessible()) {
  1700. getMethod.setAccessible(true);
  1701. }
  1702. Object invoke = getMethod.invoke(object, i);
  1703. resultList.add(invoke);
  1704. }
  1705. } catch (Exception e) {
  1706. e.printStackTrace();
  1707. }
  1708. }
  1709. return resultList;
  1710. }
  1711. /**
  1712. * 小数转换带上0
  1713. *
  1714. * @param decimalValue
  1715. */
  1716. public static String getDecimalStr(Object decimalValue) {
  1717. if (Objects.isNull(decimalValue)) {
  1718. return "";
  1719. }
  1720. if (decimalValue instanceof BigDecimal) {
  1721. BigDecimal bd = (BigDecimal) decimalValue;
  1722. return bd.toPlainString();
  1723. }
  1724. return String.valueOf(decimalValue);
  1725. }
  1726. /**
  1727. * 获取当前组织完整路径
  1728. *
  1729. * @param orgId
  1730. * @return
  1731. */
  1732. public String getCurrentOrgIds(String orgId, String showLevel) {
  1733. return flowFormDataUtil.getCurrentOrgIds(orgId, showLevel);
  1734. }
  1735. /* ****************以下vue3转换信息****************** */
  1736. /**
  1737. * 通过副表名取副表数据map
  1738. *
  1739. * @param data
  1740. * @param tableName
  1741. */
  1742. public static Map<String, Object> getMastTabelData(Object data, String tableName) {
  1743. Map<String, Object> map = JsonUtil.entityToMap(data);
  1744. Map<String, Object> mapRes = new HashMap<>();
  1745. for (String key : map.keySet()) {
  1746. String[] jnpf_s = key.split(JnpfConst.SIDE_MARK);
  1747. if (jnpf_s.length == 2 && jnpf_s[0].contains(tableName)) {
  1748. mapRes.put(jnpf_s[1], map.get(key));
  1749. }
  1750. }
  1751. return mapRes;
  1752. }
  1753. /**
  1754. * List数据转换
  1755. *
  1756. * @param realList
  1757. * @return
  1758. */
  1759. public List<Map<String, Object>> swapDataList(List<Map<String, Object>> realList, GenerParamConst paramConst, String moduleId, boolean inlineEdit) {
  1760. List<FieLdsModel> fieLdsModels = JsonUtil.getJsonToList(paramConst.getFields(), FieLdsModel.class);
  1761. List<FieLdsModel> fields = new ArrayList<>();
  1762. VisualUtils.recursionFields(fieLdsModels, fields);
  1763. //树形-添加父级字段+_id
  1764. if (OnlineDevData.COLUMNTYPE_FIVE.equals(paramConst.getColumnType())) {
  1765. realList.forEach(item -> {
  1766. item.put(paramConst.getColumnParentField() + "_id", item.get(paramConst.getColumnParentField()));
  1767. });
  1768. }
  1769. //数据转换
  1770. realList = swapDataUtils.getSwapList(realList, fields, moduleId, inlineEdit);
  1771. return realList;
  1772. }
  1773. /**
  1774. * 列表补充流程状态
  1775. *
  1776. * @param realList
  1777. * @throws WorkFlowException
  1778. */
  1779. @DS("")
  1780. public void getFlowStatus(List<Map<String, Object>> realList) throws WorkFlowException {
  1781. swapDataUtils.getFlowStatus(realList);
  1782. }
  1783. /**
  1784. * List数据转树形和分组
  1785. *
  1786. * @param realList
  1787. * @param columnDataStr
  1788. * @return
  1789. */
  1790. public List<Map<String, Object>> swapDataList(List<Map<String, Object>> realList, String columnDataStr, String subField) {
  1791. ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(columnDataStr, ColumnDataModel.class);
  1792. //判断数据是否分组
  1793. if (OnlineDevData.COLUMNTYPE_THREE.equals(columnDataModel.getType())) {
  1794. realList = OnlineDevListUtils.groupData(realList, columnDataModel);
  1795. }
  1796. //树形列表
  1797. if (OnlineDevData.COLUMNTYPE_FIVE.equals(columnDataModel.getType())) {
  1798. columnDataModel.setSubField(subField);
  1799. realList = OnlineDevListUtils.treeListData(realList, columnDataModel);
  1800. }
  1801. return realList;
  1802. }
  1803. /**
  1804. * 树形列表转换
  1805. *
  1806. * @param realList
  1807. * @param parentField
  1808. * @param subField
  1809. * @return
  1810. */
  1811. public List<Map<String, Object>> treeTable(List<Map<String, Object>> realList, String parentField, String subField) {
  1812. ColumnDataModel columnDataModel = new ColumnDataModel();
  1813. columnDataModel.setSubField(subField);
  1814. columnDataModel.setParentField(parentField);
  1815. realList = OnlineDevListUtils.treeListData(realList, columnDataModel);
  1816. return realList;
  1817. }
  1818. /**
  1819. * 列表分组方法
  1820. *
  1821. * @param realList
  1822. * @param groupField 分组字段
  1823. * @param firstField 非分组第一个字段(用于展示分组数据)
  1824. * @return
  1825. */
  1826. public static List<Map<String, Object>> groupTable(List<Map<String, Object>> realList, String groupField, String firstField) {
  1827. Map<String, List<Map<String, Object>>> twoMap = new LinkedHashMap<>(16);
  1828. for (Map<String, Object> realMap : realList) {
  1829. String value = String.valueOf(realMap.get(groupField));
  1830. if (realMap.get(groupField) instanceof Double) {
  1831. value = realMap.get(groupField).toString().replaceAll(".0+?$", "").replaceAll("[.]$", "");
  1832. }
  1833. boolean isKey = twoMap.get(value) != null;
  1834. if (isKey) {
  1835. List<Map<String, Object>> maps = twoMap.get(value);
  1836. maps.add(realMap);
  1837. twoMap.put(value, maps);
  1838. } else {
  1839. List<Map<String, Object>> childrenList = new ArrayList<>();
  1840. childrenList.add(realMap);
  1841. twoMap.put(value, childrenList);
  1842. }
  1843. }
  1844. List<Map<String, Object>> resultList = new ArrayList<>();
  1845. for (String key : twoMap.keySet()) {
  1846. Map<String, Object> thirdMap = new HashMap<>(16);
  1847. thirdMap.put(firstField, !key.equals("null") ? key : "");
  1848. thirdMap.put("top", true);
  1849. thirdMap.put("id", RandomUtil.uuId());
  1850. thirdMap.put("children", twoMap.get(key));
  1851. resultList.add(thirdMap);
  1852. }
  1853. return resultList;
  1854. }
  1855. /**
  1856. * 编辑form数据转换
  1857. *
  1858. * @param dataMap
  1859. * @return
  1860. */
  1861. public Map<String, Object> swapDataForm(Map<String, Object> dataMap, GenerParamConst paramConst) {
  1862. List<FieLdsModel> fieLdsModels = JsonUtil.getJsonToList(paramConst.getFields(), FieLdsModel.class);
  1863. List<FieLdsModel> fields = new ArrayList<>();
  1864. VisualUtils.recursionFields(fieLdsModels, fields);
  1865. //是流程添加流程相关字段
  1866. swapDataUtils.getFLowFields(dataMap);
  1867. //数据转换
  1868. return this.swapDataForm(dataMap, fields, null, paramConst.getTableFieldKey(), paramConst.getTableRenames());
  1869. }
  1870. private Map<String, Object> swapDataForm(Map<String, Object> dataMap, List<FieLdsModel> fields, Map<String, Object> mainMap
  1871. , Map<String, String> tableField, Map<String, String> tableRename) {
  1872. if (dataMap == null || dataMap.isEmpty()) return new HashMap<>();
  1873. for (FieLdsModel item : fields) {
  1874. String jnpfKey = item.getConfig().getJnpfKey();
  1875. String vModel = item.getVModel();
  1876. String dataType = item.getConfig().getDataType();
  1877. Boolean isMultiple = Objects.nonNull(item.getMultiple()) ? item.getMultiple() : false;
  1878. //获取原字段数据
  1879. FormPublicUtils.relationGetJnpfId(dataMap, jnpfKey, dataMap.get(vModel), vModel);
  1880. List<String> systemConditions = new ArrayList() {{
  1881. add(JnpfKeyConsts.CURRORGANIZE);
  1882. add(JnpfKeyConsts.CURRDEPT);
  1883. add(JnpfKeyConsts.CURRPOSITION);
  1884. }};
  1885. //多选二维数组
  1886. List<String> multTow = new ArrayList() {{
  1887. add(JnpfKeyConsts.CASCADER);
  1888. add(JnpfKeyConsts.ADDRESS);
  1889. }};
  1890. //一维维数组
  1891. List<String> multOne = new ArrayList() {{
  1892. add(JnpfKeyConsts.CHECKBOX);
  1893. }};
  1894. List<String> nullIsList = new ArrayList() {{
  1895. add(JnpfKeyConsts.UPLOADFZ);
  1896. add(JnpfKeyConsts.UPLOADIMG);
  1897. }};
  1898. if (Objects.nonNull(dataMap.get(vModel))) {
  1899. if (multTow.contains(jnpfKey) && isMultiple) {
  1900. //二维数据转换
  1901. dataMap.replace(vModel, JSONObject.parseArray(dataMap.get(vModel).toString(), List.class));
  1902. } else if (multTow.contains(jnpfKey) || isMultiple || multOne.contains(jnpfKey)) {
  1903. //一维数据转换
  1904. dataMap.replace(vModel, JSONObject.parseArray(dataMap.get(vModel).toString(), String.class));
  1905. }
  1906. } else if (!JnpfKeyConsts.CHILD_TABLE.equals(jnpfKey)) {
  1907. if (systemConditions.contains(jnpfKey)) {
  1908. dataMap.put(vModel, " ");
  1909. }
  1910. if (nullIsList.contains(jnpfKey)) {
  1911. dataMap.put(vModel, Collections.emptyList());
  1912. }
  1913. continue;
  1914. }
  1915. switch (jnpfKey) {
  1916. case JnpfKeyConsts.RATE:
  1917. case JnpfKeyConsts.SLIDER:
  1918. BigDecimal value = new BigDecimal(0);
  1919. if (dataMap.get(vModel) != null) {
  1920. value = new BigDecimal(dataMap.get(vModel).toString());
  1921. }
  1922. dataMap.put(vModel, value);
  1923. break;
  1924. case JnpfKeyConsts.SWITCH:
  1925. dataMap.put(vModel, dataMap.get(vModel) != null ? Integer.parseInt(String.valueOf(dataMap.get(vModel))) : null);
  1926. break;
  1927. case JnpfKeyConsts.DATE:
  1928. case JnpfKeyConsts.DATE_CALCULATE:
  1929. Long dateTime = DateTimeFormatConstant.getDateObjToLong(dataMap.get(vModel));
  1930. dataMap.put(vModel, dateTime != null ? dateTime : dataMap.get(vModel));
  1931. break;
  1932. //编辑是的系统控件转换
  1933. case JnpfKeyConsts.CURRORGANIZE:
  1934. case JnpfKeyConsts.CURRDEPT:
  1935. String orgName = organizeService.getNameByIdStr(String.valueOf(dataMap.get(vModel)));
  1936. dataMap.put(vModel, StringUtil.isNotEmpty(orgName) ? orgName : " ");
  1937. break;
  1938. case JnpfKeyConsts.CREATEUSER:
  1939. case JnpfKeyConsts.MODIFYUSER:
  1940. UserEntity userEntity = userService.getInfo(String.valueOf(dataMap.get(vModel)));
  1941. String userValue = Objects.nonNull(userEntity) ? userEntity.getAccount().equalsIgnoreCase(ADMIN_KEY)
  1942. ? "管理员/" + ADMIN_KEY : userEntity.getRealName() + "/" + userEntity.getAccount() : String.valueOf(dataMap.get(vModel));
  1943. dataMap.put(vModel, userValue);
  1944. break;
  1945. case JnpfKeyConsts.CURRPOSITION:
  1946. String posName = positionService.getNameByIdStr(String.valueOf(dataMap.get(vModel)));
  1947. dataMap.put(vModel, StringUtil.isNotEmpty(posName) ? posName : " ");
  1948. break;
  1949. case JnpfKeyConsts.CREATETIME:
  1950. case JnpfKeyConsts.MODIFYTIME:
  1951. if (ObjectUtil.isNotEmpty(dataMap.get(vModel))) {
  1952. Long dateLong = Long.parseLong(String.valueOf(dataMap.get(vModel)));
  1953. String dateStr = DateUtil.dateFormat(new Date(dateLong));
  1954. dataMap.put(vModel, dateStr);
  1955. }
  1956. break;
  1957. case JnpfKeyConsts.UPLOADFZ:
  1958. case JnpfKeyConsts.UPLOADIMG:
  1959. //数据传递-乱塞有bug强行置空
  1960. if (ObjectUtil.isNotEmpty(dataMap.get(vModel))) {
  1961. List<Map<String, Object>> fileList = new ArrayList<>();
  1962. try {
  1963. fileList = JsonUtil.getJsonToListMap(dataMap.get(vModel).toString());
  1964. } catch (Exception e) {
  1965. e.printStackTrace();
  1966. }
  1967. dataMap.put(vModel, fileList);
  1968. }
  1969. break;
  1970. case JnpfKeyConsts.CHILD_TABLE:
  1971. List<FieLdsModel> childrens = item.getConfig().getChildren();
  1972. String childTableRename = "";
  1973. try {
  1974. childTableRename = tableRename.get(tableField.get(vModel));
  1975. } catch (Exception e) {
  1976. }
  1977. if (StringUtil.isNotEmpty(childTableRename)) {
  1978. vModel = childTableRename + "List";
  1979. }
  1980. vModel = DataControlUtils.initialLowercase(vModel);
  1981. List<Map<String, Object>> childList = (List<Map<String, Object>>) dataMap.get(vModel);
  1982. if (CollectionUtils.isEmpty(childList)) break;
  1983. for (int i = 0; i < childList.size(); i++) {
  1984. Map<String, Object> childMap = childList.get(i);
  1985. childList.set(i, this.swapDataForm(childMap, childrens, dataMap, tableField, tableRename));
  1986. }
  1987. dataMap.put(vModel, childList);
  1988. break;
  1989. default:
  1990. dataMap.put(vModel, dataMap.get(vModel));
  1991. break;
  1992. }
  1993. }
  1994. return dataMap;
  1995. }
  1996. /**
  1997. * 详情Detail数据转换
  1998. *
  1999. * @param map
  2000. * @return
  2001. */
  2002. public Map<String, Object> swapDataDetail(Map<String, Object> map, JSONArray filedArray, String moduleId, boolean inlineEdit) {
  2003. List<FieLdsModel> fieLdsModels = JsonUtil.getJsonToList(filedArray, FieLdsModel.class);
  2004. List<FieLdsModel> fields = new ArrayList<>();
  2005. VisualUtils.recursionFields(fieLdsModels, fields);
  2006. //数据转换
  2007. if (map != null) {
  2008. Map<String, Object> finalMap = map;
  2009. List<Map<String, Object>> realList = new ArrayList() {{
  2010. add(finalMap);
  2011. }};
  2012. realList = swapDataUtils.getSwapInfo(realList, fields, moduleId, inlineEdit, null);
  2013. map = realList.get(0);
  2014. }
  2015. return map;
  2016. }
  2017. /**
  2018. * 导入数据
  2019. */
  2020. public ExcelImportModel importData(GenerParamConst paramConst, List<Map<String, Object>> dataList, ImportFormCheckUniqueModel uniqueModel) throws WorkFlowException {
  2021. FormDataModel formDataModel = new FormDataModel();
  2022. formDataModel.setBusinessKeyList(new String[]{});
  2023. formDataModel.setBusinessKeyTip("");
  2024. ExcelImportModel importModel = new ExcelImportModel();
  2025. Map<String, Object> localCache = swapDataUtils.getlocalCache();
  2026. List<Map<String, Object>> failResult = new ArrayList<>();
  2027. List<FieLdsModel> fieLdsModels = JsonUtil.getJsonToList(paramConst.getFields(), FieLdsModel.class);
  2028. List<FieLdsModel> fields = new ArrayList<>();
  2029. VisualUtils.recursionFields(fieLdsModels, fields);
  2030. uniqueModel.setMain(true);
  2031. uniqueModel.setTableModelList(JsonUtil.getJsonToList(paramConst.getTableList(), TableModel.class));
  2032. DbLinkEntity linkEntity = dblinkService.getInfo(uniqueModel.getDbLinkId());
  2033. uniqueModel.setLinkEntity(linkEntity);
  2034. //流程表单导入,传流程小id查询,查询各个版本flowIds用于过滤数据
  2035. String mainFlowID = null;
  2036. if (StringUtil.isNotEmpty(uniqueModel.getFlowId())) {
  2037. List<TemplateJsonEntity> flowVersionIds = templateApi.getFlowIdsByTemplate(uniqueModel.getFlowId());
  2038. uniqueModel.setFlowId(uniqueModel.getFlowId());
  2039. uniqueModel.setFlowIdList(flowVersionIds.stream().map(TemplateJsonEntity::getId).distinct().collect(Collectors.toList()));
  2040. mainFlowID = flowVersionIds.stream().filter(t -> Objects.equals(t.getState(), 1)).findFirst().orElse(new TemplateJsonEntity()).getId();
  2041. }
  2042. try {
  2043. for (int i = 0, len = dataList.size(); i < len; i++) {
  2044. Map<String, Object> data = dataList.get(i);
  2045. //导入时默认第一个流程
  2046. data.put(FlowFormConstant.FLOWID, mainFlowID);
  2047. data.put(TableFeildsEnum.FLOWID.getField(), mainFlowID);
  2048. Map<String, Object> resultMap = new HashMap<>(data);
  2049. StringJoiner errInfo = new StringJoiner(",");
  2050. Map<String, Object> errorMap = new HashMap<>(data);
  2051. List<String> errList = swapDataUtils.checkExcelData(fields, data, localCache, resultMap, errorMap, uniqueModel);
  2052. //业务主键判断--导入新增或者跟新
  2053. VisualErrInfo visualErrInfo;
  2054. try {
  2055. DynamicDataSourceUtil.switchToDataSource(linkEntity);
  2056. visualErrInfo = formCheckUtils.checkBusinessKey(fields, resultMap, uniqueModel.getTableModelList(), formDataModel, null);
  2057. } finally {
  2058. DynamicDataSourceUtil.clearSwitchDataSource();
  2059. }
  2060. if (uniqueModel.isUpdate()) {
  2061. if (ObjectUtil.isNotEmpty(visualErrInfo) && StringUtil.isNotEmpty(visualErrInfo.getId())) {
  2062. uniqueModel.setId(visualErrInfo.getId());
  2063. //判断流程是否已发起
  2064. if (StringUtil.isNotEmpty(visualErrInfo.getFlowTaskId())) {
  2065. String finalTaskId = visualErrInfo.getFlowTaskId();
  2066. List<String> flowIdList = new ArrayList<>();
  2067. flowIdList.add(finalTaskId);
  2068. List<TaskEntity> tasks = taskApi.getInfosSubmit(flowIdList.toArray(new String[]{}), TaskEntity::getStatus, TaskEntity::getId);
  2069. if (tasks.size() > 0) {
  2070. boolean errorMsg = tasks.stream().filter(t -> Objects.equals(t.getStatus(), 0)).count() == 0;
  2071. String msg = "已发起流程,导入失败";
  2072. if (errorMsg) {
  2073. errorMap.put("errorsInfo", msg);
  2074. failResult.add(errorMap);
  2075. continue;
  2076. }
  2077. }
  2078. }
  2079. } else {
  2080. String excelHas = formCheckUtils.checkBusinessKeyExcel(formDataModel, resultMap, uniqueModel);
  2081. if (StringUtil.isNotEmpty(excelHas)) {
  2082. continue;
  2083. }
  2084. }
  2085. } else {
  2086. if (ObjectUtil.isNotEmpty(visualErrInfo) && StringUtil.isNotEmpty(visualErrInfo.getErrMsg())) {
  2087. errorMap.put("errorsInfo", visualErrInfo.getErrMsg());
  2088. failResult.add(errorMap);
  2089. continue;
  2090. }
  2091. String excelHas = formCheckUtils.checkBusinessKeyExcel(formDataModel, resultMap, uniqueModel);
  2092. if (StringUtil.isNotEmpty(excelHas)) {
  2093. errorMap.put("errorsInfo", excelHas);
  2094. failResult.add(errorMap);
  2095. continue;
  2096. }
  2097. }
  2098. swapDataUtils.checkUnique(fields, data, errList, uniqueModel);
  2099. errList.stream().forEach(t -> {
  2100. if (StringUtil.isNotEmpty(t)) {
  2101. errInfo.add(t);
  2102. }
  2103. });
  2104. if (errInfo.length() > 0) {
  2105. errorMap.put("errorsInfo", errInfo.toString());
  2106. failResult.add(errorMap);
  2107. } else {
  2108. List<ImportDataModel> importDataModel = uniqueModel.getImportDataModel();
  2109. ImportDataModel model = new ImportDataModel();
  2110. model.setId(uniqueModel.getId());
  2111. Map<String, Map<String, Object>> map = new HashMap<>(16);
  2112. Map<String, Object> tableMap = new HashMap<>(16);
  2113. for (Object key : resultMap.keySet().toArray()) {
  2114. if (paramConst.getTableFieldKey().get(key) != null) {
  2115. tableMap.put(paramConst.getTableFieldKey().get(key) + "List", resultMap.remove(key));
  2116. }
  2117. }
  2118. resultMap.putAll(map);
  2119. resultMap.putAll(tableMap);
  2120. model.setResultData(resultMap);
  2121. importDataModel.add(model);
  2122. }
  2123. }
  2124. } catch (Exception e) {
  2125. e.printStackTrace();
  2126. throw new WorkFlowException("导入异常!");
  2127. }
  2128. importModel.setFnum(failResult.size());
  2129. importModel.setSnum(dataList.size() - failResult.size());
  2130. importModel.setResultType(failResult.size() > 0 ? 1 : 0);
  2131. importModel.setFailResult(failResult);
  2132. return importModel;
  2133. }
  2134. /**
  2135. * vue3获取数据过滤方案列表
  2136. *
  2137. * @param columnStr
  2138. * @param appColumnStr
  2139. * @return
  2140. */
  2141. public List<RuleInfo> getFilterRules(String columnStr, String appColumnStr) {
  2142. ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(columnStr, ColumnDataModel.class);
  2143. ColumnDataModel appColumnDataModel = JsonUtil.getJsonToBean(appColumnStr, ColumnDataModel.class);
  2144. List<Map> ruleList = JsonUtil.getJsonToList(columnDataModel.getRuleList().getConditionList(), Map.class);
  2145. List<Map> appRuleList = JsonUtil.getJsonToList(appColumnDataModel.getRuleList().getConditionList(), Map.class);
  2146. boolean isPc = RequestContext.isOrignPc();
  2147. List<RuleInfo> res = JsonUtil.getJsonToList(ruleList, RuleInfo.class);
  2148. if (!isPc) {
  2149. res = JsonUtil.getJsonToList(appRuleList, RuleInfo.class);
  2150. }
  2151. return res;
  2152. }
  2153. public QueryWrapper wrapperHandle(String columnStr, String appColumnStr, QueryWrapper<?> wrapper, Class<?> aClass, String type, String tableName) {
  2154. try {
  2155. // 避免空and
  2156. wrapper.apply(" 1=1 ");
  2157. List<RuleInfo> ruleInfos = getFilterRules(columnStr, appColumnStr);
  2158. for (RuleInfo info : ruleInfos) {
  2159. String field = info.getField();
  2160. if ("main".equals(type) && field.contains("-")) {
  2161. continue;
  2162. }
  2163. if ("main".equals(type) && field.contains(JnpfConst.SIDE_MARK)) {
  2164. continue;
  2165. }
  2166. if ("sub".equals(type) && !field.contains("-")) {
  2167. continue;
  2168. }
  2169. if ("sub-jnpf".equals(type) && !field.contains(JnpfConst.SIDE_MARK)) {
  2170. continue;
  2171. }
  2172. String fieldName = field;
  2173. String table = "";
  2174. if (field.contains("-")) {
  2175. fieldName = field.split("-")[1];
  2176. if (!tableName.equals(field.split("-")[0])) {
  2177. continue;
  2178. }
  2179. }
  2180. if (field.contains(JnpfConst.SIDE_MARK)) {
  2181. fieldName = field.split(JnpfConst.SIDE_MARK)[1];
  2182. table = field.split(JnpfConst.SIDE_MARK)[0];
  2183. table = table.replace(JnpfConst.SIDE_MARK_PRE, "");
  2184. }
  2185. if ("sub-jnpf".equals(type) && !tableName.equals(table)) {
  2186. continue;
  2187. }
  2188. Field declaredField = aClass.getDeclaredField(fieldName);
  2189. declaredField.setAccessible(true);
  2190. String fieldDb = declaredField.getAnnotation(TableField.class).value();
  2191. GenUtil genUtil = JsonUtil.getJsonToBean(info, GenUtil.class);
  2192. genUtil.setOperator(info.getOperator());
  2193. genUtil.solveValue(wrapper, fieldDb);
  2194. }
  2195. return wrapper;
  2196. } catch (Exception e) {
  2197. return wrapper;
  2198. }
  2199. }
  2200. /**
  2201. * 是否只有主表过滤
  2202. *
  2203. * @param columnStr
  2204. * @param appColumnStr
  2205. * @return
  2206. */
  2207. public boolean onlyMainFilter(String columnStr, String appColumnStr) {
  2208. List<RuleInfo> ruleInfos = getFilterRules(columnStr, appColumnStr);
  2209. for (RuleInfo info : ruleInfos) {
  2210. if (info.getField().contains(JnpfConst.SIDE_MARK) || info.getField().contains("-")) {
  2211. return false;
  2212. }
  2213. }
  2214. return true;
  2215. }
  2216. /**
  2217. * 输入时表单时间字段根据格式转换去尾巴
  2218. *
  2219. * @param obj 数据
  2220. */
  2221. public static String swapDatetime(JSONArray fieldsStr, Object obj, Map<String, String> tableRename) {
  2222. List<FieLdsModel> fieLdsModels = JsonUtil.getJsonToList(fieldsStr, FieLdsModel.class);
  2223. Map<String, Object> map = JsonUtil.entityToMap(obj);
  2224. for (String tabelRealName : tableRename.keySet()) {
  2225. String reName = DataControlUtils.initialLowercase(tableRename.get(tabelRealName));
  2226. map.put(tabelRealName + "List", map.get(reName + "List"));
  2227. }
  2228. OnlineSwapDataUtils.swapDatetime(fieLdsModels, map);
  2229. for (String tabelRealName : tableRename.keySet()) {
  2230. if (map.get(tabelRealName + "List") != null) {
  2231. String reName = DataControlUtils.initialLowercase(tableRename.get(tabelRealName));
  2232. JSONArray listToJsonArray = JsonUtil.getListToJsonArray((List) map.get(tabelRealName + "List"));
  2233. map.replace(reName + "List", listToJsonArray);
  2234. }
  2235. }
  2236. return JsonUtil.getObjectToString(map);
  2237. }
  2238. /**
  2239. * 三种搜索条件组合查询
  2240. *
  2241. * @param queryAllModel
  2242. * @return
  2243. */
  2244. @DS("")
  2245. public MPJLambdaWrapper getConditionAllTable(QueryAllModel queryAllModel) {
  2246. UserInfo userInfo = UserProvider.getUser();
  2247. try {
  2248. queryAllModel.setSystemCode(RequestContext.getAppCode());
  2249. DbLinkEntity linkEntity = queryAllModel.getDbLink() != null ? getDataSource(queryAllModel.getDbLink()) : null;
  2250. DynamicDataSourceUtil.switchToDataSource(linkEntity);
  2251. @Cleanup Connection connection = ConnUtil.getConnOrDefault(linkEntity);
  2252. queryAllModel.setDbType(connection.getMetaData().getDatabaseProductName().trim());
  2253. } catch (Exception e) {
  2254. } finally {
  2255. DynamicDataSourceUtil.clearSwitchDataSource();
  2256. }
  2257. MPJLambdaWrapper wrapper = queryAllModel.getWrapper();
  2258. List<List<SuperJsonModel>> superList = new ArrayList<>();
  2259. //高级查询
  2260. String superQuery = queryAllModel.getSuperJson();
  2261. if (StringUtil.isNotEmpty(superQuery)) {
  2262. List<SuperJsonModel> list = new ArrayList<>();
  2263. SuperJsonModel jsonToBean = JsonUtil.getJsonToBean(queryAllModel.getSuperJson(), SuperJsonModel.class);
  2264. list.add(jsonToBean);
  2265. superList.add(list);
  2266. }
  2267. //数据过滤
  2268. String ruleQuery = queryAllModel.getRuleJson();
  2269. if (StringUtil.isNotEmpty(ruleQuery)) {
  2270. List<SuperJsonModel> list = new ArrayList<>();
  2271. SuperJsonModel jsonToBean = JsonUtil.getJsonToBean(queryAllModel.getRuleJson(), SuperJsonModel.class);
  2272. list.add(jsonToBean);
  2273. superList.add(list);
  2274. }
  2275. //数据权限 不为空有开启权限(存在多权限--权限方案之间用or,和其他条件之间用and)
  2276. if (queryAllModel.getModuleId() != null) {
  2277. if (!userInfo.getIsAdministrator()) {
  2278. List<SuperJsonModel> authorizeListAll = authorizeService.getConditionSql(queryAllModel.getModuleId(),queryAllModel.getSystemCode());
  2279. if (CollectionUtils.isNotEmpty(authorizeListAll)) {
  2280. superList.add(authorizeListAll);
  2281. } else {
  2282. return null;
  2283. }
  2284. }
  2285. }
  2286. //系统参数替换
  2287. List<String> json = superList.stream().flatMap(List::stream).map(SuperJsonModel::toString).collect(Collectors.toList());
  2288. Map<String, String> systemFieldValue = userApi.getSystemFieldValue(new SystemParamModel(json));
  2289. for (List<SuperJsonModel> superJsonModels : superList) {
  2290. for (SuperJsonModel superJsonModel : superJsonModels) {
  2291. for (SuperQueryJsonModel superQueryJsonModel : superJsonModel.getConditionList()) {
  2292. for (FieLdsModel fieLdsModel : superQueryJsonModel.getGroups()) {
  2293. OnlineProductSqlUtils.replaceSystemParam(systemFieldValue, fieLdsModel);
  2294. }
  2295. }
  2296. }
  2297. }
  2298. QueryUtil queryUtil = new QueryUtil();
  2299. queryAllModel.setQueryList(superList);
  2300. queryUtil.queryList(queryAllModel);
  2301. return wrapper;
  2302. }
  2303. /**
  2304. * 视图代码生成数据接口调用在线开发
  2305. *
  2306. * @param hasPage 是否分页
  2307. * @param viewKey 视图主键
  2308. * @return
  2309. */
  2310. @DS("")
  2311. public PageListVO getInterfaceData(Object pagination, GenerViewConst paramConst, Boolean hasPage, String viewKey) {
  2312. boolean isPc = "pc".equals(ServletUtil.getHeader("jnpf-origin" ));
  2313. VisualdevReleaseEntity visualdevEntity = new VisualdevReleaseEntity();
  2314. visualdevEntity.setInterfaceId(paramConst.getInterfaceId());
  2315. visualdevEntity.setInterfaceParam(paramConst.getInterfaceParam().toJSONString());
  2316. ColumnDataModel columnDataModel = new ColumnDataModel();
  2317. columnDataModel.setType(paramConst.getColumnType());
  2318. columnDataModel.setHasPage(hasPage);
  2319. columnDataModel.setViewKey(viewKey);
  2320. if(isPc){
  2321. columnDataModel.setSearchList(paramConst.getSearchList().toString());
  2322. }else{
  2323. columnDataModel.setSearchList(paramConst.getSearchListApp().toString());
  2324. }
  2325. PaginationModelExport jsonToBean = JsonUtil.getJsonToBean(pagination, PaginationModelExport.class);
  2326. jsonToBean.setQueryJson(JsonUtil.getObjectToString(pagination));
  2327. List<Map<String, Object>> interfaceData = swapDataUtils.getInterfaceData(visualdevEntity, jsonToBean, columnDataModel);
  2328. if (isPc && columnDataModel.getType() == 3) {
  2329. //分组数据转换
  2330. interfaceData = this.groupTable(interfaceData, paramConst.getGroupField(), paramConst.getFirstField());
  2331. }
  2332. //返回对象
  2333. PageListVO vo = new PageListVO();
  2334. vo.setList(interfaceData);
  2335. PaginationVO page = JsonUtil.getJsonToBean(jsonToBean, PaginationVO.class);
  2336. vo.setPagination(page);
  2337. return vo;
  2338. }
  2339. @DS("")
  2340. public DownloadVO exportInterfaceData(Object pagination, GenerViewConst paramConst, Boolean hasPage, String viewKey) {
  2341. boolean isPc = "pc".equals(ServletUtil.getHeader("jnpf-origin" ));
  2342. VisualdevReleaseEntity visualdevEntity = new VisualdevReleaseEntity();
  2343. visualdevEntity.setInterfaceId(paramConst.getInterfaceId());
  2344. visualdevEntity.setInterfaceParam(paramConst.getInterfaceParam().toJSONString());
  2345. ColumnDataModel columnDataModel = new ColumnDataModel();
  2346. columnDataModel.setType(paramConst.getColumnType());
  2347. columnDataModel.setHasPage(hasPage);
  2348. columnDataModel.setViewKey(viewKey);
  2349. columnDataModel.setComplexHeaderList(JsonUtil.getJsonToList(paramConst.getComplexHeaderList().toString(),HeaderModel.class));
  2350. if(isPc){
  2351. columnDataModel.setSearchList(paramConst.getSearchList().toString());
  2352. columnDataModel.setColumnList(paramConst.getColumnData().toString());
  2353. }else{
  2354. columnDataModel.setSearchList(paramConst.getSearchListApp().toString());
  2355. columnDataModel.setColumnList(paramConst.getColumnDataApp().toString());
  2356. }
  2357. PaginationModelExport jsonToBean = JsonUtil.getJsonToBean(pagination, PaginationModelExport.class);
  2358. jsonToBean.setQueryJson(JsonUtil.getObjectToString(pagination));
  2359. List<Map<String, Object>> realList = swapDataUtils.getInterfaceData(visualdevEntity, jsonToBean, columnDataModel);
  2360. ModuleEntity menuInfo = moduleService.getInfo(jsonToBean.getMenuId());
  2361. String[] keys = jsonToBean.getSelectKey();
  2362. List<Object> selectIds = Arrays.asList(jsonToBean.getSelectIds());
  2363. realList = "2".equals(jsonToBean.getDataType()) ? realList.stream().filter(t -> selectIds.contains(t.get(columnDataModel.getViewKey()))).collect(Collectors.toList()) : realList;
  2364. return VisualUtils.createModelExcelApiData(JsonUtil.getObjectToString(columnDataModel), realList, Arrays.asList(keys), "表单信息", menuInfo.getFullName(), new ExcelModel());
  2365. }
  2366. /**
  2367. * 根据菜单ID获取菜单名称
  2368. *
  2369. * @param menuId
  2370. * @return
  2371. */
  2372. @DS("")
  2373. public String getMenuName(String menuId) {
  2374. String name = "";
  2375. if (StringUtil.isNotEmpty(menuId)) {
  2376. ModuleEntity menuInfo = moduleService.getInfo(menuId);
  2377. if (menuInfo != null && StringUtil.isNotEmpty(menuInfo.getFullName())) {
  2378. name = menuInfo.getFullName();
  2379. }
  2380. }
  2381. return name;
  2382. }
  2383. /**
  2384. * 根据表单获取所有字段
  2385. *
  2386. * @param fieldStr
  2387. * @return
  2388. */
  2389. @DS("")
  2390. public ExcelModel getExcelParams(String fieldStr, List<String> selectKey) {
  2391. FormDataModel formJson = new FormDataModel();
  2392. formJson.setFields(fieldStr);
  2393. return swapDataUtils.getDefaultValue(JsonUtil.getObjectToString(formJson), selectKey);
  2394. }
  2395. /**
  2396. * 导出Excel
  2397. *
  2398. * @param entitys
  2399. * @param list
  2400. * @param keys
  2401. * @param menuId
  2402. * @param moduleId
  2403. * @return
  2404. */
  2405. @DS("")
  2406. public DownloadVO creatModelExcel(List<ExcelExportEntity> entitys, List<Map<String, Object>> list, String[] keys, String menuId, String moduleId,
  2407. GenerParamConst generParamConst, boolean inlineEdit) {
  2408. //数据转换
  2409. list = this.swapDataList(list, generParamConst, moduleId, inlineEdit);
  2410. String menuFullName = this.getMenuName(menuId);
  2411. DownloadVO vo = DownloadVO.builder().build();
  2412. ExportParams exportParams = new ExportParams(null, "表单信息");
  2413. exportParams.setType(ExcelType.XSSF);
  2414. try {
  2415. @Cleanup Workbook workbook = new HSSFWorkbook();
  2416. if (entitys.size() > 0) {
  2417. if (list.size() == 0) {
  2418. list.add(new HashMap<>());
  2419. }
  2420. //去除空数据
  2421. List<Map<String, Object>> dataList = new ArrayList<>();
  2422. for (Map<String, Object> map : list) {
  2423. int i = 0;
  2424. for (String key : keys) {
  2425. //子表
  2426. if (key.toLowerCase().startsWith("tablefield")) {
  2427. String tableField = key.substring(0, key.indexOf("-"));
  2428. String field = key.substring(key.indexOf("-") + 1);
  2429. Object o = map.get(tableField);
  2430. if (o != null) {
  2431. List<Map<String, Object>> childList = (List<Map<String, Object>>) o;
  2432. for (Map<String, Object> childMap : childList) {
  2433. if (childMap.get(field) != null) {
  2434. i++;
  2435. }
  2436. }
  2437. }
  2438. } else {
  2439. Object o = map.get(key);
  2440. if (o != null) {
  2441. i++;
  2442. }
  2443. }
  2444. }
  2445. if (i > 0) {
  2446. dataList.add(map);
  2447. }
  2448. }
  2449. List<ExcelExportEntity> mergerEntitys = new ArrayList<>(entitys);
  2450. List<Map<String, Object>> mergerList = new ArrayList<>(dataList);
  2451. //复杂表头-表头和数据处理
  2452. List<HeaderModel> complexHeaderList = JsonUtil.getJsonToList(generParamConst.getComplexHeaderList(), HeaderModel.class);
  2453. if (!Objects.equals(generParamConst.getColumnType(), 3) && !Objects.equals(generParamConst.getColumnType(), 5)) {
  2454. entitys = VisualUtils.complexHeaderHandel(entitys, complexHeaderList, Objects.equals(generParamConst.getColumnType(), 4));
  2455. dataList = VisualUtils.complexHeaderDataHandel(dataList, complexHeaderList, Objects.equals(generParamConst.getColumnType(), 4));
  2456. }
  2457. exportParams.setStyle(ExcelExportStyler.class);
  2458. workbook = ExcelExportUtil.exportExcel(exportParams, entitys, dataList);
  2459. VisualUtils.mergerVertical(workbook, mergerEntitys, mergerList);
  2460. ExcelModel excelModel = this.getExcelParams(generParamConst.getFields().toJSONString(), Arrays.asList(keys));
  2461. ExcelHelper helper = new ExcelHelper();
  2462. helper.init(workbook, exportParams, entitys, excelModel);
  2463. helper.doPreHandle();
  2464. helper.doPostHandle();
  2465. }
  2466. String fileName = menuFullName + "_" + DateUtil.dateNow("yyyyMMddHHmmss") + ".xls";
  2467. MultipartFile multipartFile = ExcelUtil.workbookToCommonsMultipartFile(workbook, fileName);
  2468. FileInfo fileInfo = FileUploadUtils.uploadFile(new FileParameter(FileTypeConstant.TEMPORARY, fileName), multipartFile);
  2469. vo.setName(fileInfo.getFilename());
  2470. vo.setUrl(UploaderUtil.uploaderFile(fileInfo.getFilename() + "#" + FileTypeConstant.TEMPORARY) + "&name=" + fileName);
  2471. } catch (Exception e) {
  2472. e.printStackTrace();
  2473. }
  2474. return vo;
  2475. }
  2476. //以下新的流程api
  2477. /**
  2478. * 获取流程版本列表
  2479. *
  2480. * @param templateId
  2481. * @return
  2482. */
  2483. @DS("")
  2484. public List<String> getFlowIds(String templateId) {
  2485. List<String> flowIds = new ArrayList<>();
  2486. if (StringUtil.isNotEmpty(templateId)) {
  2487. flowIds.addAll(templateApi.getFlowIdsByTemplateId(templateId));
  2488. if (CollectionUtils.isNotEmpty(flowIds)) {
  2489. return flowIds;
  2490. }
  2491. String templateByVersionId = templateApi.getTemplateByVersionId(templateId);
  2492. if (StringUtil.isNotEmpty(templateByVersionId)) {
  2493. flowIds.addAll(templateApi.getFlowIdsByTemplateId(templateByVersionId));
  2494. }
  2495. }
  2496. if (CollectionUtils.isEmpty(flowIds)) {
  2497. flowIds.add("noFlowVer");
  2498. }
  2499. return flowIds;
  2500. }
  2501. /**
  2502. * 删除流程任务
  2503. *
  2504. * @param flowTaskId
  2505. * @return
  2506. */
  2507. @DS("")
  2508. public String deleteFlowTask(String flowTaskId) {
  2509. String errMsg = "";
  2510. TaskEntity taskEntity = taskApi.getInfoSubmit(flowTaskId, TaskEntity::getId, TaskEntity::getParentId, TaskEntity::getFullName, TaskEntity::getStatus);
  2511. if (taskEntity != null) {
  2512. try {
  2513. taskApi.delete(taskEntity);
  2514. } catch (Exception e) {
  2515. errMsg = e.getMessage();
  2516. }
  2517. }
  2518. return errMsg;
  2519. }
  2520. }