| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391 |
- package jnpf.base.controller;
- import cn.dev33.satoken.annotation.SaCheckPermission;
- import cn.dev33.satoken.annotation.SaMode;
- import io.swagger.v3.oas.annotations.Operation;
- import io.swagger.v3.oas.annotations.Parameter;
- import io.swagger.v3.oas.annotations.Parameters;
- import io.swagger.v3.oas.annotations.tags.Tag;
- import jakarta.validation.Valid;
- import jnpf.base.ActionResult;
- import jnpf.base.Pagination;
- import jnpf.base.entity.ModuleColumnEntity;
- import jnpf.base.entity.ModuleEntity;
- import jnpf.base.model.ColumnDataModel;
- import jnpf.base.model.Template6.ColumnListField;
- import jnpf.base.model.column.*;
- import jnpf.base.model.module.PropertyJsonModel;
- import jnpf.base.service.ModuleColumnService;
- import jnpf.base.service.ModuleService;
- import jnpf.base.vo.ListVO;
- import jnpf.base.vo.PageListVO;
- import jnpf.base.vo.PaginationVO;
- import jnpf.constant.JnpfConst;
- import jnpf.constant.MsgCode;
- import jnpf.exception.DataException;
- import jnpf.util.JsonUtil;
- import jnpf.util.JsonUtilEx;
- import jnpf.util.ReflectionUtil;
- import jnpf.util.StringUtil;
- import jnpf.util.context.SpringContext;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.*;
- import java.util.*;
- /**
- * 列表权限
- *
- * @author JNPF开发平台组
- * @version V3.1.0
- * @copyright 引迈信息技术有限公司
- * @date 2019年9月27日 上午9:18
- */
- @Tag(name = "列表权限", description = "ModuleColumn")
- @Validated
- @RestController
- @RequestMapping("/api/system/ModuleColumn")
- public class ModuleColumnController extends SuperController<ModuleColumnService, ModuleColumnEntity> {
- @Autowired
- private ModuleColumnService moduleColumnService;
- @Autowired
- private ModuleService moduleService;
- /**
- * 获取列表权限信息列表
- *
- * @param moduleId 功能主键
- * @param pagination 分页参数
- * @return ignore
- */
- @Operation(summary = "获取列表权限列表")
- @Parameters({
- @Parameter(name = "moduleId", description = "功能主键", required = true)
- })
- @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
- @GetMapping("/{moduleId}/Fields")
- public ActionResult<PageListVO<ColumnListVO>> getList(@PathVariable("moduleId") String moduleId, Pagination pagination) {
- List<ModuleColumnEntity> list = moduleColumnService.getList(moduleId, pagination);
- List<ColumnListVO> voList = JsonUtil.getJsonToList(list, ColumnListVO.class);
- voList.stream().forEach(t -> {
- String enCode = t.getEnCode();
- if (StringUtil.isNotEmpty(enCode)) {
- if (enCode.contains("-")) {
- enCode = enCode.substring(enCode.indexOf("-") + 1);
- }
- t.setEnCode(enCode.replace(JnpfConst.SIDE_MARK_PRE + t.getBindTable() + JnpfConst.SIDE_MARK, ""));
- }
- });
- PaginationVO paginationVO = JsonUtil.getJsonToBean(pagination, PaginationVO.class);
- return ActionResult.page(voList, paginationVO);
- }
- /**
- * 菜单列表权限
- *
- * @param moduleId 功能主键
- * @return ignore
- */
- @Operation(summary = "菜单列表权限")
- @Parameters({
- @Parameter(name = "moduleId", description = "功能主键", required = true)
- })
- @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
- @GetMapping("/{moduleId}/FieldList")
- public ActionResult<List<Map<String, String>>> fieldList(@PathVariable("moduleId") String moduleId) {
- List<Map<String, String>> list = new ArrayList<>();
- // 得到菜单id
- ModuleEntity entity = moduleService.getInfo(moduleId);
- if (entity != null) {
- PropertyJsonModel model = JsonUtil.getJsonToBean(entity.getPropertyJson(), PropertyJsonModel.class);
- if (model == null) {
- model = new PropertyJsonModel();
- }
- // 得到bean
- Object bean = SpringContext.getBean("visualdevServiceImpl");
- Object method = ReflectionUtil.invokeMethod(bean, "getInfo", new Class[]{String.class}, new Object[]{model.getModuleId()});
- Map<String, Object> map = JsonUtil.entityToMap(method);
- boolean isPc = entity.getCategory().equalsIgnoreCase("web");
- if (map != null) {
- Object columnData = isPc ? map.get("columnData") : map.get("appColumnData");
- if (Objects.nonNull(columnData)) {
- ColumnDataModel columnDataModel = JsonUtil.getJsonToBean(columnData.toString(), ColumnDataModel.class);
- List<ColumnListField> columnListFields = JsonUtil.getJsonToList(columnDataModel.getDefaultColumnList(), ColumnListField.class);
- if (Objects.nonNull(columnListFields)) {
- columnListFields.stream().forEach(col -> {
- Map<String, String> dataMap = new HashMap<>();
- dataMap.put("field", col.getProp());
- dataMap.put("fieldName", col.getLabel());
- list.add(dataMap);
- });
- }
- }
- }
- }
- // if (map != null && map.containsKey("formData")) {
- // // 需要排除的key
- // String[] filterKey = new String[]{"PsdInput", "colorPicker", "rate", "slider", "divider",
- // "uploadImg", "uploadFz", "editor", "JNPFText", "relationFormAttr", "popupAttr", "groupTitle"};
- // List<String> filterKeyList = Arrays.asList(filterKey);
- // FormDataModel formDataModel = JsonUtil.getJsonToBean(String.valueOf(map.get("formData")), FormDataModel.class);
- // List<FieLdsModel> fieLdsModelList = JsonUtil.getJsonToList(formDataModel.getFields(), FieLdsModel.class);
- // RecursionForm recursionForm = new RecursionForm();
- // recursionForm.setList(fieLdsModelList);
- // recursionForm.setTableModelList(JsonUtil.getJsonToList(String.valueOf(map.get("tables")), TableModel.class));
- // List<FormAllModel> formAllModel = new ArrayList<>();
- // FormCloumnUtil.recursionForm(recursionForm, formAllModel);
- // for (FormAllModel allModel : formAllModel) {
- // if (FormEnum.mast.getMessage().equals(allModel.getJnpfKey())) {
- // FormColumnModel formColumnModel = allModel.getFormColumnModel();
- // FieLdsModel fieLdsModel = formColumnModel.getFieLdsModel();
- // long count = filterKeyList.stream().filter(t -> fieLdsModel != null && fieLdsModel.getConfig()!=null && t.equals(fieLdsModel.getConfig().getJnpfKey())).count();
- // if (count < 1) {
- // if (fieLdsModel != null && StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
- // Map<String, String> map1 = new HashedMap<>();
- // map1.put("field", fieLdsModel.getVModel());
- // map1.put("fieldName", fieLdsModel.getConfig().getLabel());
- // list.add(map1);
- // }
- // }
- // } else if (FormEnum.mastTable.getMessage().equals(allModel.getJnpfKey())) {
- // FormMastTableModel formColumnModel = allModel.getFormMastTableModel();
- // FieLdsModel fieLdsModel = formColumnModel.getMastTable().getFieLdsModel();
- // long count = filterKeyList.stream().filter(t -> fieLdsModel != null && fieLdsModel.getConfig() != null && t.equals(fieLdsModel.getConfig().getJnpfKey())).count();
- // if (count < 1) {
- // if (fieLdsModel != null && StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
- // Map<String, String> map1 = new HashedMap<>();
- // map1.put("field", fieLdsModel.getVModel());
- // map1.put("fieldName", fieLdsModel.getConfig().getLabel());
- // list.add(map1);
- // }
- // }
- // }
- //
- ///// 后面会用到
- //// else if (FormEnum.table.getMessage().equals(allModel.getJnpfKey())) {
- //// FormColumnTableModel childList = allModel.getChildList();
- //// List<FormColumnModel> childList1 = childList.getChildList();
- //// for (FormColumnModel formColumnModel : childList1) {
- //// FieLdsModel fieLdsModel = formColumnModel.getFieLdsModel();
- //// if (StringUtil.isNotEmpty(fieLdsModel.getVModel())) {
- //// Map<String, String> map1 = new HashedMap<>();
- //// map1.put("field", fieLdsModel.getVModel());
- //// map1.put("fieldName", fieLdsModel.getConfig().getLabel());
- //// list.add(map1);
- //// }
- //// }
- //// }
- /////
- // }
- // }
- return ActionResult.success(list);
- }
- /**
- * 获取列表权限信息
- *
- * @param id 主键值
- * @return ignore
- * @throws DataException ignore
- */
- @Operation(summary = "获取列表权限信息")
- @Parameters({
- @Parameter(name = "id", description = "主键值", required = true)
- })
- @GetMapping("/{id}")
- public ActionResult<ModuleColumnInfoVO> info(@PathVariable("id") String id) throws DataException {
- ModuleColumnEntity entity = moduleColumnService.getInfo(id);
- String enCode = entity.getEnCode();
- if (StringUtil.isNotEmpty(enCode)) {
- if (enCode.contains("-") && entity.getFieldRule() == 2) {
- enCode = enCode.substring(enCode.indexOf("-") + 1);
- entity.setEnCode(enCode);
- }
- if (Objects.equals(entity.getFieldRule(), 1) && entity.getBindTable() != null) {
- entity.setEnCode(enCode.replace(JnpfConst.SIDE_MARK_PRE + entity.getBindTable() + JnpfConst.SIDE_MARK, ""));
- }
- }
- ModuleColumnInfoVO vo = JsonUtilEx.getJsonToBeanEx(entity, ModuleColumnInfoVO.class);
- return ActionResult.success(vo);
- }
- /**
- * 新建列表权限
- *
- * @param moduleColumnCrForm 实体对象
- * @return ignore
- */
- @Operation(summary = "新建列表权限")
- @Parameters({
- @Parameter(name = "moduleColumnCrForm", description = "实体对象", required = true)
- })
- @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
- @PostMapping
- public ActionResult create(@RequestBody @Valid ModuleColumnCrForm moduleColumnCrForm) {
- ModuleEntity moduleEntity = moduleService.getInfo(moduleColumnCrForm.getModuleId());
- ModuleColumnEntity entity = JsonUtil.getJsonToBean(moduleColumnCrForm, ModuleColumnEntity.class);
- if (moduleEntity != null) {
- PropertyJsonModel model = JsonUtil.getJsonToBean(moduleEntity.getPropertyJson(), PropertyJsonModel.class);
- if (model == null) {
- model = new PropertyJsonModel();
- }
- if (entity.getFieldRule() == 1 && StringUtil.isNotEmpty(moduleColumnCrForm.getBindTable())) {
- String enCode = JnpfConst.SIDE_MARK_PRE + moduleColumnCrForm.getBindTable() + JnpfConst.SIDE_MARK + entity.getEnCode();
- entity.setEnCode(enCode);
- }
- if (entity.getFieldRule() == 2 && StringUtil.isNotEmpty(moduleColumnCrForm.getChildTableKey())) {
- // 得到bean
- // Object bean = SpringContext.getBean("visualdevServiceImpl");
- // Object method = ReflectionUtil.invokeMethod(bean, "getTableNameToKey", new Class[]{String.class}, new Object[]{model.getModuleId()});
- // Map<String, Object> map = JsonUtil.entityToMap(method);
- //
- // String enCode = map.get(moduleColumnCrForm.getBindTable().toLowerCase()) + "-" + entity.getEnCode();
- String enCode = moduleColumnCrForm.getChildTableKey() + "-" + entity.getEnCode();
- entity.setEnCode(enCode);
- }
- }
- if (moduleColumnService.isExistByEnCode(entity.getModuleId(), entity.getEnCode(), entity.getId())) {
- return ActionResult.fail(MsgCode.EXIST002.get());
- }
- moduleColumnService.create(entity);
- return ActionResult.success(MsgCode.SU001.get());
- }
- /**
- * 更新列表权限
- *
- * @param id 主键值
- * @param moduleColumnUpForm 实体对象
- * @return ignore
- */
- @Operation(summary = "更新列表权限")
- @Parameters({
- @Parameter(name = "id", description = "主键值", required = true),
- @Parameter(name = "moduleColumnUpForm", description = "实体对象", required = true)
- })
- @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
- @PutMapping("/{id}")
- public ActionResult update(@PathVariable("id") String id, @RequestBody @Valid ModuleColumnUpForm moduleColumnUpForm) {
- ModuleEntity moduleEntity = moduleService.getInfo(moduleColumnUpForm.getModuleId());
- ModuleColumnEntity entity = JsonUtil.getJsonToBean(moduleColumnUpForm, ModuleColumnEntity.class);
- if (moduleEntity != null) {
- PropertyJsonModel model = JsonUtil.getJsonToBean(moduleEntity.getPropertyJson(), PropertyJsonModel.class);
- if (model == null) {
- model = new PropertyJsonModel();
- }
- if (entity.getFieldRule() == 1 && StringUtil.isNotEmpty(moduleColumnUpForm.getBindTable())) {
- String enCode = JnpfConst.SIDE_MARK_PRE + moduleColumnUpForm.getBindTable() + JnpfConst.SIDE_MARK + entity.getEnCode();
- entity.setEnCode(enCode);
- }
- if (entity.getFieldRule() == 2 && StringUtil.isNotEmpty(moduleColumnUpForm.getChildTableKey())) {
- // // 得到bean
- // Object bean = SpringContext.getBean("visualdevServiceImpl");
- // Object method = ReflectionUtil.invokeMethod(bean, "getTableNameToKey", new Class[]{String.class}, new Object[]{model.getModuleId()});
- // Map<String, Object> map = JsonUtil.entityToMap(method);
- // String enCode = map.get(moduleColumnUpForm.getBindTable().toLowerCase()) + "-" + entity.getEnCode();
- String enCode = moduleColumnUpForm.getChildTableKey() + "-" + entity.getEnCode();
- entity.setEnCode(enCode);
- }
- }
- if (moduleColumnService.isExistByEnCode(entity.getModuleId(), entity.getEnCode(), id)) {
- return ActionResult.fail(MsgCode.EXIST002.get());
- }
- boolean flag = moduleColumnService.update(id, entity);
- if (!flag) {
- return ActionResult.success(MsgCode.FA002.get());
- }
- return ActionResult.success(MsgCode.SU004.get());
- }
- /**
- * 删除列表权限
- *
- * @param id 主键值
- * @return ignore
- */
- @Operation(summary = "删除列表权限")
- @Parameters({
- @Parameter(name = "id", description = "主键值", required = true)
- })
- @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
- @DeleteMapping("/{id}")
- public ActionResult delete(@PathVariable("id") String id) {
- ModuleColumnEntity entity = moduleColumnService.getInfo(id);
- if (entity != null) {
- moduleColumnService.delete(entity);
- return ActionResult.success(MsgCode.SU003.get());
- }
- return ActionResult.fail(MsgCode.FA003.get());
- }
- /**
- * 更新列表权限状态
- *
- * @param id 主键值
- * @return ignore
- */
- @Operation(summary = "更新列表权限状态")
- @Parameters({
- @Parameter(name = "id", description = "主键值", required = true)
- })
- @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
- @PutMapping("/{id}/Actions/State")
- public ActionResult upState(@PathVariable("id") String id) {
- ModuleColumnEntity entity = moduleColumnService.getInfo(id);
- if (entity.getEnabledMark() == null || "1".equals(String.valueOf(entity.getEnabledMark()))) {
- entity.setEnabledMark(0);
- } else {
- entity.setEnabledMark(1);
- }
- boolean flag = moduleColumnService.update(id, entity);
- if (!flag) {
- return ActionResult.success(MsgCode.FA002.get());
- }
- return ActionResult.success(MsgCode.SU004.get());
- }
- /**
- * 批量新建
- *
- * @param columnBatchForm 权限模型
- * @return ignore
- */
- @Operation(summary = "批量新建列表权限")
- @Parameters({
- @Parameter(name = "columnBatchForm", description = "权限模型", required = true)
- })
- @SaCheckPermission(value = {"permission.resource", "appConfig.appResource"}, mode = SaMode.OR)
- @PostMapping("/Actions/Batch")
- public ActionResult batchCreate(@RequestBody @Valid ColumnBatchForm columnBatchForm) {
- List<ModuleColumnEntity> entitys = columnBatchForm.getColumnJson() != null ? JsonUtil.getJsonToList(columnBatchForm.getColumnJson(), ModuleColumnEntity.class) : new ArrayList<>();
- List<String> name = new ArrayList<>();
- for (ModuleColumnEntity entity : entitys) {
- entity.setModuleId(columnBatchForm.getModuleId());
- if (entity.getFieldRule() == 1) {
- String enCode = JnpfConst.SIDE_MARK_PRE + entity.getBindTable() + JnpfConst.SIDE_MARK + entity.getEnCode();
- entity.setEnCode(enCode);
- }
- if (entity.getFieldRule() == 2) {
- String enCode = entity.getChildTableKey() + "-" + entity.getEnCode();
- entity.setEnCode(enCode);
- }
- if (moduleColumnService.isExistByEnCode(entity.getModuleId(), entity.getEnCode(), null)) {
- return ActionResult.fail(MsgCode.EXIST002.get());
- }
- if (name.contains(entity.getEnCode())) {
- return ActionResult.fail(MsgCode.EXIST002.get());
- }
- name.add(entity.getEnCode());
- }
- moduleColumnService.create(entitys);
- return ActionResult.success(MsgCode.SU001.get());
- }
- }
|