123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366 |
- package cn.aiyangniu.api.controller.system;
- import cn.aiyangniu.api.common.entity.system.AuthEntity;
- import cn.aiyangniu.api.common.entity.system.SysModEntity;
- import cn.aiyangniu.api.common.entity.system.SysModVo;
- import cn.aiyangniu.api.service.system.SysModService;
- import cn.aiyangniu.api.common.util.AuthUtil;
- import cn.aiyangniu.api.common.util.CharacterFiltUtil;
- import cn.aiyangniu.api.common.util.RandomUtil;
- import com.alibaba.fastjson.JSONObject;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiImplicitParam;
- import io.swagger.annotations.ApiImplicitParams;
- import io.swagger.annotations.ApiOperation;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.web.bind.annotation.RequestBody;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RequestMethod;
- import org.springframework.web.bind.annotation.RestController;
- import javax.annotation.Resource;
- import javax.servlet.http.HttpServletRequest;
- import java.util.*;
- /**
- * 模块业务接口类
- *
- * @author Henry Hall
- * @since 2020-08-08
- */
- @Slf4j
- @RestController
- @Api(tags="系统模块接口")
- @RequestMapping("/sysModule")
- public class SysModController {
- @Resource
- private SysModService modService;
- @Resource
- private RandomUtil randomUtil;
- @Resource
- private AuthUtil authUtil;
- /**
- * saveMod 新增/修改模块
- *
- * @param req 请求对象
- * @return 返回结果Json串
- */
- @ApiOperation(value = "新增/修改模块信息")
- @RequestMapping(value="/save", method= RequestMethod.POST)
- @ApiImplicitParam(name = "modEntity", value = "模块信息实体对象", paramType = "body", dataType="SysModEntity", dataTypeClass = SysModEntity.class, required = true)
- public Map<String, Object> saveMod(@RequestBody SysModEntity modEntity, HttpServletRequest req) {
- Map<String, Object> result = new HashMap<>();
- String retCode, retMsg, sysRandom, token, reqRandom, userId, modId, modName, code, parentId, logo, url;
- token = req.getHeader("Authorization");
- if(token == null || "null".equals(token)) {
- retCode = "1002";
- retMsg = "对不起,您的操作非法,请登录!";
- } else {
- AuthEntity auth = authUtil.getUserId(token);
- if(auth == null || !auth.isSuccess()) {
- retCode = "1002";
- retMsg = "对不起,您没有登录或会话超时,请重新登录!";
- } else {
- userId = auth.getUserId();
- sysRandom = randomUtil.getSysRandom(userId);
- modId = modEntity.getModId();
- modName = modEntity.getModName();
- code = modEntity.getModCode();
- parentId = modEntity.getParentId();
- logo = modEntity.getLogo();
- url = modEntity.getUrl();
- reqRandom = modEntity.getReqRandom();
- modId = CharacterFiltUtil.inputFilter(modId, true);
- modName = CharacterFiltUtil.inputFilter(modName, true);
- code = CharacterFiltUtil.inputFilter(code, true);
- parentId = CharacterFiltUtil.inputFilter(parentId, true);
- logo = CharacterFiltUtil.inputFilter(logo, true);
- url = CharacterFiltUtil.inputFilter(url, true);
- reqRandom = CharacterFiltUtil.inputFilter(reqRandom, true);
- if("".equals(modName) || "".equals(code) || "0".equals(parentId) || "".equals(reqRandom)) {
- retCode = "100110020101";
- retMsg = "对不起,您输入的信息有为空的必填项,请检查!";
- } else if(modName.length() > 30 || code.length() > 10 || logo.length() > 30 || url.length() > 60 || parentId.length() != 36) {
- retCode = "100110020102";
- retMsg = "对不起,您输入的信息有超出字数限制的项,请检查!";
- } else if(RandomUtil.verifySysRandom(reqRandom, sysRandom)) {
- retCode = "100110020103";
- retMsg = "对不起,您已经提交过了,请不要重复提交!";
- } else {
- randomUtil.setSysRandom(userId);
- modEntity.setModName(modName);
- modEntity.setModCode(code);
- modEntity.setParentId(parentId);
- modEntity.setUrl(url);
- modEntity.setLogo(logo);
- modEntity.setOptUser(userId);
- int r;
- if("".equals(modId)) {
- r = modService.addMod(modEntity);
- } else {
- modEntity.setModId(modId);
- r = modService.edtMod(modEntity);
- }
- if(r != 0) {
- retCode = "1001";
- retMsg = "恭喜您,模块保存成功!";
- } else {
- retCode = "100110020104";
- retMsg = "对不起,系统错误,请联系系统管理员!";
- }
- }
- }
- }
- result.put("code", retCode);
- result.put("msg", retMsg);
- return result;
- }
- /**
- * deleteMod 删除模块
- *
- * @param req 请求对象
- * @return 返回结果Json串
- */
- @ApiOperation(value = "删除模块信息")
- @RequestMapping(value="/delete", method= RequestMethod.POST)
- @ApiImplicitParam(name = "vo", value = "删除模块的请求对象", paramType = "body", dataType="SysModVo", dataTypeClass = SysModVo.class, required = true)
- public Map<String, Object> deleteMod(@RequestBody SysModVo vo, HttpServletRequest req) {
- Map<String, Object> result = new HashMap<>();
- String retCode, retMsg, token;
- token = req.getHeader("Authorization");
- if(token == null || "null".equals(token)) {
- retCode = "1002";
- retMsg = "对不起,您的操作非法,请登录!";
- } else {
- AuthEntity auth = authUtil.getUserId(token);
- if(auth == null || !auth.isSuccess()) {
- retCode = "1002";
- retMsg = "对不起,您没有登录或会话超时,请重新登录!";
- } else {
- List<String> ids = vo.getModIds();
- if(ids==null || ids.size()==0) {
- retCode = "100110020201";
- retMsg = "对不起,您提交的信息有为空的必填项,请检查!";
- } else {
- int r = modService.delMods(auth.getUserId(), ids);
- if(r != 0) {
- retCode = "1001";
- retMsg = "恭喜您,模块删除成功!";
- } else {
- retCode = "100110020204";
- retMsg = "对不起,系统错误,请联系系统管理员!";
- }
- }
- }
- }
- result.put("code", retCode);
- result.put("msg", retMsg);
- return result;
- }
- /**
- * getMod 获取单一模块
- *
- * @param req 请求对象
- * @return 返回结果Json串
- */
- @ApiOperation(value = "获取模块详情")
- @RequestMapping(value="/getById", method= RequestMethod.GET)
- @ApiImplicitParam(name = "modId", value = "模块编号", paramType = "query", dataType="string", dataTypeClass = String.class, required = true)
- public Map<String, Object> getMod(String modId, HttpServletRequest req) {
- Map<String, Object> result = new HashMap<>();
- String retCode, retMsg, token;
- SysModEntity modEntity;
- token = req.getHeader("Authorization");
- if(token == null || "null".equals(token)) {
- retCode = "1002";
- retMsg = "对不起,您的操作非法,请登录!";
- } else {
- boolean auth = authUtil.hasLogin(token);
- if(!auth) {
- retCode = "1002";
- retMsg = "对不起,您没有登录或会话超时,请重新登录!";
- } else {
- modId = CharacterFiltUtil.inputFilter(modId, true);
- if("".equals(modId) || modId.length() != 36) {
- retCode = "100110020301";
- retMsg = "对不起,您请求的参数非法,请重试!";
- } else {
- modEntity = modService.getMod(modId);
- if(modEntity != null) {
- result.put("data", modEntity);
- retCode = "1001";
- retMsg = "查询成功。";
- } else {
- retCode = "100110020305";
- retMsg = "暂无内容";
- }
- }
- }
- }
- result.put("code", retCode);
- result.put("msg", retMsg);
- return result;
- }
- /**
- * list 列表显示模块
- *
- * @param req 请求对象
- * @return 返回结果Json串
- */
- @ApiOperation(value = "获取模块树状列表")
- @RequestMapping(value="/list", method= RequestMethod.GET)
- @ApiImplicitParam(name = "parentId", value = "父级模块编号", paramType = "query", dataType="string", dataTypeClass = String.class)
- public Map<String, Object> listMods(String parentId, HttpServletRequest req) {
- Map<String, Object> result = new HashMap<>();
- String retCode, retMsg, token;
- token = req.getHeader("Authorization");
- if(token == null || "null".equals(token)) {
- retCode = "1002";
- retMsg = "对不起,您的操作非法,请登录!";
- } else {
- boolean auth = authUtil.hasLogin(token);
- if(!auth) {
- retCode = "1002";
- retMsg = "对不起,您没有登录或会话超时,请重新登录!";
- } else {
- parentId = parentId==null || "".equals(parentId) ? "00000000-0000-0000-0000-000000000000" : parentId; // 一级模块的父级编号
- List<SysModEntity> modEntities = modService.listMods(parentId);
- if(modEntities != null && modEntities.size() > 0) {
- result.put("data", modEntities);
- retCode = "1001";
- retMsg = "查询成功。";
- } else {
- retCode = "100110020405";
- retMsg = "暂无内容";
- }
- }
- }
- result.put("code", retCode);
- result.put("msg", retMsg);
- return result;
- }
- /**
- * select 选择显示模块
- *
- * @param req 请求对象
- * @return 返回结果Json串
- */
- @ApiOperation(value = "获取模块下拉列表")
- @RequestMapping(value="/select", method= RequestMethod.GET)
- @ApiImplicitParams({
- @ApiImplicitParam(name = "kind", value = "种类,1为全部,2为当前用户所拥有的", paramType = "query", dataType="string", dataTypeClass = String.class),
- @ApiImplicitParam(name = "schName", value = "关键字", paramType = "query", dataType="string", dataTypeClass = String.class)
- })
- public Map<String, Object> selMods(String kind, String schName, HttpServletRequest req) {
- Map<String, Object> result = new HashMap<>();
- String retCode, retMsg, token, parentId;
- token = req.getHeader("Authorization");
- if(token == null || "null".equals(token)) {
- retCode = "1002";
- retMsg = "对不起,您的操作非法,请登录!";
- } else {
- JSONObject userSession = authUtil.getUserSession(token);
- if(userSession == null) {
- retCode = "1002";
- retMsg = "对不起,您没有登录或会话超时,请重新登录!";
- } else {
- kind = CharacterFiltUtil.inputFilter(kind, true);
- schName = CharacterFiltUtil.inputFilter(schName, true);
- String userMods = userSession.get("modCodes").toString();
- parentId = "00000000-0000-0000-0000-000000000000"; // 一级模块的父级编号
- List<SysModEntity> modEntities = modService.selMods(kind, parentId, schName, userMods);
- if(modEntities != null && modEntities.size() > 0) {
- result.put("data", modEntities);
- retCode = "1001";
- retMsg = "查询成功。";
- } else {
- retCode = "100110020505";
- retMsg = "暂无内容";
- }
- }
- }
- result.put("code", retCode);
- result.put("msg", retMsg);
- return result;
- }
- /**
- * sortMods 统计某模块下的子模块数量,用于自动排序
- */
- @ApiOperation(value = "获取模块数量")
- @RequestMapping(value="/sort", method= RequestMethod.GET)
- @ApiImplicitParam(name = "parentId", value = "父级模块编号", paramType = "query", dataType="string", dataTypeClass = String.class)
- private Map<String, Object> sortMods(String parentId, HttpServletRequest req) {
- Map<String, Object> result = new HashMap<>();
- String retCode, retMsg, token;
- token = req.getHeader("Authorization");
- if(token == null || "null".equals(token)) {
- retCode = "1002";
- retMsg = "对不起,您的操作非法,请登录!";
- } else {
- boolean auth = authUtil.hasLogin(token);
- if(!auth) {
- retCode = "1002";
- retMsg = "对不起,您没有登录或会话超时,请重新登录!";
- } else {
- parentId = CharacterFiltUtil.inputFilter(parentId, true);
- if("".equals(parentId) || parentId.length() != 36) {
- retCode = "100110020601";
- retMsg = "对不起,您请求的参数不正确,请重试!";
- } else {
- int modNum = modService.sortMods(parentId);
- result.put("data", modNum);
- retCode = "1001";
- retMsg = "查询成功。";
- }
- }
- }
- result.put("code", retCode);
- result.put("msg", retMsg);
- return result;
- }
- /**
- * getModBtns 获取模块及按钮信息
- *
- * @param req 请求对象
- * @return 返回结果Json串
- */
- @ApiOperation(value = "获取模块及数量")
- @RequestMapping(value="/getModBtns", method= RequestMethod.GET)
- public Map<String, Object> getModBtns(HttpServletRequest req) {
- Map<String, Object> result = new HashMap<>();
- String retCode, retMsg, token;
- token = req.getHeader("Authorization");
- if(token == null || "null".equals(token)) {
- retCode = "1002";
- retMsg = "对不起,您的操作非法,请登录!";
- } else {
- boolean auth = authUtil.hasLogin(token);
- if(!auth) {
- retCode = "1002";
- retMsg = "对不起,您没有登录或会话超时,请重新登录!";
- } else {
- List<SysModEntity> modEntities = modService.getModBtns();
- if(modEntities != null && modEntities.size() > 0) {
- result.put("data", modEntities);
- retCode = "1001";
- retMsg = "查询成功。";
- } else {
- retCode = "100110020905";
- retMsg = "暂无内容";
- }
- }
- }
- result.put("code", retCode);
- result.put("msg", retMsg);
- return result;
- }
- }
|