ModuleFormController.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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.ModuleEntity;
  12. import jnpf.base.entity.ModuleFormEntity;
  13. import jnpf.base.model.form.*;
  14. import jnpf.base.model.module.PropertyJsonModel;
  15. import jnpf.base.service.ModuleFormService;
  16. import jnpf.base.service.ModuleService;
  17. import jnpf.base.vo.ListVO;
  18. import jnpf.base.vo.PageListVO;
  19. import jnpf.base.vo.PaginationVO;
  20. import jnpf.constant.JnpfConst;
  21. import jnpf.constant.MsgCode;
  22. import jnpf.exception.DataException;
  23. import jnpf.model.visualJson.FieLdsModel;
  24. import jnpf.model.visualJson.FormCloumnUtil;
  25. import jnpf.model.visualJson.FormDataModel;
  26. import jnpf.model.visualJson.TableModel;
  27. import jnpf.model.visualJson.analysis.*;
  28. import jnpf.util.JsonUtil;
  29. import jnpf.util.JsonUtilEx;
  30. import jnpf.util.ReflectionUtil;
  31. import jnpf.util.StringUtil;
  32. import jnpf.util.context.SpringContext;
  33. import org.apache.commons.collections4.map.HashedMap;
  34. import org.springframework.beans.factory.annotation.Autowired;
  35. import org.springframework.web.bind.annotation.*;
  36. import java.util.ArrayList;
  37. import java.util.List;
  38. import java.util.Map;
  39. /**
  40. * 表单权限
  41. * 版本: V3.1.0
  42. * 版权: 引迈信息技术有限公司(https://www.jnpfsoft.com)
  43. * 作者: JNPF开发平台组
  44. * 日期: 2021-09-14
  45. */
  46. @Tag(name = "表单权限", description = "ModuleForm")
  47. @RestController
  48. @RequestMapping("/api/system/ModuleForm")
  49. public class ModuleFormController extends SuperController<ModuleFormService, ModuleFormEntity> {
  50. @Autowired
  51. private ModuleFormService moduleFormService;
  52. @Autowired
  53. private ModuleService moduleService;
  54. /**
  55. * 获取表单权限列表
  56. *
  57. * @param moduleId 功能主键
  58. * @param pagination 分页参数
  59. * @return ignore
  60. */
  61. @Operation(summary = "获取表单权限列表")
  62. @Parameters({
  63. @Parameter(name = "moduleId", description = "功能主键", required = true)
  64. })
  65. @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
  66. @GetMapping("/{moduleId}/Fields")
  67. public ActionResult<PageListVO<ModuleFormListVO>> getList(@PathVariable("moduleId") String moduleId, Pagination pagination) {
  68. List<ModuleFormEntity> list = moduleFormService.getList(moduleId, pagination);
  69. List<ModuleFormListVO> voList = JsonUtil.getJsonToList(list, ModuleFormListVO.class);
  70. voList.stream().forEach(t -> {
  71. String enCode = t.getEnCode();
  72. if (StringUtil.isNotEmpty(enCode)) {
  73. if (enCode.contains("-")) {
  74. enCode = enCode.substring(enCode.indexOf("-") + 1);
  75. }
  76. t.setEnCode(enCode.replace(JnpfConst.SIDE_MARK_PRE + t.getBindTable() + JnpfConst.SIDE_MARK, ""));
  77. }
  78. });
  79. PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
  80. return ActionResult.page(voList, paginationVO);
  81. }
  82. /**
  83. * 菜单数据权限
  84. *
  85. * @param moduleId 功能主键
  86. * @return ignore
  87. */
  88. @Operation(summary = "菜单数据权限")
  89. @Parameters({
  90. @Parameter(name = "moduleId", description = "功能主键", required = true)
  91. })
  92. @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
  93. @GetMapping("/{moduleId}/FieldList")
  94. public ActionResult<List<Map<String, String>>> fieldList(@PathVariable("moduleId") String moduleId) {
  95. List<Map<String, String>> list = new ArrayList<>();
  96. // 得到菜单id
  97. ModuleEntity entity = moduleService.getInfo(moduleId);
  98. PropertyJsonModel model = JsonUtil.getJsonToBean(entity.getPropertyJson(), PropertyJsonModel.class);
  99. if (model == null) {
  100. model = new PropertyJsonModel();
  101. }
  102. // 得到bean
  103. Object bean = SpringContext.getBean("visualdevServiceImpl");
  104. Object method = ReflectionUtil.invokeMethod(bean, "getInfo", new Class[]{String.class}, new Object[]{model.getModuleId()});
  105. Map<String, Object> map = JsonUtil.entityToMap(method);
  106. if (map != null && map.containsKey("formData")) {
  107. FormDataModel formDataModel = JsonUtil.getJsonToBean(String.valueOf(map.get("formData")), FormDataModel.class);
  108. List<FieLdsModel> fieLdsModelList = JsonUtil.getJsonToList(formDataModel.getFields(), FieLdsModel.class);
  109. RecursionForm recursionForm = new RecursionForm();
  110. recursionForm.setList(fieLdsModelList);
  111. recursionForm.setTableModelList(JsonUtil.getJsonToList(String.valueOf(map.get("tables")), TableModel.class));
  112. List<FormAllModel> formAllModel = new ArrayList<>();
  113. FormCloumnUtil.recursionForm(recursionForm, formAllModel);
  114. for (FormAllModel allModel : formAllModel) {
  115. if (FormEnum.table.getMessage().equals(allModel.getJnpfKey())) {
  116. FormColumnTableModel childList = allModel.getChildList();
  117. Map<String, String> map1 = new HashedMap<>();
  118. map1.put("field", childList.getTableModel());
  119. map1.put("fieldName", childList.getLabel());
  120. list.add(map1);
  121. } else if (FormEnum.mast.getMessage().equals(allModel.getJnpfKey())) {
  122. FormColumnModel formColumnModel = allModel.getFormColumnModel();
  123. FieLdsModel fieLdsModel = formColumnModel.getFieLdsModel();
  124. if (StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
  125. Map<String, String> map1 = new HashedMap<>();
  126. map1.put("field", fieLdsModel.getVModel());
  127. map1.put("fieldName", fieLdsModel.getConfig().getLabel());
  128. list.add(map1);
  129. }
  130. } else if (FormEnum.mastTable.getMessage().equals(allModel.getJnpfKey())) {
  131. FormMastTableModel formColumnModel = allModel.getFormMastTableModel();
  132. FieLdsModel fieLdsModel = formColumnModel.getMastTable().getFieLdsModel();
  133. if (StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
  134. Map<String, String> map1 = new HashedMap<>();
  135. map1.put("field", fieLdsModel.getVModel());
  136. map1.put("fieldName", fieLdsModel.getConfig().getLabel());
  137. list.add(map1);
  138. }
  139. }
  140. }
  141. }
  142. return ActionResult.success(list);
  143. }
  144. /**
  145. * 获取表单权限信息
  146. *
  147. * @param id 主键值
  148. * @return ignore
  149. * @throws DataException ignore
  150. */
  151. @Operation(summary = "获取表单权限信息")
  152. @Parameters({
  153. @Parameter(name = "id", description = "主键值", required = true)
  154. })
  155. @GetMapping("/{id}")
  156. public ActionResult<ModuleFormInfoVO> info(@PathVariable("id") String id) throws DataException {
  157. ModuleFormEntity entity = moduleFormService.getInfo(id);
  158. String enCode = entity.getEnCode();
  159. if (StringUtil.isNotEmpty(enCode)) {
  160. if (enCode.contains("-") && entity.getFieldRule() == 2) {
  161. enCode = enCode.substring(enCode.indexOf("-") + 1);
  162. entity.setEnCode(enCode);
  163. }
  164. if (entity.getFieldRule() == 1 && entity.getBindTable() != null) {
  165. entity.setEnCode(enCode.replace(JnpfConst.SIDE_MARK_PRE + entity.getBindTable() + JnpfConst.SIDE_MARK, ""));
  166. }
  167. }
  168. ModuleFormInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, ModuleFormInfoVO.class);
  169. return ActionResult.success(vo);
  170. }
  171. /**
  172. * 新建表单权限
  173. *
  174. * @param moduleFormCrForm 实体对象
  175. * @return ignore
  176. */
  177. @Operation(summary = "新建表单权限")
  178. @Parameters({
  179. @Parameter(name = "moduleFormCrForm", description = "实体对象", required = true)
  180. })
  181. @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
  182. @PostMapping
  183. public ActionResult create(@RequestBody @Valid ModuleFormCrForm moduleFormCrForm) {
  184. ModuleEntity moduleEntity = moduleService.getInfo(moduleFormCrForm.getModuleId());
  185. ModuleFormEntity entity = JsonUtil.getJsonToBean(moduleFormCrForm, ModuleFormEntity.class);
  186. if (moduleEntity != null) {
  187. PropertyJsonModel model = JsonUtil.getJsonToBean(moduleEntity.getPropertyJson(), PropertyJsonModel.class);
  188. if (model == null) {
  189. model = new PropertyJsonModel();
  190. }
  191. if (entity.getFieldRule() == 1 && StringUtil.isNotEmpty(moduleFormCrForm.getBindTable())) {
  192. String enCode = JnpfConst.SIDE_MARK_PRE + moduleFormCrForm.getBindTable() + JnpfConst.SIDE_MARK + entity.getEnCode();
  193. entity.setEnCode(enCode);
  194. }
  195. if (entity.getFieldRule() == 2 && StringUtil.isNotEmpty(moduleFormCrForm.getChildTableKey())) {
  196. // 得到bean
  197. // Object bean = SpringContext.getBean("visualdevServiceImpl");
  198. // Object method = ReflectionUtil.invokeMethod(bean, "getTableNameToKey", new Class[]{String.class}, new Object[]{model.getModuleId()});
  199. // Map<String, Object> map = JsonUtil.entityToMap(method);
  200. //
  201. // String enCode = map.get(moduleFormCrForm.getBindTable().toLowerCase()) + "-" + entity.getEnCode();
  202. String enCode = moduleFormCrForm.getChildTableKey() + "-" + entity.getEnCode();
  203. entity.setEnCode(enCode);
  204. }
  205. }
  206. if (moduleFormService.isExistByEnCode(entity.getModuleId(), entity.getEnCode(), entity.getId())) {
  207. return ActionResult.fail(MsgCode.EXIST002.get());
  208. }
  209. moduleFormService.create(entity);
  210. return ActionResult.success(MsgCode.SU001.get());
  211. }
  212. /**
  213. * 更新表单权限
  214. *
  215. * @param id 主键值
  216. * @param moduleFormUpForm 实体对象
  217. * @return ignore
  218. */
  219. @Operation(summary = "更新表单权限")
  220. @Parameters({
  221. @Parameter(name = "id", description = "主键值", required = true),
  222. @Parameter(name = "moduleFormUpForm", description = "实体对象", required = true)
  223. })
  224. @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
  225. @PutMapping("/{id}")
  226. public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid ModuleFormUpForm moduleFormUpForm) {
  227. ModuleEntity moduleEntity = moduleService.getInfo(moduleFormUpForm.getModuleId());
  228. ModuleFormEntity entity = JsonUtil.getJsonToBean(moduleFormUpForm, ModuleFormEntity.class);
  229. if (moduleEntity != null) {
  230. PropertyJsonModel model = JsonUtil.getJsonToBean(moduleEntity.getPropertyJson(), PropertyJsonModel.class);
  231. if (model == null) {
  232. model = new PropertyJsonModel();
  233. }
  234. if (entity.getFieldRule() == 1 && StringUtil.isNotEmpty(moduleFormUpForm.getBindTable())) {
  235. String enCode = JnpfConst.SIDE_MARK_PRE + moduleFormUpForm.getBindTable() + JnpfConst.SIDE_MARK + entity.getEnCode();
  236. entity.setEnCode(enCode);
  237. }
  238. if (entity.getFieldRule() == 2 && StringUtil.isNotEmpty(moduleFormUpForm.getChildTableKey())) {
  239. // // 得到bean
  240. // Object bean = SpringContext.getBean("visualdevServiceImpl");
  241. // Object method = ReflectionUtil.invokeMethod(bean, "getTableNameToKey", new Class[]{String.class}, new Object[]{model.getModuleId()});
  242. // Map<String, Object> map = JsonUtil.entityToMap(method);
  243. //
  244. // String enCode = map.get(moduleFormUpForm.getBindTable().toLowerCase()) + "-" + entity.getEnCode();
  245. String enCode = moduleFormUpForm.getChildTableKey() + "-" + entity.getEnCode();
  246. entity.setEnCode(enCode);
  247. }
  248. }
  249. if (moduleFormService.isExistByEnCode(entity.getModuleId(), entity.getEnCode(), id)) {
  250. return ActionResult.fail(MsgCode.EXIST002.get());
  251. }
  252. boolean flag = moduleFormService.update(id, entity);
  253. if (!flag) {
  254. return ActionResult.success(MsgCode.FA002.get());
  255. }
  256. return ActionResult.success(MsgCode.SU004.get());
  257. }
  258. /**
  259. * 删除表单权限
  260. *
  261. * @param id 主键值
  262. * @return
  263. */
  264. @Operation(summary = "删除表单权限")
  265. @Parameters({
  266. @Parameter(name = "id", description = "主键值", required = true)
  267. })
  268. @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
  269. @DeleteMapping("/{id}")
  270. public ActionResult delete(@PathVariable("id") String id) {
  271. ModuleFormEntity entity = moduleFormService.getInfo(id);
  272. if (entity != null) {
  273. moduleFormService.delete(entity);
  274. return ActionResult.success(MsgCode.SU003.get());
  275. }
  276. return ActionResult.fail(MsgCode.FA003.get());
  277. }
  278. /**
  279. * 批量新建
  280. *
  281. * @param formBatchForm 批量表单模型
  282. * @return
  283. */
  284. @Operation(summary = "批量新建表单权限")
  285. @Parameters({
  286. @Parameter(name = "formBatchForm", description = "批量表单模型", required = true)
  287. })
  288. @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
  289. @PostMapping("/Actions/Batch")
  290. public ActionResult batchCreate(@RequestBody @Valid FormBatchForm formBatchForm) {
  291. List<ModuleFormEntity> entitys = formBatchForm.getFormJson() != null ? JsonUtil.getJsonToList(formBatchForm.getFormJson(), ModuleFormEntity.class) : new ArrayList<>();
  292. List<String> name = new ArrayList<>();
  293. for (ModuleFormEntity entity : entitys) {
  294. if (entity.getFieldRule() == 1) {
  295. String enCode = JnpfConst.SIDE_MARK_PRE + entity.getBindTable() + JnpfConst.SIDE_MARK + entity.getEnCode();
  296. entity.setEnCode(enCode);
  297. }
  298. if (entity.getFieldRule() == 2) {
  299. String enCode = entity.getChildTableKey() + "-" + entity.getEnCode();
  300. entity.setEnCode(enCode);
  301. }
  302. entity.setModuleId(formBatchForm.getModuleId());
  303. if (moduleFormService.isExistByEnCode(entity.getModuleId(), entity.getEnCode(), null)) {
  304. return ActionResult.fail(MsgCode.EXIST002.get());
  305. }
  306. if (name.contains(entity.getEnCode())) {
  307. return ActionResult.fail(MsgCode.EXIST002.get());
  308. }
  309. name.add(entity.getEnCode());
  310. }
  311. moduleFormService.create(entitys);
  312. return ActionResult.success(MsgCode.SU001.get());
  313. }
  314. /**
  315. * 更新表单权限状态
  316. *
  317. * @param id 主键值
  318. * @return
  319. */
  320. @Operation(summary = "更新表单权限状态")
  321. @Parameters({
  322. @Parameter(name = "id", description = "主键值", required = true)
  323. })
  324. @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
  325. @PutMapping("/{id}/Actions/State")
  326. public ActionResult upState(@PathVariable("id") String id) {
  327. ModuleFormEntity entity = moduleFormService.getInfo(id);
  328. entity.setEnabledMark("1".equals(String.valueOf(entity.getEnabledMark())) ? 0 : 1);
  329. boolean flag = moduleFormService.update(id, entity);
  330. if (!flag) {
  331. return ActionResult.success(MsgCode.FA002.get());
  332. }
  333. return ActionResult.success(MsgCode.SU004.get());
  334. }
  335. }