ModuleColumnController.java 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. package jnpf.base.controller;
  2. import cn.dev33.satoken.annotation.SaCheckPermission;
  3. import cn.dev33.satoken.annotation.SaMode;
  4. import io.swagger.v3.oas.annotations.Operation;
  5. import io.swagger.v3.oas.annotations.Parameter;
  6. import io.swagger.v3.oas.annotations.Parameters;
  7. import io.swagger.v3.oas.annotations.tags.Tag;
  8. import jakarta.validation.Valid;
  9. import jnpf.base.ActionResult;
  10. import jnpf.base.Pagination;
  11. import jnpf.base.entity.ModuleColumnEntity;
  12. import jnpf.base.entity.ModuleEntity;
  13. import jnpf.base.model.ColumnDataModel;
  14. import jnpf.base.model.Template6.ColumnListField;
  15. import jnpf.base.model.column.*;
  16. import jnpf.base.model.module.PropertyJsonModel;
  17. import jnpf.base.service.ModuleColumnService;
  18. import jnpf.base.service.ModuleService;
  19. import jnpf.base.vo.ListVO;
  20. import jnpf.base.vo.PageListVO;
  21. import jnpf.base.vo.PaginationVO;
  22. import jnpf.constant.JnpfConst;
  23. import jnpf.constant.MsgCode;
  24. import jnpf.exception.DataException;
  25. import jnpf.util.JsonUtil;
  26. import jnpf.util.JsonUtilEx;
  27. import jnpf.util.ReflectionUtil;
  28. import jnpf.util.StringUtil;
  29. import jnpf.util.context.SpringContext;
  30. import org.springframework.beans.factory.annotation.Autowired;
  31. import org.springframework.validation.annotation.Validated;
  32. import org.springframework.web.bind.annotation.*;
  33. import java.util.*;
  34. /**
  35. * 列表权限
  36. *
  37. * @author JNPF开发平台组
  38. * @version V3.1.0
  39. * @copyright 引迈信息技术有限公司
  40. * @date 2019年9月27日 上午9:18
  41. */
  42. @Tag(name = "列表权限", description = "ModuleColumn")
  43. @Validated
  44. @RestController
  45. @RequestMapping("/api/system/ModuleColumn")
  46. public class ModuleColumnController extends SuperController<ModuleColumnService, ModuleColumnEntity> {
  47. @Autowired
  48. private ModuleColumnService moduleColumnService;
  49. @Autowired
  50. private ModuleService moduleService;
  51. /**
  52. * 获取列表权限信息列表
  53. *
  54. * @param moduleId 功能主键
  55. * @param pagination 分页参数
  56. * @return ignore
  57. */
  58. @Operation(summary = "获取列表权限列表")
  59. @Parameters({
  60. @Parameter(name = "moduleId", description = "功能主键", required = true)
  61. })
  62. @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
  63. @GetMapping("/{moduleId}/Fields")
  64. public ActionResult<PageListVO<ColumnListVO>> getList(@PathVariable("moduleId") String moduleId, Pagination pagination) {
  65. List<ModuleColumnEntity> list = moduleColumnService.getList(moduleId, pagination);
  66. List<ColumnListVO> voList = JsonUtil.getJsonToList(list, ColumnListVO.class);
  67. voList.stream().forEach(t -> {
  68. String enCode = t.getEnCode();
  69. if (StringUtil.isNotEmpty(enCode)) {
  70. if (enCode.contains("-")) {
  71. enCode = enCode.substring(enCode.indexOf("-") + 1);
  72. }
  73. t.setEnCode(enCode.replace(JnpfConst.SIDE_MARK_PRE + t.getBindTable() + JnpfConst.SIDE_MARK, ""));
  74. }
  75. });
  76. PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
  77. return ActionResult.page(voList, paginationVO);
  78. }
  79. /**
  80. * 菜单列表权限
  81. *
  82. * @param moduleId 功能主键
  83. * @return ignore
  84. */
  85. @Operation(summary = "菜单列表权限")
  86. @Parameters({
  87. @Parameter(name = "moduleId", description = "功能主键", required = true)
  88. })
  89. @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
  90. @GetMapping("/{moduleId}/FieldList")
  91. public ActionResult<List<Map<String, String>>> fieldList(@PathVariable("moduleId") String moduleId) {
  92. List<Map<String, String>> list = new ArrayList<>();
  93. // 得到菜单id
  94. ModuleEntity entity = moduleService.getInfo(moduleId);
  95. if (entity != null) {
  96. PropertyJsonModel model = JsonUtil.getJsonToBean(entity.getPropertyJson(), PropertyJsonModel.class);
  97. if (model == null) {
  98. model = new PropertyJsonModel();
  99. }
  100. // 得到bean
  101. Object bean = SpringContext.getBean("visualdevServiceImpl");
  102. Object method = ReflectionUtil.invokeMethod(bean, "getInfo", new Class[]{String.class}, new Object[]{model.getModuleId()});
  103. Map<String, Object> map = JsonUtil.entityToMap(method);
  104. boolean isPc = entity.getCategory().equalsIgnoreCase("web");
  105. if (map != null) {
  106. Object columnData = isPc ? map.get("columnData") : map.get("appColumnData");
  107. if (Objects.nonNull(columnData)) {
  108. ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(columnData.toString(), ColumnDataModel.class);
  109. List<ColumnListField> columnListFields = JsonUtil.getJsonToList(columnDataModel.getDefaultColumnList(), ColumnListField.class);
  110. if (Objects.nonNull(columnListFields)) {
  111. columnListFields.stream().forEach(col -> {
  112. Map<String, String> dataMap = new HashMap<>();
  113. dataMap.put("field", col.getProp());
  114. dataMap.put("fieldName", col.getLabel());
  115. list.add(dataMap);
  116. });
  117. }
  118. }
  119. }
  120. }
  121. // if (map != null && map.containsKey("formData")) {
  122. // // 需要排除的key
  123. // String[] filterKey = new String[]{"PsdInput", "colorPicker", "rate", "slider", "divider",
  124. // "uploadImg", "uploadFz", "editor", "JNPFText", "relationFormAttr", "popupAttr", "groupTitle"};
  125. // List<String> filterKeyList = Arrays.asList(filterKey);
  126. // FormDataModel formDataModel = JsonUtil.getJsonToBean(String.valueOf(map.get("formData")), FormDataModel.class);
  127. // List<FieLdsModel> fieLdsModelList = JsonUtil.getJsonToList(formDataModel.getFields(), FieLdsModel.class);
  128. // RecursionForm recursionForm = new RecursionForm();
  129. // recursionForm.setList(fieLdsModelList);
  130. // recursionForm.setTableModelList(JsonUtil.getJsonToList(String.valueOf(map.get("tables")), TableModel.class));
  131. // List<FormAllModel> formAllModel = new ArrayList<>();
  132. // FormCloumnUtil.recursionForm(recursionForm, formAllModel);
  133. // for (FormAllModel allModel : formAllModel) {
  134. // if (FormEnum.mast.getMessage().equals(allModel.getJnpfKey())) {
  135. // FormColumnModel formColumnModel = allModel.getFormColumnModel();
  136. // FieLdsModel fieLdsModel = formColumnModel.getFieLdsModel();
  137. // long count = filterKeyList.stream().filter(t -> fieLdsModel != null && fieLdsModel.getConfig()!=null && t.equals(fieLdsModel.getConfig().getJnpfKey())).count();
  138. // if (count < 1) {
  139. // if (fieLdsModel != null && StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
  140. // Map<String, String> map1 = new HashedMap<>();
  141. // map1.put("field", fieLdsModel.getVModel());
  142. // map1.put("fieldName", fieLdsModel.getConfig().getLabel());
  143. // list.add(map1);
  144. // }
  145. // }
  146. // } else if (FormEnum.mastTable.getMessage().equals(allModel.getJnpfKey())) {
  147. // FormMastTableModel formColumnModel = allModel.getFormMastTableModel();
  148. // FieLdsModel fieLdsModel = formColumnModel.getMastTable().getFieLdsModel();
  149. // long count = filterKeyList.stream().filter(t -> fieLdsModel != null && fieLdsModel.getConfig() != null && t.equals(fieLdsModel.getConfig().getJnpfKey())).count();
  150. // if (count < 1) {
  151. // if (fieLdsModel != null && StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
  152. // Map<String, String> map1 = new HashedMap<>();
  153. // map1.put("field", fieLdsModel.getVModel());
  154. // map1.put("fieldName", fieLdsModel.getConfig().getLabel());
  155. // list.add(map1);
  156. // }
  157. // }
  158. // }
  159. //
  160. ///// 后面会用到
  161. //// else if (FormEnum.table.getMessage().equals(allModel.getJnpfKey())) {
  162. //// FormColumnTableModel childList = allModel.getChildList();
  163. //// List<FormColumnModel> childList1 = childList.getChildList();
  164. //// for (FormColumnModel formColumnModel : childList1) {
  165. //// FieLdsModel fieLdsModel = formColumnModel.getFieLdsModel();
  166. //// if (StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
  167. //// Map<String, String> map1 = new HashedMap<>();
  168. //// map1.put("field", fieLdsModel.getVModel());
  169. //// map1.put("fieldName", fieLdsModel.getConfig().getLabel());
  170. //// list.add(map1);
  171. //// }
  172. //// }
  173. //// }
  174. /////
  175. // }
  176. // }
  177. return ActionResult.success(list);
  178. }
  179. /**
  180. * 获取列表权限信息
  181. *
  182. * @param id 主键值
  183. * @return ignore
  184. * @throws DataException ignore
  185. */
  186. @Operation(summary = "获取列表权限信息")
  187. @Parameters({
  188. @Parameter(name = "id", description = "主键值", required = true)
  189. })
  190. @GetMapping("/{id}")
  191. public ActionResult<ModuleColumnInfoVO> info(@PathVariable("id") String id) throws DataException {
  192. ModuleColumnEntity entity = moduleColumnService.getInfo(id);
  193. String enCode = entity.getEnCode();
  194. if (StringUtil.isNotEmpty(enCode)) {
  195. if (enCode.contains("-") && entity.getFieldRule() == 2) {
  196. enCode = enCode.substring(enCode.indexOf("-") + 1);
  197. entity.setEnCode(enCode);
  198. }
  199. if (Objects.equals(entity.getFieldRule(), 1) && entity.getBindTable() != null) {
  200. entity.setEnCode(enCode.replace(JnpfConst.SIDE_MARK_PRE + entity.getBindTable() + JnpfConst.SIDE_MARK, ""));
  201. }
  202. }
  203. ModuleColumnInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, ModuleColumnInfoVO.class);
  204. return ActionResult.success(vo);
  205. }
  206. /**
  207. * 新建列表权限
  208. *
  209. * @param moduleColumnCrForm 实体对象
  210. * @return ignore
  211. */
  212. @Operation(summary = "新建列表权限")
  213. @Parameters({
  214. @Parameter(name = "moduleColumnCrForm", description = "实体对象", required = true)
  215. })
  216. @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
  217. @PostMapping
  218. public ActionResult create(@RequestBody @Valid ModuleColumnCrForm moduleColumnCrForm) {
  219. ModuleEntity moduleEntity = moduleService.getInfo(moduleColumnCrForm.getModuleId());
  220. ModuleColumnEntity entity = JsonUtil.getJsonToBean(moduleColumnCrForm, ModuleColumnEntity.class);
  221. if (moduleEntity != null) {
  222. PropertyJsonModel model = JsonUtil.getJsonToBean(moduleEntity.getPropertyJson(), PropertyJsonModel.class);
  223. if (model == null) {
  224. model = new PropertyJsonModel();
  225. }
  226. if (entity.getFieldRule() == 1 && StringUtil.isNotEmpty(moduleColumnCrForm.getBindTable())) {
  227. String enCode = JnpfConst.SIDE_MARK_PRE + moduleColumnCrForm.getBindTable() + JnpfConst.SIDE_MARK + entity.getEnCode();
  228. entity.setEnCode(enCode);
  229. }
  230. if (entity.getFieldRule() == 2 && StringUtil.isNotEmpty(moduleColumnCrForm.getChildTableKey())) {
  231. // 得到bean
  232. // Object bean = SpringContext.getBean("visualdevServiceImpl");
  233. // Object method = ReflectionUtil.invokeMethod(bean, "getTableNameToKey", new Class[]{String.class}, new Object[]{model.getModuleId()});
  234. // Map<String, Object> map = JsonUtil.entityToMap(method);
  235. //
  236. // String enCode = map.get(moduleColumnCrForm.getBindTable().toLowerCase()) + "-" + entity.getEnCode();
  237. String enCode = moduleColumnCrForm.getChildTableKey() + "-" + entity.getEnCode();
  238. entity.setEnCode(enCode);
  239. }
  240. }
  241. if (moduleColumnService.isExistByEnCode(entity.getModuleId(), entity.getEnCode(), entity.getId())) {
  242. return ActionResult.fail(MsgCode.EXIST002.get());
  243. }
  244. moduleColumnService.create(entity);
  245. return ActionResult.success(MsgCode.SU001.get());
  246. }
  247. /**
  248. * 更新列表权限
  249. *
  250. * @param id 主键值
  251. * @param moduleColumnUpForm 实体对象
  252. * @return ignore
  253. */
  254. @Operation(summary = "更新列表权限")
  255. @Parameters({
  256. @Parameter(name = "id", description = "主键值", required = true),
  257. @Parameter(name = "moduleColumnUpForm", description = "实体对象", required = true)
  258. })
  259. @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
  260. @PutMapping("/{id}")
  261. public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid ModuleColumnUpForm moduleColumnUpForm) {
  262. ModuleEntity moduleEntity = moduleService.getInfo(moduleColumnUpForm.getModuleId());
  263. ModuleColumnEntity entity = JsonUtil.getJsonToBean(moduleColumnUpForm, ModuleColumnEntity.class);
  264. if (moduleEntity != null) {
  265. PropertyJsonModel model = JsonUtil.getJsonToBean(moduleEntity.getPropertyJson(), PropertyJsonModel.class);
  266. if (model == null) {
  267. model = new PropertyJsonModel();
  268. }
  269. if (entity.getFieldRule() == 1 && StringUtil.isNotEmpty(moduleColumnUpForm.getBindTable())) {
  270. String enCode = JnpfConst.SIDE_MARK_PRE + moduleColumnUpForm.getBindTable() + JnpfConst.SIDE_MARK + entity.getEnCode();
  271. entity.setEnCode(enCode);
  272. }
  273. if (entity.getFieldRule() == 2 && StringUtil.isNotEmpty(moduleColumnUpForm.getChildTableKey())) {
  274. // // 得到bean
  275. // Object bean = SpringContext.getBean("visualdevServiceImpl");
  276. // Object method = ReflectionUtil.invokeMethod(bean, "getTableNameToKey", new Class[]{String.class}, new Object[]{model.getModuleId()});
  277. // Map<String, Object> map = JsonUtil.entityToMap(method);
  278. // String enCode = map.get(moduleColumnUpForm.getBindTable().toLowerCase()) + "-" + entity.getEnCode();
  279. String enCode = moduleColumnUpForm.getChildTableKey() + "-" + entity.getEnCode();
  280. entity.setEnCode(enCode);
  281. }
  282. }
  283. if (moduleColumnService.isExistByEnCode(entity.getModuleId(), entity.getEnCode(), id)) {
  284. return ActionResult.fail(MsgCode.EXIST002.get());
  285. }
  286. boolean flag = moduleColumnService.update(id, entity);
  287. if (!flag) {
  288. return ActionResult.success(MsgCode.FA002.get());
  289. }
  290. return ActionResult.success(MsgCode.SU004.get());
  291. }
  292. /**
  293. * 删除列表权限
  294. *
  295. * @param id 主键值
  296. * @return ignore
  297. */
  298. @Operation(summary = "删除列表权限")
  299. @Parameters({
  300. @Parameter(name = "id", description = "主键值", required = true)
  301. })
  302. @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
  303. @DeleteMapping("/{id}")
  304. public ActionResult delete(@PathVariable("id") String id) {
  305. ModuleColumnEntity entity = moduleColumnService.getInfo(id);
  306. if (entity != null) {
  307. moduleColumnService.delete(entity);
  308. return ActionResult.success(MsgCode.SU003.get());
  309. }
  310. return ActionResult.fail(MsgCode.FA003.get());
  311. }
  312. /**
  313. * 更新列表权限状态
  314. *
  315. * @param id 主键值
  316. * @return ignore
  317. */
  318. @Operation(summary = "更新列表权限状态")
  319. @Parameters({
  320. @Parameter(name = "id", description = "主键值", required = true)
  321. })
  322. @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
  323. @PutMapping("/{id}/Actions/State")
  324. public ActionResult upState(@PathVariable("id") String id) {
  325. ModuleColumnEntity entity = moduleColumnService.getInfo(id);
  326. if (entity.getEnabledMark() == null || "1".equals(String.valueOf(entity.getEnabledMark()))) {
  327. entity.setEnabledMark(0);
  328. } else {
  329. entity.setEnabledMark(1);
  330. }
  331. boolean flag = moduleColumnService.update(id, entity);
  332. if (!flag) {
  333. return ActionResult.success(MsgCode.FA002.get());
  334. }
  335. return ActionResult.success(MsgCode.SU004.get());
  336. }
  337. /**
  338. * 批量新建
  339. *
  340. * @param columnBatchForm 权限模型
  341. * @return ignore
  342. */
  343. @Operation(summary = "批量新建列表权限")
  344. @Parameters({
  345. @Parameter(name = "columnBatchForm", description = "权限模型", required = true)
  346. })
  347. @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
  348. @PostMapping("/Actions/Batch")
  349. public ActionResult batchCreate(@RequestBody @Valid ColumnBatchForm columnBatchForm) {
  350. List<ModuleColumnEntity> entitys = columnBatchForm.getColumnJson() != null ? JsonUtil.getJsonToList(columnBatchForm.getColumnJson(), ModuleColumnEntity.class) : new ArrayList<>();
  351. List<String> name = new ArrayList<>();
  352. for (ModuleColumnEntity entity : entitys) {
  353. entity.setModuleId(columnBatchForm.getModuleId());
  354. if (entity.getFieldRule() == 1) {
  355. String enCode = JnpfConst.SIDE_MARK_PRE + entity.getBindTable() + JnpfConst.SIDE_MARK + entity.getEnCode();
  356. entity.setEnCode(enCode);
  357. }
  358. if (entity.getFieldRule() == 2) {
  359. String enCode = entity.getChildTableKey() + "-" + entity.getEnCode();
  360. entity.setEnCode(enCode);
  361. }
  362. if (moduleColumnService.isExistByEnCode(entity.getModuleId(), entity.getEnCode(), null)) {
  363. return ActionResult.fail(MsgCode.EXIST002.get());
  364. }
  365. if (name.contains(entity.getEnCode())) {
  366. return ActionResult.fail(MsgCode.EXIST002.get());
  367. }
  368. name.add(entity.getEnCode());
  369. }
  370. moduleColumnService.create(entitys);
  371. return ActionResult.success(MsgCode.SU001.get());
  372. }
  373. }