OnlineSwapDataUtils.java 164 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947
  1. package jnpf.onlinedev.util.onlineDevUtil;
  2. import cn.hutool.core.bean.BeanUtil;
  3. import cn.hutool.core.collection.CollectionUtil;
  4. import cn.hutool.core.date.LocalDateTimeUtil;
  5. import cn.hutool.core.map.CaseInsensitiveMap;
  6. import cn.hutool.core.text.StrPool;
  7. import cn.hutool.core.util.ObjectUtil;
  8. import com.alibaba.fastjson.JSONArray;
  9. import com.alibaba.fastjson.JSONObject;
  10. import com.google.common.collect.ImmutableList;
  11. import com.google.common.collect.Lists;
  12. import jnpf.base.ActionResult;
  13. import jnpf.base.UserInfo;
  14. import jnpf.base.entity.*;
  15. import jnpf.base.mapper.FlowFormDataMapper;
  16. import jnpf.base.model.ColumnDataModel;
  17. import jnpf.base.model.OnlineImport.ExcelImportModel;
  18. import jnpf.base.model.OnlineImport.ImportDataModel;
  19. import jnpf.base.model.OnlineImport.ImportFormCheckUniqueModel;
  20. import jnpf.base.model.OnlineImport.VisualdevModelDataInfoVO;
  21. import jnpf.base.model.VisualDevJsonModel;
  22. import jnpf.base.model.datainterface.DataInterfaceModel;
  23. import jnpf.base.model.datainterface.DataInterfacePage;
  24. import jnpf.base.model.flow.DataModel;
  25. import jnpf.base.service.*;
  26. import jnpf.base.util.*;
  27. import jnpf.base.vo.PageListVO;
  28. import jnpf.base.vo.PaginationVO;
  29. import jnpf.constant.DataInterfaceVarConst;
  30. import jnpf.constant.JnpfConst;
  31. import jnpf.constant.MsgCode;
  32. import jnpf.constant.PermissionConst;
  33. import jnpf.database.model.entity.DbLinkEntity;
  34. import jnpf.database.util.DynamicDataSourceUtil;
  35. import jnpf.emnus.SysParamEnum;
  36. import jnpf.exception.DataException;
  37. import jnpf.exception.WorkFlowException;
  38. import jnpf.flowable.entity.TaskEntity;
  39. import jnpf.flowable.entity.TemplateJsonEntity;
  40. import jnpf.model.ExcelColumnAttr;
  41. import jnpf.model.ExcelModel;
  42. import jnpf.model.SystemParamModel;
  43. import jnpf.model.visualJson.*;
  44. import jnpf.model.visualJson.config.ConfigModel;
  45. import jnpf.model.visualJson.config.RegListModel;
  46. import jnpf.model.visualJson.props.PropsModel;
  47. import jnpf.onlinedev.model.OnlineDevEnum.MultipleControlEnum;
  48. import jnpf.onlinedev.model.OnlineDevEnum.OnlineDataTypeEnum;
  49. import jnpf.onlinedev.model.OnlineDevListModel.InterefaceParamModel;
  50. import jnpf.onlinedev.model.OnlineInfoModel;
  51. import jnpf.onlinedev.model.PaginationModel;
  52. import jnpf.onlinedev.model.VisualErrInfo;
  53. import jnpf.onlinedev.model.VisualParamModel;
  54. import jnpf.onlinedev.service.VisualDevInfoService;
  55. import jnpf.onlinedev.service.VisualdevModelDataService;
  56. import jnpf.permission.entity.OrganizeEntity;
  57. import jnpf.permission.entity.PositionEntity;
  58. import jnpf.permission.entity.UserEntity;
  59. import jnpf.permission.entity.UserRelationEntity;
  60. import jnpf.permission.model.authorize.AuthorizeConditionEnum;
  61. import jnpf.permission.model.organize.OrganizeConditionModel;
  62. import jnpf.permission.model.organize.OrganizeModel;
  63. import jnpf.permission.service.*;
  64. import jnpf.util.*;
  65. import jnpf.util.visiual.JnpfKeyConsts;
  66. import jnpf.workflow.service.TaskApi;
  67. import jnpf.workflow.service.TemplateApi;
  68. import lombok.Cleanup;
  69. import lombok.extern.slf4j.Slf4j;
  70. import org.apache.commons.collections4.CollectionUtils;
  71. import org.apache.poi.ss.usermodel.IndexedColors;
  72. import org.mybatis.dynamic.sql.BasicColumn;
  73. import org.mybatis.dynamic.sql.SqlBuilder;
  74. import org.mybatis.dynamic.sql.SqlTable;
  75. import org.mybatis.dynamic.sql.render.RenderingStrategies;
  76. import org.mybatis.dynamic.sql.select.QueryExpressionDSL;
  77. import org.mybatis.dynamic.sql.select.SelectModel;
  78. import org.mybatis.dynamic.sql.select.join.EqualTo;
  79. import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
  80. import org.springframework.beans.factory.annotation.Autowired;
  81. import org.springframework.stereotype.Component;
  82. import java.math.BigDecimal;
  83. import java.nio.charset.StandardCharsets;
  84. import java.sql.Connection;
  85. import java.sql.SQLException;
  86. import java.text.DecimalFormat;
  87. import java.text.SimpleDateFormat;
  88. import java.time.LocalDateTime;
  89. import java.time.format.DateTimeFormatter;
  90. import java.util.*;
  91. import java.util.concurrent.ConcurrentHashMap;
  92. import java.util.stream.Collectors;
  93. /**
  94. * 数据解析
  95. *
  96. * @author JNPF开发平台组
  97. * @version V3.4.2
  98. * @copyright 引迈信息技术有限公司(https://www.jnpfsoft.com)
  99. * @date 2022/7/18
  100. */
  101. @Slf4j
  102. @Component
  103. public class OnlineSwapDataUtils {
  104. @Autowired
  105. private RedisUtil redisUtil;
  106. @Autowired
  107. private DictionaryDataService dictionaryDataApi;
  108. @Autowired
  109. private UserService userApi;
  110. @Autowired
  111. private PositionService positionApi;
  112. @Autowired
  113. private ProvinceService areaApi;
  114. @Autowired
  115. private OrganizeService organizeApi;
  116. @Autowired
  117. private VisualdevService visualdevService;
  118. @Autowired
  119. private VisualdevModelDataService visualdevModelDataService;
  120. @Autowired
  121. private DataInterfaceService dataInterFaceApi;
  122. @Autowired
  123. private VisualDevInfoService visualDevInfoService;
  124. @Autowired
  125. private RoleService roleApi;
  126. @Autowired
  127. private GroupService groupApi;
  128. @Autowired
  129. private DbLinkService dataSourceApi;
  130. @Autowired
  131. private OnlineDevInfoUtils onlineDevInfoUtils;
  132. @Autowired
  133. private FlowFormDataMapper flowFormDataMapper;
  134. @Autowired
  135. private UserRelationService userRelationApi;
  136. @Autowired
  137. private FlowFormDataUtil flowDataUtil;
  138. @Autowired
  139. private OnlineExecutor executor;
  140. @Autowired
  141. private ProvinceService provinceService;
  142. @Autowired
  143. private FormCheckUtils formCheckUtils;
  144. @Autowired
  145. private TemplateApi templateApi;
  146. @Autowired
  147. private TaskApi taskApi;
  148. @Autowired
  149. private UserRelationService userRelationService;
  150. public final static long DEFAULT_CACHE_TIME = 60 * 5;
  151. //后期将是否缓存转到前端控件配置
  152. //缓存系统权限数据, 组织、岗位、分组、角色、用户
  153. public final static boolean NEEDCACHE_SYS = true;
  154. //缓存远端数据, 静态、字典、接口、弹窗选择
  155. public final static boolean NEEDCACHE_REMOTE = true;
  156. //缓存关联数据, 关联表单
  157. public final static boolean NEEDCACHE_RELATION = true;
  158. public List<Map<String, Object>> getSwapList(List<Map<String, Object>> list, List<FieLdsModel> swapDataVoList, String visualDevId, Boolean inlineEdit) {
  159. if (list.isEmpty()) {
  160. return list;
  161. }
  162. return getSwapList(list, swapDataVoList, visualDevId, inlineEdit, null, true, null);
  163. }
  164. public List<Map<String, Object>> getSwapInfo(List<Map<String, Object>> list, List<FieLdsModel> swapDataVoList, String visualDevId, Boolean inlineEdit, Map<String, Object> mainAndMast) {
  165. if (list.isEmpty()) {
  166. return list;
  167. }
  168. return getSwapList(list, swapDataVoList, visualDevId, inlineEdit, null, false, mainAndMast);
  169. }
  170. public List<Map<String, Object>> getSwapList(List<Map<String, Object>> list, List<FieLdsModel> swapDataVoList, String visualDevId, Boolean inlineEdit,
  171. Map<String, Object> localCacheParent, boolean isList, Map<String, Object> mainAndMast) {
  172. try {
  173. DynamicDataSourceUtil.switchToDataSource(null);
  174. if (list.isEmpty()) {
  175. return list;
  176. }
  177. //主表的缓存数据继续使用, 不重新初始化
  178. Map<String, Object> localCache = Optional.ofNullable(localCacheParent).orElse(new ConcurrentHashMap<>());
  179. //初始化系统缓存
  180. // sysNeedSwapData(swapDataVoList, visualDevId, localCache);
  181. //初始化系统缓存-多线程
  182. executor.executorRedis(localCache, swapDataVoList, visualDevId, inlineEdit, list, mainAndMast);
  183. //redis key
  184. String dsName = Optional.ofNullable(TenantHolder.getDatasourceId()).orElse("");
  185. writeRedisAndList(localCache, swapDataVoList, dsName, visualDevId, inlineEdit, list, isList, mainAndMast);
  186. } catch (SQLException e) {
  187. throw new RuntimeException(e);
  188. } finally {
  189. DynamicDataSourceUtil.clearSwitchDataSource();
  190. }
  191. return list;
  192. }
  193. private List<Map<String, Object>> writeRedisAndList(Map<String, Object> localCache, List<FieLdsModel> swapDataVoList, String dsName, String visualDevId, Boolean inlineEdit,
  194. List<Map<String, Object>> list, boolean isList, Map<String, Object> mainAndMast) {
  195. Map<String, Object> userMap = (Map<String, Object>) localCache.get("__user_map");
  196. Map<String, Object> orgMap = (Map<String, Object>) localCache.get("__org_map");
  197. Map<String, Object> posMap = (Map<String, Object>) localCache.get("__pos_map");
  198. Map<String, Object> orgTreeMap = (Map<String, Object>) localCache.get("__orgTree_map");
  199. Map<String, Object> roleMap = (Map<String, Object>) localCache.get("__role_map");
  200. Map<String, Object> groupMap = (Map<String, Object>) localCache.get("__group_map");
  201. List<Map<String, String>> proMapList = (List<Map<String, String>>) localCache.get("__pro_maplist");
  202. List<String> arrJnpfKey = new ArrayList() {{
  203. add(JnpfKeyConsts.UPLOADFZ);
  204. add(JnpfKeyConsts.UPLOADIMG);
  205. }};
  206. for (int x = 0; x < list.size(); x++) {
  207. Map<String, Object> dataMap = list.get(x);
  208. if (dataMap == null) {
  209. dataMap = new HashMap<>();
  210. list.set(x, dataMap);
  211. }
  212. Map<String, Object> dataCopyMap = new HashMap<>(dataMap);
  213. for (FieLdsModel swapDataVo : swapDataVoList) {
  214. String jnpfKey = swapDataVo.getConfig().getJnpfKey();
  215. if (StringUtil.isEmpty(swapDataVo.getVModel())) {
  216. continue;
  217. }
  218. String swapVModel = swapDataVo.getVModel();
  219. String vModel = inlineEdit && isList ? swapDataVo.getVModel() + "_name" : swapDataVo.getVModel();
  220. String dataType = swapDataVo.getConfig().getDataType();
  221. Boolean isMultiple = Objects.nonNull(swapDataVo.getMultiple()) ? swapDataVo.getMultiple() : false;
  222. //clob字段转换
  223. FormInfoUtils.swapClob(dataMap, swapDataVo.getVModel());
  224. try {
  225. Map<String, Map<String, Object>> dataDetailMap = new HashMap<>();
  226. // 关联表单获取原字段数据
  227. FormPublicUtils.relationGetJnpfId(dataMap, jnpfKey, dataMap.get(swapVModel), swapVModel);
  228. if (StringUtil.isEmpty(String.valueOf(dataMap.get(swapVModel))) || String.valueOf(dataMap.get(swapVModel)).equals("[]")
  229. || String.valueOf(dataMap.get(swapVModel)).equals("null")) {
  230. if (jnpfKey.equals(JnpfKeyConsts.CHILD_TABLE)) {
  231. dataMap.put(vModel, new ArrayList<>());
  232. } else if (arrJnpfKey.contains(jnpfKey)) {
  233. dataMap.put(swapVModel, new ArrayList<>());
  234. } else {
  235. // dataCopyMap.putAll(dataMap);
  236. if (inlineEdit) {
  237. dataMap.put(swapVModel, null);
  238. }
  239. dataMap.put(vModel, null);
  240. }
  241. continue;
  242. } else {
  243. //是否联动
  244. boolean DynamicNeedCache;
  245. String redisKey;
  246. String separator = swapDataVo.getSeparator();
  247. switch (jnpfKey) {
  248. case JnpfKeyConsts.CALCULATE:
  249. case JnpfKeyConsts.NUM_INPUT:
  250. Object decimalValue = dataCopyMap.get(swapDataVo.getVModel());
  251. Integer precision = swapDataVo.getPrecision();
  252. if (decimalValue instanceof BigDecimal) {
  253. BigDecimal bd = (BigDecimal) decimalValue;
  254. String value = bd.toPlainString();
  255. List<Integer> IntegerType = ImmutableList.of(3, 4);
  256. if (!IntegerType.contains(swapDataVo.getRoundType())) {
  257. if (precision != null && precision > 0) {
  258. String formatZ = "000000000000000";
  259. String format = formatZ.substring(0, precision);
  260. DecimalFormat decimalFormat = new DecimalFormat("0." + format);
  261. value = decimalFormat.format(bd);
  262. } else {
  263. value = String.valueOf(bd.stripTrailingZeros().toPlainString());
  264. }
  265. } else {
  266. //向上(下)取整,去掉末尾0
  267. value = bd.stripTrailingZeros().toPlainString();
  268. }
  269. dataMap.put(vModel, value);
  270. } else {
  271. dataMap.put(vModel, decimalValue);
  272. }
  273. break;
  274. //公司组件
  275. case JnpfKeyConsts.COMSELECT:
  276. //部门组件
  277. case JnpfKeyConsts.DEPSELECT:
  278. //所属部门
  279. case JnpfKeyConsts.CURRDEPT:
  280. dataMap.put(vModel, OnlinePublicUtils.getDataInMethod(orgTreeMap, dataMap.get(swapVModel), isMultiple));
  281. break;
  282. //所属组织
  283. case JnpfKeyConsts.CURRORGANIZE:
  284. //多级组织
  285. getTreeName(dataMap, swapVModel, orgTreeMap, vModel);
  286. break;
  287. //岗位组件
  288. case JnpfKeyConsts.POSSELECT:
  289. //所属岗位
  290. case JnpfKeyConsts.CURRPOSITION:
  291. //多级组织
  292. getTreeName(dataMap, swapVModel, posMap, vModel);
  293. break;
  294. //用户组件
  295. case JnpfKeyConsts.USERSELECT:
  296. //创建用户
  297. case JnpfKeyConsts.CREATEUSER:
  298. //修改用户
  299. case JnpfKeyConsts.MODIFYUSER:
  300. String userData = OnlinePublicUtils.getDataInMethod(userMap, dataMap.get(swapVModel), isMultiple);
  301. dataMap.put(vModel, userData);
  302. break;
  303. case JnpfKeyConsts.CUSTOMUSERSELECT:
  304. List<String> dataNoSwapInMethod = OnlinePublicUtils.getDataNoSwapInMethod(dataMap.get(swapVModel));
  305. StringJoiner valueJoin = new StringJoiner(",");
  306. for (String data : dataNoSwapInMethod) {
  307. String id = data.contains("--") ? data.substring(0, data.lastIndexOf("--")) : data;
  308. String type = data.contains("--") ? data.substring(data.lastIndexOf("--") + 2) : "";
  309. Map<String, Object> cacheMap;
  310. switch (type) {
  311. case "role":
  312. cacheMap = roleMap;
  313. break;
  314. case "position":
  315. cacheMap = posMap;
  316. break;
  317. case "company":
  318. case "department":
  319. cacheMap = orgMap;
  320. break;
  321. case "group":
  322. cacheMap = groupMap;
  323. break;
  324. case "user":
  325. default:
  326. cacheMap = userMap;
  327. break;
  328. }
  329. valueJoin.add(Optional.ofNullable(cacheMap.get(id)).orElse("").toString());
  330. }
  331. dataMap.put(vModel, valueJoin.toString());
  332. break;
  333. //角色选择
  334. case JnpfKeyConsts.ROLESELECT:
  335. String roleData = OnlinePublicUtils.getDataInMethod(roleMap, dataMap.get(swapVModel), isMultiple);
  336. dataMap.put(vModel, roleData);
  337. break;
  338. case JnpfKeyConsts.GROUPSELECT:
  339. String groupData = OnlinePublicUtils.getDataInMethod(groupMap, dataMap.get(swapVModel), isMultiple);
  340. dataMap.put(vModel, groupData);
  341. break;
  342. //省市区联动
  343. case JnpfKeyConsts.ADDRESS:
  344. String addressValue = String.valueOf(dataMap.get(swapVModel));
  345. if (OnlinePublicUtils.getMultiple(addressValue, MultipleControlEnum.MULTIPLE_JSON_TWO.getMultipleChar())) {
  346. String[][] data = JsonUtil.getJsonToBean(addressValue, String[][].class);
  347. List<String> proDataS = Arrays.stream(data)
  348. .flatMap(Arrays::stream)
  349. .collect(Collectors.toList());
  350. Map<String, String> provinceNames = provinceService.getProList(proDataS).stream().collect(Collectors.toMap(
  351. ProvinceEntity::getId, ProvinceEntity::getFullName
  352. , (k1, k2) -> k2
  353. , () -> new LinkedHashMap<>(proDataS.size(), 1.0F)
  354. ));
  355. List<String> addList = new ArrayList<>();
  356. for (String[] AddressData : data) {
  357. List<String> adList = new ArrayList<>();
  358. for (int i = 0; i < AddressData.length; i++) {
  359. String addressDatum = AddressData[i];
  360. String value = provinceNames.getOrDefault(addressDatum, "");
  361. adList.add(value);
  362. }
  363. addList.add(String.join("/", adList));
  364. }
  365. dataMap.put(vModel, String.join(";", addList));
  366. } else if (OnlinePublicUtils.getMultiple(addressValue, MultipleControlEnum.MULTIPLE_JSON_ONE.getMultipleChar())) {
  367. List<String> proDataS = JsonUtil.getJsonToList(String.valueOf(dataMap.get(swapVModel)), String.class);
  368. Map<String, String> provinceNames = provinceService.getProList(proDataS).stream().collect(Collectors.toMap(
  369. ProvinceEntity::getId, ProvinceEntity::getFullName
  370. , (k1, k2) -> k2
  371. , () -> new LinkedHashMap<>(proDataS.size(), 1.0F)
  372. ));
  373. List<String> adList = new ArrayList<>();
  374. for (String addressDatum : proDataS) {
  375. String value = provinceNames.getOrDefault(addressDatum, "");
  376. adList.add(value);
  377. }
  378. dataMap.put(vModel, String.join("/", adList));
  379. }
  380. break;
  381. //开关
  382. case JnpfKeyConsts.SWITCH:
  383. String switchValue = String.valueOf(dataMap.get(swapVModel)).equals("1") ? swapDataVo.getActiveTxt() : swapDataVo.getInactiveTxt();
  384. dataMap.put(vModel, switchValue);
  385. break;
  386. case JnpfKeyConsts.CASCADER:
  387. case JnpfKeyConsts.RADIO:
  388. case JnpfKeyConsts.CHECKBOX:
  389. case JnpfKeyConsts.SELECT:
  390. case JnpfKeyConsts.TREESELECT:
  391. if (StringUtil.isEmpty(separator)) {
  392. separator = "/";
  393. }
  394. if (JnpfKeyConsts.CHECKBOX.equals(jnpfKey)) {
  395. isMultiple = true;
  396. }
  397. DynamicNeedCache = swapDataVo.getConfig().getTemplateJson().isEmpty();
  398. String interfacelabel = swapDataVo.getProps().getLabel() != null ? swapDataVo.getProps().getLabel() : "";
  399. String interfaceValue = swapDataVo.getProps().getValue() != null ? swapDataVo.getProps().getValue() : "";
  400. String interfaceChildren = swapDataVo.getProps().getChildren() != null ? swapDataVo.getProps().getChildren() : "";
  401. if (DynamicNeedCache) {
  402. if (OnlineDataTypeEnum.STATIC.getType().equals(dataType)) {
  403. redisKey = String.format("%s-%s-%s", visualDevId, swapDataVo.getConfig().getRelationTable() + swapDataVo.getVModel(), OnlineDataTypeEnum.STATIC.getType());
  404. } else if (dataType.equals(OnlineDataTypeEnum.DYNAMIC.getType())) {
  405. redisKey = String.format("%s-%s-%s-%s-%s-%s", dsName, OnlineDataTypeEnum.DYNAMIC.getType(), swapDataVo.getConfig().getPropsUrl(), interfaceValue, interfacelabel, interfaceChildren);
  406. } else {
  407. redisKey = String.format("%s-%s-%s", dsName, OnlineDataTypeEnum.DICTIONARY.getType(), swapDataVo.getConfig().getDictionaryType());
  408. }
  409. Map<String, Object> cascaderMap;
  410. if (dataType.equals(OnlineDataTypeEnum.DICTIONARY.getType())) {
  411. List<Map<String, Object>> checkBoxList = (List<Map<String, Object>>) localCache.get(redisKey);
  412. cascaderMap = OnlinePublicUtils.getDataMap(checkBoxList, swapDataVo);
  413. } else {
  414. cascaderMap = (Map<String, Object>) localCache.get(redisKey);
  415. }
  416. dataMap.put(vModel, FormPublicUtils.getDataConversion(cascaderMap, dataMap.get(swapVModel), isMultiple, separator));
  417. } else {
  418. List<TemplateJsonModel> templateJsonModels = JsonUtil.getJsonToList(swapDataVo.getConfig().getTemplateJson(), TemplateJsonModel.class);
  419. Map<String, String> systemFieldValue = userApi.getSystemFieldValue(new SystemParamModel(JsonUtil.getObjectToString(templateJsonModels)));
  420. if (dataCopyMap != null) {
  421. systemFieldValue.put(AuthorizeConditionEnum.FORMID.getCondition(), String.valueOf(dataCopyMap.get(FlowFormConstant.ID)));
  422. }
  423. Map<String, String> paramMap = new HashMap<>();
  424. for (TemplateJsonModel templateJsonModel : templateJsonModels) {
  425. String relationField = Objects.isNull(templateJsonModel.getRelationField()) ? "" : templateJsonModel.getRelationField();
  426. String Field = templateJsonModel.getField();
  427. String obj = inlineEdit ? "" : Optional.ofNullable(dataCopyMap.get(relationField)).orElse("").toString();
  428. if (templateJsonModel.getSourceType() != null && !Objects.equals(templateJsonModel.getSourceType(), 1)) {
  429. String dataValue = paramSourceTypeReplaceValue(templateJsonModel, systemFieldValue);
  430. paramMap.put(Field, dataValue);
  431. continue;
  432. }
  433. if (relationField.toLowerCase().contains(JnpfKeyConsts.CHILD_TABLE_PREFIX)) {
  434. String childField = relationField.split("-")[1];
  435. obj = Optional.ofNullable(dataCopyMap.get(childField)).orElse("").toString();
  436. } else if (mainAndMast != null) {
  437. obj = Optional.ofNullable(mainAndMast.get(relationField)).orElse("").toString();
  438. }
  439. paramMap.put(Field, obj);
  440. }
  441. List<Map<String, Object>> dataList = null;
  442. List<Map<String, Object>> options = new ArrayList<>();
  443. Map<String, Object> dataInterfaceMap = new HashMap();
  444. //缓存Key 租户-远端数据-id-base64({params})
  445. redisKey = String.format("%s-%s-%s-%s", dsName, OnlineDataTypeEnum.DYNAMIC.getType(), swapDataVo.getConfig().getPropsUrl(), Base64.getEncoder().encodeToString(JsonUtil.getObjectToString(paramMap).getBytes(StandardCharsets.UTF_8)));
  446. if (localCache.containsKey(redisKey) || redisUtil.exists(redisKey)) {
  447. if (localCache.containsKey(redisKey)) {
  448. dataList = (List<Map<String, Object>>) localCache.get(redisKey);
  449. } else {
  450. List<Object> tmpList = redisUtil.get(redisKey, 0, -1);
  451. List<Map<String, Object>> tmpMapList = new ArrayList<>();
  452. tmpList.forEach(item -> {
  453. tmpMapList.add(JsonUtil.entityToMap(item));
  454. });
  455. dataList = tmpMapList;
  456. localCache.put(redisKey, dataList);
  457. }
  458. } else {
  459. ActionResult data = dataInterFaceApi.infoToId(swapDataVo.getConfig().getPropsUrl(), null, paramMap);
  460. if (data != null && data.getData() != null) {
  461. if (data.getData() instanceof List) {
  462. dataList = (List<Map<String, Object>>) data.getData();
  463. if (NEEDCACHE_REMOTE && CollectionUtils.isNotEmpty(dataList) && !JnpfKeyConsts.TREESELECT.equals(jnpfKey) && swapDataVo.getConfig().getUseCache()) {
  464. redisUtil.insert(redisKey, dataList, DEFAULT_CACHE_TIME);
  465. }
  466. localCache.put(redisKey, dataList);
  467. }
  468. }
  469. }
  470. if (dataList != null) {
  471. JSONArray dataAll = JsonUtil.getListToJsonArray(dataList);
  472. treeToList(interfacelabel, interfaceValue, interfaceChildren, dataAll, options);
  473. options.forEach(o -> {
  474. dataInterfaceMap.put(String.valueOf(o.get(interfaceValue)), String.valueOf(o.get(interfacelabel)));
  475. });
  476. }
  477. dataMap.put(vModel, FormPublicUtils.getDataConversion(dataInterfaceMap, dataMap.get(swapVModel), isMultiple, separator));
  478. }
  479. break;
  480. case JnpfKeyConsts.RELATIONFORM:
  481. //取关联表单数据 按绑定功能加字段区分数据
  482. redisKey = String.format("%s-%s-%s-%s-%s", dsName, JnpfKeyConsts.RELATIONFORM, swapDataVo.getModelId(), swapDataVo.getRelationField(), dataMap.get(swapDataVo.getVModel()));
  483. VisualdevModelDataInfoVO infoVO = null;
  484. if (localCache.containsKey(redisKey) || redisUtil.exists(redisKey)) {
  485. infoVO = new VisualdevModelDataInfoVO();
  486. if (localCache.containsKey(redisKey)) {
  487. infoVO.setData(localCache.get(redisKey).toString());
  488. } else {
  489. infoVO.setData(redisUtil.getString(redisKey).toString());
  490. localCache.put(redisKey, infoVO.getData());
  491. }
  492. } else {
  493. String keyId = String.valueOf(dataMap.get(swapVModel));
  494. VisualdevEntity entity = visualdevService.getInfo(swapDataVo.getModelId());
  495. String propsValue = StringUtil.isNotEmpty(swapDataVo.getPropsValue()) && swapDataVo.getPropsValue().contains(JnpfConst.FIELD_SUFFIX_JNPFID) ?
  496. swapDataVo.getPropsValue().split(JnpfConst.FIELD_SUFFIX_JNPFID)[0] : swapDataVo.getPropsValue();
  497. if (Objects.nonNull(entity)) {
  498. infoVO = visualDevInfoService.getDetailsDataInfo(keyId, entity,
  499. OnlineInfoModel.builder().needSwap(true).needRlationFiled(false).propsValue(propsValue).build());
  500. }
  501. String data = infoVO == null ? StringUtil.EMPTY : infoVO.getData();
  502. if (NEEDCACHE_RELATION) {
  503. redisUtil.insert(redisKey, data, DEFAULT_CACHE_TIME);
  504. }
  505. localCache.put(redisKey, data);
  506. }
  507. if (infoVO != null && StringUtil.isNotEmpty(infoVO.getData())) {
  508. Map<String, Object> formDataMap = JsonUtil.stringToMap(infoVO.getData());
  509. String relationField = swapDataVo.getRelationField();
  510. if (formDataMap != null && !formDataMap.isEmpty()) {
  511. dataMap.put(swapDataVo.getVModel() + "_id", dataMap.get(swapVModel));
  512. dataMap.put(vModel, formDataMap.get(relationField));
  513. dataDetailMap.put(vModel, formDataMap);
  514. }
  515. }
  516. break;
  517. case JnpfKeyConsts.POPUPSELECT:
  518. case JnpfKeyConsts.POPUPTABLESELECT:
  519. //是否联动
  520. Map<String, String> systemFieldValue = userApi.getSystemFieldValue(new SystemParamModel(swapDataVo.getTemplateJson()));
  521. if (dataCopyMap != null) {
  522. systemFieldValue.put(AuthorizeConditionEnum.FORMID.getCondition(), String.valueOf(dataCopyMap.get(FlowFormConstant.ID)));
  523. }
  524. List<TemplateJsonModel> templateJsonModels = JsonUtil.getJsonToList(swapDataVo.getTemplateJson(), TemplateJsonModel.class);
  525. //DynamicNeedCache = templateJsonModels.size() == 0;
  526. List<Map<String, Object>> mapList;
  527. Map<String, Object> popMaps = new HashMap<>();
  528. String value = String.valueOf(dataMap.get(swapVModel));
  529. List<DataInterfaceModel> listParam = new ArrayList<>();
  530. for (TemplateJsonModel templateJsonModel : templateJsonModels) {
  531. String relationField = templateJsonModel.getRelationField();
  532. DataInterfaceModel dataInterfaceModel = JsonUtil.getJsonToBean(templateJsonModel, DataInterfaceModel.class);
  533. if (templateJsonModel.getSourceType() != null && !Objects.equals(templateJsonModel.getSourceType(), 1)) {
  534. String dataValue = paramSourceTypeReplaceValue(templateJsonModel, systemFieldValue);
  535. dataInterfaceModel.setDefaultValue(dataValue);
  536. listParam.add(dataInterfaceModel);
  537. continue;
  538. }
  539. String obj = inlineEdit ? "" : Optional.ofNullable(dataCopyMap.get(relationField)).orElse("").toString();
  540. if (relationField.toLowerCase().contains(JnpfKeyConsts.CHILD_TABLE_PREFIX)) {
  541. String childField = relationField.split("-")[1];
  542. obj = Optional.ofNullable(dataCopyMap.get(childField)).orElse("").toString();
  543. } else if (mainAndMast != null) {
  544. obj = Optional.ofNullable(mainAndMast.get(relationField)).orElse("").toString();
  545. }
  546. dataInterfaceModel.setDefaultValue(obj);
  547. listParam.add(dataInterfaceModel);
  548. }
  549. DataInterfacePage dataInterfacePage = new DataInterfacePage();
  550. dataInterfacePage.setParamList(listParam);
  551. dataInterfacePage.setInterfaceId(swapDataVo.getInterfaceId());
  552. List<String> ids = new ArrayList<>();
  553. if (value.startsWith("[")) {
  554. ids = JsonUtil.getJsonToList(value, String.class);
  555. } else {
  556. ids.add(value);
  557. }
  558. dataInterfacePage.setIds(ids);
  559. //缓存Key 租户-远端数据-base64({id, params, ids})
  560. redisKey = String.format("%s-%s-%s-%s", dsName, OnlineDataTypeEnum.DYNAMIC.getType(), swapDataVo.getInterfaceId(), Base64.getEncoder().encodeToString(JsonUtil.getObjectToString(dataInterfacePage).getBytes(StandardCharsets.UTF_8)));
  561. if (localCache.containsKey(redisKey) || redisUtil.exists(redisKey)) {
  562. if (localCache.containsKey(redisKey)) {
  563. mapList = (List<Map<String, Object>>) localCache.get(redisKey);
  564. } else {
  565. List<Object> tmpList = redisUtil.get(redisKey, 0, -1);
  566. List<Map<String, Object>> tmpMapList = new ArrayList<>();
  567. tmpList.forEach(item -> {
  568. tmpMapList.add(JsonUtil.entityToMap(item));
  569. });
  570. mapList = tmpMapList;
  571. localCache.put(redisKey, mapList);
  572. }
  573. } else {
  574. dataInterfacePage.setPropsValue(swapDataVo.getPropsValue());
  575. dataInterfacePage.setRelationField(swapDataVo.getRelationField());
  576. mapList = dataInterFaceApi.infoToInfo(swapDataVo.getInterfaceId(), dataInterfacePage);
  577. if (NEEDCACHE_REMOTE && swapDataVo.getConfig().getUseCache()) {
  578. redisUtil.insert(redisKey, mapList, DEFAULT_CACHE_TIME);
  579. }
  580. localCache.put(redisKey, mapList);
  581. }
  582. StringJoiner stringJoiner = new StringJoiner(",");
  583. List<String> popList = new ArrayList<>();
  584. if (value.startsWith("[")) {
  585. popList = JsonUtil.getJsonToList(value, String.class);
  586. } else {
  587. popList.add(value);
  588. }
  589. for (String va : popList) {
  590. if (!popMaps.isEmpty()) {
  591. stringJoiner.add(String.valueOf(popMaps.get(va)));
  592. } else {
  593. Map<String, Object> PopMap = mapList.stream().filter(map ->
  594. Objects.equals(String.valueOf(map.get(swapDataVo.getPropsValue())), va)).findFirst().orElse(new HashMap<>());
  595. if (!PopMap.isEmpty()) {
  596. dataMap.put(vModel + "_id", dataMap.get(swapVModel));
  597. stringJoiner.add(String.valueOf(PopMap.get(swapDataVo.getRelationField())));
  598. dataDetailMap.put(vModel, PopMap);
  599. }
  600. }
  601. }
  602. dataMap.put(vModel, String.valueOf(stringJoiner));
  603. break;
  604. case JnpfKeyConsts.MODIFYTIME:
  605. case JnpfKeyConsts.CREATETIME:
  606. // case JnpfKeyConsts.TIME:
  607. case JnpfKeyConsts.DATE:
  608. case JnpfKeyConsts.DATE_CALCULATE:
  609. //判断是否为时间戳格式
  610. Object dateObj = dataMap.get(swapVModel);
  611. LocalDateTime dateTime = LocalDateTimeUtil.of(new Date(DateTimeFormatConstant.getDateObjToLong(dateObj)));
  612. String format = DateTimeFormatConstant.getFormat(swapDataVo.getFormat());
  613. // if (isList && (JnpfKeyConsts.MODIFYTIME.equals(jnpfKey) || JnpfKeyConsts.CREATETIME.equals(jnpfKey))) {
  614. // format = DateTimeFormatConstant.YEAR_MOnTH_DHM;
  615. // }
  616. if (StringUtil.isEmpty(format)) {
  617. format = DateTimeFormatConstant.YEAR_MOnTH_DHMS;
  618. }
  619. DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(format);
  620. String date = dateTimeFormatter.format(dateTime);
  621. dataMap.put(vModel, date);
  622. if (JnpfKeyConsts.MODIFYTIME.equals(jnpfKey) || JnpfKeyConsts.CREATETIME.equals(jnpfKey)) {
  623. dataMap.put(swapDataVo.getVModel(), date);
  624. }
  625. break;
  626. case JnpfKeyConsts.RATE:
  627. case JnpfKeyConsts.SLIDER:
  628. //滑块评分不需要补零转浮点型
  629. Double ratevalue = (double) 0;
  630. if (dataMap.get(swapVModel) != null) {
  631. ratevalue = Double.valueOf(dataMap.get(swapVModel).toString());
  632. }
  633. dataMap.put(vModel, ratevalue);
  634. break;
  635. case JnpfKeyConsts.UPLOADFZ:
  636. case JnpfKeyConsts.UPLOADIMG:
  637. //数据传递-乱塞有bug强行置空
  638. List fileList = new ArrayList<>();
  639. try {
  640. fileList = (List) dataMap.get(swapVModel);
  641. } catch (Exception e) {
  642. try {
  643. fileList = JsonUtil.getJsonToListMap(String.valueOf(dataMap.get(swapVModel)));
  644. } catch (Exception e1) {
  645. // e1.printStackTrace();
  646. }
  647. // e.printStackTrace();
  648. }
  649. dataMap.put(vModel, fileList);
  650. break;
  651. case JnpfKeyConsts.LOCATION:
  652. //定位-列表取全名。
  653. if (isList) {
  654. Map omap = JsonUtil.stringToMap(String.valueOf(dataMap.get(swapVModel)));
  655. dataMap.put(vModel, omap.get("fullAddress") != null ? omap.get("fullAddress") : "");
  656. }
  657. break;
  658. case JnpfKeyConsts.CHILD_TABLE:
  659. List<FieLdsModel> childrens = swapDataVo.getConfig().getChildren();
  660. List<Map<String, Object>> childList = (List<Map<String, Object>>) dataMap.get(swapDataVo.getVModel());
  661. List<Map<String, Object>> swapList = getSwapList(childList, childrens, visualDevId, inlineEdit, localCache, isList, dataCopyMap);
  662. dataMap.put(swapDataVo.getVModel(), swapList);
  663. break;
  664. default:
  665. dataMap.put(vModel, dataMap.get(swapVModel));
  666. break;
  667. }
  668. }
  669. //关联选择属性
  670. if (!dataDetailMap.isEmpty()) {
  671. getDataAttr(swapDataVoList, dataMap, dataDetailMap);
  672. }
  673. } catch (Exception e) {
  674. e.printStackTrace();
  675. log.error("在线开发转换数据错误:" + e.getMessage());
  676. }
  677. }
  678. //二维码 条形码最后处理
  679. swapCodeDataInfo(swapDataVoList, dataMap, dataCopyMap);
  680. }
  681. if (inlineEdit && isList) {
  682. for (Map<String, Object> map : list) {
  683. //行内编辑过滤子表
  684. swapDataVoList = swapDataVoList.stream().filter(s -> !s.getVModel().toLowerCase().contains("tablefield")).collect(Collectors.toList());
  685. onlineDevInfoUtils.getInitLineData(swapDataVoList, map, localCache);
  686. }
  687. }
  688. return list;
  689. }
  690. private static void getTreeName(Map<String, Object> dataMap, String swapVModel, Map<String, Object> posMap, String vModel) {
  691. String posIds = String.valueOf(dataMap.get(swapVModel));
  692. StringJoiner posName = new StringJoiner(",");
  693. List<String> posList = new ArrayList<>();
  694. try {
  695. posList = JsonUtil.getJsonToList(posIds, String.class);
  696. } catch (Exception e) {
  697. posList.add(posIds);
  698. }
  699. if (!posList.isEmpty()) {
  700. for (String t : posList) {
  701. if (posMap.get(t) != null) {
  702. posName.add(posMap.get(t).toString());
  703. }
  704. }
  705. }
  706. if (posName.length() > 0) {
  707. dataMap.put(vModel, posName.toString());
  708. } else {
  709. dataMap.put(vModel, " ");
  710. }
  711. }
  712. /**
  713. * 按sourceType替换数据接口参数
  714. */
  715. public String paramSourceTypeReplaceValue(TemplateJsonModel item, Map<String, String> systemFieldValue) {
  716. String defaultValue = "";
  717. if (item.getSourceType() != null) {
  718. switch (item.getSourceType()) {
  719. case 1://字段
  720. defaultValue = item.getDefaultValue();
  721. break;
  722. case 2://自定义
  723. defaultValue = item.getRelationField();
  724. break;
  725. case 3://为空
  726. defaultValue = "";
  727. break;
  728. case 4://系统参数
  729. defaultValue = this.getSystemFieldValue(item, systemFieldValue);
  730. break;
  731. default:
  732. defaultValue = item.getDefaultValue();
  733. break;
  734. }
  735. } else {
  736. defaultValue = item.getDefaultValue();
  737. }
  738. return defaultValue;
  739. }
  740. /**
  741. * 获取系统参数值
  742. *
  743. * @param templateJsonModel
  744. * @param systemFieldValue
  745. * @return
  746. */
  747. private String getSystemFieldValue(TemplateJsonModel templateJsonModel, Map<String, String> systemFieldValue) {
  748. String relationField = templateJsonModel.getRelationField();
  749. String dataValue;
  750. if (AuthorizeConditionEnum.getResListType().contains(relationField)) {
  751. List<String> strings = StringUtil.isNotEmpty(systemFieldValue.get(relationField)) ?
  752. JsonUtil.getJsonToList(systemFieldValue.get(relationField), String.class) : Collections.EMPTY_LIST;
  753. dataValue = CollectionUtil.isEmpty(strings) ? "" : String.join(",", strings);
  754. } else if (systemFieldValue.containsKey(relationField)) {
  755. dataValue = systemFieldValue.get(relationField);
  756. } else {
  757. dataValue = templateJsonModel.getDefaultValue();
  758. }
  759. return dataValue;
  760. }
  761. private List<Map<String, String>> fillProMap(String dsName) {
  762. List<Map<String, String>> proMapList = new ArrayList<>();
  763. //分级存储
  764. for (int i = 1; i <= 4; i++) {
  765. String redisKey = String.format("%s-%s-%d", dsName, "province", i);
  766. if (!redisUtil.exists(redisKey)) {
  767. List<ProvinceEntity> provinceEntityList = areaApi.getProListBytype(String.valueOf(i));
  768. Map<String, String> provinceMap = new HashMap<>(16);
  769. if (provinceEntityList != null) {
  770. provinceEntityList.stream().forEach(p -> provinceMap.put(p.getId(), p.getFullName()));
  771. }
  772. proMapList.add(provinceMap);
  773. //区划基本不修改 不做是否缓存判断
  774. redisUtil.insert(redisKey, provinceMap, RedisUtil.CAHCEWEEK);
  775. }
  776. }
  777. return proMapList;
  778. }
  779. /**
  780. * 级联递归
  781. *
  782. * @param value
  783. * @param label
  784. * @param children
  785. * @param data
  786. * @param result
  787. */
  788. public static void treeToList(String value, String label, String children, JSONArray data, List<Map<String, Object>> result) {
  789. for (int i = 0; i < data.size(); i++) {
  790. JSONObject ob = data.getJSONObject(i);
  791. Map<String, Object> tree = new HashMap<>(16);
  792. tree.put(value, String.valueOf(ob.get(value)));
  793. tree.put(label, String.valueOf(ob.get(label)));
  794. result.add(tree);
  795. if (ob.get(children) != null) {
  796. JSONArray childArray = ob.getJSONArray(children);
  797. treeToList(value, label, children, childArray, result);
  798. }
  799. }
  800. }
  801. /**
  802. * 递归查询
  803. *
  804. * @param label
  805. * @param value
  806. * @param Children
  807. * @param data
  808. * @param options
  809. */
  810. public static void getOptions(String label, String value, String Children, JSONArray data, List<Map<String, Object>> options) {
  811. for (int i = 0; i < data.size(); i++) {
  812. JSONObject ob = data.getJSONObject(i);
  813. Map<String, Object> tree = new HashMap<>(16);
  814. tree.put(value, String.valueOf(ob.get(value)));
  815. tree.put(label, String.valueOf(ob.get(label)));
  816. options.add(tree);
  817. if (ob.get(Children) != null) {
  818. JSONArray childrenArray = ob.getJSONArray(Children);
  819. getOptions(label, value, Children, childrenArray, options);
  820. }
  821. }
  822. }
  823. /**
  824. * 生成关联属性(弹窗选择属性,关联表单属性)
  825. *
  826. * @param fieLdsModelList
  827. * @param dataMap
  828. * @param dataDetailMap
  829. */
  830. private static void getDataAttr(List<FieLdsModel> fieLdsModelList, Map<String, Object> dataMap, Map<String, Map<String, Object>> dataDetailMap) {
  831. for (FieLdsModel fieLdsModel : fieLdsModelList) {
  832. if (ObjectUtil.isEmpty(fieLdsModel)) {
  833. continue;
  834. }
  835. ConfigModel config = fieLdsModel.getConfig();
  836. String jnpfKey = config.getJnpfKey();
  837. if (jnpfKey.equals(JnpfKeyConsts.RELATIONFORM_ATTR) || jnpfKey.equals(JnpfKeyConsts.POPUPSELECT_ATTR)) {
  838. //0展示数据 ? 1存储数据
  839. boolean isShow = fieLdsModel.getIsStorage() == 0;
  840. if (isShow) {
  841. String relationField = fieLdsModel.getRelationField();
  842. if (relationField.contains("_jnpfTable_")) {
  843. relationField = relationField.split("_jnpfTable_")[0];
  844. }
  845. String showField = fieLdsModel.getShowField();
  846. Map<String, Object> formDataMap = dataDetailMap.get(relationField);
  847. if (formDataMap != null) {
  848. dataMap.put(relationField + "_" + showField, formDataMap.get(showField));
  849. }
  850. }
  851. }
  852. }
  853. }
  854. /**
  855. * 二维码 条形码详情数据
  856. *
  857. * @param codeList 控件集合
  858. * @param swapDataMap 转换后的数据
  859. * @param dataMap 转换前
  860. * @return
  861. */
  862. public static void swapCodeDataInfo(List<FieLdsModel> codeList, Map<String, Object> swapDataMap, Map<String, Object> dataMap) {
  863. for (FieLdsModel formModel : codeList) {
  864. String jnpfKey = formModel.getConfig().getJnpfKey();
  865. if (jnpfKey.equals(JnpfKeyConsts.QR_CODE) || jnpfKey.equals(JnpfKeyConsts.BARCODE)) {
  866. String codeDataType = formModel.getDataType();
  867. if (OnlineDataTypeEnum.RELATION.getType().equals(codeDataType)) {
  868. String relationFiled = formModel.getRelationField();
  869. if (StringUtil.isNotEmpty(relationFiled)) {
  870. Object relationValue = dataMap.get(relationFiled);
  871. if (ObjectUtil.isNotEmpty(relationValue)) {
  872. swapDataMap.put(relationFiled + "_id", relationValue);
  873. }
  874. }
  875. }
  876. }
  877. }
  878. }
  879. public ExcelImportModel createExcelData(List<Map<String, Object>> dataList, VisualDevJsonModel visualJsonModel, VisualdevEntity visualdevEntity) throws WorkFlowException {
  880. ExcelImportModel excelImportModel = new ExcelImportModel();
  881. Integer primaryKeyPolicy = visualJsonModel.getFormData().getPrimaryKeyPolicy();
  882. String uploaderTemplateJson = visualJsonModel.getColumnData().getUploaderTemplateJson();
  883. UploaderTemplateModel uploaderTemplateModel = JsonUtil.getJsonToBean(uploaderTemplateJson, UploaderTemplateModel.class);
  884. String dataType = uploaderTemplateModel.getDataType();
  885. ImportFormCheckUniqueModel uniqueModel = new ImportFormCheckUniqueModel();
  886. uniqueModel.setMain(true);
  887. uniqueModel.setDbLinkId(visualJsonModel.getDbLinkId());
  888. uniqueModel.setUpdate(dataType.equals("2"));
  889. uniqueModel.setPrimaryKeyPolicy(primaryKeyPolicy);
  890. uniqueModel.setLogicalDelete(visualJsonModel.getFormData().getLogicalDelete());
  891. uniqueModel.setTableModelList(visualJsonModel.getVisualTables());
  892. DbLinkEntity linkEntity = dataSourceApi.getInfo(visualJsonModel.getDbLinkId());
  893. uniqueModel.setLinkEntity(linkEntity);
  894. //流程表单导入,传流程大id查询小idlist用于过滤数据
  895. String mainFlowID = null;
  896. if (StringUtil.isNotEmpty(visualJsonModel.getFlowId())) {
  897. List<TemplateJsonEntity> flowVersionIds = templateApi.getFlowIdsByTemplate(visualJsonModel.getFlowId());
  898. uniqueModel.setFlowId(visualJsonModel.getFlowId());
  899. uniqueModel.setFlowIdList(flowVersionIds.stream().map(TemplateJsonEntity::getId).distinct().collect(Collectors.toList()));
  900. mainFlowID = flowVersionIds.stream().filter(t -> Objects.equals(t.getState(), 1)).findFirst().orElse(new TemplateJsonEntity()).getId();
  901. }
  902. //获取缓存
  903. Map<String, Object> localCache = getlocalCache();
  904. List<Map<String, Object>> failResult = new ArrayList<>();
  905. List<VisualdevModelDataInfoVO> dataInfo = new ArrayList<>();
  906. try {
  907. for (int i = 0, len = dataList.size(); i < len; i++) {
  908. Map<String, Object> data = dataList.get(i);
  909. //导入时默认第一个流程
  910. data.put(FlowFormConstant.FLOWID, mainFlowID);
  911. Map<String, Object> resultMap = new HashMap<>(data);
  912. StringJoiner errInfo = new StringJoiner(",");
  913. Map<String, Object> errorMap = new HashMap<>(data);
  914. List<String> errList = this.checkExcelData(visualJsonModel.getFormListModels(), data, localCache, resultMap, errorMap, uniqueModel);
  915. //业务主键判断--导入新增或者跟新
  916. VisualErrInfo visualErrInfo;
  917. try {
  918. DynamicDataSourceUtil.switchToDataSource(linkEntity);
  919. visualErrInfo = formCheckUtils.checkBusinessKey(visualJsonModel.getFormListModels(), resultMap,
  920. visualJsonModel.getVisualTables(), visualJsonModel.getFormData(), null);
  921. } finally {
  922. DynamicDataSourceUtil.clearSwitchDataSource();
  923. }
  924. if (uniqueModel.isUpdate()) {
  925. if (ObjectUtil.isNotEmpty(visualErrInfo) && StringUtil.isNotEmpty(visualErrInfo.getId())) {
  926. uniqueModel.setId(visualErrInfo.getId());
  927. //判断流程是否已发起
  928. if (StringUtil.isNotEmpty(visualErrInfo.getFlowTaskId())) {
  929. String finalTaskId = visualErrInfo.getFlowTaskId();
  930. List<String> flowIdList = new ArrayList<>();
  931. flowIdList.add(finalTaskId);
  932. List<TaskEntity> tasks = taskApi.getInfosSubmit(flowIdList.toArray(new String[]{}), TaskEntity::getStatus, TaskEntity::getId);
  933. if (tasks.size() > 0) {
  934. boolean errorMsg = tasks.stream().filter(t -> Objects.equals(t.getStatus(), 0)).count() == 0;
  935. String msg = "已发起流程,导入失败";
  936. if (errorMsg) {
  937. errorMap.put("errorsInfo", msg);
  938. failResult.add(errorMap);
  939. continue;
  940. }
  941. }
  942. }
  943. }
  944. } else {
  945. if (ObjectUtil.isNotEmpty(visualErrInfo) && StringUtil.isNotEmpty(visualErrInfo.getErrMsg())) {
  946. errorMap.put("errorsInfo", visualErrInfo.getErrMsg());
  947. failResult.add(errorMap);
  948. continue;
  949. }
  950. }
  951. this.checkUnique(visualJsonModel.getFormListModels(), data, errList, uniqueModel);
  952. errList.stream().forEach(t -> {
  953. if (StringUtil.isNotEmpty(t)) {
  954. errInfo.add(t);
  955. }
  956. });
  957. if (errInfo.length() > 0) {
  958. errorMap.put("errorsInfo", errInfo.toString());
  959. failResult.add(errorMap);
  960. } else {
  961. VisualdevModelDataInfoVO infoVO = new VisualdevModelDataInfoVO();
  962. if (StringUtil.isNotEmpty(uniqueModel.getId())) {
  963. visualdevModelDataService.visualUpdate(
  964. VisualParamModel.builder().visualdevEntity(visualdevEntity).data(resultMap).id(uniqueModel.getId()).isUpload(true).build());
  965. infoVO.setId(uniqueModel.getId());
  966. infoVO.setIntegrateId(uniqueModel.getId());
  967. infoVO.setData(JsonUtil.getObjectToString(resultMap));
  968. } else {
  969. DataModel dataModel = visualdevModelDataService.visualCreate(
  970. VisualParamModel.builder().visualdevEntity(visualdevEntity).data(resultMap).isUpload(true).build());
  971. infoVO.setId(dataModel.getMainId());
  972. infoVO.setData(JsonUtil.getObjectToString(resultMap));
  973. }
  974. dataInfo.add(infoVO);
  975. }
  976. }
  977. } catch (Exception e) {
  978. e.printStackTrace();
  979. throw new WorkFlowException(MsgCode.IMP004.get());
  980. } finally {
  981. DynamicDataSourceUtil.clearSwitchDataSource();
  982. }
  983. excelImportModel.setFnum(failResult.size());
  984. excelImportModel.setSnum(dataList.size() - failResult.size());
  985. excelImportModel.setResultType(failResult.size() > 0 ? 1 : 0);
  986. excelImportModel.setFailResult(failResult);
  987. excelImportModel.setDataInfoList(dataInfo);
  988. return excelImportModel;
  989. }
  990. /**
  991. * 获取系统控件缓存数据
  992. */
  993. public Map<String, Object> getlocalCache() {
  994. Map<String, Object> localCache = new HashMap<>();
  995. //读取系统控件 所需编码 id
  996. Map<String, Object> depMap = organizeApi.getOrgEncodeAndName("department");
  997. localCache.put("_dep_map", depMap);
  998. Map<String, Object> comMap = organizeApi.getOrgNameAndId("");
  999. localCache.put("_com_map", comMap);
  1000. Map<String, String> posMap = positionApi.getPosFullNameMap();
  1001. localCache.put("_pos_map", posMap);
  1002. Map<String, Object> userMap = userApi.getUserNameAndIdMap();
  1003. localCache.put("_user_map", userMap);
  1004. Map<String, Object> roleMap = roleApi.getRoleNameAndIdMap();
  1005. localCache.put("_role_map", roleMap);
  1006. Map<String, Object> groupMap = groupApi.getGroupEncodeMap();
  1007. localCache.put("_group_map", groupMap);
  1008. Map<String, Object> allOrgsTreeName = organizeApi.getAllOrgsTreeName();
  1009. localCache.put("_com_tree_map", allOrgsTreeName);
  1010. return localCache;
  1011. }
  1012. /**
  1013. * 获取组织id
  1014. *
  1015. * @param type
  1016. * @param isTree true 返回【xxx,xxx】json树形列表 | false 返回 xxx 最后组织id列表
  1017. * @return
  1018. */
  1019. public List<String> orgList(String type, boolean isTree, Map<String, String> orgIdNameMaps) {
  1020. List<String> org = new ArrayList() {{
  1021. add(type);
  1022. }};
  1023. OrganizeConditionModel orgType = new OrganizeConditionModel();
  1024. orgType.setDepartIds(org);
  1025. orgType.setOrgIdNameMaps(orgIdNameMaps);
  1026. List<String> orgList = new ArrayList<>();
  1027. List<OrganizeModel> orgIdsList = organizeApi.getOrgIdsList(orgType);
  1028. for (OrganizeModel organizeModel : orgIdsList) {
  1029. if (isTree) {
  1030. List<String> treeList = StringUtil.isNotEmpty(organizeModel.getOrganizeIdTree()) ? Arrays.asList(organizeModel.getOrganizeIdTree().split(",")) : new ArrayList<>();
  1031. orgList.add(JsonUtil.getListToJsonArray(treeList).toJSONString());
  1032. } else {
  1033. orgList.add(organizeModel.getId());
  1034. }
  1035. }
  1036. return orgList;
  1037. }
  1038. public List<String> checkExcelData(List<FieLdsModel> modelList, Map<String, Object> data, Map<String, Object> localCache, Map<String, Object> insMap,
  1039. Map<String, Object> errorMap, ImportFormCheckUniqueModel uniqueModel) {
  1040. List<String> errList = new ArrayList<>(modelList.size());
  1041. try {
  1042. UserInfo userInfo = UserProvider.getUser();
  1043. UserEntity userEntity = userApi.getInfo(userInfo.getUserId());
  1044. //读取系统控件 所需编码 id
  1045. Map<String, Object> depMap = (Map<String, Object>) localCache.get("_dep_map");
  1046. Map<String, Object> comMap = (Map<String, Object>) localCache.get("_com_map");
  1047. Map<String, Object> posMap = (Map<String, Object>) localCache.get("_pos_map");
  1048. //key value对调
  1049. posMap = posMap.entrySet().stream().collect(Collectors.toMap(t -> String.valueOf(t.getValue()), Map.Entry::getKey, (e, r) -> r));
  1050. Map<String, Object> userMap = (Map<String, Object>) localCache.get("_user_map");
  1051. Map<String, Object> roleMap = (Map<String, Object>) localCache.get("_role_map");
  1052. Map<String, Object> groupMap = (Map<String, Object>) localCache.get("_group_map");
  1053. Map<String, Object> allOrgsTreeName = (Map<String, Object>) localCache.get("_com_tree_map");
  1054. //系统参数,及xxxx--当前组织数据缓存
  1055. Map<String, List<String>> allTypeMap = new HashMap<>();
  1056. allTypeMap = localCache.containsKey("allTypeMap") ? (Map<String, List<String>>) localCache.get("allTypeMap") : allTypeMap;
  1057. //异常数据
  1058. for (int i = 0; i < modelList.size(); i++) {
  1059. FieLdsModel swapDataVo = modelList.get(i);
  1060. errList.add(i, "");
  1061. try {
  1062. String jnpfKey = swapDataVo.getConfig().getJnpfKey();
  1063. String dataType = swapDataVo.getConfig().getDataType();
  1064. Object valueO = data.get(swapDataVo.getVModel());
  1065. String label = swapDataVo.getConfig().getLabel();
  1066. //不支持导入控件
  1067. if (JnpfKeyConsts.getUploadMaybeNull().contains(jnpfKey)) {
  1068. insMap.put(swapDataVo.getVModel(), null);
  1069. continue;
  1070. }
  1071. //是否必填
  1072. boolean required = swapDataVo.getConfig().isRequired();
  1073. if (valueO == null || "null".equals(valueO) || StringUtil.isEmpty(String.valueOf(valueO))) {
  1074. if (required) {
  1075. errList.set(i, label + "不能为空");
  1076. }
  1077. continue;
  1078. }
  1079. String value = String.valueOf(valueO);
  1080. if (StringUtil.isEmpty(value)) {
  1081. continue;
  1082. }
  1083. Boolean multiple = swapDataVo.getMultiple();
  1084. if (JnpfKeyConsts.CHECKBOX.equals(jnpfKey)) {
  1085. multiple = true;
  1086. }
  1087. if (JnpfKeyConsts.CASCADER.equals(jnpfKey)) {
  1088. multiple = swapDataVo.getMultiple();
  1089. }
  1090. boolean valueMul = value.contains(",");
  1091. value = value.trim();
  1092. List<String> valueList = valueMul ? Arrays.asList(value.split(",")) : new ArrayList<>();
  1093. if (!valueMul) {
  1094. valueList.add(value);
  1095. }
  1096. String ableIds = swapDataVo.getAbleIds() != null ? swapDataVo.getAbleIds() : "[]";
  1097. List<String> ableList = JsonUtil.getJsonToList(ableIds, String.class);
  1098. //处理自定义范围:系统参数及、选中组织、选中组织及子组织、选中组织及子孙组织、
  1099. OnlineCusCheckModel cusCheckModel = getSystemParamIds(ableList, allTypeMap, jnpfKey);
  1100. cusCheckModel.setControlType(jnpfKey);
  1101. List<String> dataList;
  1102. switch (jnpfKey) {
  1103. case JnpfKeyConsts.NUM_INPUT:
  1104. String regNum = "-?\\d+(\\.\\d+)?";
  1105. if (StringUtil.isNotEmpty(value) && !value.matches(regNum)) {
  1106. errList.set(i, label + "值不正确");
  1107. break;
  1108. }
  1109. //有精度,验证精度
  1110. BigDecimal valueDecimal = null;
  1111. try {
  1112. valueDecimal = new BigDecimal(value);
  1113. } catch (Exception e) {
  1114. }
  1115. if (valueDecimal == null) {
  1116. errList.set(i, label + "值不正确");
  1117. break;
  1118. }
  1119. int configPrecision = swapDataVo.getPrecision() == null ? 0 : swapDataVo.getPrecision();
  1120. if (valueDecimal.scale() > configPrecision) {
  1121. errList.set(i, label + "值的精度不正确");
  1122. break;
  1123. }
  1124. if (swapDataVo.getMin() != null) {
  1125. if (valueDecimal.compareTo(new BigDecimal(swapDataVo.getMin())) < 0) {
  1126. errList.set(i, label + "值不能小于最小值");
  1127. break;
  1128. }
  1129. }
  1130. if (swapDataVo.getMax() != null) {
  1131. if (valueDecimal.compareTo(new BigDecimal(swapDataVo.getMax())) > 0) {
  1132. errList.set(i, label + "值不能大于最大值");
  1133. break;
  1134. }
  1135. }
  1136. break;
  1137. /**
  1138. * 高级控件
  1139. */
  1140. case JnpfKeyConsts.COMSELECT:
  1141. if (!multiple && valueList.size() > 1) {
  1142. errList.set(i, label + "值不正确");
  1143. break;
  1144. }
  1145. //验证值是否正确
  1146. // List<List<String>> comTwoList = new ArrayList<>();
  1147. List<String> comOneList = new ArrayList<>();
  1148. boolean comErrorHapen = false;
  1149. for (String comValue : valueList) {
  1150. if (StringUtil.isEmpty(comValue)) {
  1151. errList.set(i, label + "值不正确");
  1152. comErrorHapen = true;
  1153. break;
  1154. }
  1155. boolean find = false;
  1156. for (String key : allOrgsTreeName.keySet()) {
  1157. Object o = allOrgsTreeName.get(key);
  1158. if (comValue.equals(o.toString())) {
  1159. comOneList.add(key);
  1160. find = true;
  1161. break;
  1162. }
  1163. }
  1164. if (!find) {
  1165. errList.set(i, label + "值不正确");
  1166. comErrorHapen = true;
  1167. break;
  1168. }
  1169. }
  1170. if (comErrorHapen) {
  1171. break;
  1172. }
  1173. //判断是否是可选范围
  1174. insMap.put(swapDataVo.getVModel(), !multiple ? (comOneList.size() > 0 ? comOneList.get(0) : "") : JsonUtil.getObjectToString(comOneList));
  1175. if ("custom".equals(swapDataVo.getSelectType())) {
  1176. cusCheckModel.setDataList(comOneList);
  1177. checkCustomControl(cusCheckModel, errList, i, label);
  1178. }
  1179. break;
  1180. case JnpfKeyConsts.DEPSELECT:
  1181. dataList = checkOptionsControl(multiple, insMap, swapDataVo.getVModel(), label, depMap, valueList, errList, i);
  1182. if (dataList.size() == valueList.size() && swapDataVo.getSelectType().equals("custom")) {
  1183. cusCheckModel.setDataList(dataList);
  1184. checkCustomControl(cusCheckModel, errList, i, label);
  1185. }
  1186. break;
  1187. case JnpfKeyConsts.POSSELECT:
  1188. dataList = checkOptionsControl(multiple, insMap, swapDataVo.getVModel(), label, posMap, valueList, errList, i);
  1189. if (dataList.size() == valueList.size() && swapDataVo.getSelectType().equals("custom")) {
  1190. cusCheckModel.setDataList(dataList);
  1191. checkCustomControl(cusCheckModel, errList, i, label);
  1192. }
  1193. break;
  1194. case JnpfKeyConsts.USERSELECT:
  1195. dataList = checkOptionsControl(multiple, insMap, swapDataVo.getVModel(), label, userMap, valueList, errList, i);
  1196. if (dataList.size() == valueList.size() && swapDataVo.getSelectType().equals("custom")) {
  1197. cusCheckModel.setDataList(dataList);
  1198. checkCustomControl(cusCheckModel, errList, i, label);
  1199. }
  1200. break;
  1201. case JnpfKeyConsts.CUSTOMUSERSELECT:
  1202. boolean cusUserErrorHapen = false;
  1203. if (!multiple) {
  1204. //非多选填入多选值
  1205. if (valueList.size() > 1) {
  1206. cusUserErrorHapen = true;
  1207. errList.set(i, label + "值不正确");
  1208. }
  1209. }
  1210. if (!cusUserErrorHapen) {
  1211. boolean cusUserErrorHapen1 = false;
  1212. List<String> cusUserList = new ArrayList<>();
  1213. for (String va : valueList) {
  1214. if (StringUtil.isEmpty(va)) {
  1215. cusUserErrorHapen1 = true;
  1216. break;
  1217. }
  1218. String type = null;
  1219. String id = null;
  1220. if (groupMap.get(va) != null) {
  1221. type = "group";
  1222. id = groupMap.get(va).toString();
  1223. } else if (roleMap.get(va) != null) {
  1224. type = "role";
  1225. id = roleMap.get(va).toString();
  1226. } else if (depMap.get(va) != null) {
  1227. type = "department";
  1228. id = depMap.get(va).toString();
  1229. } else if (comMap.get(va) != null) {
  1230. type = "company";
  1231. id = comMap.get(va).toString();
  1232. } else if (posMap.get(va) != null) {
  1233. type = "position";
  1234. id = posMap.get(va).toString();
  1235. } else if (userMap.get(va) != null) {
  1236. type = "user";
  1237. id = userMap.get(va).toString();
  1238. }
  1239. if (type == null && id == null) {
  1240. cusUserErrorHapen1 = true;
  1241. } else {
  1242. String lastCusId = id + "--" + type;
  1243. cusUserList.add(lastCusId);
  1244. }
  1245. }
  1246. if (cusUserErrorHapen1) {
  1247. errList.set(i, label + "值不正确");
  1248. } else {
  1249. insMap.put(swapDataVo.getVModel(), !multiple ? cusUserList.get(0) : JsonUtil.getObjectToString(cusUserList));
  1250. if (swapDataVo.getSelectType().equals("custom")) {
  1251. cusCheckModel.setDataList(cusUserList);
  1252. checkCustomControl(cusCheckModel, errList, i, label);
  1253. }
  1254. }
  1255. }
  1256. break;
  1257. case JnpfKeyConsts.ROLESELECT:
  1258. dataList = checkOptionsControl(multiple, insMap, swapDataVo.getVModel(), label, roleMap, valueList, errList, i);
  1259. if (dataList.size() == valueList.size() && swapDataVo.getSelectType().equals("custom")) {
  1260. cusCheckModel.setDataList(dataList);
  1261. checkCustomControl(cusCheckModel, errList, i, label);
  1262. }
  1263. break;
  1264. case JnpfKeyConsts.GROUPSELECT:
  1265. dataList = checkOptionsControl(multiple, insMap, swapDataVo.getVModel(), label, groupMap, valueList, errList, i);
  1266. if (dataList.size() == valueList.size() && swapDataVo.getSelectType().equals("custom")) {
  1267. cusCheckModel.setDataList(dataList);
  1268. checkCustomControl(cusCheckModel, errList, i, label);
  1269. }
  1270. break;
  1271. case JnpfKeyConsts.ADDRESS:
  1272. if (!multiple && valueList.size() > 1) {
  1273. errList.set(i, label + "值不正确");
  1274. break;
  1275. }
  1276. boolean errorHapen = false;
  1277. valueList = Arrays.asList(value.split(","));
  1278. List<String[]> addresss = new ArrayList<>();
  1279. List<String> addressList1 = new ArrayList<>();
  1280. for (String va : valueList) {
  1281. if (StringUtil.isEmpty(va)) {
  1282. errList.set(i, label + "值不正确");
  1283. errorHapen = true;
  1284. break;
  1285. }
  1286. String[] addressSplit = va.split("/");
  1287. if (addressSplit.length != swapDataVo.getLevel() + 1) {
  1288. errList.set(i, label + "值的格式不正确");
  1289. errorHapen = true;
  1290. break;
  1291. }
  1292. List<String> addressJoined = new ArrayList<>();
  1293. List<String> addressParentID = new ArrayList<>();
  1294. for (String add : addressSplit) {
  1295. ProvinceEntity PRO = areaApi.getInfo(add, addressParentID);
  1296. if (PRO == null) {
  1297. errList.set(i, label + "值不正确");
  1298. errorHapen = true;
  1299. break;
  1300. } else {
  1301. addressJoined.add(PRO.getId());
  1302. addressParentID.add(PRO.getId());
  1303. }
  1304. }
  1305. if (errorHapen) {
  1306. break;
  1307. }
  1308. addressList1.addAll(addressJoined);
  1309. addresss.add(addressJoined.toArray(new String[addressJoined.size()]));
  1310. }
  1311. if (errorHapen) {
  1312. break;
  1313. }
  1314. insMap.put(swapDataVo.getVModel(), multiple ? JsonUtil.getObjectToString(addresss) : JsonUtil.getObjectToString(addressList1));
  1315. break;
  1316. /**
  1317. * 系统控件
  1318. */
  1319. case JnpfKeyConsts.CURRORGANIZE:
  1320. List<UserRelationEntity> OrgRelations = userRelationApi.getListByUserId(userInfo.getUserId(), PermissionConst.ORGANIZE);
  1321. insMap.put(swapDataVo.getVModel(), OrgRelations.size() > 0 ? OrgRelations.get(0).getObjectId() : null);
  1322. break;
  1323. case JnpfKeyConsts.CURRDEPT:
  1324. List<UserRelationEntity> depUserRelations = userRelationApi.getListByUserId(userInfo.getUserId(), PermissionConst.DEPARTMENT);
  1325. insMap.put(swapDataVo.getVModel(), depUserRelations.size() > 0 ? depUserRelations.get(0).getObjectId() : null);
  1326. break;
  1327. case JnpfKeyConsts.CREATEUSER:
  1328. insMap.put(swapDataVo.getVModel(), userEntity.getId());
  1329. break;
  1330. case JnpfKeyConsts.CREATETIME:
  1331. insMap.put(swapDataVo.getVModel(), DateUtil.getNow());
  1332. break;
  1333. case JnpfKeyConsts.MODIFYTIME:
  1334. break;
  1335. case JnpfKeyConsts.MODIFYUSER:
  1336. break;
  1337. case JnpfKeyConsts.CURRPOSITION:
  1338. insMap.put(swapDataVo.getVModel(), userEntity.getPositionId());
  1339. break;
  1340. /**
  1341. * 基础控件
  1342. */
  1343. case JnpfKeyConsts.SWITCH:
  1344. String activeTxt = swapDataVo.getActiveTxt();
  1345. String inactiveTxt = swapDataVo.getInactiveTxt();
  1346. if (value.equals(activeTxt)) {
  1347. insMap.put(swapDataVo.getVModel(), 1);
  1348. } else if (value.equals(inactiveTxt)) {
  1349. insMap.put(swapDataVo.getVModel(), 0);
  1350. } else {
  1351. errList.set(i, label + "值不正确");
  1352. }
  1353. break;
  1354. case JnpfKeyConsts.RATE:
  1355. Double ratevalue = null;
  1356. try {
  1357. ratevalue = Double.valueOf(value);
  1358. if (ratevalue == null) {
  1359. errList.set(i, label + "值不正确");
  1360. break;
  1361. }
  1362. } catch (Exception e) {
  1363. errList.set(i, label + "值不正确");
  1364. break;
  1365. }
  1366. Double maxvalue = Double.valueOf(0);
  1367. if (swapDataVo.getCount() != -1) {
  1368. maxvalue = Double.valueOf(swapDataVo.getCount());
  1369. }
  1370. if (ratevalue > maxvalue) {
  1371. errList.set(i, label + "值不能大于最大值");
  1372. break;
  1373. }
  1374. if (swapDataVo.getAllowhalf()) {
  1375. if (ratevalue % 0.5 != 0 || ratevalue < 0) {
  1376. errList.set(i, label + "值不正确");
  1377. }
  1378. } else {
  1379. if (ratevalue % 1 != 0 || ratevalue < 0) {
  1380. errList.set(i, label + "值不正确");
  1381. }
  1382. }
  1383. insMap.put(swapDataVo.getVModel(), ratevalue);
  1384. break;
  1385. case JnpfKeyConsts.SLIDER:
  1386. BigDecimal Ivalue = null;
  1387. try {
  1388. Ivalue = new BigDecimal(value);
  1389. if (Ivalue == null) {
  1390. errList.set(i, label + "值不正确");
  1391. break;
  1392. }
  1393. } catch (Exception e) {
  1394. errList.set(i, label + "值不正确");
  1395. break;
  1396. }
  1397. if (swapDataVo.getMin() != null) {
  1398. BigDecimal min = new BigDecimal(swapDataVo.getMin());
  1399. if (Ivalue.compareTo(min) == -1) {
  1400. errList.set(i, label + "值不能小于最小值");
  1401. break;
  1402. }
  1403. }
  1404. if (swapDataVo.getMax() != null) {
  1405. BigDecimal max = new BigDecimal(swapDataVo.getMax());
  1406. if (Ivalue.compareTo(max) == 1) {
  1407. errList.set(i, label + "值不能大于最大值");
  1408. break;
  1409. }
  1410. }
  1411. insMap.put(swapDataVo.getVModel(), Ivalue);
  1412. break;
  1413. case JnpfKeyConsts.TEXTAREA:
  1414. if (StringUtil.isNotEmpty(swapDataVo.getMaxlength())) {
  1415. if (value.length() > Integer.valueOf(swapDataVo.getMaxlength())) {
  1416. errList.set(i, label + "值超出最多输入字符限制");
  1417. break;
  1418. }
  1419. }
  1420. break;
  1421. case JnpfKeyConsts.COM_INPUT:
  1422. //只验证子表。主副表在外面做唯一验证
  1423. Boolean unique = swapDataVo.getConfig().getUnique();
  1424. if (!uniqueModel.isMain()) {
  1425. if (StringUtil.isNotEmpty(swapDataVo.getMaxlength())) {
  1426. if (value.length() > Integer.valueOf(swapDataVo.getMaxlength())) {
  1427. errList.set(i, label + "值超出最多输入字符限制");
  1428. break;
  1429. }
  1430. }
  1431. boolean comInputError = false;
  1432. if (unique) {
  1433. //子表重复只判断同一个表单
  1434. if (insMap.get("child_table_list") != null) {
  1435. List<Map<String, Object>> childList = uniqueModel.getChildMap();
  1436. String finalValue = value;
  1437. for (int j = 0; j < childList.size(); j++) {
  1438. Map<String, Object> t = childList.get(j);
  1439. if (finalValue.equals(t.get(swapDataVo.getVModel()))) {
  1440. comInputError = true;
  1441. errList.set(i, label + "值已存在");
  1442. uniqueModel.setChildIndex(j);
  1443. break;
  1444. }
  1445. }
  1446. }
  1447. }
  1448. //验证正则
  1449. if (StringUtil.isNotEmpty(swapDataVo.getConfig().getRegList())) {
  1450. List<RegListModel> regList = JsonUtil.getJsonToList(swapDataVo.getConfig().getRegList(), RegListModel.class);
  1451. for (RegListModel regListModel : regList) {
  1452. //处理正则格式
  1453. String reg = regListModel.getPattern();
  1454. if (reg.startsWith("/") && reg.endsWith("/")) {
  1455. reg = reg.substring(1, reg.length() - 1);
  1456. }
  1457. boolean matches = value.matches(reg);
  1458. if (!matches) {
  1459. comInputError = true;
  1460. errList.set(i, label + regListModel.getMessage());
  1461. }
  1462. }
  1463. }
  1464. if (!comInputError) {
  1465. insMap.put(swapDataVo.getVModel(), value);
  1466. }
  1467. }
  1468. break;
  1469. case JnpfKeyConsts.TIME:
  1470. //格式
  1471. String dataFomrat = "yyyy-MM-dd " + swapDataVo.getFormat();
  1472. String valueTime = jnpf.util.DateUtil.daFormat(new Date()) + " " + value;
  1473. try {
  1474. if (swapDataVo.getFormat().length() != value.length()) throw new DataException();
  1475. SimpleDateFormat formatter = new SimpleDateFormat(dataFomrat);
  1476. formatter.setLenient(false);
  1477. Date d = formatter.parse(valueTime);
  1478. } catch (Exception e) {
  1479. errList.set(i, label + "值不正确");
  1480. break;
  1481. }
  1482. //范围
  1483. try {
  1484. //判断时间是否在设置范围内
  1485. boolean timeHasRangeError = FormPublicUtils.dateTimeCondition(swapDataVo, dataFomrat, valueTime, data, jnpfKey);
  1486. if (timeHasRangeError) {
  1487. errList.set(i, label + "值不在范围内");
  1488. break;
  1489. }
  1490. } catch (Exception e) {
  1491. errList.set(i, label + "值不在范围内");
  1492. break;
  1493. }
  1494. break;
  1495. case JnpfKeyConsts.DATE:
  1496. case JnpfKeyConsts.DATE_CALCULATE:
  1497. String format = swapDataVo.getFormat();
  1498. Date valueDate = null;
  1499. try {
  1500. if (format.length() != value.length()) throw new DataException();
  1501. SimpleDateFormat formatter = new SimpleDateFormat(format);
  1502. formatter.setLenient(false);
  1503. valueDate = formatter.parse(value);
  1504. } catch (Exception e) {
  1505. errList.set(i, label + "值不正确");
  1506. break;
  1507. }
  1508. try {
  1509. //判断时间是否在设置范围内
  1510. boolean timeHasRangeError = FormPublicUtils.dateTimeCondition(swapDataVo, format, value, data, jnpfKey);
  1511. if (timeHasRangeError) {
  1512. errList.set(i, label + "值不在范围内");
  1513. break;
  1514. }
  1515. } catch (Exception e) {
  1516. errList.set(i, label + "值不在范围内");
  1517. break;
  1518. }
  1519. insMap.put(swapDataVo.getVModel(), valueDate.getTime());
  1520. break;
  1521. /**
  1522. * 子表
  1523. */
  1524. case JnpfKeyConsts.CHILD_TABLE:
  1525. StringJoiner childJoiner = new StringJoiner(",");
  1526. List<Map<String, Object>> childAllData = (List<Map<String, Object>>) data.get(swapDataVo.getVModel());
  1527. List<Map<String, Object>> childTable = new ArrayList<>(childAllData.size());
  1528. uniqueModel.setChildMap(new ArrayList<>());
  1529. //子表条数限制
  1530. if (swapDataVo.getIsNumLimit() && childAllData.size() > swapDataVo.getNumLimit()) {
  1531. errList.set(i, MsgCode.VS033.get(swapDataVo.getConfig().getLabel()));
  1532. continue;
  1533. }
  1534. for (int childI = 0, childLen = childAllData.size(); childI < childLen; childI++) {
  1535. Map<String, Object> item = childAllData.get(childI);
  1536. Map<String, Object> childMap = new HashMap<>(item);
  1537. childMap.put("mainAndMast", data);
  1538. childMap.put("child_table_list", data.get(swapDataVo.getVModel()));
  1539. Map<String, Object> childTableMap = new HashMap<>(childMap);
  1540. Map<String, Object> childerrorMap = new HashMap<>(childMap);
  1541. uniqueModel.setMain(false);
  1542. StringJoiner childJoiner1 = new StringJoiner(",");
  1543. List<String> childErrList = this.checkExcelData(swapDataVo.getConfig().getChildren(), childMap, localCache, childTableMap, childerrorMap, uniqueModel);
  1544. childErrList.stream().forEach(t -> {
  1545. if (StringUtil.isNotEmpty(t)) {
  1546. childJoiner1.add(t);
  1547. }
  1548. });
  1549. List<Map<String, Object>> childList = uniqueModel.getChildMap();
  1550. if (childJoiner1.length() > 0) {
  1551. if (uniqueModel.isUpdate() && uniqueModel.getChildIndex() != null
  1552. && childJoiner1.toString().split(",").length == 1 && childJoiner1.toString().contains("值已存在")) {
  1553. childList.set(uniqueModel.getChildIndex(), childTableMap);
  1554. } else {
  1555. childJoiner.add(childJoiner1.toString());
  1556. }
  1557. } else {
  1558. childList.add(childTableMap);
  1559. childTable.add(childTableMap);
  1560. }
  1561. }
  1562. if (childJoiner.length() == 0) {
  1563. insMap.put(swapDataVo.getVModel(), childTable);
  1564. } else {
  1565. errList.set(i, childJoiner.toString());
  1566. }
  1567. uniqueModel.setMain(true);
  1568. break;
  1569. default:
  1570. break;
  1571. }
  1572. /**
  1573. * 数据接口
  1574. */
  1575. if (dataType != null) {
  1576. List<Map<String, Object>> options = new ArrayList<>();
  1577. String dataLabel = swapDataVo.getProps().getLabel() != null ? swapDataVo.getProps().getLabel() : "";
  1578. String dataValue = swapDataVo.getProps().getValue() != null ? swapDataVo.getProps().getValue() : "";
  1579. String children = swapDataVo.getProps().getChildren() != null ? swapDataVo.getProps().getChildren() : "";
  1580. boolean isCascader = JnpfKeyConsts.CASCADER.equals(jnpfKey);
  1581. String localCacheKey;
  1582. Map<String, Object> dataInterfaceMap = new HashMap<>();
  1583. //静态数据
  1584. if (dataType.equals(OnlineDataTypeEnum.STATIC.getType())) {
  1585. localCacheKey = String.format("%s-%s", swapDataVo.getConfig().getRelationTable() + swapDataVo.getVModel(), OnlineDataTypeEnum.STATIC.getType());
  1586. if (!localCache.containsKey(localCacheKey)) {
  1587. if (swapDataVo.getOptions() != null) {
  1588. options = JsonUtil.getJsonToListMap(swapDataVo.getOptions());
  1589. String Children = swapDataVo.getProps().getChildren();
  1590. JSONArray staticData = JsonUtil.getListToJsonArray(options);
  1591. getOptions(dataLabel, dataValue, Children, staticData, options);
  1592. } else {
  1593. options = JsonUtil.getJsonToListMap(swapDataVo.getOptions());
  1594. }
  1595. Map<String, Object> finalDataInterfaceMap = new HashMap<>(16);
  1596. String finalDataLabel = dataLabel;
  1597. String finalDataValue = dataValue;
  1598. options.stream().forEach(o -> {
  1599. finalDataInterfaceMap.put(String.valueOf(o.get(finalDataLabel)), o.get(finalDataValue));
  1600. });
  1601. localCache.put(localCacheKey, finalDataInterfaceMap);
  1602. dataInterfaceMap = finalDataInterfaceMap;
  1603. } else {
  1604. dataInterfaceMap = (Map<String, Object>) localCache.get(localCacheKey);
  1605. }
  1606. checkFormDataInteface(multiple, insMap, swapDataVo.getVModel(), label, dataInterfaceMap, valueList, errList, i, isCascader);
  1607. //远端数据
  1608. } else if (dataType.equals(OnlineDataTypeEnum.DYNAMIC.getType())) {
  1609. localCacheKey = String.format("%s-%s-%s-%s", OnlineDataTypeEnum.DYNAMIC.getType(), swapDataVo.getConfig().getPropsUrl(), dataValue, dataLabel);
  1610. if (!localCache.containsKey(localCacheKey)) {
  1611. List<TemplateJsonModel> templateJson = swapDataVo.getConfig().getTemplateJson();
  1612. Map<String, String> param = new HashMap<>();
  1613. for (TemplateJsonModel tm : templateJson) {
  1614. param.put(tm.getField(), tm.getDefaultValue());
  1615. }
  1616. ActionResult actionResult = dataInterFaceApi.infoToId(swapDataVo.getConfig().getPropsUrl(), null, param);
  1617. if (actionResult != null && actionResult.getData() != null) {
  1618. List<Map<String, Object>> dycDataList = new ArrayList<>();
  1619. if (actionResult.getData() instanceof List) {
  1620. dycDataList = (List<Map<String, Object>>) actionResult.getData();
  1621. }
  1622. JSONArray dataAll = JsonUtil.getListToJsonArray(dycDataList);
  1623. treeToList(dataLabel, dataValue, children, dataAll, options);
  1624. Map<String, Object> finalDataInterfaceMap1 = new HashMap<>(16);
  1625. String finalDataLabel2 = dataLabel;
  1626. String finalDataValue1 = dataValue;
  1627. options.stream().forEach(o -> {
  1628. finalDataInterfaceMap1.put(String.valueOf(o.get(finalDataLabel2)), String.valueOf(o.get(finalDataValue1)));
  1629. });
  1630. dataInterfaceMap = finalDataInterfaceMap1;
  1631. localCache.put(localCacheKey, dataInterfaceMap);
  1632. }
  1633. } else {
  1634. dataInterfaceMap = (Map<String, Object>) localCache.get(localCacheKey);
  1635. }
  1636. checkFormDataInteface(multiple, insMap, swapDataVo.getVModel(), label, dataInterfaceMap, valueList, errList, i, isCascader);
  1637. //数据字典
  1638. } else if (dataType.equals(OnlineDataTypeEnum.DICTIONARY.getType())) {
  1639. localCacheKey = String.format("%s-%s", OnlineDataTypeEnum.DICTIONARY.getType(), swapDataVo.getConfig().getDictionaryType());
  1640. dataLabel = swapDataVo.getProps().getLabel();
  1641. dataValue = swapDataVo.getProps().getValue();
  1642. if (!localCache.containsKey(localCacheKey)) {
  1643. List<DictionaryDataEntity> list = dictionaryDataApi.getDicList(swapDataVo.getConfig().getDictionaryType());
  1644. options = list.stream().map(dic -> {
  1645. Map<String, Object> dictionaryMap = new HashMap<>(16);
  1646. dictionaryMap.put("id", dic.getId());
  1647. dictionaryMap.put("enCode", dic.getEnCode());
  1648. dictionaryMap.put("fullName", dic.getFullName());
  1649. return dictionaryMap;
  1650. }).collect(Collectors.toList());
  1651. localCache.put(localCacheKey, options);
  1652. } else {
  1653. options = (List<Map<String, Object>>) localCache.get(localCacheKey);
  1654. }
  1655. Map<String, Object> finalDataInterfaceMap1 = new HashMap<>(16);
  1656. String finalDataLabel3 = dataLabel;
  1657. String finalDataValue3 = dataValue;
  1658. options.stream().forEach(o -> finalDataInterfaceMap1.put(String.valueOf(o.get(finalDataLabel3)), o.get(finalDataValue3)));
  1659. checkFormDataInteface(multiple, insMap, swapDataVo.getVModel(), label, finalDataInterfaceMap1, valueList, errList, i, isCascader);
  1660. }
  1661. }
  1662. } catch (Exception e) {
  1663. e.printStackTrace();
  1664. errList.set(i, e.getMessage());
  1665. }
  1666. }
  1667. localCache.put("allTypeMap", allTypeMap);
  1668. } catch (Exception e) {
  1669. throw new RuntimeException(e);
  1670. }
  1671. return errList;
  1672. }
  1673. //处理自定义范围:系统参数及、选中组织、选中组织及子组织、选中组织及子孙组织、
  1674. private OnlineCusCheckModel getSystemParamIds(List<String> ableList, Map<String, List<String>> allTypeMap, String jnpfKey) {
  1675. UserInfo userInfo = UserProvider.getUser();
  1676. OnlineCusCheckModel cusCheckModel = new OnlineCusCheckModel();
  1677. for (String item : ableList) {
  1678. List<String> itemList = new ArrayList<>();
  1679. if (DataInterfaceVarConst.ORG.equals(item)) {
  1680. if (allTypeMap.containsKey(item)) {
  1681. cusCheckModel.getAbleComIds().addAll(allTypeMap.get(item));
  1682. } else {
  1683. itemList = userInfo.getOrganizeIds();
  1684. allTypeMap.put(item, itemList);
  1685. cusCheckModel.getAbleComIds().addAll(itemList);
  1686. }
  1687. } else if (DataInterfaceVarConst.ORGANDSUB.equals(item)) {
  1688. if (allTypeMap.containsKey(item)) {
  1689. cusCheckModel.getAbleComIds().addAll(allTypeMap.get(item));
  1690. } else {
  1691. List<OrganizeEntity> listByParentIds = organizeApi.getListByParentIds(userInfo.getOrganizeIds());
  1692. itemList.addAll(userInfo.getOrganizeIds());
  1693. itemList.addAll(listByParentIds.stream().map(OrganizeEntity::getId).collect(Collectors.toList()));
  1694. allTypeMap.put(item, itemList);
  1695. cusCheckModel.getAbleComIds().addAll(itemList);
  1696. }
  1697. } else if (DataInterfaceVarConst.ORGANIZEANDPROGENY.equals(item)) {
  1698. if (allTypeMap.containsKey(item)) {
  1699. cusCheckModel.getAbleComIds().addAll(allTypeMap.get(item));
  1700. } else {
  1701. List<OrganizeEntity> listByParentIds = organizeApi.getProgeny(userInfo.getOrganizeIds(), null);
  1702. itemList.addAll(listByParentIds.stream().map(OrganizeEntity::getId).collect(Collectors.toList()));
  1703. allTypeMap.put(item, itemList);
  1704. cusCheckModel.getAbleComIds().addAll(itemList);
  1705. }
  1706. } else if (DataInterfaceVarConst.POSITIONID.equals(item)) {
  1707. if (allTypeMap.containsKey(item)) {
  1708. cusCheckModel.getAblePosIds().addAll(allTypeMap.get(item));
  1709. } else {
  1710. itemList = userInfo.getPositionIds();
  1711. allTypeMap.put(item, itemList);
  1712. cusCheckModel.getAblePosIds().addAll(itemList);
  1713. }
  1714. } else if (DataInterfaceVarConst.POSITIONANDSUB.equals(item)) {
  1715. if (allTypeMap.containsKey(item)) {
  1716. cusCheckModel.getAblePosIds().addAll(allTypeMap.get(item));
  1717. } else {
  1718. List<PositionEntity> listByParentIds = positionApi.getListByParentIds(userInfo.getPositionIds());
  1719. itemList.addAll(userInfo.getOrganizeIds());
  1720. itemList.addAll(listByParentIds.stream().map(PositionEntity::getId).collect(Collectors.toList()));
  1721. allTypeMap.put(item, itemList);
  1722. cusCheckModel.getAblePosIds().addAll(itemList);
  1723. }
  1724. } else if (DataInterfaceVarConst.POSITIONANDPROGENY.equals(item)) {
  1725. if (allTypeMap.containsKey(item)) {
  1726. cusCheckModel.getAblePosIds().addAll(allTypeMap.get(item));
  1727. } else {
  1728. List<PositionEntity> listByParentIds = positionApi.getProgeny(userInfo.getPositionIds(), null);
  1729. itemList.addAll(listByParentIds.stream().map(PositionEntity::getId).collect(Collectors.toList()));
  1730. allTypeMap.put(item, itemList);
  1731. cusCheckModel.getAblePosIds().addAll(itemList);
  1732. }
  1733. } else if (DataInterfaceVarConst.USER.equals(item)) {
  1734. cusCheckModel.getAbleUserIds().add(userInfo.getUserId());
  1735. } else {
  1736. String[] split = item.split("--");
  1737. if (split.length > 1) {
  1738. if (SysParamEnum.ORG.getCode().equalsIgnoreCase(split[1])) {
  1739. cusCheckModel.getAbleComIds().add(split[0]);
  1740. } else if (SysParamEnum.SUBORG.getCode().equalsIgnoreCase(split[1])) {
  1741. if (allTypeMap.containsKey(item)) {
  1742. cusCheckModel.getAbleComIds().addAll(allTypeMap.get(item));
  1743. } else {
  1744. List<OrganizeEntity> listByParentIds = organizeApi.getListByParentIds(Arrays.asList(split[0]));
  1745. itemList.add(split[0]);
  1746. itemList.addAll(listByParentIds.stream().map(OrganizeEntity::getId).collect(Collectors.toList()));
  1747. List<PositionEntity> listByOrgIds = positionApi.getListByOrgIds(itemList);
  1748. itemList.addAll(listByOrgIds.stream().map(PositionEntity::getId).collect(Collectors.toList()));
  1749. allTypeMap.put(item, itemList);
  1750. allTypeMap.put(item, itemList);
  1751. cusCheckModel.getAbleComIds().addAll(itemList);
  1752. }
  1753. } else if (SysParamEnum.PROGENYORG.getCode().equalsIgnoreCase(split[1])) {
  1754. if (allTypeMap.containsKey(item)) {
  1755. cusCheckModel.getAbleComIds().addAll(allTypeMap.get(item));
  1756. } else {
  1757. List<OrganizeEntity> listByParentIds = organizeApi.getProgeny(Arrays.asList(split[0]), null);
  1758. itemList.addAll(listByParentIds.stream().map(OrganizeEntity::getId).collect(Collectors.toList()));
  1759. List<PositionEntity> listByOrgIds = positionApi.getListByOrgIds(itemList);
  1760. itemList.addAll(listByOrgIds.stream().map(PositionEntity::getId).collect(Collectors.toList()));
  1761. allTypeMap.put(item, itemList);
  1762. cusCheckModel.getAbleComIds().addAll(itemList);
  1763. }
  1764. } else if (SysParamEnum.POS.getCode().equalsIgnoreCase(split[1])) {
  1765. cusCheckModel.getAblePosIds().add(split[0]);
  1766. } else if (SysParamEnum.SUBPOS.getCode().equalsIgnoreCase(split[1])) {
  1767. if (allTypeMap.containsKey(item)) {
  1768. cusCheckModel.getAblePosIds().addAll(allTypeMap.get(item));
  1769. } else {
  1770. List<PositionEntity> listByParentIds = positionApi.getListByParentIds(Arrays.asList(split[0]));
  1771. itemList.addAll(Arrays.asList(split[0]));
  1772. itemList.addAll(listByParentIds.stream().map(PositionEntity::getId).collect(Collectors.toList()));
  1773. allTypeMap.put(item, itemList);
  1774. cusCheckModel.getAblePosIds().addAll(itemList);
  1775. }
  1776. } else if (SysParamEnum.PROGENYPOS.getCode().equalsIgnoreCase(split[1])) {
  1777. if (allTypeMap.containsKey(item)) {
  1778. cusCheckModel.getAblePosIds().addAll(allTypeMap.get(item));
  1779. } else {
  1780. List<PositionEntity> listByParentIds = positionApi.getProgeny(Arrays.asList(split[0]), null);
  1781. itemList.addAll(listByParentIds.stream().map(PositionEntity::getId).collect(Collectors.toList()));
  1782. allTypeMap.put(item, itemList);
  1783. cusCheckModel.getAblePosIds().addAll(itemList);
  1784. }
  1785. } else if (SysParamEnum.ROLE.getCode().equalsIgnoreCase(split[1])) {
  1786. cusCheckModel.getAbleRoleIds().add(split[0]);
  1787. } else if (SysParamEnum.GROUP.getCode().equalsIgnoreCase(split[1])) {
  1788. cusCheckModel.getAbleGroupIds().add(split[0]);
  1789. } else if (SysParamEnum.USER.getCode().equalsIgnoreCase(split[1])) {
  1790. cusCheckModel.getAbleUserIds().add(split[0]);
  1791. }
  1792. } else {
  1793. if (JnpfKeyConsts.COMSELECT.equalsIgnoreCase(jnpfKey)) {
  1794. cusCheckModel.getAbleComIds().add(item);
  1795. }
  1796. if (JnpfKeyConsts.ROLESELECT.equalsIgnoreCase(jnpfKey)) {
  1797. cusCheckModel.getAbleRoleIds().add(item);
  1798. }
  1799. if (JnpfKeyConsts.GROUPSELECT.equalsIgnoreCase(jnpfKey)) {
  1800. cusCheckModel.getAbleGroupIds().add(item);
  1801. }
  1802. if (JnpfKeyConsts.USERSELECT.equalsIgnoreCase(jnpfKey) || JnpfKeyConsts.CUSTOMUSERSELECT.equalsIgnoreCase(jnpfKey)) {
  1803. cusCheckModel.getAbleUserIds().add(item);
  1804. }
  1805. }
  1806. }
  1807. }
  1808. return cusCheckModel;
  1809. }
  1810. private List<String> checkOptionsControl(boolean multiple, Map<String, Object> insMap, String vModel, String label, Map<String, Object> cacheMap,
  1811. List<String> valueList, List<String> errList, int i) {
  1812. boolean error = false;
  1813. if (!multiple) {
  1814. //非多选填入多选值
  1815. if (valueList.size() > 1) {
  1816. error = true;
  1817. errList.set(i, label + "值不正确");
  1818. }
  1819. }
  1820. List<String> dataList = new ArrayList<>();
  1821. if (!error) {
  1822. boolean errorHapen = false;
  1823. for (String va : valueList) {
  1824. if (StringUtil.isEmpty(va)) {
  1825. errorHapen = true;
  1826. break;
  1827. }
  1828. Object vo = cacheMap.get(va);
  1829. if (vo == null) {
  1830. errorHapen = true;
  1831. break;
  1832. } else {
  1833. dataList.add(vo.toString());
  1834. }
  1835. }
  1836. if (errorHapen) {
  1837. errList.set(i, label + "值不正确");
  1838. } else {
  1839. insMap.put(vModel, !multiple ? dataList.get(0) : JsonUtil.getObjectToString(dataList));
  1840. }
  1841. }
  1842. return dataList;
  1843. }
  1844. public void checkCustomControl(OnlineCusCheckModel cusCheckModel, List<String> errList, int i, String label) {
  1845. boolean contains;
  1846. List<String> ableIdsAll = new ArrayList<>();
  1847. List<String> ableDepIds = cusCheckModel.getAbleDepIds();
  1848. List<String> ableGroupIds = cusCheckModel.getAbleGroupIds();
  1849. List<String> ablePosIds = cusCheckModel.getAblePosIds();
  1850. List<String> ableRoleIds = cusCheckModel.getAbleRoleIds();
  1851. List<String> ableUserIds = cusCheckModel.getAbleUserIds();
  1852. List<String> ableComIds = cusCheckModel.getAbleComIds();
  1853. // List<String> ableComIdsStr = cusCheckModel.getAbleComIdsStr();
  1854. List<String> dataList = cusCheckModel.getDataList();
  1855. String controlType = cusCheckModel.getControlType();
  1856. switch (controlType) {
  1857. case JnpfKeyConsts.GROUPSELECT:
  1858. ableIdsAll.addAll(ableGroupIds);
  1859. break;
  1860. case JnpfKeyConsts.ROLESELECT:
  1861. ableIdsAll.addAll(ableRoleIds);
  1862. break;
  1863. case JnpfKeyConsts.DEPSELECT:
  1864. ableIdsAll.addAll(ableDepIds);
  1865. break;
  1866. case JnpfKeyConsts.COMSELECT:
  1867. ableIdsAll.addAll(ableComIds);
  1868. break;
  1869. case JnpfKeyConsts.CUSTOMUSERSELECT:
  1870. for (String id : ableGroupIds) {
  1871. ableIdsAll.add(id + "--group");
  1872. }
  1873. for (String id : ablePosIds) {
  1874. ableIdsAll.add(id + "--pos");
  1875. }
  1876. for (String id : ableRoleIds) {
  1877. ableIdsAll.add(id + "--role");
  1878. }
  1879. for (String id : ableUserIds) {
  1880. ableIdsAll.add(id + "--user");
  1881. }
  1882. for (String id : ableComIds) {
  1883. ableIdsAll.add(id + "--org");
  1884. }
  1885. ableIdsAll.addAll(ableDepIds);
  1886. ableIdsAll.addAll(ableGroupIds);
  1887. ableIdsAll.addAll(ablePosIds);
  1888. ableIdsAll.addAll(ableRoleIds);
  1889. ableIdsAll.addAll(ableUserIds);
  1890. ableIdsAll.addAll(ableComIds);
  1891. List<UserRelationEntity> listByObjectIdAll = userRelationApi.getListByObjectIdAll(ableIdsAll);
  1892. for (UserRelationEntity userRelationEntity : listByObjectIdAll) {
  1893. ableIdsAll.add(userRelationEntity.getUserId() + "--user");
  1894. }
  1895. break;
  1896. case JnpfKeyConsts.USERSELECT:
  1897. List<String> objIds = new ArrayList<>();
  1898. if (ableComIds.size() > 0) {
  1899. List<String> lastIds = new ArrayList<>();
  1900. for (String str : ableComIds) {
  1901. lastIds.add(str);
  1902. }
  1903. objIds.addAll(lastIds);
  1904. }
  1905. if (ableDepIds.size() > 0) {
  1906. List<String> lastIds = new ArrayList<>();
  1907. for (String str : ableDepIds) {
  1908. lastIds.add(str);
  1909. }
  1910. objIds.addAll(lastIds);
  1911. }
  1912. if (ableGroupIds.size() > 0) {
  1913. objIds.addAll(ableGroupIds);
  1914. }
  1915. if (ablePosIds.size() > 0) {
  1916. objIds.addAll(ablePosIds);
  1917. }
  1918. if (ableRoleIds.size() > 0) {
  1919. objIds.addAll(ableRoleIds);
  1920. }
  1921. List<String> UserIds = userRelationApi.getListByObjectIdAll(objIds).stream().map(UserRelationEntity::getUserId).collect(Collectors.toList());
  1922. UserIds.addAll(ableUserIds);
  1923. ableIdsAll.addAll(UserIds);
  1924. break;
  1925. case JnpfKeyConsts.POSSELECT:
  1926. List<String> posIds = new ArrayList<>();
  1927. if (ableDepIds.size() > 0) {
  1928. List<String> depIds = positionApi.getListByOrganizeId(ableDepIds, false).stream().map(PositionEntity::getId).collect(Collectors.toList());
  1929. posIds.addAll(depIds);
  1930. }
  1931. if (ablePosIds.size() > 0) {
  1932. posIds.addAll(ablePosIds);
  1933. }
  1934. ableIdsAll.addAll(posIds);
  1935. break;
  1936. default:
  1937. break;
  1938. }
  1939. if (ableIdsAll.size() > 0) {
  1940. for (String id : dataList) {
  1941. contains = ableIdsAll.contains(id);
  1942. if (!contains) {
  1943. errList.set(i, label + "值不在范围内");
  1944. break;
  1945. }
  1946. }
  1947. }
  1948. }
  1949. public void checkFormDataInteface(boolean multiple, Map<String, Object> insMap, String vModel, String label, Map<String, Object> cacheMap,
  1950. List<String> valueList, List<String> errList, int i, boolean isCascader) {
  1951. List<String[]> staticStrData = new ArrayList<>();
  1952. List<String> staticStrDataList1 = new ArrayList<>();
  1953. //单选给多选直接报错
  1954. if (!multiple && valueList.size() > 1) {
  1955. errList.set(i, label + "值不正确");
  1956. return;
  1957. }
  1958. boolean hasError = false;
  1959. boolean takeOne = false;
  1960. for (String dicValue : valueList) {
  1961. if (isCascader) {
  1962. List<String> staticStrDataList2 = new ArrayList<>();
  1963. if (!multiple && valueList.size() > 1) hasError = true;
  1964. if (dicValue.contains("/")) {
  1965. String[] split = dicValue.split("/");
  1966. for (String s : split) {
  1967. Object s1 = cacheMap.get(s);
  1968. if (s1 != null) {
  1969. staticStrDataList2.add(s1.toString());
  1970. staticStrDataList1.add(s1.toString());
  1971. } else {
  1972. hasError = true;
  1973. }
  1974. }
  1975. staticStrData.add(staticStrDataList2.toArray(new String[staticStrDataList2.size()]));
  1976. } else {
  1977. if (cacheMap.get(dicValue) == null) {
  1978. hasError = true;
  1979. } else {
  1980. staticStrDataList1.add(cacheMap.get(dicValue).toString());
  1981. staticStrData.add(new String[]{cacheMap.get(dicValue).toString()});
  1982. }
  1983. }
  1984. } else {
  1985. takeOne = true;
  1986. Object s1 = cacheMap.get(dicValue);
  1987. if (s1 != null) {
  1988. staticStrDataList1.add(s1.toString());
  1989. } else {
  1990. hasError = true;
  1991. }
  1992. }
  1993. }
  1994. if (hasError) {
  1995. errList.set(i, label + "值不正确");
  1996. } else {
  1997. String v = multiple ? takeOne ? JsonUtil.getObjectToString(staticStrDataList1) : JsonUtil.getObjectToString(staticStrData)
  1998. : takeOne ? staticStrDataList1.get(0) : JsonUtil.getObjectToString(staticStrDataList1);
  1999. insMap.put(vModel, v);
  2000. }
  2001. }
  2002. /**
  2003. * 获取接口api数据结果
  2004. *
  2005. * @param
  2006. * @return
  2007. * @copyright 引迈信息技术有限公司
  2008. * @date 2023/1/10
  2009. */
  2010. public List<Map<String, Object>> getInterfaceData(VisualdevReleaseEntity visualdevEntity
  2011. , PaginationModel paginationModel, ColumnDataModel columnDataModel) {
  2012. List<Map<String, Object>> realList = new ArrayList<>();
  2013. try {
  2014. Map<String, Object> queryMap = JsonUtil.stringToMap(paginationModel.getQueryJson());
  2015. //页签搜索
  2016. Map<String, Object> extraMap = JsonUtil.stringToMap(paginationModel.getExtraQueryJson());
  2017. extraMap = extraMap == null ? new HashMap<>() : extraMap;
  2018. DataInterfaceEntity info = dataInterFaceApi.getInfo(visualdevEntity.getInterfaceId());
  2019. //接口真分页
  2020. if (info.getHasPage() == 1) {
  2021. DataInterfacePage page = new DataInterfacePage();
  2022. page.setCurrentPage(paginationModel.getCurrentPage());
  2023. page.setPageSize(paginationModel.getPageSize());
  2024. if ("1".equals(paginationModel.getDataType())) {
  2025. page.setPageSize(99999999);
  2026. }
  2027. List<DataInterfaceModel> jsonToList = JsonUtil.getJsonToList(visualdevEntity.getInterfaceParam(), DataInterfaceModel.class);
  2028. for (DataInterfaceModel df : jsonToList) {
  2029. if (queryMap != null && queryMap.containsKey(df.getField()) && queryMap.get(df.getField()) != null
  2030. && StringUtil.isNotEmpty(queryMap.get(df.getField()).toString())) {
  2031. String thisValue = queryMap.get(df.getField()).toString();
  2032. if (extraMap.containsKey(df.getField())) {
  2033. thisValue = extraMap.get(df.getField()).toString();
  2034. }
  2035. if (Objects.equals(df.getSourceType(), 2)) {
  2036. df.setRelationField(thisValue);
  2037. }
  2038. df.setDefaultValue(thisValue);
  2039. } else if (extraMap.containsKey(df.getField())) {
  2040. String thisValue = extraMap.get(df.getField()).toString();
  2041. if (Objects.equals(df.getSourceType(), 2)) {
  2042. df.setRelationField(thisValue);
  2043. }
  2044. df.setDefaultValue(thisValue);
  2045. }
  2046. }
  2047. page.setParamList(jsonToList);
  2048. ActionResult actionResult = dataInterFaceApi.infoToIdPageList(visualdevEntity.getInterfaceId(), page);
  2049. if (actionResult.getCode() == 200) {
  2050. PageListVO data = JsonUtil.getJsonToBean(actionResult.getData(), PageListVO.class);
  2051. realList = (List<Map<String, Object>>) data.getList();
  2052. PaginationVO pagination = data.getPagination();
  2053. paginationModel.setTotal(pagination.getTotal());
  2054. }
  2055. } else {
  2056. Map<String, String> parameterMap = new HashMap<>();
  2057. if (StringUtil.isNotEmpty(visualdevEntity.getInterfaceParam())) {
  2058. List<InterefaceParamModel> jsonToList = JsonUtil.getJsonToList(visualdevEntity.getInterfaceParam(), InterefaceParamModel.class);
  2059. Map<String, String> systemFieldValue = userApi.getSystemFieldValue(new SystemParamModel(visualdevEntity.getInterfaceParam()));
  2060. for (InterefaceParamModel mapStr : jsonToList) {
  2061. TemplateJsonModel jsonToBean = JsonUtil.getJsonToBean(mapStr, TemplateJsonModel.class);
  2062. String dataValue = paramSourceTypeReplaceValue(jsonToBean, systemFieldValue);
  2063. mapStr.setDefaultValue(dataValue);
  2064. if (mapStr.getUseSearch() != null && Objects.equals(mapStr.getUseSearch(), true)) {
  2065. Map<String, Object> keyJsonMap = queryMap;
  2066. if (keyJsonMap != null && keyJsonMap.get(mapStr.getField()) != null && StringUtil.isNotEmpty(keyJsonMap.get(mapStr.getField()).toString())) {
  2067. parameterMap.put(mapStr.getField(), keyJsonMap.get(mapStr.getField()).toString());
  2068. } else {
  2069. parameterMap.put(mapStr.getField(), null);
  2070. }
  2071. } else {
  2072. parameterMap.put(mapStr.getField(), mapStr.getDefaultValue());
  2073. }
  2074. }
  2075. }
  2076. //组装查询条件
  2077. List<FieLdsModel> queryCondition = this.getQueryCondition(paginationModel, columnDataModel);
  2078. //封装sql---sql普通查询塞参数到数据接口那边去组装sql
  2079. OnlinePublicUtils.getViewQuerySql(info, queryCondition, parameterMap, extraMap);
  2080. ActionResult dataInterfaceInfo = dataInterFaceApi.infoToId(visualdevEntity.getInterfaceId(), null, parameterMap);
  2081. if (dataInterfaceInfo.getCode() == 200) {
  2082. List<Map<String, Object>> dataRes = (List<Map<String, Object>>) dataInterfaceInfo.getData();
  2083. //假查询条件-不为sql时查询在此过滤
  2084. List<Map<String, Object>> dataInterfaceList = OnlinePublicUtils.getViewQueryNotSql(info, queryCondition, dataRes, extraMap);
  2085. //判断是否有id没有则随机
  2086. dataInterfaceList.forEach(item -> {
  2087. if (item.get("id") == null) {
  2088. item.put("id", RandomUtil.uuId());
  2089. }
  2090. if (item.get("f_id") != null) {
  2091. item.put("id", item.get("f_id"));
  2092. }
  2093. if (item.get("children") != null) {
  2094. item.remove("children");
  2095. }
  2096. });
  2097. //排序
  2098. if (StringUtil.isNotEmpty(paginationModel.getSidx())) {
  2099. String[] split = paginationModel.getSidx().split(",");
  2100. Collections.sort(dataInterfaceList, new Comparator<Map<String, Object>>() {
  2101. @Override
  2102. public int compare(Map<String, Object> a, Map<String, Object> b) {
  2103. for (String sidx : split) {
  2104. String key = sidx;
  2105. boolean asc = true;
  2106. if (sidx.startsWith("-")) {
  2107. key = sidx.substring(1);
  2108. asc = false;
  2109. }
  2110. if (a.get(key) == null) {
  2111. if (b.get(key) == null) {
  2112. return 0;
  2113. }
  2114. return 1;
  2115. }
  2116. if (b.get(key) == null) {
  2117. return -1;
  2118. }
  2119. if (!a.get(key).equals(b.get(key))) {
  2120. return asc ? String.valueOf(b.get(key)).compareTo(String.valueOf(a.get(key))) :
  2121. String.valueOf(a.get(key)).compareTo(String.valueOf(b.get(key)));
  2122. }
  2123. }
  2124. return 0;
  2125. }
  2126. });
  2127. }
  2128. if ("1".equals(paginationModel.getDataType())) {//导出全部数据用
  2129. return dataInterfaceList;
  2130. }
  2131. //假分页
  2132. if (columnDataModel.getHasPage() && CollectionUtils.isNotEmpty(dataInterfaceList)) {
  2133. List<List<Map<String, Object>>> partition = Lists.partition(dataInterfaceList, (int) paginationModel.getPageSize());
  2134. int i = (int) paginationModel.getCurrentPage() - 1;
  2135. realList = partition.size() > i ? partition.get(i) : Collections.emptyList();
  2136. paginationModel.setTotal(dataInterfaceList.size());
  2137. } else {
  2138. realList = dataInterfaceList;
  2139. }
  2140. }
  2141. }
  2142. } catch (Exception e) {
  2143. e.printStackTrace();
  2144. log.error("数据视图,接口请求失败!message={}", e.getMessage());
  2145. }
  2146. //数据添加随机id
  2147. dataId(realList, columnDataModel.getViewKey());
  2148. return realList;
  2149. }
  2150. /**
  2151. * 数据添加随机id
  2152. *
  2153. * @param data
  2154. * @param key
  2155. */
  2156. private void dataId(List<Map<String, Object>> data, String key) {
  2157. for (Map<String, Object> item : data) {
  2158. if (item.get("id") == null) {
  2159. item.put("id", RandomUtil.uuId());
  2160. }
  2161. if (item.get("f_id") != null) {
  2162. item.put("id", item.get("f_id"));
  2163. }
  2164. if (item.get(key) != null) {
  2165. item.put("id", item.get(key));
  2166. }
  2167. if (item.get("children") != null) {
  2168. List<Map<String, Object>> children = new ArrayList<>();
  2169. try {
  2170. children.addAll(JsonUtil.getJsonToListMap(String.valueOf(item.get("children"))));
  2171. } catch (Exception e) {
  2172. }
  2173. if (children.size() > 0) {
  2174. dataId(children, null);
  2175. item.put("children", children);
  2176. }
  2177. }
  2178. }
  2179. }
  2180. public static List convertToList(Object obj) {
  2181. if (obj instanceof List) {
  2182. List arrayList = (List) obj;
  2183. return arrayList;
  2184. } else {
  2185. List arrayList = new ArrayList();
  2186. arrayList.add(obj);
  2187. return arrayList;
  2188. }
  2189. }
  2190. public static String convertValueToString(String obj, boolean mult, boolean isOrg) {
  2191. if (StringUtil.isNotEmpty(obj)) {
  2192. String prefix = "[";
  2193. if (isOrg) {
  2194. prefix = "[[";
  2195. }
  2196. if (mult) {
  2197. if (!obj.startsWith(prefix)) {
  2198. JSONArray arr = new JSONArray();
  2199. if (isOrg) {
  2200. //组织多选为二维数组
  2201. arr.add(JSONArray.parse(obj));
  2202. } else {
  2203. arr.add(obj);
  2204. }
  2205. return arr.toJSONString();
  2206. }
  2207. } else {
  2208. if (obj.startsWith(prefix)) {
  2209. JSONArray objects = JSONArray.parseArray(obj);
  2210. return objects.size() > 0 ? objects.get(0).toString() : "";
  2211. }
  2212. }
  2213. }
  2214. return obj;
  2215. }
  2216. /**
  2217. * 获取组织数据中的最后一级组织ID
  2218. * 单选数据获取数组中最后一个组织本身的ID
  2219. * 多选数据获取最后一组组织数据中的最后一个组织本身的ID
  2220. *
  2221. * @param data
  2222. * @return
  2223. */
  2224. public static String getLastOrganizeId(Object data) {
  2225. if (data instanceof List) {
  2226. List listData = (List) data;
  2227. data = listData.get(listData.size() - 1);
  2228. return getLastOrganizeId(data);
  2229. } else if (data instanceof String) {
  2230. String strData = (String) data;
  2231. if (strData.startsWith(StrPool.BRACKET_START)) {
  2232. JSONArray jsonArray = JSONArray.parseArray(strData);
  2233. return getLastOrganizeId(jsonArray);
  2234. } else {
  2235. return strData;
  2236. }
  2237. }
  2238. return data.toString();
  2239. }
  2240. /**
  2241. * 输入时表单时间字段根据格式转换去尾巴
  2242. *
  2243. * @param list 字段属性
  2244. * @param map 数据
  2245. */
  2246. public static void swapDatetime(List<FieLdsModel> list, Map<String, Object> map) {
  2247. List<FieLdsModel> fields = new ArrayList<>();
  2248. FormPublicUtils.recursionFieldsExceptChild(fields, list);
  2249. //主副表
  2250. for (FieLdsModel field : fields) {
  2251. try {
  2252. String vModel = field.getVModel();
  2253. String format = DateTimeFormatConstant.getFormat(field.getFormat());
  2254. ConfigModel config = field.getConfig();
  2255. if (map.get(vModel) != null) {
  2256. String s = map.get(vModel).toString();
  2257. if (StringUtil.isBlank(s) || "[]".equals(s) || "[[]]".equals(s)) {
  2258. map.replace(vModel, null);
  2259. }
  2260. }
  2261. //SQL Server text字段先这样处理。
  2262. if (map.get(vModel) == null) {
  2263. String dbType = "";
  2264. try {
  2265. @Cleanup Connection connection = DynamicDataSourceUtil.getCurrentConnection();
  2266. dbType = connection.getMetaData().getDatabaseProductName().trim();
  2267. } catch (Exception e) {
  2268. }
  2269. if (JnpfKeyConsts.getTextField().contains(config.getJnpfKey()) && "Microsoft SQL Server".equals(dbType)) {
  2270. map.put(vModel, "");
  2271. }
  2272. }
  2273. if ((JnpfKeyConsts.DATE.equals(config.getJnpfKey()) || JnpfKeyConsts.DATE_CALCULATE.equals(config.getJnpfKey())) && map.get(vModel) != null) {
  2274. Date date = new Date(Long.parseLong(String.valueOf(map.get(vModel))));
  2275. String completionStr = "";
  2276. switch (format) {
  2277. case "yyyy":
  2278. completionStr = "-01-01 00:00:00";
  2279. break;
  2280. case "yyyy-MM":
  2281. completionStr = "-01 00:00:00";
  2282. break;
  2283. case "yyyy-MM-dd":
  2284. completionStr = " 00:00:00";
  2285. break;
  2286. case "yyyy-MM-dd HH":
  2287. completionStr = ":00:00";
  2288. break;
  2289. case "yyyy-MM-dd HH:mm":
  2290. completionStr = ":00";
  2291. break;
  2292. default:
  2293. break;
  2294. }
  2295. String datestr = jnpf.util.DateUtil.dateToString(date, format);
  2296. long time = jnpf.util.DateUtil.stringToDate(datestr + completionStr).getTime();
  2297. map.replace(vModel, time);
  2298. }
  2299. if (JnpfKeyConsts.EDITOR.equals(config.getJnpfKey()) && map.get(vModel) != null) {
  2300. map.replace(vModel, XSSEscape.escapeImgOnlyBase64(map.get(vModel).toString()));
  2301. }
  2302. } catch (Exception e) {
  2303. e.printStackTrace();
  2304. }
  2305. }
  2306. //子表
  2307. for (FieLdsModel field : fields) {
  2308. if (field.getVModel().toLowerCase().startsWith(JnpfKeyConsts.CHILD_TABLE_PREFIX)) {
  2309. List<FieLdsModel> children = field.getConfig().getChildren();
  2310. if (CollectionUtils.isNotEmpty(children)) {
  2311. String tableKey = field.getConfig().getTableName() + "List";
  2312. if (map.get(tableKey) != null) {
  2313. List<Object> listObj = (List) map.get(tableKey);
  2314. if (CollectionUtils.isEmpty(listObj)) continue;
  2315. List<Object> listObjNew = new ArrayList<>();
  2316. for (Object o : listObj) {
  2317. Map<String, Object> stringObjectMap = JsonUtil.entityToMap(o);
  2318. swapDatetime(children, stringObjectMap);
  2319. listObjNew.add(stringObjectMap);
  2320. }
  2321. if (CollectionUtils.isNotEmpty(listObjNew)) {
  2322. map.replace(tableKey, listObjNew);
  2323. }
  2324. }
  2325. String tableFieldKey = field.getVModel();
  2326. if (map.get(tableFieldKey) != null) {
  2327. List<Object> listObj = (List) map.get(tableFieldKey);
  2328. if (CollectionUtils.isEmpty(listObj)) continue;
  2329. List<Object> listObjNew = new ArrayList<>();
  2330. for (Object o : listObj) {
  2331. Map<String, Object> stringObjectMap = JsonUtil.entityToMap(o);
  2332. swapDatetime(children, stringObjectMap);
  2333. listObjNew.add(stringObjectMap);
  2334. }
  2335. if (CollectionUtils.isNotEmpty(listObjNew)) {
  2336. map.replace(tableFieldKey, listObjNew);
  2337. }
  2338. }
  2339. }
  2340. }
  2341. }
  2342. }
  2343. /**
  2344. * 判断组织层级是否正确
  2345. *
  2346. * @param comTwoList
  2347. * @param comOneList
  2348. * @return
  2349. */
  2350. private boolean orgListRight(List<List<String>> comTwoList, List<String> comOneList) {
  2351. if (CollectionUtils.isNotEmpty(comOneList)) {
  2352. String one = comOneList.get(comOneList.size() - 1);
  2353. List<String> realOrgs = new ArrayList<>();
  2354. OrganizeEntity organizeEntity = organizeApi.getInfo(one);
  2355. if (organizeEntity != null) {
  2356. if (StringUtil.isNotEmpty(organizeEntity.getOrganizeIdTree())) {
  2357. String[] split = organizeEntity.getOrganizeIdTree().split(",");
  2358. if (split.length > 0) {
  2359. realOrgs = Arrays.asList(split);
  2360. }
  2361. if (!JsonUtil.getObjectToString(comOneList).equals(JsonUtil.getObjectToString(realOrgs))) {
  2362. return true;
  2363. }
  2364. }
  2365. }
  2366. }
  2367. if (CollectionUtils.isNotEmpty(comTwoList) && comTwoList.size() > 0) {
  2368. for (List<String> two : comTwoList) {
  2369. if (two.size() <= 0) {
  2370. return false;
  2371. }
  2372. String one = two.get(two.size() - 1);
  2373. List<String> realOrgs = new ArrayList<>();
  2374. OrganizeEntity organizeEntity = organizeApi.getInfo(one);
  2375. if (organizeEntity != null) {
  2376. if (StringUtil.isNotEmpty(organizeEntity.getOrganizeIdTree())) {
  2377. String[] split = organizeEntity.getOrganizeIdTree().split(",");
  2378. if (split.length > 0) {
  2379. realOrgs = Arrays.asList(split);
  2380. }
  2381. if (!JsonUtil.getObjectToString(comOneList).equals(JsonUtil.getObjectToString(realOrgs))) {
  2382. return true;
  2383. }
  2384. }
  2385. }
  2386. }
  2387. }
  2388. return false;
  2389. }
  2390. /**
  2391. * 视图条件组装
  2392. *
  2393. * @param paginationModel
  2394. * @param columnDataModel
  2395. * @return
  2396. */
  2397. public List<FieLdsModel> getQueryCondition(PaginationModel paginationModel, ColumnDataModel columnDataModel) {
  2398. List<FieLdsModel> searchVOList = JsonUtil.getJsonToList(columnDataModel.getSearchList(), FieLdsModel.class);
  2399. Map<String, Object> keyJsonMap = JsonUtil.stringToMap(paginationModel.getQueryJson());
  2400. List<FieLdsModel> searchResList = new ArrayList<>();
  2401. if (keyJsonMap == null) {
  2402. return searchResList;
  2403. }
  2404. for (String key : keyJsonMap.keySet()) {
  2405. if (keyJsonMap.get(key) == null || (keyJsonMap.get(key) instanceof List && ((List<?>) keyJsonMap.get(key)).size() == 0)) {
  2406. continue;
  2407. }
  2408. for (FieLdsModel item : searchVOList) {
  2409. String vModel = item.getVModel();
  2410. if (key.equals(vModel) && keyJsonMap.get(key) != null) {
  2411. if (!item.getConfig().getIsFromParam()) {//非接口参数的条件
  2412. FieLdsModel model = BeanUtil.copyProperties(item, FieLdsModel.class);
  2413. String jnpfKey = model.getConfig().getJnpfKey();
  2414. switch (jnpfKey) {
  2415. case JnpfKeyConsts.COM_INPUT:
  2416. if (Objects.equals(model.getSearchType(), 3)) {
  2417. model.setSearchType(2);//单行输入范围调整为模糊
  2418. }
  2419. model.setFieldValue(String.valueOf(keyJsonMap.get(vModel)));
  2420. break;
  2421. case JnpfKeyConsts.NUM_INPUT:
  2422. model.setSearchType(3);//定义为between
  2423. List<Long> integerList = JsonUtil.getJsonToList(keyJsonMap.get(vModel), Long.class);
  2424. model.setFieldValueOne(integerList.get(0));
  2425. model.setFieldValueTwo(integerList.get(1));
  2426. break;
  2427. case JnpfKeyConsts.DATE:
  2428. case JnpfKeyConsts.DATE_CALCULATE:
  2429. model.setSearchType(3);//定义为between
  2430. List<Long> dateList = JsonUtil.getJsonToList(keyJsonMap.get(vModel), Long.class);
  2431. String timeOne = FormPublicUtils.getTimeFormat(jnpf.util.DateUtil.dateToString(new Date(dateList.get(0)), model.getFormat()));
  2432. String timeTwo = FormPublicUtils.getTimeFormat(jnpf.util.DateUtil.dateToString(new Date(dateList.get(1)), model.getFormat()));
  2433. model.setFieldValueOne(timeOne);
  2434. model.setFieldValueTwo(timeTwo);
  2435. break;
  2436. case JnpfKeyConsts.TIME:
  2437. model.setSearchType(3);//定义为between
  2438. List<String> stringList = JsonUtil.getJsonToList(keyJsonMap.get(vModel), String.class);
  2439. model.setFieldValueOne(stringList.get(0));
  2440. model.setFieldValueTwo(stringList.get(1));
  2441. break;
  2442. case JnpfKeyConsts.SELECT:
  2443. case JnpfKeyConsts.ROLESELECT:
  2444. case JnpfKeyConsts.GROUPSELECT:
  2445. model.setSearchType(4);
  2446. List<String> dataList = new ArrayList<>();
  2447. try {
  2448. List<String> list = JsonUtil.getJsonToList(keyJsonMap.get(vModel), String.class);
  2449. dataList.addAll(list);
  2450. } catch (Exception e1) {
  2451. dataList.add(String.valueOf(keyJsonMap.get(vModel)));
  2452. }
  2453. model.setDataList(dataList);
  2454. break;
  2455. case JnpfKeyConsts.POSSELECT:
  2456. model.setSearchType(4);
  2457. List<String> listPos = new ArrayList<>();
  2458. if (model.getSearchMultiple()) {
  2459. listPos = JsonUtil.getJsonToBean(keyJsonMap.get(vModel), List.class);
  2460. } else {
  2461. String posId = JsonUtil.getJsonToBean(keyJsonMap.get(vModel), String.class);
  2462. listPos.add(posId);
  2463. }
  2464. //包含子岗位
  2465. if (Objects.equals(model.getSelectRange(), "2")) {
  2466. List<PositionEntity> childList = positionApi.getListByParentIds(listPos);
  2467. listPos.addAll(childList.stream().map(PositionEntity::getId).collect(Collectors.toList()));
  2468. //包含子孙岗位
  2469. } else if (Objects.equals(model.getSelectRange(), "3")) {
  2470. List<PositionEntity> childList = positionApi.getProgeny(listPos, 1);
  2471. listPos.addAll(childList.stream().map(PositionEntity::getId).collect(Collectors.toList()));
  2472. }
  2473. model.setDataList(listPos);
  2474. break;
  2475. case JnpfKeyConsts.COMSELECT:
  2476. model.setSearchType(4);
  2477. List<String> listOrg = new ArrayList<>();
  2478. if (model.getSearchMultiple()) {
  2479. listOrg = JsonUtil.getJsonToBean(keyJsonMap.get(vModel), List.class);
  2480. } else {
  2481. String orgId = JsonUtil.getJsonToBean(keyJsonMap.get(vModel), String.class);
  2482. listOrg.add(orgId);
  2483. }
  2484. //包含子组织
  2485. if (Objects.equals(model.getSelectRange(), "2")) {
  2486. List<OrganizeEntity> childList = organizeApi.getListByParentIds(listOrg);
  2487. listOrg.addAll(childList.stream().map(OrganizeEntity::getId).collect(Collectors.toList()));
  2488. //包含子孙组织
  2489. } else if (Objects.equals(model.getSelectRange(), "3")) {
  2490. List<OrganizeEntity> childList = organizeApi.getProgeny(listOrg, 1);
  2491. listOrg.addAll(childList.stream().map(OrganizeEntity::getId).collect(Collectors.toList()));
  2492. }
  2493. model.setDataList(listOrg);
  2494. break;
  2495. case JnpfKeyConsts.USERSELECT:
  2496. model.setSearchType(4);
  2497. List<String> listUser = new ArrayList<>();
  2498. if (model.getSearchMultiple()) {
  2499. List<String> list = JsonUtil.getJsonToBean(keyJsonMap.get(vModel), List.class);
  2500. listUser.addAll(list);
  2501. } else {
  2502. listUser.add(String.valueOf(keyJsonMap.get(vModel)));
  2503. }
  2504. //包含当前用户及下属
  2505. if (CollectionUtils.isNotEmpty(listUser)) {
  2506. List<String> posIds = userRelationService.getListByUserIdAll(listUser).stream()
  2507. .filter(t -> PermissionConst.POSITION.equals(t.getObjectType()))
  2508. .map(UserRelationEntity::getObjectId).collect(Collectors.toList());
  2509. if (Objects.equals(model.getSelectRange(), "2")) {
  2510. List<UserEntity> childList = userRelationService.getUserAndSub(posIds, null);
  2511. listUser.addAll(childList.stream().map(UserEntity::getId).collect(Collectors.toList()));
  2512. //包含子孙用户
  2513. } else if (Objects.equals(model.getSelectRange(), "3")) {
  2514. List<UserEntity> childList = userRelationService.getUserProgeny(posIds, null);
  2515. listUser.addAll(childList.stream().map(UserEntity::getId).collect(Collectors.toList()));
  2516. }
  2517. }
  2518. model.setDataList(listUser);
  2519. break;
  2520. default:
  2521. model.setFieldValue(String.valueOf(keyJsonMap.get(vModel)));
  2522. break;
  2523. }
  2524. searchResList.add(model);
  2525. }
  2526. }
  2527. }
  2528. }
  2529. return searchResList;
  2530. }
  2531. /**
  2532. * 获取默认数据和下拉列表map
  2533. *
  2534. * @param formJson 表单设计json
  2535. * @param selectKey 选中字段key
  2536. */
  2537. public ExcelModel getDefaultValue(String formJson, List<String> selectKey) {
  2538. FormDataModel formDataModel = JsonUtil.getJsonToBean(formJson, FormDataModel.class);
  2539. List<FieLdsModel> fieLdsModels = JsonUtil.getJsonToList(formDataModel.getFields(), FieLdsModel.class);
  2540. List<FieLdsModel> allFieLds = new ArrayList<>();
  2541. VisualUtils.recursionFields(fieLdsModels, allFieLds);
  2542. Map<String, String[]> optionMap = new HashMap<>();
  2543. Map<String, Object> dataMap = new HashMap<>();
  2544. List<ExcelColumnAttr> models = new ArrayList<>();
  2545. for (String s : selectKey.stream().filter(s -> !s.toLowerCase().startsWith(JnpfKeyConsts.CHILD_TABLE_PREFIX)).collect(Collectors.toList())) {
  2546. FieLdsModel fieLdsModel = allFieLds.stream().filter(c -> c.getVModel().equals(s)).findFirst().orElse(null);
  2547. assert fieLdsModel != null;
  2548. fieLdsModel.setId(fieLdsModel.getVModel());
  2549. models.add(ExcelColumnAttr.builder().key(fieLdsModel.getVModel()).name(fieLdsModel.getLabel()).require(fieLdsModel.getConfig().isRequired()).fontColor(IndexedColors.RED.getIndex()).build());
  2550. dataMap.put(s, VisualUtils.exampleExcelMessage(fieLdsModel));
  2551. String[] options = getOptions(fieLdsModel);
  2552. if (options != null && options.length > 0) {
  2553. optionMap.put(fieLdsModel.getVModel(), options);
  2554. }
  2555. }
  2556. List<FieLdsModel> childFields = allFieLds.stream().filter(f -> f.getConfig().getJnpfKey().equals(JnpfKeyConsts.CHILD_TABLE)).collect(Collectors.toList());
  2557. for (FieLdsModel child : childFields) {
  2558. List<String> childList = selectKey.stream().filter(s -> s.startsWith(child.getVModel())).collect(Collectors.toList());
  2559. childList.forEach(c -> c.replace(child.getVModel() + "-", ""));
  2560. List<FieLdsModel> children = child.getConfig().getChildren();
  2561. List<Map<String, Object>> childData = new ArrayList<>();
  2562. Map<String, Object> childMap = new HashMap<>();
  2563. for (String cl : childList) {
  2564. String substring = cl.substring(cl.indexOf("-") + 1);
  2565. FieLdsModel fieLdsModel = children.stream().filter(c -> c.getVModel().equals(substring)).findFirst().orElse(null);
  2566. assert fieLdsModel != null;
  2567. String id = fieLdsModel.getConfig().getParentVModel() + "-" + fieLdsModel.getVModel();
  2568. fieLdsModel.setId(id);
  2569. models.add(ExcelColumnAttr.builder().key(cl).name(fieLdsModel.getLabel()).require(fieLdsModel.getConfig().isRequired()).fontColor(IndexedColors.RED.getIndex()).build());
  2570. childMap.put(substring, VisualUtils.exampleExcelMessage(fieLdsModel));
  2571. String[] options = getOptions(fieLdsModel);
  2572. if (options != null && options.length > 0) {
  2573. optionMap.put(id, options);
  2574. }
  2575. }
  2576. childData.add(childMap);
  2577. dataMap.put(child.getVModel(), childData);
  2578. }
  2579. return ExcelModel.builder().selectKey(selectKey).models(models).dataMap(dataMap).optionMap(optionMap).build();
  2580. }
  2581. /**
  2582. * 根据配置获取下拉列表
  2583. *
  2584. * @param model
  2585. * @return
  2586. */
  2587. public String[] getOptions(FieLdsModel model) {
  2588. ConfigModel config = model.getConfig();
  2589. String jnpfKey = config.getJnpfKey();
  2590. String[] options = null;
  2591. if (JnpfKeyConsts.SWITCH.equals(jnpfKey)) {
  2592. options = new String[2];
  2593. options[0] = model.getActiveTxt();
  2594. options[1] = model.getInactiveTxt();
  2595. }
  2596. Boolean multiple = model.getMultiple();
  2597. if ((JnpfKeyConsts.SELECT.equals(jnpfKey) && !multiple) || JnpfKeyConsts.RADIO.equals(jnpfKey)) {
  2598. String selectOptions = model.getOptions();
  2599. PropsModel props = model.getProps();
  2600. String labelkey = props.getLabel();
  2601. String dataType = model.getConfig().getDataType();
  2602. if ("static".equals(dataType)) {
  2603. List<Map> list = JsonUtil.getJsonToList(selectOptions, Map.class);
  2604. options = new String[list.size()];
  2605. for (int i = 0; i < list.size(); i++) {
  2606. Map map = list.get(i);
  2607. String label = (String) map.get(props.getLabel());
  2608. options[i] = label;
  2609. }
  2610. } else if ("dictionary".equals(dataType)) {
  2611. List<DictionaryDataEntity> list = dictionaryDataApi.getList(model.getConfig().getDictionaryType(), true);
  2612. options = list.stream().map(DictionaryDataEntity::getFullName).collect(Collectors.toList()).toArray(new String[0]);
  2613. } else if ("dynamic".equals(dataType)) {
  2614. ActionResult result = dataInterFaceApi.infoToId(model.getConfig().getPropsUrl(), null, new HashMap<>());
  2615. ArrayList arr = (ArrayList) result.getData();
  2616. options = new String[arr.size()];
  2617. for (int i = 0; i < arr.size(); i++) {
  2618. Map data = (Map) arr.get(i);
  2619. options[i] = (String) data.get(labelkey);
  2620. }
  2621. }
  2622. }
  2623. return options;
  2624. }
  2625. /**
  2626. * 获取流程任务状态
  2627. *
  2628. * @param list 功能数据列表
  2629. * @throws WorkFlowException
  2630. */
  2631. public void getFlowStatus(List<Map<String, Object>> list) throws WorkFlowException {
  2632. List<String> ids = new ArrayList<>();
  2633. for (Map<String, Object> item : list) {
  2634. getFLowFields(item);
  2635. if (Objects.nonNull(item.get(FlowFormConstant.FLOWTASKID))) {
  2636. ids.add(item.get(FlowFormConstant.FLOWTASKID).toString());
  2637. }
  2638. //流程状态添加
  2639. if (item != null && item.get(FlowFormConstant.FLOW_STATE) == null) {
  2640. Integer flowState = null;
  2641. if (flowState == null && item.get(TableFeildsEnum.FLOWSTATE.getField()) != null) {
  2642. flowState = (int) item.get(TableFeildsEnum.FLOWSTATE.getField());
  2643. }
  2644. if (flowState == null && item.get(TableFeildsEnum.FLOWSTATE.getField().toUpperCase()) != null) {
  2645. flowState = (int) item.get(TableFeildsEnum.FLOWSTATE.getField().toUpperCase());
  2646. }
  2647. if (flowState == null && item.get(FlowFormConstant.FLOW_STATE.toUpperCase()) != null) {
  2648. flowState = (int) item.get(FlowFormConstant.FLOW_STATE.toUpperCase());
  2649. }
  2650. if (flowState == null && item.get(FlowFormConstant.FLOW_STATE.toLowerCase()) != null) {
  2651. flowState = (int) item.get(FlowFormConstant.FLOW_STATE.toLowerCase());
  2652. }
  2653. if (flowState == null) {
  2654. flowState = 0;
  2655. }
  2656. item.put(FlowFormConstant.FLOW_STATE, flowState);
  2657. }
  2658. }
  2659. // List<TaskEntity> tasks = taskApi.getInfosSubmit(ids.toArray(new String[]{}), TaskEntity::getStatus, TaskEntity::getId);
  2660. // for (Map<String, Object> m : list) {
  2661. // if (m != null && Objects.nonNull(m.get(FlowFormConstant.FLOWTASKID))) {
  2662. // String flowTaskId = m.get(FlowFormConstant.FLOWTASKID).toString();
  2663. // m.put(FlowFormConstant.FLOW_STATE, 0);
  2664. // tasks.forEach(i -> {
  2665. // if (i.getId().equals(flowTaskId)) {
  2666. // m.put(FlowFormConstant.FLOW_STATE, i.getStatus());
  2667. // }
  2668. // });
  2669. // }
  2670. // }
  2671. }
  2672. /**
  2673. * 获取流程相关字段
  2674. *
  2675. * @param item
  2676. */
  2677. public void getFLowFields(Map<String, Object> item) {
  2678. Map<String, Object> t = new CaseInsensitiveMap(item);
  2679. String flowTaskId = "";
  2680. if (t != null && t.get(FlowFormConstant.FLOWTASKID) != null) {
  2681. flowTaskId = t.get(FlowFormConstant.FLOWTASKID).toString();
  2682. }
  2683. if (t != null && t.get(TableFeildsEnum.FLOWTASKID.getField()) != null) {
  2684. flowTaskId = t.get(TableFeildsEnum.FLOWTASKID.getField()).toString();
  2685. }
  2686. item.put(FlowFormConstant.FLOWTASKID, flowTaskId);
  2687. String flowId = "";
  2688. if (t != null && t.get(FlowFormConstant.FLOWID) != null) {
  2689. flowId = t.get(FlowFormConstant.FLOWID).toString();
  2690. }
  2691. if (t != null && t.get(TableFeildsEnum.FLOWID.getField()) != null) {
  2692. flowId = t.get(TableFeildsEnum.FLOWID.getField()).toString();
  2693. }
  2694. item.put(FlowFormConstant.FLOWID, flowId);
  2695. }
  2696. /**
  2697. * 主附表单行输入验证
  2698. */
  2699. public void checkUnique(List<FieLdsModel> modelList, Map<String, Object> data, List<String> errList, ImportFormCheckUniqueModel uniqueModel) {
  2700. for (int i = 0; i < modelList.size(); i++) {
  2701. FieLdsModel swapDataVo = modelList.get(i);
  2702. String jnpfKey = swapDataVo.getConfig().getJnpfKey();
  2703. Object valueO = data.get(swapDataVo.getVModel());
  2704. String label = swapDataVo.getConfig().getLabel();
  2705. String value = String.valueOf(valueO);
  2706. if (ObjectUtil.isEmpty(valueO)) {
  2707. continue;
  2708. }
  2709. if (JnpfKeyConsts.COM_INPUT.equals(jnpfKey) && uniqueModel.isMain()) {
  2710. if (StringUtil.isNotEmpty(swapDataVo.getMaxlength())) {
  2711. if (value.length() > Integer.valueOf(swapDataVo.getMaxlength())) {
  2712. errList.set(i, label + "值超出最多输入字符限制");
  2713. break;
  2714. }
  2715. }
  2716. Boolean unique = swapDataVo.getConfig().getUnique();
  2717. if (unique) {
  2718. try {
  2719. DbLinkEntity linkEntity = uniqueModel.getLinkEntity();
  2720. DynamicDataSourceUtil.switchToDataSource(linkEntity);
  2721. @Cleanup Connection connection = DynamicDataSourceUtil.getCurrentConnection();
  2722. String databaseProductName = connection.getMetaData().getDatabaseProductName().trim();
  2723. //表格中出现多个的唯一值判断
  2724. boolean exists = false;
  2725. List<ImportDataModel> importDataModel = uniqueModel.getImportDataModel();
  2726. List<Map<String, Object>> successList = importDataModel.stream().map(ImportDataModel::getResultData).collect(Collectors.toList());
  2727. if (CollectionUtils.isNotEmpty(successList)) {
  2728. for (int uniqueIndex = 0; uniqueIndex < successList.size(); uniqueIndex++) {
  2729. if (value.equals(String.valueOf(successList.get(uniqueIndex).get(swapDataVo.getVModel())))) {
  2730. errList.set(i, label + "值已存在");
  2731. exists = true;
  2732. break;
  2733. }
  2734. }
  2735. }
  2736. if (exists) {
  2737. break;
  2738. }
  2739. String tableName = Optional.ofNullable(swapDataVo.getConfig().getRelationTable()).orElse(swapDataVo.getConfig().getTableName());
  2740. //验证唯一
  2741. SqlTable sqlTable = SqlTable.of(tableName);
  2742. String key = flowDataUtil.getTableKey(connection, tableName);
  2743. String vModelThis = swapDataVo.getVModel();
  2744. String foriegKey = "";
  2745. String columnName = "";
  2746. boolean isMain = uniqueModel.isMain();
  2747. TableModel mainTableModel = new TableModel();
  2748. TableModel tableModel = new TableModel();
  2749. for (TableModel item : uniqueModel.getTableModelList()) {
  2750. if (Objects.equals(item.getTypeId(), "1")) {
  2751. mainTableModel = item;
  2752. }
  2753. if (StringUtil.isNotEmpty(swapDataVo.getConfig().getRelationTable())) {
  2754. //子表判断
  2755. if (swapDataVo.getConfig().getRelationTable().equals(item.getTable())) {
  2756. tableModel = item;
  2757. }
  2758. } else {
  2759. //主副表判断
  2760. if (swapDataVo.getConfig().getTableName().equals(item.getTable())) {
  2761. tableModel = item;
  2762. }
  2763. }
  2764. }
  2765. if (tableModel != null) {
  2766. String fieldName = vModelThis;
  2767. if (vModelThis.contains(JnpfConst.SIDE_MARK)) {
  2768. fieldName = vModelThis.split(JnpfConst.SIDE_MARK)[1];
  2769. isMain = false;
  2770. foriegKey = tableModel.getTableField();
  2771. }
  2772. String finalFieldName = fieldName;
  2773. TableFields tableFields = tableModel.getFields().stream().filter(t -> t.getField().equals(finalFieldName)).findFirst().orElse(null);
  2774. if (tableFields != null) {
  2775. columnName = StringUtil.isNotEmpty(tableFields.getField()) ? tableFields.getField() : fieldName;
  2776. }
  2777. }
  2778. List<BasicColumn> selectKey = new ArrayList<>();
  2779. selectKey.add(sqlTable.column(columnName));
  2780. selectKey.add(sqlTable.column(key));
  2781. if (StringUtil.isNotEmpty(foriegKey)) {
  2782. String finalForiegKey = foriegKey;
  2783. TableFields tableFields = tableModel.getFields().stream().filter(t -> t.getField().equals(finalForiegKey)).findFirst().orElse(null);
  2784. if (tableFields != null) {
  2785. foriegKey = StringUtil.isNotEmpty(tableFields.getField()) ? tableFields.getField() : finalForiegKey;
  2786. }
  2787. selectKey.add(sqlTable.column(foriegKey));
  2788. }
  2789. SqlTable sqlMainTable = SqlTable.of(mainTableModel.getTable());
  2790. String mainKey = flowDataUtil.getKey(mainTableModel, databaseProductName);
  2791. String taskIdField = TableFeildsEnum.FLOWTASKID.getField();
  2792. if (databaseProductName.contains("Oracle") || databaseProductName.contains("DM DBMS")) {
  2793. taskIdField = TableFeildsEnum.FLOWTASKID.getField().toUpperCase();
  2794. }
  2795. if (StringUtil.isNotEmpty(uniqueModel.getFlowId())) {
  2796. selectKey.add(sqlMainTable.column(taskIdField));
  2797. }
  2798. QueryExpressionDSL<SelectModel>.QueryExpressionWhereBuilder where;
  2799. //是否主表
  2800. if (isMain) {
  2801. where = SqlBuilder
  2802. .select(selectKey)
  2803. .from(sqlTable)
  2804. .where(sqlTable.column(columnName), SqlBuilder.isEqualTo(value));
  2805. } else {
  2806. where = SqlBuilder
  2807. .select(selectKey)
  2808. .from(sqlMainTable)
  2809. .leftJoin(sqlTable)
  2810. .on(sqlTable.column(tableModel.getTableField()), new EqualTo(sqlMainTable.column(tableModel.getRelationField())))
  2811. .where(sqlTable.column(columnName), SqlBuilder.isEqualTo(value));
  2812. }
  2813. //是流程
  2814. if (StringUtil.isNotEmpty(uniqueModel.getFlowId())) {
  2815. where.and(sqlMainTable.column(TableFeildsEnum.FLOWID.getField()), SqlBuilder.isIn(uniqueModel.getFlowIdList()));
  2816. } else {
  2817. where.and(sqlMainTable.column(TableFeildsEnum.FLOWID.getField()), SqlBuilder.isNull());
  2818. }
  2819. //开启逻辑删除
  2820. if (uniqueModel.getLogicalDelete()) {
  2821. where.and(sqlMainTable.column(TableFeildsEnum.DELETEMARK.getField()), SqlBuilder.isNull());
  2822. }
  2823. //业务主键存在的话需要剔除当前数据
  2824. if (StringUtil.isNotEmpty(uniqueModel.getId())) {
  2825. where.and(sqlTable.column(mainKey), SqlBuilder.isNotEqualTo(uniqueModel.getId()));
  2826. }
  2827. SelectStatementProvider render = where.build().render(RenderingStrategies.MYBATIS3);
  2828. List<Map<String, Object>> mapList = flowFormDataMapper.selectManyMappedRows(render);
  2829. int count = mapList.size();
  2830. if (count > 0) {
  2831. errList.set(i, label + "值已存在");
  2832. break;
  2833. }
  2834. } catch (Exception e) {
  2835. errList.set(i, label + "值不正确");
  2836. } finally {
  2837. DynamicDataSourceUtil.clearSwitchDataSource();
  2838. }
  2839. }
  2840. }
  2841. }
  2842. }
  2843. }