diff --git a/src/main/java/neatlogic/module/tenant/api/auth/AuthModuleGetApi.java b/src/main/java/neatlogic/module/tenant/api/auth/AuthModuleGetApi.java index 1a40eb27dda86ef26cf8d0b307ff6dc6515d04bf..f22537eb1ddb3ff333c12d149f1d85301864d60a 100644 --- a/src/main/java/neatlogic/module/tenant/api/auth/AuthModuleGetApi.java +++ b/src/main/java/neatlogic/module/tenant/api/auth/AuthModuleGetApi.java @@ -28,6 +28,7 @@ import neatlogic.framework.common.constvalue.ApiParamType; import neatlogic.framework.common.util.ModuleUtil; import neatlogic.framework.config.ConfigManager; import neatlogic.framework.config.FrameworkTenantConfig; +import neatlogic.framework.dao.mapper.HomePageMapper; import neatlogic.framework.dao.mapper.UserMapper; import neatlogic.framework.dto.*; import neatlogic.framework.dto.module.ModuleGroupVo; @@ -54,6 +55,9 @@ public class AuthModuleGetApi extends PrivateApiComponentBase { @Resource UserMapper userMapper; + @Resource + HomePageMapper homePageMapper; + @Override public String getToken() { return "auth/module/get"; @@ -123,6 +127,15 @@ public class AuthModuleGetApi extends PrivateApiComponentBase { //****获取用户默认模块首页开始**** HashMap> OuterMap = new HashMap<>(16); UserDataVo userDataVo = userMapper.getUserDataByUserUuidAndType(UserContext.get().getUserUuid(), "defaultModulePage"); + if (userDataVo == null) { + List homePageIdList = homePageMapper.getHomePageIdListByAuthority(UserContext.get().getAuthenticationInfoVo()); + if (CollectionUtils.isNotEmpty(homePageIdList)) { + HomePageVo homePage = homePageMapper.getMinSortHomePageByIdList(homePageIdList); + if (homePage != null) { + userDataVo = new UserDataVo(UserContext.get().getUserUuid(), homePage.getConfigStr(), "defaultModulePage"); + } + } + } if (userDataVo != null) { String data = userDataVo.getData(); JSONObject dataJson = JSONObject.parseObject(data); diff --git a/src/main/java/neatlogic/module/tenant/api/homepage/ActiveHomePageApi.java b/src/main/java/neatlogic/module/tenant/api/homepage/ActiveHomePageApi.java new file mode 100644 index 0000000000000000000000000000000000000000..7c9fb116bf453694ec13bcd7ecf2fccafcfbefa2 --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/api/homepage/ActiveHomePageApi.java @@ -0,0 +1,58 @@ +package neatlogic.module.tenant.api.homepage; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.auth.label.HOME_PAGE_MODIFY; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.dao.mapper.HomePageMapper; +import neatlogic.framework.dto.HomePageVo; +import neatlogic.framework.exception.homepage.HomePageNotFoundException; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; + +@Service +@Transactional +@AuthAction(action = HOME_PAGE_MODIFY.class) +@OperationType(type = OperationTypeEnum.UPDATE) +public class ActiveHomePageApi extends PrivateApiComponentBase { + + @Resource + private HomePageMapper homePageMapper; + + @Override + public String getToken() { + return "homepage/active"; + } + + @Override + public String getName() { + return "nmtah.activehomepageapi.getname"; + } + + @Override + public String getConfig() { + return null; + } + + @Input({ + @Param(name = "id", type = ApiParamType.LONG, isRequired = true, desc = "common.id") + }) + @Output({}) + @Description(desc = "nmtah.activehomepageapi.getname") + @Override + public Object myDoService(JSONObject jsonObj) throws Exception { + Long id = jsonObj.getLong("id"); + HomePageVo homePage = homePageMapper.getHomePageById(id); + if (homePage == null) { + throw new HomePageNotFoundException(id); + } + homePageMapper.updateHomePageIsActiveById(id); + return null; + } + +} diff --git a/src/main/java/neatlogic/module/tenant/api/homepage/DeleteHomePageApi.java b/src/main/java/neatlogic/module/tenant/api/homepage/DeleteHomePageApi.java new file mode 100644 index 0000000000000000000000000000000000000000..c8ac4d441852b88e609c84b9f41db77767a060d3 --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/api/homepage/DeleteHomePageApi.java @@ -0,0 +1,59 @@ +package neatlogic.module.tenant.api.homepage; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.auth.label.HOME_PAGE_MODIFY; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.dao.mapper.HomePageMapper; +import neatlogic.framework.dto.HomePageVo; +import neatlogic.framework.exception.homepage.HomePageNotFoundException; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; + +@Service +@Transactional +@AuthAction(action = HOME_PAGE_MODIFY.class) +@OperationType(type = OperationTypeEnum.DELETE) +public class DeleteHomePageApi extends PrivateApiComponentBase { + + @Resource + private HomePageMapper homePageMapper; + + @Override + public String getToken() { + return "homepage/delete"; + } + + @Override + public String getName() { + return "nmtah.deletehomepageapi.getname"; + } + + @Override + public String getConfig() { + return null; + } + + @Input({ + @Param(name = "id", type = ApiParamType.LONG, isRequired = true, desc = "common.id") + }) + @Output({}) + @Description(desc = "nmtah.deletehomepageapi.getname") + @Override + public Object myDoService(JSONObject jsonObj) throws Exception { + Long id = jsonObj.getLong("id"); + HomePageVo homePage = homePageMapper.getHomePageById(id); + if (homePage == null) { + throw new HomePageNotFoundException(id); + } + homePageMapper.deleteHomePageById(id); + homePageMapper.deleteHomePageAuthorityByHomePageId(id); + return null; + } + +} diff --git a/src/main/java/neatlogic/module/tenant/api/homepage/GetHomePageApi.java b/src/main/java/neatlogic/module/tenant/api/homepage/GetHomePageApi.java new file mode 100644 index 0000000000000000000000000000000000000000..a23cce214a78af861cc25604f22c788d4cd5a1c4 --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/api/homepage/GetHomePageApi.java @@ -0,0 +1,62 @@ +package neatlogic.module.tenant.api.homepage; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.auth.label.HOME_PAGE_MODIFY; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.dao.mapper.HomePageMapper; +import neatlogic.framework.dto.AuthorityVo; +import neatlogic.framework.dto.HomePageVo; +import neatlogic.framework.exception.homepage.HomePageNotFoundException; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.List; + +@Service +@AuthAction(action = HOME_PAGE_MODIFY.class) +@OperationType(type = OperationTypeEnum.SEARCH) +public class GetHomePageApi extends PrivateApiComponentBase { + + @Resource + private HomePageMapper homePageMapper; + + @Override + public String getToken() { + return "homepage/get"; + } + + @Override + public String getName() { + return "nmtah.gethomepageapi.getname"; + } + + @Override + public String getConfig() { + return null; + } + + @Input({ + @Param(name = "id", type = ApiParamType.LONG, isRequired = true, desc = "common.id") + }) + @Output({ + @Param(explode = HomePageVo.class, desc = "common.tbodylist") + }) + @Description(desc = "nmtah.gethomepageapi.getname") + @Override + public Object myDoService(JSONObject jsonObj) throws Exception { + Long id = jsonObj.getLong("id"); + HomePageVo homePage = homePageMapper.getHomePageById(id); + if (homePage == null) { + throw new HomePageNotFoundException(id); + } + + List authorityVoList = homePageMapper.getHomePageAuthorityListByHomePageId(id); + homePage.setAuthorityList(AuthorityVo.getAuthorityList(authorityVoList)); + return homePage; + } + +} diff --git a/src/main/java/neatlogic/module/tenant/api/homepage/ListHomePageApi.java b/src/main/java/neatlogic/module/tenant/api/homepage/ListHomePageApi.java new file mode 100644 index 0000000000000000000000000000000000000000..2196f72b850b7e7f7736a4a1514fba50c55e7efa --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/api/homepage/ListHomePageApi.java @@ -0,0 +1,116 @@ +package neatlogic.module.tenant.api.homepage; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.auth.label.HOME_PAGE_MODIFY; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.common.constvalue.GroupSearch; +import neatlogic.framework.common.constvalue.UserType; +import neatlogic.framework.common.dto.BasePageVo; +import neatlogic.framework.dao.mapper.HomePageMapper; +import neatlogic.framework.dao.mapper.RoleMapper; +import neatlogic.framework.dao.mapper.TeamMapper; +import neatlogic.framework.dao.mapper.UserMapper; +import neatlogic.framework.dto.*; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.framework.util.TableResultUtil; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +@Service +@AuthAction(action = HOME_PAGE_MODIFY.class) +@OperationType(type = OperationTypeEnum.SEARCH) +public class ListHomePageApi extends PrivateApiComponentBase { + + @Resource + private HomePageMapper homePageMapper; + + @Resource + private UserMapper userMapper; + + @Resource + private TeamMapper teamMapper; + + @Resource + private RoleMapper roleMapper; + + @Override + public String getToken() { + return "homepage/list"; + } + + @Override + public String getName() { + return "nmtah.listhomepageapi.getname"; + } + + @Override + public String getConfig() { + return null; + } + + @Input({ + @Param(name = "keyword", type = ApiParamType.STRING, desc = "common.keyword"), + @Param(name = "pageSize", type = ApiParamType.INTEGER, desc = "common.pagesize"), + @Param(name = "currentPage", type = ApiParamType.INTEGER, desc = "common.currentpage") + }) + @Output({ + @Param(explode = BasePageVo.class), + @Param(name="tbodyList",explode= HomePageVo[].class,desc="common.tbodylist") + }) + @Description(desc = "nmtah.listhomepageapi.getname") + @Override + public Object myDoService(JSONObject jsonObj) throws Exception { + BasePageVo basePageVo = jsonObj.toJavaObject(BasePageVo.class); + int rowNum = homePageMapper.getHomePageCount(basePageVo); + if (rowNum > 0) { + basePageVo.setRowNum(rowNum); + List tbodyList = homePageMapper.getHomePageList(basePageVo); + for (HomePageVo homePageVo : tbodyList) { + JSONArray authorityVoArray = new JSONArray(); + List authorityVoList = homePageMapper.getHomePageAuthorityListByHomePageId(homePageVo.getId()); + homePageVo.setAuthorityList(AuthorityVo.getAuthorityList(authorityVoList)); + if (CollectionUtils.isNotEmpty(authorityVoList)) { + for (AuthorityVo authorityVo : authorityVoList) { + if (Objects.equals(authorityVo.getType(), GroupSearch.USER.getValue())) { + UserVo userVo = userMapper.getUserBaseInfoByUuid(authorityVo.getUuid()); + if (userVo != null) { + authorityVoArray.add(userVo); + } + } else if (Objects.equals(authorityVo.getType(), GroupSearch.TEAM.getValue())) { + TeamVo search = new TeamVo(); + search.setUuid(authorityVo.getUuid()); + TeamVo teamVo = teamMapper.getTeamSimpleInfoByUuid(search); + if (teamVo != null) { + authorityVoArray.add(teamVo); + } + } else if (Objects.equals(authorityVo.getType(), GroupSearch.ROLE.getValue())) { + RoleVo roleVo = roleMapper.getRoleSimpleInfoByUuid(authorityVo.getUuid()); + if (roleVo != null) { + authorityVoArray.add(roleVo); + } + } else if (Objects.equals(authorityVo.getType(), GroupSearch.COMMON.getValue())) { + WorkAssignmentUnitVo workAssignmentUnitVo = new WorkAssignmentUnitVo(); + workAssignmentUnitVo.setUuid(authorityVo.getUuid()); + workAssignmentUnitVo.setName(UserType.getText(authorityVo.getUuid())); + workAssignmentUnitVo.setInitType(GroupSearch.COMMON.getValue()); + authorityVoArray.add(workAssignmentUnitVo); + } + } + } + homePageVo.setAuthorityVoList(authorityVoArray); + } + return TableResultUtil.getResult(tbodyList, basePageVo); + } + return TableResultUtil.getResult(new ArrayList<>(), basePageVo); + } + +} diff --git a/src/main/java/neatlogic/module/tenant/api/homepage/MoveHomePageApi.java b/src/main/java/neatlogic/module/tenant/api/homepage/MoveHomePageApi.java new file mode 100644 index 0000000000000000000000000000000000000000..37fd66f4732c58e6b18b7810a2529405f674444c --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/api/homepage/MoveHomePageApi.java @@ -0,0 +1,84 @@ +/*Copyright (C) $today.year 深圳极向量科技有限公司 All Rights Reserved. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see .*/ + +package neatlogic.module.tenant.api.homepage; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.auth.label.HOME_PAGE_MODIFY; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.dto.HomePageVo; +import neatlogic.framework.exception.homepage.HomePageNotFoundException; +import neatlogic.framework.restful.annotation.Description; +import neatlogic.framework.restful.annotation.Input; +import neatlogic.framework.restful.annotation.OperationType; +import neatlogic.framework.restful.annotation.Param; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.framework.dao.mapper.HomePageMapper; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; + +@Service +@Transactional +@OperationType(type = OperationTypeEnum.UPDATE) +@AuthAction(action = HOME_PAGE_MODIFY.class) +public class MoveHomePageApi extends PrivateApiComponentBase { + + @Resource + private HomePageMapper homePageMapper; + + @Override + public String getToken() { + return "homepage/move"; + } + + @Override + public String getName() { + return "nmtah.movehomepageapi.getname"; + } + + @Override + public String getConfig() { + return null; + } + + @Input({ + @Param(name = "id", type = ApiParamType.STRING, isRequired = true, desc = "common.id"), + @Param(name = "sort", type = ApiParamType.INTEGER, isRequired = true, desc = "common.sort") + }) + @Description(desc = "nmtah.movehomepageapi.getname") + @Override + public Object myDoService(JSONObject jsonObj) throws Exception { + Long id = jsonObj.getLong("id"); + HomePageVo homePage = homePageMapper.getHomePageById(id); + if (homePage == null) { + throw new HomePageNotFoundException(id); + } + int oldSort = homePage.getSort(); + int newSort = jsonObj.getIntValue("sort"); + if(oldSort < newSort) {//往后移动 + homePageMapper.updateSortDecrement(oldSort, newSort); + }else if(oldSort > newSort) {//往前移动 + homePageMapper.updateSortIncrement(newSort, oldSort); + } + homePage.setSort(newSort); + homePageMapper.updateHomePageSortById(homePage); + return null; + } + +} diff --git a/src/main/java/neatlogic/module/tenant/api/homepage/SaveHomePageApi.java b/src/main/java/neatlogic/module/tenant/api/homepage/SaveHomePageApi.java new file mode 100644 index 0000000000000000000000000000000000000000..77cbe08aaf1763c14332ce01c0843c1d526c72e0 --- /dev/null +++ b/src/main/java/neatlogic/module/tenant/api/homepage/SaveHomePageApi.java @@ -0,0 +1,115 @@ +/*Copyright (C) $today.year 深圳极向量科技有限公司 All Rights Reserved. + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see .*/ + +package neatlogic.module.tenant.api.homepage; + +import com.alibaba.fastjson.JSONObject; +import neatlogic.framework.auth.core.AuthAction; +import neatlogic.framework.auth.label.HOME_PAGE_MODIFY; +import neatlogic.framework.common.constvalue.ApiParamType; +import neatlogic.framework.dao.mapper.HomePageMapper; +import neatlogic.framework.dto.AuthorityVo; +import neatlogic.framework.dto.FieldValidResultVo; +import neatlogic.framework.dto.HomePageVo; +import neatlogic.framework.exception.homepage.HomePageNameRepeatException; +import neatlogic.framework.exception.homepage.HomePageNotFoundException; +import neatlogic.framework.restful.annotation.*; +import neatlogic.framework.restful.constvalue.OperationTypeEnum; +import neatlogic.framework.restful.core.IValid; +import neatlogic.framework.restful.core.privateapi.PrivateApiComponentBase; +import neatlogic.framework.util.RegexUtils; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import javax.annotation.Resource; +import java.util.List; + +@Service +@Transactional +@OperationType(type = OperationTypeEnum.CREATE) +@AuthAction(action = HOME_PAGE_MODIFY.class) +public class SaveHomePageApi extends PrivateApiComponentBase { + + @Resource + private HomePageMapper homePageMapper; + + @Override + public String getToken() { + return "homepage/save"; + } + + @Override + public String getName() { + return "nmtah.savehomepageapi.getname"; + } + + @Override + public String getConfig() { + return null; + } + + @Input({ + @Param(name = "id", type = ApiParamType.STRING, desc = "common.id"), + @Param(name = "name", type = ApiParamType.REGEX, rule = RegexUtils.NAME, isRequired = true, maxLength = 50, desc = "common.name"), + @Param(name = "isActive", type = ApiParamType.ENUM, isRequired = true, desc = "common.isactive", rule = "0,1"), + @Param(name = "authorityList", type = ApiParamType.JSONARRAY, desc = "common.authoritylist", help = "可多选,格式[\"user#userUuid\",\"team#teamUuid\",\"role#roleUuid\"]"), + @Param(name = "config", type = ApiParamType.JSONOBJECT, isRequired = true, desc = "common.config") + }) + @Output({ + @Param(name = "Return", type = ApiParamType.LONG, desc = "common.id") + }) + @Description(desc = "nmtah.savehomepageapi.getname") + @Override + public Object myDoService(JSONObject jsonObj) throws Exception { + Long id = jsonObj.getLong("id"); + HomePageVo homePage = jsonObj.toJavaObject(HomePageVo.class); + if (id != null) { + HomePageVo oldHomePage = homePageMapper.getHomePageById(id); + if (oldHomePage == null) { + throw new HomePageNotFoundException(id); + } + homePage.setSort(oldHomePage.getSort()); + homePageMapper.deleteHomePageAuthorityByHomePageId(homePage.getId()); + } else { + Integer sort = homePageMapper.getMaxSort(); + if(sort == null) { + sort = 0; + } + sort++; + homePage.setSort(sort); + } + homePageMapper.insertHomePage(homePage); + List authorityList = homePage.getAuthorityList(); + if (CollectionUtils.isNotEmpty(authorityList)) { + List authorityVoList = AuthorityVo.getAuthorityVoList(authorityList, null); + for(AuthorityVo authorityVo : authorityVoList) { + homePageMapper.insertHomePageAuthority(homePage.getId(), authorityVo); + } + } + return homePage.getId(); + } + + public IValid name() { + return value -> { + HomePageVo homePage = value.toJavaObject(HomePageVo.class); + if (homePageMapper.checkHomePageNameIsRepeat(homePage) > 0) { + return new FieldValidResultVo(new HomePageNameRepeatException(homePage.getName())); + } + return new FieldValidResultVo(); + }; + } + +} diff --git a/src/main/java/neatlogic/module/tenant/api/util/JavascriptTestApi.java b/src/main/java/neatlogic/module/tenant/api/util/JavascriptTestApi.java index 8c66b2c63558810f7be76612ef6191f906c3238a..95ebe4c767de0c193e83f0eb73edf7cf841f35d1 100644 --- a/src/main/java/neatlogic/module/tenant/api/util/JavascriptTestApi.java +++ b/src/main/java/neatlogic/module/tenant/api/util/JavascriptTestApi.java @@ -34,7 +34,7 @@ public class JavascriptTestApi extends PrivateApiComponentBase { } @Input({ - @Param(name = "data", type = ApiParamType.STRING, isRequired = true, desc = "参数"), + @Param(name = "data", type = ApiParamType.JSONOBJECT, isRequired = true, desc = "参数"), @Param(name = "script", type = ApiParamType.STRING, isRequired = true, desc = "脚本") }) @Output({