Browse Source

Merge branch 'dev' of http://192.168.1.220:10080/chenweida/jw2.0 into dev

chenyongxing 7 years ago
parent
commit
9a4cb84cf0

+ 26 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/exception/ManageException.java

@ -0,0 +1,26 @@
package com.yihu.jw.restmodel.exception;
/**
 * Created by chenweida on 2017/6/9.
 * 基卫自己的错误异常
 */
public class ManageException extends Exception{
    public ManageException() {
    }
    public ManageException(String message) {
        super(message);
    }
    public ManageException(String message, Throwable cause) {
        super(message, cause);
    }
    public ManageException(Throwable cause) {
        super(cause);
    }
    public ManageException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
        super(message, cause, enableSuppression, writableStackTrace);
    }
}

+ 144 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/manage/ManageUserVO.java

@ -0,0 +1,144 @@
package com.yihu.jw.restmodel.manage;
import java.util.Date;
/**
 * Created by chenweida on 2017/6/9.
 */
public class ManageUserVO {
    private Integer id;
    private String code;
    private String name;
    private String password;//密码  密码是 密码+salt MD5加密
    private String salt;//盐值
    private String loginAccount;//登陆的账号
    private String mobile;
    private Integer status;
    private Date createTime;
    private String createUser;
    private String createUserName;
    private Date updateTime;
    private String updateUser;
    private String updateUserName;
    private String remark;
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getCode() {
        return code;
    }
    public void setCode(String code) {
        this.code = code;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public String getSalt() {
        return salt;
    }
    public void setSalt(String salt) {
        this.salt = salt;
    }
    public String getLoginAccount() {
        return loginAccount;
    }
    public void setLoginAccount(String loginAccount) {
        this.loginAccount = loginAccount;
    }
    public String getMobile() {
        return mobile;
    }
    public void setMobile(String mobile) {
        this.mobile = mobile;
    }
    public Integer getStatus() {
        return status;
    }
    public void setStatus(Integer status) {
        this.status = status;
    }
    public Date getCreateTime() {
        return createTime;
    }
    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
    public String getCreateUser() {
        return createUser;
    }
    public void setCreateUser(String createUser) {
        this.createUser = createUser;
    }
    public String getCreateUserName() {
        return createUserName;
    }
    public void setCreateUserName(String createUserName) {
        this.createUserName = createUserName;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
    public String getUpdateUser() {
        return updateUser;
    }
    public void setUpdateUser(String updateUser) {
        this.updateUser = updateUser;
    }
    public String getUpdateUserName() {
        return updateUserName;
    }
    public void setUpdateUserName(String updateUserName) {
        this.updateUserName = updateUserName;
    }
    public String getRemark() {
        return remark;
    }
    public void setRemark(String remark) {
        this.remark = remark;
    }
}

+ 5 - 1
common/common-swagger/src/main/java/com/yihu/jw/config/SwaggerConfig.java

@ -103,7 +103,11 @@ public class SwaggerConfig {
                         regex("/"+ BaseContants.Function.api_common+"/.*")
                        ,regex("/"+ BaseContants.Saas.api_common+"/.*")
                        ,regex("/"+ BaseContants.Module.api_common+"/.*")
                        ,regex("/"+ WxContants.Wechat.api_common+"/.*")
                        ,regex("/"+ WxContants.WxTemplate.api_common+"/.*")
                        ,regex("/"+ WxContants.WxGraphicMessage.api_common+"/.*")
                        ,regex("/"+ WxContants.WxMenu.api_common+"/.*")
                        ,regex("/"+ WxContants.WxAccessToken.api_common+"/.*")
                ))
                .build()
                .apiInfo(jwBaseApiInfo());

+ 8 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/model/Function.java

@ -20,6 +20,7 @@ public class Function extends IdEntity implements java.io.Serializable {
	private String saasId; // saasid
	private String parentCode; //父功能code
	private Integer status; //状态 -1 删除 0 禁用 可用
	private String url;//功能对应的后台url路径
	private String createUser;
	private String createUserName;
	private Date createTime;
@ -176,4 +177,11 @@ public class Function extends IdEntity implements java.io.Serializable {
		this.remark = remark;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}
}

+ 5 - 0
svr/svr-manage/pom.xml

@ -88,6 +88,11 @@
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
        </dependency>
        <dependency>
            <groupId>net.sf.json-lib</groupId>
            <artifactId>json-lib</artifactId>
        </dependency>
    </dependencies>
    <build>
        <finalName>svr-manage</finalName>

+ 3 - 1
svr/svr-manage/readme.MD

@ -1,2 +1,4 @@
登陆页面
http://localhost:8080/login/login.jsp
http://localhost:8080/login/login.jsp
默认用户
admin 123456

+ 24 - 0
svr/svr-manage/src/main/java/com/yihu/jw/manage/cache/login/LoginCache.java

@ -0,0 +1,24 @@
package com.yihu.jw.manage.cache.login;
import com.yihu.jw.manage.model.system.ManageUser;
import com.yihu.jw.restmodel.manage.ManageUserVO;
import java.util.HashMap;
import java.util.Map;
/**
 * Created by chenweida on 2017/6/9.
 * 目前登陆的信息先放在内存中
 * 后续如果做集群管理应该放入redis中,并且需要考虑并发问题
 */
public class LoginCache {
    private static Map<String,ManageUserVO> user =new HashMap<>();
    public static ManageUserVO getCache(String key) {
        return user.get(key);
    }
    public static void addCache(String key,ManageUserVO manageUserVO) {
        user.put(key,manageUserVO);
    }
}

+ 14 - 0
svr/svr-manage/src/main/java/com/yihu/jw/manage/config/MvcConfig.java

@ -1,7 +1,10 @@
package com.yihu.jw.manage.config;
import com.yihu.jw.manage.interceptors.UserInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@ -11,6 +14,9 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
@Configuration
@EnableWebMvc
public class MvcConfig extends WebMvcConfigurerAdapter {
    @Autowired
    private UserInterceptor userInterceptor;
    //会在默认的基础上增加/bootstrap/**映射到classpath:/bootstrap/,
    // 不会影响默认的方式,可以同时使用。
    @Override
@ -25,4 +31,12 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
                .addResourceHandler("/common/**")
                .addResourceLocations("classpath:/webapp/common/");
    }
    /**
     * 判断是否登陆的拦截器
     * @param registry
     */
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(userInterceptor).addPathPatterns("/**");
    }
}

