Merge branch 'dev' of http://blit.7drlb.com:8888/r/moral into dev
1 files deleted
13 files added
14 files modified
| | |
| | | // 全局配置 |
| | | GlobalConfig gc = new GlobalConfig(); |
| | | //String projectPath = System.getProperty("user.dir"); |
| | | String projectPath="E:\\workspace\\moral\\screen-api"; |
| | | String projectPath="D:\\tools\\moral\\screen-api\\"; |
| | | gc.setOutputDir(projectPath + "/src/main/java"); |
| | | gc.setAuthor("moral"); |
| | | gc.setOpen(false); |
| | |
| | | |
| | | // 数据源配置 |
| | | DataSourceConfig dsc = new DataSourceConfig(); |
| | | dsc.setUrl("jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC"); |
| | | dsc.setUrl("jdbc:mysql://39.97.177.149:3306/moral?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC"); |
| | | dsc.setDriverName("com.mysql.cj.jdbc.Driver"); |
| | | dsc.setUsername("root"); |
| | | dsc.setPassword("123456"); |
| | | dsc.setPassword("chenkaiyu111"); |
| | | mpg.setDataSource(dsc); |
| | | |
| | | // 包配置 |
| | |
| | | strategy.setColumnNaming(NamingStrategy.underline_to_camel); |
| | | strategy.setEntityLombokModel(true); |
| | | strategy.setRestControllerStyle(true); |
| | | //strategy.setInclude(scanner("表名,多个英文逗号分割").split(",")); |
| | | //自定义要生成实体类的表 |
| | | strategy.setInclude(scanner("表名,多个英文逗号分割").split(",")); |
| | | strategy.setControllerMappingHyphenStyle(true); |
| | | // strategy.setTablePrefix(pc.getModuleName() + "_"); |
| | | mpg.setStrategy(strategy); |
| | |
| | | <scope>test</scope> |
| | | </dependency> |
| | | <dependency> |
| | | <groupId>com.google.code.kaptcha</groupId> |
| | | <groupId>com.github.penggle</groupId> |
| | | <artifactId>kaptcha</artifactId> |
| | | <version>2.3.2</version> |
| | | </dependency> |
| | |
| | | package com.moral.api.controller; |
| | | |
| | | import com.moral.constant.Constants; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import com.moral.api.entity.Group; |
| | | import com.moral.api.entity.User; |
| | | import com.moral.api.service.GroupService; |
| | | import com.moral.api.service.UserService; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.constant.ResultMessage; |
| | | import com.moral.util.AESUtils; |
| | | import com.moral.util.MD5Utils; |
| | | import com.moral.util.TokenUtils; |
| | | import com.moral.util.WebUtils; |
| | | |
| | |
| | | @Autowired |
| | | private GroupService groupService; |
| | | |
| | | @Value("${AES.KEY}") |
| | | private String AESKey; |
| | | |
| | | @ApiOperation(value = "登陆", notes = "登陆") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "account", value = "账户", required = false, paramType = "query", dataType = "String"), |
| | |
| | | if (!(parameters.containsKey("account") && parameters.containsKey("password"))) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | //接收参数 |
| | | String password = parameters.get("password").toString(); |
| | | //密码解密 |
| | | password = AESUtils.decrypt(password, AESKey); |
| | | |
| | | User user = userService.selectUserInfo(parameters); |
| | | //校验账户 |
| | | if (user == null) { |
| | | return ResultMessage.fail(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode(), ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); |
| | | Map<String, Object> result = userService.login(parameters); |
| | | if (!result.containsKey("data")) { |
| | | return ResultMessage.fail(Integer.parseInt(result.get("code").toString()), result.get("msg").toString()); |
| | | } |
| | | //校验密码 |
| | | if (!MD5Utils.saltMD5Verify(password, user.getPassword())) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PASSWORD_INVALID.getCode(), ResponseCodeEnum.PASSWORD_INVALID.getMsg()); |
| | | } |
| | | //校验是否删除 |
| | | if (Constants.DELETE.equals(user.getIsDelete())) { |
| | | return ResultMessage.fail(ResponseCodeEnum.ACCOUNT_IS_DELETE.getCode(), ResponseCodeEnum.ACCOUNT_IS_DELETE.getMsg()); |
| | | } |
| | | //校验是否过期 |
| | | if (user.getExpireTime() != null && user.getExpireTime().getTime() < System.currentTimeMillis()) { |
| | | return ResultMessage.fail(ResponseCodeEnum.ACCOUNT_IS_EXPIRE.getCode(), ResponseCodeEnum.ACCOUNT_IS_EXPIRE.getMsg()); |
| | | } |
| | | Map<String, Object> result = userService.login(user); |
| | | if (!result.containsKey("token")) { |
| | | return ResultMessage.fail(ResponseCodeEnum.TOKEN_CREATE_ERROR.getCode(), ResponseCodeEnum.TOKEN_CREATE_ERROR.getMsg()); |
| | | } |
| | | return ResultMessage.ok(); |
| | | return ResultMessage.ok(result.get("data")); |
| | | } |
| | | |
| | | @ApiOperation(value = "注销", notes = "注销") |
| | |
| | | if (!parameters.containsKey("uid")) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | String userId = request.getParameter("uid"); |
| | | String userId = parameters.get("uid").toString(); |
| | | String token = request.getHeader("token"); |
| | | TokenUtils.destoryToken(userId, token); |
| | | return ResultMessage.ok(); |
| | |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.moral.api.entity.User; |
| | | import com.moral.api.service.UserService; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | |
| | | |
| | | @ApiOperation(value = "添加账户", notes = "添加账户") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "account", value = "账户,长度6-10", required = false, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "password", value = "密码,长度6-20", required = false, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "account", value = "账户,长度6-10", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "password", value = "密码,长度6-20", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "userName", value = "账户名称", required = false, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "email", value = "邮箱,格式123456@qq.com", required = false, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "mobile", value = "手机号,1开头11为数字", required = false, paramType = "query", dataType = "String"), |
| | |
| | | }) |
| | | @RequestMapping(value = "addUser", method = RequestMethod.POST) |
| | | public ResultMessage addUser(User user, HttpServletRequest request) { |
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); |
| | | if (!(parameters.containsKey("account") && parameters.containsKey("password"))) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | if (user.getAccount().isEmpty() || user.getPassword().isEmpty()) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | String token = request.getHeader("token"); |
| | | Map<String, Object> map = userService.addUser(user, token); |
| | | |
| | | |
| | | if (map.containsKey("msg")) { |
| | | return ResultMessage.fail(map.get("msg").toString()); |
| | | Map<String, Object> result = userService.addUser(user, token); |
| | | if (!result.isEmpty()) { |
| | | return ResultMessage.fail((int) result.get("code"), result.get("msg").toString()); |
| | | } |
| | | return ResultMessage.ok(); |
| | | } |
| | |
| | | @ApiImplicitParam(name = "token", value = "token", required = true, paramType = "header", dataType = "String") |
| | | }) |
| | | @RequestMapping(value = "deleteUser", method = RequestMethod.POST) |
| | | public ResultMessage deleteUser(String userId, HttpServletRequest request) { |
| | | public ResultMessage deleteUser(String userId) { |
| | | if (userId == null) { |
| | | return ResultMessage.fail("请求参数错误"); |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | String token = request.getHeader("token"); |
| | | Map<String, Object> map = userService.deleteUser(Integer.parseInt(userId), token); |
| | | if (map.containsKey("msg")) { |
| | | return ResultMessage.fail(map.get("msg").toString()); |
| | | QueryWrapper<User> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("id", userId); |
| | | User user = userService.getOne(queryWrapper); |
| | | if (user == null) { |
| | | return ResultMessage.fail(ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode(), ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); |
| | | } |
| | | userService.deleteUser(user); |
| | | return ResultMessage.ok(); |
| | | } |
| | | |
| | | @ApiOperation(value = "修改账户信息", notes = "修改账户信息") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "account", value = "账户,长度6-10", required = false, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "password", value = "密码,长度6-20", required = false, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "account", value = "账户,长度6-10", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "password", value = "密码,长度6-20", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "userName", value = "账户名称", required = false, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "email", value = "邮箱,格式123456@qq.com", required = false, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "mobile", value = "手机号,1开头11位数字", required = false, paramType = "query", dataType = "String"), |
| | |
| | | }) |
| | | @RequestMapping(value = "updateUser", method = RequestMethod.POST) |
| | | public ResultMessage updateUser(User user, HttpServletRequest request) { |
| | | if (user.getAccount().isEmpty() || user.getPassword().isEmpty()) { |
| | | return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), |
| | | ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg()); |
| | | } |
| | | String token = request.getHeader("token"); |
| | | Map<String, Object> map = userService.updateUser(user, token); |
| | | if (map.containsKey("msg")) { |
| | | return ResultMessage.fail(map.get("msg").toString()); |
| | | Map<String, Object> result = userService.addUser(user, token); |
| | | if (!result.isEmpty()) { |
| | | return ResultMessage.fail((int) result.get("code"), result.get("msg").toString()); |
| | | } |
| | | return ResultMessage.ok(); |
| | | } |
New file |
| | |
| | | package com.moral.api.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.extension.activerecord.Model; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import java.time.LocalDateTime; |
| | | import java.io.Serializable; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | |
| | | /** |
| | | * <p> |
| | | * 系统配置表 |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2021-03-18 |
| | | */ |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = false) |
| | | public class SysConfig extends Model<SysConfig> { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * 序号 |
| | | */ |
| | | @TableId(value = "id", type = IdType.AUTO) |
| | | private Integer id; |
| | | |
| | | /** |
| | | * 类型 |
| | | */ |
| | | private String type; |
| | | |
| | | /** |
| | | * 状态码 |
| | | */ |
| | | private String code; |
| | | |
| | | /** |
| | | * 描述 |
| | | */ |
| | | private String desc; |
| | | |
| | | /** |
| | | * 创建时间 |
| | | */ |
| | | private LocalDateTime createTime; |
| | | |
| | | /** |
| | | * 更新时间 |
| | | */ |
| | | private LocalDateTime updateTime; |
| | | |
| | | /** |
| | | * 是否删除 |
| | | */ |
| | | private String isDelete; |
| | | |
| | | |
| | | @Override |
| | | protected Serializable pkVal() { |
| | | return this.id; |
| | | } |
| | | |
| | | } |
| | |
| | | */ |
| | | private String isDelete; |
| | | |
| | | @Transient |
| | | private Organization organization; |
| | | |
| | | @Transient |
| | | private List<Group> groups; |
| | | |
| | | |
| | | @Override |
| | | protected Serializable pkVal() { |
| | | return this.id; |
New file |
| | |
| | | package com.moral.api.mapper; |
| | | |
| | | import com.moral.api.entity.SysConfig; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | |
| | | /** |
| | | * <p> |
| | | * 系统配置表 Mapper 接口 |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2021-03-18 |
| | | */ |
| | | public interface SysConfigMapper extends BaseMapper<SysConfig> { |
| | | |
| | | } |
| | |
| | | |
| | | import com.moral.api.entity.User; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.moral.api.pojo.UserBo; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | |
| | | List<Map<String, Object>> selectUsers(Map<String, Object> parameters); |
| | | |
| | | User selectUserInfo(Map<String, Object> parameters); |
| | | UserBo selectUserInfo(Map<String, Object> parameters); |
| | | |
| | | User selectUser(Map<String, Object> parameters); |
| | | } |
New file |
| | |
| | | package com.moral.api.pojo; |
| | | |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | |
| | | import java.io.Serializable; |
| | | import java.util.List; |
| | | |
| | | import javax.persistence.Transient; |
| | | |
| | | import com.moral.api.entity.Group; |
| | | import com.moral.api.entity.Organization; |
| | | import com.moral.api.entity.User; |
| | | |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = false) |
| | | public class UserBo extends User { |
| | | |
| | | @Transient |
| | | private Organization organization; |
| | | |
| | | @Transient |
| | | private List<Group> groups; |
| | | |
| | | } |
New file |
| | |
| | | package com.moral.api.service; |
| | | |
| | | import com.moral.api.entity.SysConfig; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | |
| | | /** |
| | | * <p> |
| | | * 系统配置表 服务类 |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2021-03-18 |
| | | */ |
| | | public interface SysConfigService extends IService<SysConfig> { |
| | | |
| | | } |
| | |
| | | package com.moral.api.service; |
| | | |
| | | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | |
| | | import com.moral.api.entity.User; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.moral.api.pojo.UserBo; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | */ |
| | | public interface UserService extends IService<User> { |
| | | |
| | | Map<String, Object> login(User user); |
| | | Map<String, Object> login(Map<String, Object> parameters); |
| | | |
| | | Map<String, Object> addUser(User user, String token); |
| | | |
| | | Map<String, Object> deleteUser(int userId, String token); |
| | | void deleteUser(User user); |
| | | |
| | | Map<String, Object> updateUser(User user, String token); |
| | | |
| | | Map<String, Object> getUsers(Map<String, Object> parameters); |
| | | |
| | | User selectUserInfo(Map<String, Object> parameters); |
| | | |
| | | UserBo selectUserInfo(Map<String, Object> parameters); |
| | | |
| | | } |
New file |
| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import com.moral.api.entity.SysConfig; |
| | | import com.moral.api.mapper.SysConfigMapper; |
| | | import com.moral.api.service.SysConfigService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | | * <p> |
| | | * 系统配置表 服务实现类 |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2021-03-18 |
| | | */ |
| | | @Service |
| | | public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements SysConfigService { |
| | | |
| | | } |
| | |
| | | import java.util.stream.Collectors; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; |
| | | import com.moral.api.entity.Group; |
| | | import com.moral.api.entity.Menu; |
| | | import com.moral.api.entity.Organization; |
| | | import com.moral.api.entity.User; |
| | | |
| | | import com.moral.api.mapper.GroupMapper; |
| | | import com.moral.api.entity.UserGroup; |
| | | import com.moral.api.mapper.MenuMapper; |
| | | import com.moral.api.mapper.OrganizationMapper; |
| | | import com.moral.api.mapper.UserGroupMapper; |
| | | import com.moral.api.mapper.UserMapper; |
| | | import com.moral.api.pojo.UserBo; |
| | | import com.moral.api.service.UserService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.util.AESUtils; |
| | | import com.moral.util.MD5Utils; |
| | | import com.moral.util.RegexUtils; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Autowired |
| | | private MenuMapper menuMapper; |
| | | |
| | | @Autowired |
| | | private UserGroupMapper userGroupMapper; |
| | | |
| | | @Value("${AES.KEY}") |
| | | private String AESKey; |
| | | |
| | | @Override |
| | | public User selectUserInfo(Map<String, Object> parameters) { |
| | | public UserBo selectUserInfo(Map<String, Object> parameters) { |
| | | return userMapper.selectUserInfo(parameters); |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> login(User user) { |
| | | Map<String, Object> resultMap = new LinkedHashMap<>(); |
| | | public Map<String, Object> login(Map<String, Object> parameters) { |
| | | UserBo userBo = selectUserInfo(parameters); |
| | | Map<String, Object> result = new HashMap<>(); |
| | | //校验账户 |
| | | if (userBo == null) { |
| | | result.put("code", ResponseCodeEnum.ACCOUNT_NOT_EXIST.getCode()); |
| | | result.put("msg", ResponseCodeEnum.ACCOUNT_NOT_EXIST.getMsg()); |
| | | return result; |
| | | } |
| | | //校验密码 |
| | | String password = parameters.get("password").toString(); |
| | | //密码解密 |
| | | //password = AESUtils.decrypt(password, AESKey); |
| | | if (!MD5Utils.saltMD5Verify(password, userBo.getPassword())) { |
| | | result.put("code", ResponseCodeEnum.PASSWORD_INVALID.getCode()); |
| | | result.put("msg", ResponseCodeEnum.PASSWORD_INVALID.getMsg()); |
| | | return result; |
| | | } |
| | | //校验是否删除 |
| | | if (Constants.DELETE.equals(userBo.getIsDelete())) { |
| | | result.put("code", ResponseCodeEnum.ACCOUNT_IS_DELETE.getCode()); |
| | | result.put("msg", ResponseCodeEnum.ACCOUNT_IS_DELETE.getMsg()); |
| | | return result; |
| | | } |
| | | //校验是否过期 |
| | | if (userBo.getExpireTime() != null && userBo.getExpireTime().getTime() < System.currentTimeMillis()) { |
| | | result.put("code", ResponseCodeEnum.ACCOUNT_IS_EXPIRE.getCode()); |
| | | result.put("msg", ResponseCodeEnum.ACCOUNT_IS_EXPIRE.getMsg()); |
| | | return result; |
| | | } |
| | | //封装用户信息 |
| | | Map<String, Object> userInfo = new LinkedHashMap<>(); |
| | | List<Map<String, Object>> groups = new ArrayList<>(); |
| | | for (Group group : user.getGroups()) { |
| | | for (Group group : userBo.getGroups()) { |
| | | HashMap<String, Object> groupMap = new HashMap<>(); |
| | | groupMap.put("groupId", group.getId()); |
| | | groupMap.put("groupName", group.getGroupName()); |
| | | groups.add(groupMap); |
| | | } |
| | | Organization organization = user.getOrganization(); |
| | | userInfo.put("userId", user.getId()); |
| | | userInfo.put("account", user.getAccount()); |
| | | userInfo.put("userName", user.getUserName()); |
| | | userInfo.put("expireTime", user.getExpireTime()); |
| | | userInfo.put("isAdmin", user.getIsAdmin()); |
| | | userInfo.put("organizationId", user.getOrganizationId()); |
| | | Organization organization = userBo.getOrganization(); |
| | | userInfo.put("userId", userBo.getId()); |
| | | userInfo.put("account", userBo.getAccount()); |
| | | userInfo.put("userName", userBo.getUserName()); |
| | | userInfo.put("expireTime", userBo.getExpireTime()); |
| | | userInfo.put("isAdmin", userBo.getIsAdmin()); |
| | | userInfo.put("organizationId", userBo.getOrganizationId()); |
| | | userInfo.put("organizationName", organization.getName()); |
| | | userInfo.put("locationLevel", organization.getLocationLevel()); |
| | | userInfo.put("groups", groups); |
| | | userInfo.putAll(getMenus(user.getId())); |
| | | userInfo.putAll(getMenus(userBo.getId())); |
| | | try { |
| | | //生成token,并存入redis |
| | | String token = TokenUtils.getToken(user.getId().toString(), userInfo); |
| | | resultMap.put("token", token); |
| | | String token = TokenUtils.getToken(userBo.getId().toString(), userInfo); |
| | | Map<String, Object> data = new HashMap<>(); |
| | | data.put("token", token); |
| | | data.put("user", userInfo); |
| | | result.put("data", data); |
| | | } catch (Exception e) { |
| | | log.error("token生成异常:"+e.getMessage()); |
| | | log.error("token生成异常:" + e.getMessage()); |
| | | result.put("code", ResponseCodeEnum.TOKEN_CREATE_ERROR.getCode()); |
| | | result.put("msg", ResponseCodeEnum.TOKEN_CREATE_ERROR.getMsg()); |
| | | } |
| | | resultMap.putAll(userInfo); |
| | | return resultMap; |
| | | return result; |
| | | } |
| | | |
| | | //根据userId获取用户层级菜单 |
| | |
| | | List<List<Map<String, Object>>> resultList = new ArrayList(); |
| | | Menu newMenu = new Menu(); |
| | | newMenu.setParentId(menu.getId()); |
| | | |
| | | //筛选出下一级菜单信息 |
| | | List<Menu> nextLevelMenus = menus.stream() |
| | | .filter(o -> o.getParentId().equals(menu.getId())) |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Map<String, Object> addUser(User user, String token) { |
| | | Map<String, Object> resultMap = new HashMap<>(); |
| | | Map<String, Object> result = new HashMap<>(); |
| | | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token); |
| | | |
| | | QueryWrapper<User> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("account", user.getAccount()); |
| | | if (userMapper.selectOne(queryWrapper) != null) { |
| | | resultMap.put("msg", "账户名已存在"); |
| | | return resultMap; |
| | | queryWrapper.eq("account", user.getAccount()).eq("is_delete", Constants.NOT_DELETE); |
| | | //校验账户是否存在 |
| | | if (user.selectOne(queryWrapper) != null) { |
| | | result.put("code", ResponseCodeEnum.ACCOUNT_EXIST.getCode()); |
| | | result.put("msg", ResponseCodeEnum.ACCOUNT_EXIST.getMsg()); |
| | | return result; |
| | | } |
| | | //校验用户信息是否符合规则 |
| | | List<String> msgs = checkUserInfo(user); |
| | | if (!msgs.isEmpty()) { |
| | | resultMap.put("msg", msgs); |
| | | return resultMap; |
| | | //正则校验账户 |
| | | if (!RegexUtils.checkAccount(user.getAccount())) { |
| | | result.put("code", ResponseCodeEnum.ACCOUNT_INVALID.getCode()); |
| | | result.put("msg", ResponseCodeEnum.ACCOUNT_INVALID.getMsg()); |
| | | return result; |
| | | } |
| | | //正则校验账户 |
| | | if (user.getEmail() != null && !RegexUtils.checkEmail(user.getEmail())) { |
| | | result.put("code", ResponseCodeEnum.EMAIL_INVALID.getCode()); |
| | | result.put("msg", ResponseCodeEnum.EMAIL_INVALID.getMsg()); |
| | | return result; |
| | | } |
| | | //正则校验密码 |
| | | String password = user.getPassword(); |
| | | //密码解密 |
| | | //password = AESUtils.decrypt(password, AESKey); |
| | | if (!RegexUtils.checkPassword(password)) { |
| | | result.put("code", ResponseCodeEnum.PASSWORD_INVALID.getCode()); |
| | | result.put("msg", ResponseCodeEnum.PASSWORD_INVALID.getMsg()); |
| | | return result; |
| | | } |
| | | //正则校验手机号 |
| | | if (user.getMobile() != null && !RegexUtils.checkMobile(user.getMobile())) { |
| | | result.put("code", ResponseCodeEnum.MOBILE_INVALID.getCode()); |
| | | result.put("msg", ResponseCodeEnum.MOBILE_INVALID.getMsg()); |
| | | return result; |
| | | } |
| | | //密码加密 |
| | | String password = MD5Utils.saltMD5(user.getPassword()); |
| | | user.setPassword(password); |
| | | user.setIsAdmin(false); |
| | | user.setPassword(MD5Utils.saltMD5(password)); |
| | | user.setOrganizationId(Integer.parseInt(currentUserInfo.get("organizationId").toString())); |
| | | user.setIsAdmin(false); |
| | | //新增账户的过期时间 |
| | | Date userExpireTime = user.getExpireTime(); |
| | | //当前账户的过期时间 |
| | | Date expireTime = (Date) currentUserInfo.get("expireTime"); |
| | | if (userExpireTime == null || userExpireTime.getTime() > expireTime.getTime()) { |
| | | user.setExpireTime(expireTime); |
| | | Date currentUserExpireTime = (Date) currentUserInfo.get("expireTime"); |
| | | if (userExpireTime == null || userExpireTime.getTime() > currentUserExpireTime.getTime()) { |
| | | user.setExpireTime(currentUserExpireTime); |
| | | } |
| | | userMapper.insert(user); |
| | | return resultMap; |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public Map<String, Object> deleteUser(int userId, String token) { |
| | | Map<String, Object> resultMap = new HashMap<>(); |
| | | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token); |
| | | if (!(boolean) currentUserInfo.get("isAdmin")) { |
| | | resultMap.put("msg", "没有权限"); |
| | | } else { |
| | | User user = new User(); |
| | | user.setId(userId); |
| | | user.setIsDelete(Constants.DELETE); |
| | | userMapper.updateById(user); |
| | | } |
| | | return resultMap; |
| | | @Transactional |
| | | public void deleteUser(User user) { |
| | | //逻辑删除用户 |
| | | user.setIsDelete(Constants.DELETE); |
| | | //逻辑删除用户角色配置 |
| | | UpdateWrapper<UserGroup> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.set("is_delete", Constants.DELETE).eq("user_id", user.getId()); |
| | | userGroupMapper.update(null, updateWrapper); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Map<String, Object> updateUser(User user, String token) { |
| | | Map<String, Object> resultMap = new HashMap<>(); |
| | | Map<String, Object> result = new HashMap<>(); |
| | | Map<String, Object> currentUserInfo = (Map<String, Object>) TokenUtils.getUserInfoByToken(token); |
| | | if (!(boolean) currentUserInfo.get("isAdmin")) { |
| | | resultMap.put("msg", "没有权限"); |
| | | return resultMap; |
| | | } |
| | | |
| | | QueryWrapper<User> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("account", user.getAccount()); |
| | | queryWrapper.eq("id", user.getId()).eq("is_delete", Constants.NOT_DELETE); |
| | | if (userMapper.selectOne(queryWrapper) == null) { |
| | | result.put("code", ResponseCodeEnum.ACCOUNT_IS_DELETE.getCode()); |
| | | result.put("msg", ResponseCodeEnum.ACCOUNT_IS_DELETE.getMsg()); |
| | | return result; |
| | | } |
| | | queryWrapper.clear(); |
| | | queryWrapper.eq("account", user.getAccount()).eq("is_delete", Constants.NOT_DELETE); |
| | | //校验账户是否存在 |
| | | if (userMapper.selectOne(queryWrapper) != null) { |
| | | resultMap.put("msg", "账户已存在"); |
| | | return resultMap; |
| | | result.put("code", ResponseCodeEnum.ACCOUNT_EXIST.getCode()); |
| | | result.put("msg", ResponseCodeEnum.ACCOUNT_EXIST.getMsg()); |
| | | return result; |
| | | } |
| | | //校验用户信息是否符合规则 |
| | | List<String> msgs = checkUserInfo(user); |
| | | if (!msgs.isEmpty()) { |
| | | resultMap.put("msg", msgs); |
| | | return resultMap; |
| | | //正则校验账户 |
| | | if (!RegexUtils.checkAccount(user.getAccount())) { |
| | | result.put("code", ResponseCodeEnum.ACCOUNT_INVALID.getCode()); |
| | | result.put("msg", ResponseCodeEnum.ACCOUNT_INVALID.getMsg()); |
| | | return result; |
| | | } |
| | | //密码Md5加密 |
| | | user.setPassword(MD5Utils.saltMD5(user.getPassword())); |
| | | //正则校验账户 |
| | | if (user.getEmail() != null && !RegexUtils.checkEmail(user.getEmail())) { |
| | | result.put("code", ResponseCodeEnum.EMAIL_INVALID.getCode()); |
| | | result.put("msg", ResponseCodeEnum.EMAIL_INVALID.getMsg()); |
| | | return result; |
| | | } |
| | | //正则校验密码 |
| | | String password = user.getPassword(); |
| | | //密码解密 |
| | | //password = AESUtils.decrypt(password, AESKey); |
| | | if (!RegexUtils.checkPassword(password)) { |
| | | result.put("code", ResponseCodeEnum.PASSWORD_INVALID.getCode()); |
| | | result.put("msg", ResponseCodeEnum.PASSWORD_INVALID.getMsg()); |
| | | return result; |
| | | } |
| | | //正则校验手机号 |
| | | if (user.getMobile() != null && !RegexUtils.checkMobile(user.getMobile())) { |
| | | result.put("code", ResponseCodeEnum.MOBILE_INVALID.getCode()); |
| | | result.put("msg", ResponseCodeEnum.MOBILE_INVALID.getMsg()); |
| | | return result; |
| | | } |
| | | //密码加密 |
| | | user.setPassword(MD5Utils.saltMD5(password)); |
| | | user.setOrganizationId(Integer.parseInt(currentUserInfo.get("organizationId").toString())); |
| | | user.setIsAdmin(false); |
| | | //新增账户的过期时间 |
| | | Date userExpireTime = user.getExpireTime(); |
| | | //当前账户的过期时间 |
| | | Date currentUserExpireTime = (Date) currentUserInfo.get("expireTime"); |
| | | if (userExpireTime == null || userExpireTime.getTime() > currentUserExpireTime.getTime()) { |
| | | user.setExpireTime(currentUserExpireTime); |
| | | } |
| | | userMapper.updateById(user); |
| | | return resultMap; |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | |
| | | resultMap.put("users", users); |
| | | return resultMap; |
| | | } |
| | | |
| | | private List<String> checkUserInfo(User user) { |
| | | List<String> msgs = new ArrayList<>(); |
| | | //验证账户 |
| | | if (!RegexUtils.checkAccount(user.getAccount())) { |
| | | msgs.add("账户格式不正确"); |
| | | } |
| | | //验证密码 |
| | | if (!RegexUtils.checkPassword(user.getPassword())) { |
| | | msgs.add("密码格式不正确"); |
| | | } |
| | | //验证邮箱 |
| | | if (user.getEmail() != null) { |
| | | if (!RegexUtils.checkEmail(user.getEmail())) { |
| | | msgs.add("邮箱格式不正确"); |
| | | } |
| | | } |
| | | //验证手机号 |
| | | if (user.getMobile() != null) { |
| | | if (!RegexUtils.checkMobile(user.getMobile())) { |
| | | msgs.add("手机号格式不正确"); |
| | | } |
| | | } |
| | | return msgs; |
| | | } |
| | | |
| | | |
| | | } |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.moral.api.mapper.SysConfigMapper"> |
| | | |
| | | <!-- 通用查询映射结果 --> |
| | | <resultMap id="BaseResultMap" type="com.moral.api.entity.SysConfig"> |
| | | <id column="id" property="id" /> |
| | | <result column="type" property="type" /> |
| | | <result column="code" property="code" /> |
| | | <result column="desc" property="desc" /> |
| | | <result column="create_time" property="createTime" /> |
| | | <result column="update_time" property="updateTime" /> |
| | | <result column="is_delete" property="isDelete" /> |
| | | </resultMap> |
| | | |
| | | </mapper> |
| | |
| | | <result column="update_time" property="updateTime"/> |
| | | <result column="expire_time" property="expireTime"/> |
| | | <result column="is_delete" property="isDelete"/> |
| | | </resultMap> |
| | | |
| | | <resultMap id="userInfoMap" type="com.moral.api.pojo.UserBo" extends="BaseResultMap"> |
| | | <!--用户组织--> |
| | | <association property="organization" javaType="com.moral.api.entity.Organization"> |
| | | <result column="id" property="id" jdbcType="INTEGER"/> |
| | |
| | | <result column="location_level" property="locationLevel"/> |
| | | </association> |
| | | <!--用户组--> |
| | | <collection property="groups" ofType="com.moral.api.entity.Group" javaType = "java.util.ArrayList"> |
| | | <collection property="groups" ofType="com.moral.api.entity.Group" javaType="java.util.ArrayList"> |
| | | <id column="groupId" property="id" jdbcType="INTEGER"/> |
| | | <result column="group_name" property="groupName" jdbcType="VARCHAR"/> |
| | | </collection> |
| | | |
| | | </resultMap> |
| | | |
| | | |
| | | <select id="selectUserInfo" resultMap="BaseResultMap"> |
| | | SELECT u.id,u.account,u.password,u.user_name,u.organization_id,u.expire_time,u.is_delete, |
| | | o.name,u.is_admin,o.location_level, |
| | | g.id groupId,g.group_name |
| | | FROM `user` u, |
| | | `organization` o, |
| | | `user_group` ug, |
| | | `group` g |
| | | WHERE u.account = #{account} |
| | | AND u.organization_id=o.id |
| | | AND u.id = ug.user_id |
| | | AND ug.group_id = g.id |
| | | AND g.is_delete = 0 |
| | | AND ug.is_delete = 0 |
| | | <!--查询用户信息,包含组织,角色--> |
| | | <select id="selectUserInfo" resultMap="userInfoMap"> |
| | | SELECT u.id, u.account, u.password, u.user_name, u.organization_id, u.expire_time, u.is_delete,u.is_Admin, |
| | | o.name, o.location_level, |
| | | a.id groupId , a.group_name |
| | | FROM `user` u |
| | | LEFT JOIN |
| | | (SELECT ug.user_id,g.id,g.group_name FROM `user_group` ug ,`group` g WHERE ug.group_id=g.id AND g.is_delete = 0 |
| | | AND ug.is_delete = 0) a |
| | | ON a.user_id=u.id |
| | | LEFT JOIN `organization` o ON o.id=u.organization_id |
| | | WHERE u.account = #{account} |
| | | </select> |
| | | |
| | | |
| | | <select id="selectUsers" resultType="java.util.Map"> |
| | | SELECT id,account,user_name userName,email,mobile,wechat FROM `user` WHERE |
| | |
| | | * @return 证成功返回true,验证失败返回false |
| | | */ |
| | | public static boolean checkAccount(String account) { |
| | | String regex = "[a-zA-Z]\\w{3,19}"; |
| | | String regex = "[a-zA-Z]\\w{2,19}"; |
| | | return account.matches(regex); |
| | | } |
| | | |
| | |
| | | * @return 证成功返回true,验证失败返回false |
| | | */ |
| | | public static boolean checkPassword(String password) { |
| | | String regex = "[0-9a-zA-Z_]\\w{3,19}"; |
| | | String regex = "[0-9a-zA-Z_]\\w{2,19}"; |
| | | return password.matches(regex); |
| | | } |
| | | |
| | |
| | | package com.moral.util; |
| | | |
| | | import com.moral.constant.Constants; |
| | | import com.moral.constant.ResponseCodeEnum; |
| | | import com.moral.exception.TokenException; |
| | | import com.sun.org.apache.bcel.internal.classfile.ConstantString; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Qualifier; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | |
| | | @Component |
| | | @Slf4j |
| | | public class TokenUtils { |
| | | |
| | | private static RedisTemplate redisTemplate; |
| | | |
| | | @Autowired |
| | |
| | | } |
| | | |
| | | /** |
| | | * @Description: token延长 |
| | | * @Param: [token] |
| | | * @return: void |
| | | * @Author: 陈凯裕 |
| | | * @Date: 2021/3/11 |
| | | */ |
| | | * @Description: token延长 |
| | | * @Param: [token] |
| | | * @return: void |
| | | * @Author: 陈凯裕 |
| | | * @Date: 2021/3/11 |
| | | */ |
| | | public static void extendTokenTime(String token) { |
| | | redisTemplate.expire(token, validity_time, TimeUnit.SECONDS); |
| | | } |
New file |
| | |
| | | package com.moral.api.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.moral.api.entity.ManageMenu; |
| | | import com.moral.api.entity.ManageRole; |
| | | import com.moral.api.service.ManageMenuService; |
| | | import com.moral.api.service.ManageRoleService; |
| | | import com.moral.constant.ResultMessage; |
| | | import com.moral.util.WebUtils; |
| | | 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.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import static org.springframework.web.util.WebUtils.getParametersStartingWith; |
| | | |
| | | @Slf4j |
| | | @Api(tags = {"菜单"}) |
| | | @RestController |
| | | @RequestMapping("/manage") |
| | | public class ManageMenuController { |
| | | |
| | | @Autowired |
| | | private ManageMenuService manageMenuService; |
| | | |
| | | |
| | | @ApiOperation(value = "新增菜单", notes = "新增菜单") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "name", value = "名称", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "url", value = "url地址", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "icon", value = "图标地址", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "parent_id", value = "父菜单", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "order", value = "同级菜单顺序", required = true, paramType = "query", dataType = "String") |
| | | }) |
| | | @RequestMapping(value = "insertOneManageMenu", method = RequestMethod.POST) |
| | | public ResultMessage insertOneManageMenu(HttpServletRequest request) { |
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); |
| | | ManageMenu manageMenu = JSON.parseObject(JSON.toJSONString(parameters), ManageMenu.class); |
| | | Map<String,Object> resultMap = manageMenuService.insertManageMenu(manageMenu); |
| | | String msg = resultMap.get("msg").toString(); |
| | | boolean flag = Boolean.parseBoolean(resultMap.get("flag").toString()); |
| | | if (flag){ |
| | | return ResultMessage.ok(msg); |
| | | } |
| | | return ResultMessage.fail(msg); |
| | | } |
| | | |
| | | @ApiOperation(value = "更新菜单", notes = "更新菜单") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "序号", required = true, paramType = "query", dataType = "int"), |
| | | @ApiImplicitParam(name = "name", value = "名称", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "url", value = "url地址", required = true, paramType = "query", dataType = "String") |
| | | }) |
| | | @RequestMapping(value = "updateManageMenuById", method = RequestMethod.POST) |
| | | public ResultMessage updateManageMenuById(HttpServletRequest request) { |
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); |
| | | Map<String,Object> resultMap = manageMenuService.updateManageMenu(parameters); |
| | | String msg = resultMap.get("msg").toString(); |
| | | boolean flag = Boolean.parseBoolean(resultMap.get("flag").toString()); |
| | | if (flag){ |
| | | return ResultMessage.ok(msg); |
| | | } |
| | | return ResultMessage.fail(msg); |
| | | } |
| | | |
| | | @ApiOperation(value = "删除角色", notes = "删除角色") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "序号", required = true, paramType = "query", dataType = "int") |
| | | }) |
| | | @RequestMapping(value = "deleteManageMenu", method = RequestMethod.POST) |
| | | public ResultMessage deleteManageMenu(HttpServletRequest request) { |
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); |
| | | Map<String,Object> resultMap = manageMenuService.deleteManageMenu(parameters); |
| | | String msg = resultMap.get("msg").toString(); |
| | | boolean flag = Boolean.parseBoolean(resultMap.get("flag").toString()); |
| | | if (flag){ |
| | | return ResultMessage.ok(msg); |
| | | } |
| | | return ResultMessage.fail(msg); |
| | | } |
| | | } |
New file |
| | |
| | | package com.moral.api.controller; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.moral.api.entity.ManageMenu; |
| | | import com.moral.api.entity.ManageRole; |
| | | import com.moral.api.service.ManageMenuService; |
| | | import com.moral.api.service.ManageRoleService; |
| | | import com.moral.constant.ResultMessage; |
| | | import com.moral.util.WebUtils; |
| | | 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.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RequestMethod; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | import static org.springframework.web.util.WebUtils.getParametersStartingWith; |
| | | |
| | | @Slf4j |
| | | @Api(tags = {"角色"}) |
| | | @RestController |
| | | @RequestMapping("/manage") |
| | | public class ManageRoleController { |
| | | |
| | | @Autowired |
| | | private ManageRoleService manageRoleService; |
| | | |
| | | @ApiOperation(value = "获取所有角色", notes = "获取所有角色") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "current", value = "页码", required = true, paramType = "query", dataType = "int"), |
| | | @ApiImplicitParam(name = "size", value = "每页数量", required = true, paramType = "query", dataType = "int") |
| | | }) |
| | | @RequestMapping(value = "getAllManageRole", method = RequestMethod.GET) |
| | | public ResultMessage getAllManageRole(HttpServletRequest request) { |
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); |
| | | List<ManageRole> re = manageRoleService.getAllWithPagingQuery(parameters); |
| | | return ResultMessage.ok(re); |
| | | } |
| | | |
| | | @ApiOperation(value = "新增角色", notes = "新增角色") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "name", value = "名称", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "desc", value = "备注", required = true, paramType = "query", dataType = "String") |
| | | }) |
| | | @RequestMapping(value = "insertOneManageRole", method = RequestMethod.POST) |
| | | public ResultMessage insertOneManageRole(HttpServletRequest request) { |
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); |
| | | ManageRole manageRole = JSON.parseObject(JSON.toJSONString(parameters), ManageRole.class); |
| | | List list = new ArrayList(); |
| | | list.add(1); |
| | | list.add(2); |
| | | list.add(3); |
| | | list.add(4); |
| | | Map<String,Object> resultMap = manageRoleService.insertOne(manageRole,list); |
| | | String msg = resultMap.get("msg").toString(); |
| | | boolean flag = Boolean.parseBoolean(resultMap.get("flag").toString()); |
| | | if (flag){ |
| | | return ResultMessage.ok(msg); |
| | | } |
| | | return ResultMessage.fail(msg); |
| | | } |
| | | |
| | | @ApiOperation(value = "更新角色", notes = "更新角色") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "name", value = "名称", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "desc", value = "备注", required = true, paramType = "query", dataType = "String") |
| | | }) |
| | | @RequestMapping(value = "updateManageRole", method = RequestMethod.POST) |
| | | public ResultMessage updateManageRole(HttpServletRequest request) { |
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); |
| | | Map<String,Object> resultMap = manageRoleService.updateManageRole(parameters); |
| | | String msg = resultMap.get("msg").toString(); |
| | | boolean flag = Boolean.parseBoolean(resultMap.get("flag").toString()); |
| | | if (flag){ |
| | | return ResultMessage.ok(msg); |
| | | } |
| | | return ResultMessage.fail(msg); |
| | | } |
| | | |
| | | @ApiOperation(value = "删除角色", notes = "删除角色") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "id", value = "序号", required = true, paramType = "query", dataType = "int") |
| | | }) |
| | | @RequestMapping(value = "deleteManageRole", method = RequestMethod.POST) |
| | | public ResultMessage deleteManageRole(HttpServletRequest request) { |
| | | Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null); |
| | | Map<String,Object> resultMap = manageRoleService.deleteManageRole(parameters); |
| | | String msg = resultMap.get("msg").toString(); |
| | | boolean flag = Boolean.parseBoolean(resultMap.get("flag").toString()); |
| | | if (flag){ |
| | | return ResultMessage.ok(msg); |
| | | } |
| | | return ResultMessage.fail(msg); |
| | | } |
| | | |
| | | @ApiOperation(value = "角色模糊查询", notes = "角色模糊查询") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "name", value = "名称", required = true, paramType = "query", dataType = "String"), |
| | | @ApiImplicitParam(name = "current", value = "页码", required = true, paramType = "query", dataType = "int"), |
| | | @ApiImplicitParam(name = "size", value = "每页数量", required = true, paramType = "query", dataType = "int") |
| | | }) |
| | | @RequestMapping(value = "getManageRoleByNameFuzzy", method = RequestMethod.GET) |
| | | public ResultMessage getManageRoleByNameFuzzy(HttpServletRequest request) { |
| | | Map<String, Object> parameters = getParametersStartingWith(request, null); |
| | | //ManageRole manageRole = JSON.parseObject(JSON.toJSONString(parameters), ManageRole.class); |
| | | List<ManageRole> re = manageRoleService.getManageRoleByNameFuzzy(parameters); |
| | | return ResultMessage.ok(re); |
| | | } |
| | | } |
New file |
| | |
| | | package com.moral.api.entity; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.extension.activerecord.Model; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import java.time.LocalDateTime; |
| | | import java.io.Serializable; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | |
| | | /** |
| | | * <p> |
| | | * 系统配置表 |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2021-03-18 |
| | | */ |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = false) |
| | | public class SysConfig extends Model<SysConfig> { |
| | | |
| | | private static final long serialVersionUID = 1L; |
| | | |
| | | /** |
| | | * 序号 |
| | | */ |
| | | @TableId(value = "id", type = IdType.AUTO) |
| | | private Integer id; |
| | | |
| | | /** |
| | | * 类型 |
| | | */ |
| | | private String type; |
| | | |
| | | /** |
| | | * 状态码 |
| | | */ |
| | | private String code; |
| | | |
| | | /** |
| | | * 描述 |
| | | */ |
| | | private String desc; |
| | | |
| | | /** |
| | | * 创建时间 |
| | | */ |
| | | private LocalDateTime createTime; |
| | | |
| | | /** |
| | | * 更新时间 |
| | | */ |
| | | private LocalDateTime updateTime; |
| | | |
| | | /** |
| | | * 是否删除 |
| | | */ |
| | | private String isDelete; |
| | | |
| | | |
| | | @Override |
| | | protected Serializable pkVal() { |
| | | return this.id; |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.moral.api.mapper; |
| | | |
| | | import com.moral.api.entity.SysConfig; |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | |
| | | /** |
| | | * <p> |
| | | * 系统配置表 Mapper 接口 |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2021-03-18 |
| | | */ |
| | | public interface SysConfigMapper extends BaseMapper<SysConfig> { |
| | | |
| | | } |
| | |
| | | public interface ManageRoleService extends IService<ManageRole> { |
| | | |
| | | @Transactional |
| | | List<ManageRole> getAll(); |
| | | List<ManageRole> getAllWithPagingQuery(Map map); |
| | | |
| | | @Transactional |
| | | Map<String,Object> insertOne(ManageRole manageRole,List list); |
| | |
| | | Map<String,Object> updateManageRole(Map map); |
| | | |
| | | @Transactional |
| | | List<ManageRole> getManageRoleByNameFuzzy(ManageRole manageRole); |
| | | List<ManageRole> getManageRoleByNameFuzzy(Map map); |
| | | |
| | | @Transactional |
| | | Map<String,Object> deleteManageRole(Map map); |
New file |
| | |
| | | package com.moral.api.service; |
| | | |
| | | import com.moral.api.entity.SysConfig; |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | |
| | | /** |
| | | * <p> |
| | | * 系统配置表 服务类 |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2021-03-18 |
| | | */ |
| | | public interface SysConfigService extends IService<SysConfig> { |
| | | |
| | | } |
| | |
| | | import com.moral.api.mapper.ManageRoleMenuMapper; |
| | | import com.moral.api.service.ManageMenuService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.HashMap; |
| | |
| | | @Service |
| | | public class ManageMenuServiceImpl extends ServiceImpl<ManageMenuMapper, ManageMenu> implements ManageMenuService { |
| | | |
| | | @Resource |
| | | @Autowired(required = false) |
| | | private ManageMenuMapper manageMenuMapper; |
| | | |
| | | @Resource |
| | | @Autowired(required = false) |
| | | private ManageRoleMenuMapper manageRoleMenuMapper; |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Map<String,Object> insertManageMenu(ManageMenu manageMenu) { |
| | | Map<String,Object> resultMap = new HashMap<>(); |
| | | if (manageMenu.getName()==null){ |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Map<String,Object> updateManageMenu(Map map) { |
| | | Map<String,Object> resultMap = new HashMap<>(); |
| | | if (!map.containsKey("id")){ |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Map<String, Object> deleteManageMenu(Map map) { |
| | | Map<String,Object> resultMap = new HashMap<>(); |
| | | if (!map.containsKey("id")){ |
New file |
| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import com.moral.api.entity.SysConfig; |
| | | import com.moral.api.mapper.SysConfigMapper; |
| | | import com.moral.api.service.SysConfigService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | /** |
| | | * <p> |
| | | * 系统配置表 服务实现类 |
| | | * </p> |
| | | * |
| | | * @author moral |
| | | * @since 2021-03-18 |
| | | */ |
| | | @Service |
| | | public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements SysConfigService { |
| | | |
| | | } |
| | |
| | | </select> |
| | | |
| | | <select id="getAll" resultMap="BaseResultMap"> |
| | | select * from manage_role |
| | | where is_delete = 0 |
| | | select |
| | | <include refid="Base_Column_List"></include> |
| | | from manage_role mr |
| | | where mr.is_delete = 0 |
| | | </select> |
| | | |
| | | <select id="getManageRoleByName" resultMap="BaseResultMap"> |
| | | select * from manage_role |
| | | select |
| | | <include refid="Base_Column_List"></include> |
| | | from manage_role mr |
| | | where name = #{name} |
| | | and is_delete = 0 |
| | | and mr.is_delete = 0 |
| | | </select> |
| | | |
| | | <select id="getManageRoleById" resultMap="BaseResultMap"> |
| | | select * from manage_role |
| | | where id = #{id} |
| | | and is_delete = 0 |
| | | select |
| | | <include refid="Base_Column_List"></include> |
| | | from manage_role mr |
| | | where mr.id = #{id} |
| | | and mr.is_delete = 0 |
| | | </select> |
| | | |
| | | <select id="getManageRoleByNameFuzzy" resultMap="BaseResultMap"> |
| | | select * from manage_role |
| | | where name like concat('%',#{name},'%') |
| | | and is_delete = 0 |
| | | select |
| | | <include refid="Base_Column_List"></include> |
| | | from manage_role mr |
| | | where mr.name like concat('%',#{name},'%') |
| | | and mr.is_delete = 0 |
| | | </select> |
| | | |
| | | <insert id="insertOne" parameterType="com.moral.api.entity.ManageRole"> |
New file |
| | |
| | | <?xml version="1.0" encoding="UTF-8"?> |
| | | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| | | <mapper namespace="com.moral.api.mapper.SysConfigMapper"> |
| | | |
| | | <!-- 通用查询映射结果 --> |
| | | <resultMap id="BaseResultMap" type="com.moral.api.entity.SysConfig"> |
| | | <id column="id" property="id" /> |
| | | <result column="type" property="type" /> |
| | | <result column="code" property="code" /> |
| | | <result column="desc" property="desc" /> |
| | | <result column="create_time" property="createTime" /> |
| | | <result column="update_time" property="updateTime" /> |
| | | <result column="is_delete" property="isDelete" /> |
| | | </resultMap> |
| | | |
| | | </mapper> |