Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
zw23534572 committed Nov 11, 2018
1 parent 0796e0a commit 3b6616b
Show file tree
Hide file tree
Showing 24 changed files with 235 additions and 175 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ ADD service.sh /export/App/sjroom-admin/service.sh
RUN echo "/export/App/sjroom-admin/service.sh start" >> /export/servers/start.sh
RUN echo "/export/App/sjroom-admin/service.sh stop" >> /export/servers/stop.sh
COPY sjroom-admin-web/target/sjroom-admin-web.jar /export/App/sjroom-admin

# docker run --name sjroom-admin -p 8002:8002 -d registry.cn-hangzhou.aliyuncs.com/sjroom/sjroom-admin
10 changes: 5 additions & 5 deletions sjroom-admin-dao/src/main/resources/mapper/SysRoleDao.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@

<mapper namespace="com.github.sjroom.dao.SysRoleDao">

<select id="queryList" resultType="com.github.sjroom.domain.entity.SysRole">
<select id="selectPage" resultType="com.github.sjroom.domain.entity.SysRole">
select * from sys_role
<where>
<if test="roleName != null and roleName.trim() != ''">
and `role_name` like concat('%',#{roleName},'%')
<if test="key != null and key.trim() != ''">
and (`role_name` like concat('%',#{key},'%') or `remark` like concat('%',#{key},'%'))
</if>
<if test="createUser != null">
and create_user = #{createUser}
</if>
</where>
<choose>
<when test="orderBy != null and orderBy.trim() != ''">
order by ${orderBy} ${asc}
order by ${orderBy} ${order}
</when>
<otherwise>
order by id asc
order by id desc
</otherwise>
</choose>
</select>
Expand Down
4 changes: 2 additions & 2 deletions sjroom-admin-dao/src/main/resources/mapper/SysUserDao.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
and `create_user` = #{createUser}
</if>
<if test="key != null and key.trim() != ''">
and `user_name` like concat('%',#{key},'%')
and (`user_name` like concat('%',#{key},'%') or `account` like concat('%',#{key},'%'))
</if>
</where>
<choose>
<when test="orderBy != null and orderBy.trim() != ''">
order by ${orderBy} ${asc}
order by ${orderBy} ${order}
</when>
<otherwise>
order by id desc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class SysUserVO {
* 用户名
*/
@NotBlank(message = "用户名不能为空", groups = {AddGroup.class, UpdateGroup.class})
private String username;
private String userName;

/**
* 密码
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.github.sjroom.oauth2;

import com.github.sjroom.common.AbstractBase;
import com.github.sjroom.common.CommonStatus;
import com.github.sjroom.common.Constant;
import com.github.sjroom.common.exception.BusinessException;
import com.github.sjroom.common.util.AssertUtil;
import com.github.sjroom.domain.entity.SysUser;
import com.github.sjroom.domain.entity.SysUserToken;
Expand Down Expand Up @@ -47,7 +49,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
SysUserToken tokenEntity = shiroService.queryByToken(accessToken);
//token失效
if (tokenEntity == null || tokenEntity.getExpireTime().getTime() < System.currentTimeMillis()) {
AssertUtil.throwBusinessException("token失效,请重新登录");
throw new BusinessException(CommonStatus.TOKEN_ERROR);
}

//查询用户信息
Expand Down Expand Up @@ -86,8 +88,8 @@ private String getRequestToken(HttpServletRequest httpRequest) {
if (StringUtils.isEmpty(token)) {
token = (String) httpRequest.getSession().getAttribute("token");
}
if (StringUtils.isEmpty(token)){
AssertUtil.throwBusinessException("token失效,请重新登录");
if (StringUtils.isEmpty(token)) {
throw new BusinessException(CommonStatus.TOKEN_ERROR);
}
return token;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@
import com.github.sjroom.domain.entity.SysRoleMenu;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class SysRoleMenuServiceImpl implements SysRoleMenuService {
@Autowired
private SysRoleMenuDao sysRoleMenuDao;

@Override
@Transactional
public void saveOrUpdate(Long roleId, List<Long> menuIdList) {

SysRoleMenu sysRoleMenu = new SysRoleMenu();
sysRoleMenu.setRoleId(roleId);
sysRoleMenu = sysRoleMenuDao.selectOne(sysRoleMenu);
List<SysRoleMenu> sysRoleMenuList = sysRoleMenuDao.selectList(sysRoleMenu);
//先删除角色与菜单关系
sysRoleMenuDao.deleteById(sysRoleMenu.getId());
for (int i = 0; i < sysRoleMenuList.size(); i++) {
sysRoleMenuDao.deleteById(sysRoleMenuList.get(i).getId());
}

if (menuIdList.size() == 0) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public List<Long> queryAllMenuId(Long userId) {
@Override
public int updatePassword(Long userId, String password, String newPassword) {
SysUser sysUser = sysUserDao.selectById(userId);
sysUser.setPassword(sysUser.getPassword());
sysUser.setPassword(newPassword);
return sysUserDao.updateById(sysUser);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.annotation.ImportResource;


@SpringBootApplication
@ImportResource(locations={"classpath:application-bean.xml"})
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class StartApplication {

public static void main(String[] args) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.github.sjroom.config;

import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
import org.springframework.core.MethodParameter;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.http.server.ServerHttpResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;

/**
* <B>说明:如果返回是null值,则直接替换成""</B><BR>
*
* @author ZhouWei
* @version 1.0.0.
* @date 2018-03-15 17-27
*/
@ControllerAdvice(basePackages = "com.github.sjroom.controller.sys")
public class ResponseBodyAdviceConfig implements ResponseBodyAdvice<Object> {

@Override
public boolean supports(MethodParameter returnType, Class<? extends HttpMessageConverter<?>> converterType) {
return FastJsonHttpMessageConverter.class.isAssignableFrom(converterType);
}

@Override
public Object beforeBodyWrite(Object body, MethodParameter returnType, MediaType selectedContentType, Class<? extends HttpMessageConverter<?>> selectedConverterType, ServerHttpRequest request, ServerHttpResponse response) {
if (body == null){
return "";
}
return body;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,10 @@ public String login(HttpServletRequest request, String username, String password
* 退出
*/
@RequestMapping(value = "/sys/logout", method = RequestMethod.POST)
public void logout(HttpServletRequest request, HttpServletResponse response) {
public int logout(HttpServletRequest request, HttpServletResponse response) {
String token = (String)request.getSession().getAttribute("token");
sysUserTokenService.logout(token);
return 1;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public SysMenuResponse info(@PathVariable("menuId") Long menuId) {
*/
@RequestMapping("/save")
@RequiresPermissions("sys:menu:save")
public void save(@RequestBody SysMenuRequest sysMenuRequest) {
public int save(@RequestBody SysMenuRequest sysMenuRequest) {
//数据校验
verifyForm(sysMenuRequest);
SysMenu sysMenu = new SysMenu();
Expand All @@ -100,27 +100,29 @@ public void save(@RequestBody SysMenuRequest sysMenuRequest) {
sysMenu.setIcon("/images/f06.png");
}
sysMenuService.insertOrUpdate(sysMenu);
return 1;
}

/**
* 修改
*/
@RequestMapping("/update")
@RequiresPermissions("sys:menu:update")
public void update(@RequestBody SysMenuRequest sysMenuRequest) {
public int update(@RequestBody SysMenuRequest sysMenuRequest) {
//数据校验
verifyForm(sysMenuRequest);
SysMenu sysMenu = new SysMenu();
BeanUtils.copyProperties(sysMenuRequest, sysMenu);
sysMenuService.insertOrUpdate(sysMenu);
return 1;
}

/**
* 删除
*/
@RequestMapping("/delete")
@RequiresPermissions("sys:menu:delete")
public void delete(long menuId) {
public int delete(long menuId) {

List<String> roleNameList = sysRoleMenuDao.queryRoleNameByMenuId(menuId);
if (roleNameList != null && roleNameList.size() > 0) {
Expand All @@ -137,6 +139,7 @@ public void delete(long menuId) {
AssertUtil.throwBusinessException("请先删除子菜单或按钮");
}
sysMenuService.deleteById(menuId);
return 1;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,32 @@ public SysRole info(@PathVariable("roleId") Long roleId) {
*/
@RequestMapping("/save")
@RequiresPermissions("sys:role:save")
public void save(@RequestBody SysRole role) {
public int save(@RequestBody SysRole role) {
ValidatorUtils.validateEntity(role);
role.setCreateUser(getCreateUser());
sysRoleService.save(role);
return 1;
}

/**
* 修改角色
*/
@RequestMapping("/update")
@RequiresPermissions("sys:role:update")
public void update(@RequestBody SysRole role) {
public int update(@RequestBody SysRole role) {
ValidatorUtils.validateEntity(role);
role.setCreateUser(getCreateUser());
sysRoleService.update(role);
return 1;
}

/**
* 删除角色
*/
@RequestMapping("/delete")
@RequiresPermissions("sys:role:delete")
public void delete(@RequestBody Long[] roleIds) {
public int delete(@RequestBody Long[] roleIds) {
sysRoleService.deleteBatch(roleIds);
return 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,26 @@ public HashMap info() {
* 修改登录用户密码
*/
@RequestMapping("/password")
public void password(String password, String newPassword) {
AssertUtil.notNull(newPassword, "新密码不为能空");
public int password(String password, String newPassword) {
AssertUtil.notBlank(password, "原始密码");
AssertUtil.notBlank(newPassword, "新密码");

//sha256加密

password = TokenGeneratorUtil.generateValue(password);
//sha256加密
newPassword = TokenGeneratorUtil.generateValue(newPassword);

SysUser sysUser = getUser();
if (!sysUser.getPassword().equals(password)){
AssertUtil.throwBusinessException("原密码不正确");
}

//更新密码
int count = sysUserService.updatePassword(getUserId(), password, newPassword);
if (count == 0) {
AssertUtil.throwBusinessException("原密码不正确");
AssertUtil.throwBusinessException("更新操作,错误.");
}

return 1;
}

/**
Expand All @@ -108,7 +113,7 @@ public SysUserResponse info(@PathVariable("userId") Long userId) {
*/
@RequestMapping("/save")
@RequiresPermissions("sys:user:save")
public void save(@RequestBody SysUserVO sysUserVO) {
public int save(@RequestBody SysUserVO sysUserVO) {
ValidatorUtils.validateEntity(sysUserVO, AddGroup.class);
sysUserVO.setCreateUser(getCreateUser());

Expand All @@ -130,25 +135,28 @@ public void save(@RequestBody SysUserVO sysUserVO) {
}

sysUserService.save(sysUserVO);
return 1;
}

/**
* 修改用户
*/
@RequestMapping("/update")
@RequiresPermissions("sys:user:update")
public void update(@RequestBody SysUserVO sysUserVO) {
public int update(@RequestBody SysUserVO sysUserVO) {
ValidatorUtils.validateEntity(sysUserVO, UpdateGroup.class);
sysUserVO.setCreateUser(getCreateUser());
sysUserService.save(sysUserVO);
return 1;
}

/**
* 删除用户
*/
@RequestMapping("/delete")
@RequiresPermissions("sys:user:delete")
public void delete(@RequestBody Long[] userIds) {
public int delete(@RequestBody Long[] userIds) {
sysUserService.deleteBatch(userIds);
return 1;
}
}
2 changes: 1 addition & 1 deletion sjroom-admin-web/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
spring.profiles.active=dev
#服务端口
server.port=8002
system_code=002
system_code=101
# Tomcat
server.tomcat.uri-encoding=utf-8
server.tomcat.max-threads=1000
Expand Down
21 changes: 11 additions & 10 deletions sjroom-admin-web/src/main/resources/static/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ $.ajaxSetup({
withCredentials: true
},
complete: function (xhr) {
var code = xhr.responseJSON.code % 1000;
//token过期,则跳转到登录页面
// if (xhr.responseJSON.code == 401 || xhr.responseJSON.code == 500) {
// parent.location.href = baseURL + 'login.html';
// }
if (code == 401) {
parent.location.href = baseURL + 'login.html';
}
}
});

Expand Down Expand Up @@ -127,13 +128,13 @@ function isBlank(value) {
/*弹出层*/

/*
参数解释:
title 标题
url 请求的url
id 需要操作的数据id
w 弹出层宽度(缺省调默认值)
h 弹出层高度(缺省调默认值)
*/
参数解释:
title 标题
url 请求的url
id 需要操作的数据id
w 弹出层宽度(缺省调默认值)
h 弹出层高度(缺省调默认值)
*/
function layer_show(title, url, w, h, callback) {
if (title == null || title == '') {
title = false;
Expand Down
Loading

0 comments on commit 3b6616b

Please sign in to comment.