+ 12 - 0
svr/svr-manage/src/main/java/com/yihu/jw/manage/dao/login/ManageLoginLogDao.java

@ -0,0 +1,12 @@
package com.yihu.jw.manage.dao.login;
import com.yihu.jw.manage.model.login.ManageLoginLog;
import com.yihu.jw.manage.model.system.ManageMenu;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by chenweida on 2017/6/9.
 */
public interface ManageLoginLogDao  extends PagingAndSortingRepository<ManageLoginLog, Integer>, JpaSpecificationExecutor<ManageLoginLog> {
}

+ 45 - 0
svr/svr-manage/src/main/java/com/yihu/jw/manage/interceptors/UserInterceptor.java

@ -0,0 +1,45 @@
package com.yihu.jw.manage.interceptors;
import com.yihu.jw.restmodel.common.Envelop;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
/**
 * Created by chenweida on 2017/6/9.
 */
@Component
public class UserInterceptor implements HandlerInterceptor {
    private static Integer NOT_LOGIN=-1000;
    @Override
    public boolean preHandle(HttpServletRequest requset, HttpServletResponse response, Object o) throws Exception {
        boolean flag = true;
        try {
            Object obj= requset.getParameterMap().get("userCode");
            if(org.springframework.util.StringUtils.isEmpty(obj)){
                // 未登录
                response.getOutputStream().write(JSONObject.fromObject(Envelop.getError("请登录后再操作!",NOT_LOGIN)).toString().getBytes());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }
    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
    }
    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
    }
}

+ 115 - 0
svr/svr-manage/src/main/java/com/yihu/jw/manage/model/login/ManageLoginLog.java

@ -0,0 +1,115 @@
package com.yihu.jw.manage.model.login;// default package
import java.sql.Timestamp;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.Table;
/**
 * ManageLoginLog entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "manage_login_log")
public class ManageLoginLog implements java.io.Serializable {
	public static Integer type_error=0;
	public static Integer type_success=1;
	// Fields
	private Integer id;
	private Date loginTime;
	private String loginAccount;
	private String loginUser;
	private String loginUserName;
	private Integer type;
	private String errorMessage;
	// Constructors
	/** default constructor */
	public ManageLoginLog() {
	}
	/** minimal constructor */
	public ManageLoginLog(Timestamp loginTime) {
		this.loginTime = loginTime;
	}
	/** full constructor */
	public ManageLoginLog(Timestamp loginTime, String loginUser,
			String loginUserName, Integer type, String errorMessage) {
		this.loginTime = loginTime;
		this.loginUser = loginUser;
		this.loginUserName = loginUserName;
		this.type = type;
		this.errorMessage = errorMessage;
	}
	// Property accessors
	@Id
	@GeneratedValue(strategy = IDENTITY)
	@Column(name = "id", unique = true, nullable = false)
	public Integer getId() {
		return this.id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	@Column(name = "login_time", nullable = false, length = 0)
	public Date getLoginTime() {
		return this.loginTime;
	}
	public void setLoginTime(Date loginTime) {
		this.loginTime = loginTime;
	}
	@Column(name = "login_user", length = 100)
	public String getLoginUser() {
		return this.loginUser;
	}
	public void setLoginUser(String loginUser) {
		this.loginUser = loginUser;
	}
	@Column(name = "login_user_name", length = 100)
	public String getLoginUserName() {
		return this.loginUserName;
	}
	public void setLoginUserName(String loginUserName) {
		this.loginUserName = loginUserName;
	}
	@Column(name = "type")
	public Integer getType() {
		return this.type;
	}
	public void setType(Integer type) {
		this.type = type;
	}
	@Column(name = "error_message", length = 1000)
	public String getErrorMessage() {
		return this.errorMessage;
	}
	public void setErrorMessage(String errorMessage) {
		this.errorMessage = errorMessage;
	}
	public String getLoginAccount() {
		return loginAccount;
	}
	public void setLoginAccount(String loginAccount) {
		this.loginAccount = loginAccount;
	}
}

