dcs 1 سال پیش
والد
کامیت
34700197d5

+ 0 - 7
virgo.core/src/main/java/com/bosshand/virgo/core/controller/UserContextController.java

@@ -1,6 +1,5 @@
 package com.bosshand.virgo.core.controller;
 
-import com.alibaba.fastjson.JSONObject;
 import com.bosshand.virgo.core.model.MgrOrganization;
 import com.bosshand.virgo.core.model.MgrUser;
 import com.bosshand.virgo.core.model.UserContext;
@@ -67,12 +66,6 @@ public class UserContextController {
 		return Response.fail(405, "手机验证码有误");
 	}
 
-	@ApiOperation(value="获取微信手机号", notes="getPhoneNumber 返回的 code 与 wx.login 返回的 code 作用是不一样的,不能混用")
-	@RequestMapping(value = "/verify/getCode", method = RequestMethod.POST)
-	public Response getWxPhone(@RequestBody JSONObject json) {
-		return Response.ok(mgrUserService.phoneNumber(json.getString("code")));
-	}
-
 	@ApiOperation(value="登录注册", notes="登录注册")
 	@RequestMapping(value = "/login", method = RequestMethod.POST)
 	public Response login(@RequestBody LoginUserDto dto) {

+ 21 - 0
virgo.core/src/main/java/com/bosshand/virgo/core/dao/MgrRoleDao.java

@@ -0,0 +1,21 @@
+package com.bosshand.virgo.core.dao;
+
+import com.bosshand.virgo.core.model.MgrRole;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+@Mapper
+public interface MgrRoleDao {
+
+    MgrRole get(long id);
+
+    int insert(MgrRole mgrRole);
+
+    List<MgrRole> getList(long projectId, long organizationId);
+
+    int delete(long id);
+
+    int update(MgrRole mgrRole);
+
+}

+ 86 - 0
virgo.core/src/main/java/com/bosshand/virgo/core/model/MgrRole.java

@@ -0,0 +1,86 @@
+package com.bosshand.virgo.core.model;
+
+import java.util.List;
+
+public class MgrRole {
+
+    private long id;
+
+    private String code;
+
+    private String name;
+
+    private String memo;
+
+    private long organizationId;
+
+    private long projectId;
+
+    private long parentId;
+
+    private List<MgrRole> children;
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long 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 getMemo() {
+        return memo;
+    }
+
+    public void setMemo(String memo) {
+        this.memo = memo;
+    }
+
+    public long getOrganizationId() {
+        return organizationId;
+    }
+
+    public void setOrganizationId(long organizationId) {
+        this.organizationId = organizationId;
+    }
+
+    public long getProjectId() {
+        return projectId;
+    }
+
+    public void setProjectId(long projectId) {
+        this.projectId = projectId;
+    }
+
+    public long getParentId() {
+        return parentId;
+    }
+
+    public void setParentId(long parentId) {
+        this.parentId = parentId;
+    }
+
+    public List<MgrRole> getChildren() {
+        return children;
+    }
+
+    public void setChildren(List<MgrRole> children) {
+        this.children = children;
+    }
+}

+ 6 - 0
virgo.core/src/main/java/com/bosshand/virgo/core/service/MgrUserService.java

@@ -112,6 +112,12 @@ public class MgrUserService {
 		userRole.setUserId(userId);
 		mgrUserRoleDao.insert(userRole);
 	}
+
+	public void wxRegister(MgrUser user) {
+		user.setLastOrganizationId(-1);
+		user.setLastProjectId(-1);
+		mgrUserDao.insert(user);
+	}
 	
 	public MgrUser getById(long id) {
 		return mgrUserDao.getById(id);

+ 14 - 0
virgo.core/src/main/java/com/bosshand/virgo/core/shiro/LoginUserDto.java

@@ -17,6 +17,11 @@ public class LoginUserDto {
      */
     private String code;
 
+    /**
+     * 微信获取手机号code
+     */
+    private String pCode;
+
     public String getPhone() {
         return phone;
     }
@@ -40,4 +45,13 @@ public class LoginUserDto {
     public void setCode(String code) {
         this.code = code;
     }
+
+    public String getpCode() {
+        return pCode;
+    }
+
+    public void setpCode(String pCode) {
+        this.pCode = pCode;
+    }
+
 }

+ 23 - 11
virgo.core/src/main/java/com/bosshand/virgo/core/shiro/VirgoAuthenticationFilter.java

@@ -56,6 +56,7 @@ public class VirgoAuthenticationFilter extends AuthenticatingFilter {
 		String phone = null;
 		String phoneCode = null;
 		String wxCode = null;
+		String wxpCode = null;
 		LoginUserDto dto = null;
 		try {
 			BufferedReader streamReader = new BufferedReader(new InputStreamReader(request.getInputStream(), "UTF-8"));
@@ -72,17 +73,28 @@ public class VirgoAuthenticationFilter extends AuthenticatingFilter {
 
 			// 微信注册登录
 			wxCode = dto.getCode();
+			wxpCode = dto.getpCode();
 			if (wxCode != null) {
-				MgrUser user = mgrUserService.getByPhone(dto.getPhone());
+				if (wxpCode != null) {
+					phone = mgrUserService.phoneNumber(wxpCode);
+				} else {
+					// 携带手机验证码的
+					if (CodeCache.getKey(dto.getPhone()).equals(dto.getPhoneCode())) {
+						phone = dto.getPhone();
+					} else {
+						throw new AuthException("验证码有误", Constant.RET_AUTH_FAILED);
+					}
+				}
+				MgrUser user = mgrUserService.getByPhone(phone);
 				init(mgrUserService.wxLogin(wxCode));
 				if (user != null) {
-					return createToken(dto.getPhone(), wxCode, request, response);
+					return createToken(phone, wxCode, request, response);
 				} else {
 					//注册
 					MgrUser u = new MgrUser();
-					u.setPhone(dto.getPhone());
-					mgrUserService.register(u);
-					return createToken(dto.getPhone(), wxCode, request, response);
+					u.setPhone(phone);
+					mgrUserService.wxRegister(u);
+					return createToken(phone, wxCode, request, response);
 				}
 			}
 
@@ -93,20 +105,19 @@ public class VirgoAuthenticationFilter extends AuthenticatingFilter {
 			}
 
 			// 手机号验证码注册登录
-			String code = CodeCache.getKey(dto.getPhone());
+			phoneCode = CodeCache.getKey(dto.getPhone());
+			if (!dto.getPhoneCode().equals(phoneCode)) {
+				throw new AuthException("验证码有误", Constant.RET_AUTH_FAILED);
+			}
 			MgrUser user = mgrUserService.getByPhone(dto.getPhone());
 			if (user != null) {
-				if (dto.getPhoneCode().equals(code)) {
-					phone = user.getPhone();
-					phoneCode = code;
-				}
+				phone = user.getPhone();
 			} else {
 				//注册
 				MgrUser u = new MgrUser();
 				u.setPhone(dto.getPhone());
 				mgrUserService.register(u);
 				phone = dto.getPhone();
-				phoneCode = code;
 			}
 		} catch (Exception e) {
 			log.error("Can not create token", e);
@@ -121,6 +132,7 @@ public class VirgoAuthenticationFilter extends AuthenticatingFilter {
 			mgrUserService.loadContext(subject);
 			if (wxJson != null) {
 				JSONObject jsonObject = JSONObject.parseObject(wxJson);
+				release();
 				jsonObject.put("token", subject.getSession().getId().toString());
 				response.getWriter().write(JSON.toJSONString(Response.ok(jsonObject)));
 			} else {

+ 35 - 0
virgo.core/src/main/resources/mapper/MgrRoleMapper.xml

@@ -0,0 +1,35 @@
+<?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.bosshand.virgo.core.dao.MgrRoleDao">
+
+    <resultMap type="com.bosshand.virgo.core.model.MgrRole" id="mgrRoleResult">
+        <id column="id" property="id"/>
+        <result column="code" property="code"/>
+        <result column="name" property="name"/>
+        <result column="memo" property="memo"/>
+        <result column="projectId" property="projectId"/>
+        <result column="organizationId" property="organizationId"/>
+        <result column="parentId" property="parentId"/>
+    </resultMap>
+
+    <select id="getList" resultMap="mgrRoleResult">
+        select * from mgr_role where projectId = #{projectId} and organizationId = #{organizationId}
+    </select>
+
+    <select id="get" resultMap="mgrRoleResult">
+        select * from mgr_role where id = #{id}
+    </select>
+
+    <insert id="insert" parameterType="com.bosshand.virgo.core.model.MgrRole" useGeneratedKeys="true" keyProperty="id">
+        INSERT INTO mgr_role(code, name, memo, projectId, organizationId, parentId) VALUES (#{code}, #{name}, #{memo}, #{projectId}, #{organizationId}, #{parentId})
+    </insert>
+
+    <delete id="delete">
+        DELETE FROM mgr_role WHERE id = #{id}
+    </delete>
+
+    <update id="update" parameterType="com.bosshand.virgo.core.model.MgrRole">
+        UPDATE mgr_role SET name = #{name} WHERE id = #{id}
+    </update>
+
+</mapper>

+ 45 - 0
virgo.manager/src/main/java/com/bosshand/virgo/controller/RoleController.java

@@ -0,0 +1,45 @@
+package com.bosshand.virgo.controller;
+
+
+import com.bosshand.virgo.core.model.MgrRole;
+import com.bosshand.virgo.core.response.Response;
+import com.bosshand.virgo.service.RoleService;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+@RestController
+@RequestMapping("role")
+public class RoleController {
+
+    @Autowired
+    RoleService roleService;
+
+    @ApiOperation(value = "角色树", notes = "角色树")
+    @GetMapping("/{organizationId}/{projectId}")
+    public Response getOrganizationId(@PathVariable long organizationId, @PathVariable long projectId) {
+        return Response.ok(roleService.getList(projectId, organizationId));
+    }
+
+    @ApiOperation(value = "新增", notes = "新增")
+    @PostMapping
+    public Response save(@RequestBody MgrRole mgrRole) {
+        roleService.save(mgrRole);
+        return Response.ok();
+    }
+
+    @ApiOperation(value = "修改", notes = "修改")
+    @PutMapping
+    public Response update(@RequestBody MgrRole mgrRole) {
+        roleService.update(mgrRole);
+        return Response.ok();
+    }
+
+    @ApiOperation(value = "删除", notes = "删除")
+    @DeleteMapping("/{id}")
+    public Response delete(@PathVariable long id) {
+        roleService.delete(id);
+        return Response.ok();
+    }
+
+}

+ 75 - 0
virgo.manager/src/main/java/com/bosshand/virgo/service/RoleService.java

@@ -0,0 +1,75 @@
+package com.bosshand.virgo.service;
+
+import com.bosshand.virgo.core.dao.MgrRoleDao;
+import com.bosshand.virgo.core.model.MgrRole;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@Service
+public class RoleService {
+
+    @Autowired
+    MgrRoleDao mgrRoleDao;
+
+    public int save(MgrRole mgrRole) {
+        return mgrRoleDao.insert(mgrRole);
+    }
+
+    public int update(MgrRole mgrRole) {
+        return mgrRoleDao.update(mgrRole);
+    }
+
+    public int delete(long id) {
+        return mgrRoleDao.delete(id);
+    }
+
+    public List<MgrRole> getList(long projectId, long organizationId) {
+        List<MgrRole> list = mgrRoleDao.getList(projectId, organizationId);
+        List<Long> ids = new ArrayList<>();
+        list.forEach(ls -> {
+            if (ls.getParentId() == -1) {
+                ids.add(ls.getId());
+            }
+        });
+        List<MgrRole> hierarchy = new ArrayList<>();
+        if (ids.size() > 0) {
+            ids.forEach(ll -> hierarchy.add(getNodeTreeById(ll, list)));
+        }
+        return hierarchy;
+    }
+
+    private MgrRole getNodeTreeById(long id, List<MgrRole> list) {
+        MgrRole node = null;
+        List<MgrRole> roleList = list;
+        for (MgrRole data : roleList) {
+            if (data.getId() == id) {
+                node = data;
+                break;
+            }
+        }
+        if (node != null) {
+            node.setChildren(getChildNode(node.getId(), roleList));
+        }
+        return node;
+    }
+
+    private List<MgrRole> getChildNode(long parentId, List<MgrRole> list) {
+        List<MgrRole> nodeList = new ArrayList<MgrRole>();
+        nodeList.clear();
+        for (MgrRole data : list) {
+            if (data.getParentId() == parentId) {
+                nodeList.add(data);
+            }
+        }
+        if (nodeList.size() > 0) {
+            for (MgrRole data : nodeList) {
+                List<MgrRole> childList = getChildNode(data.getId(), list);
+                data.setChildren(childList);
+            }
+        }
+        return nodeList;
+    }
+}