+ 50 - 11
svr/svr-manage/src/main/java/com/yihu/jw/manage/service/login/LoginService.java

@ -1,16 +1,23 @@
package com.yihu.jw.manage.service.login;
import com.yihu.jw.manage.cache.login.LoginCache;
import com.yihu.jw.manage.dao.login.ManageLoginLogDao;
import com.yihu.jw.manage.model.login.ManageLoginLog;
import com.yihu.jw.manage.model.system.ManageMenu;
import com.yihu.jw.manage.model.system.ManageRole;
import com.yihu.jw.manage.model.system.ManageUser;
import com.yihu.jw.manage.service.system.MenuService;
import com.yihu.jw.manage.service.system.RoleService;
import com.yihu.jw.manage.service.system.UserService;
import com.yihu.jw.restmodel.exception.ManageException;
import com.yihu.jw.restmodel.manage.ManageUserVO;
import com.yihu.jw.util.security.MD5;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -26,30 +33,62 @@ public class LoginService {
    private MenuService menuService;
    @Autowired
    private RoleService roleService;
    @Autowired
    private ManageLoginLogDao manageLoginLogDao;
    public ManageUser login(String username, String password) throws Exception{
    /**
     * ManageException异常不回滚
     * @param username
     * @param password
     * @return
     * @throws Exception
     */
    @Transactional(noRollbackForClassName = "ManageException")
    public ManageUser login(String username, String password) throws ManageException {
        ManageLoginLog manageLoginLog = new ManageLoginLog();
        manageLoginLog.setLoginAccount(username);
        manageLoginLog.setLoginTime(new Date());
        Map<String, List> data = new HashMap<>();
        //判断是否登陆信息是否正确
        ManageUser user = userService.findByAccount(username);
        if(user==null){
            throw new Exception("账号不存在");
        if (user == null) {
            //保存登陆信息
            String message = "账号不存在";
            manageLoginLog.setType(ManageLoginLog.type_error);
            manageLoginLog.setErrorMessage(message);
            manageLoginLogDao.save(manageLoginLog);
            throw new ManageException(message);
        }
        if (!user.getPassword().equals(MD5.GetMD5Code(password + user.getSalt()))) {
            throw new Exception("密码错误");
            //保存登陆信息
            String message = "密码错误";
            manageLoginLog.setLoginUser(user.getCode());
            manageLoginLog.setLoginUserName(user.getName());
            manageLoginLog.setType(ManageLoginLog.type_error);
            manageLoginLog.setErrorMessage(message);
            manageLoginLogDao.save(manageLoginLog);
            throw new ManageException(message);
        }
        //保存登陆信息
        manageLoginLog.setType(ManageLoginLog.type_success);
        manageLoginLog.setLoginUser(user.getCode());
        manageLoginLog.setLoginUserName(user.getName());
        manageLoginLogDao.save(manageLoginLog);
        //添加登陆缓存中
        ManageUserVO manageUserVO=new ManageUserVO();
        BeanUtils.copyProperties(user,manageLoginLog);
        LoginCache.addCache(user.getCode(),manageUserVO);
        return user;
    }
    public Map<String,List> index(String usercode) {
    public Map<String, List> index(String usercode) {
        Map<String, List> data = new HashMap<>();
        //得到角色
        List<ManageRole> roles=roleService.findByUserCode(usercode);
        List<ManageRole> roles = roleService.findByUserCode(usercode);
        //得到用户所有菜单
        List<ManageMenu> menus=menuService.findByUserCode(usercode);
        data.put("role",roles);
        data.put("menus",menus);
        List<ManageMenu> menus = menuService.findByUserCode(usercode);
        data.put("role", roles);
        data.put("menus", menus);
        return data;
    }
}

+ 8 - 0
svr/svr-manage/src/main/resources/banner.txt

@ -0,0 +1,8 @@
   _____                __  __
  / ____|              |  \/  |
 | (_____   ___ __     | \  / | __ _ _ __   __ _  __ _  ___
  \___ \ \ / / '__|    | |\/| |/ _` | '_ \ / _` |/ _` |/ _ \
  ____) \ V /| |       | |  | | (_| | | | | (_| | (_| |  __/
 |_____/ \_/ |_|       |_|  |_|\__,_|_| |_|\__,_|\__, |\___|
                                                  __/ |
                                                 |___/

+ 1 - 0
svr/svr-manage/src/main/resources/webapp/common/js/common.js

@ -1 +1,2 @@
var server="localhost:8080";
var not_login=-1000;