Commit 3003a6c4 by manxiaoqiang

user

parent 6635f598
......@@ -3,5 +3,12 @@
<component name="FrameworkDetectionExcludesConfiguration">
<file type="web" url="file://$PROJECT_DIR$" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
</project>
\ No newline at end of file
......@@ -80,7 +80,7 @@
<orderEntry type="module-library">
<library name="Maven: com.alibaba:jconsole:1.8.0">
<CLASSES>
<root url="jar://D:/java/jdk1.8.0_91/lib/jconsole.jar!/" />
<root url="jar://E:/Java/jdk1.8.0_65/lib/jconsole.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
......@@ -89,7 +89,7 @@
<orderEntry type="module-library">
<library name="Maven: com.alibaba:tools:1.8.0">
<CLASSES>
<root url="jar://D:/java/jdk1.8.0_91/lib/tools.jar!/" />
<root url="jar://E:/Java/jdk1.8.0_65/lib/tools.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
......
......@@ -5,6 +5,8 @@ package common.controller;
import com.sun.corba.se.spi.ior.ObjectKey;
import common.model.User;
import common.repository.RoleRepository;
import common.repository.RoleTypeRepository;
import common.repository.UserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -37,6 +39,10 @@ public class LoginController {
RedisLoginStatusManager redisLoginStatusManager;
@Autowired
TokenManager tokenManager;
@Autowired
RoleRepository roleRepository;
@Autowired
RoleTypeRepository roleTypeRepository;
@RequestMapping(value = "login", method = RequestMethod.GET)
......@@ -44,11 +50,20 @@ public class LoginController {
public ResultModel login(HttpServletResponse response, @RequestParam String email, @RequestParam String password) {
User user = userRepository.login(email, CipherUtil.generatePassword(password));
if(null != user){
if(null != user.getStatus() && !user.getStatus()){
Map<String, Object> map = new HashMap();;
map.put("code",201);
return ResultModel.OK(map);
}
//存储token
String token = tokenManager.createToken(String.valueOf(user.getId()));
//存储登陆密码
redisLoginStatusManager.createLoginStatus(token, user.getPassword());
user.setRoleName(roleRepository.getName(user.getRole()));
if(null != user.getRoleType()){
user.setRoleTypeName(roleTypeRepository.getName(user.getRoleType()));
}
Cookie cookie = new Cookie("TOKEN", token);
cookie.setPath("/");
cookie.setMaxAge(60 * 60 * 24 * 7);
......
......@@ -2,6 +2,9 @@ package common.controller;
import common.model.Menu;
import common.model.User;
import common.repository.AuthRepository;
import common.repository.RoleRepository;
import common.repository.RoleTypeRepository;
import common.repository.UserRepository;
import common.service.MenuService;
import common.service.UserService;
......@@ -27,33 +30,78 @@ public class UserController {
@Autowired
UserRepository userRepository;
@Autowired
RoleRepository roleRepository;
@Autowired
RoleTypeRepository roleTypeRepository;
@Autowired
AuthRepository authRepository;
@RequestMapping(value = "/valid/email", method = RequestMethod.GET)
@ResponseBody
public ResultModel validEmail(@RequestParam String email) {
return ResultModel.OK(userService.validEmail(email));
}
@RequestMapping(value = "/create", method = RequestMethod.POST)
@ResponseBody
public ResultModel create(@CurrentAccount User loginAccount, @RequestBody User resource) {
userService.create(loginAccount, resource);
return ResultModel.OK();
if(userService.validEmail(resource.getEmail())){
userService.create(loginAccount, resource);
return ResultModel.OK(true);
}else{
return ResultModel.OK(false);
}
}
@RequestMapping(value = "/update", method = RequestMethod.PUT)
@ResponseBody
public ResultModel update(@CurrentAccount User loginAccount, @RequestBody User resource) {
userService.create(loginAccount, resource);
return ResultModel.OK();
return ResultModel.OK(userService.update(loginAccount, resource));
}
@RequestMapping(value = "/find", method = RequestMethod.GET)
@ResponseBody
public ResultModel find(@CurrentAccount User loginAccount, @RequestBody User resource) {
userService.create(loginAccount, resource);
return ResultModel.OK();
public ResultModel find(@CurrentAccount User loginAccount) {
return ResultModel.OK(userService.find(loginAccount));
}
@RequestMapping(value = "/find/role", method = RequestMethod.GET)
@ResponseBody
public ResultModel findRole(@CurrentAccount User loginAccount) {
return ResultModel.OK(roleRepository.findAll());
}
@RequestMapping(value = "/find/roletype", method = RequestMethod.GET)
@ResponseBody
public ResultModel findRoleType(@CurrentAccount User loginAccount) {
return ResultModel.OK(roleTypeRepository.findAll());
}
@RequestMapping(value = "/find/auth", method = RequestMethod.GET)
@ResponseBody
public ResultModel findAuth(@CurrentAccount User loginAccount) {
return ResultModel.OK(authRepository.findByUser(loginAccount.getId()));
}
@RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
@ResponseBody
public ResultModel delete(@CurrentAccount User loginAccount, @PathVariable Long id) {
return ResultModel.OK(userService.delete(loginAccount, id));
}
@RequestMapping(value = "/enable/{id}", method = RequestMethod.PUT)
@ResponseBody
public ResultModel enable(@CurrentAccount User loginAccount, @PathVariable Long id) {
return ResultModel.OK(userService.enable(loginAccount, id));
}
@RequestMapping(value = "/delete", method = RequestMethod.GET)
@RequestMapping(value = "/forbiden/{id}", method = RequestMethod.PUT)
@ResponseBody
public ResultModel delete(@CurrentAccount User loginAccount, @RequestBody User resource) {
userService.create(loginAccount, resource);
return ResultModel.OK();
public ResultModel forbiden(@CurrentAccount User loginAccount, @PathVariable Long id) {
return ResultModel.OK(userService.forbiden(loginAccount, id));
}
@RequestMapping(value = "/update/name", method = RequestMethod.PUT)
......
package common.model;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
public class Role {
private Long id;
//
private String role;
//
private Long roleKey;
public Role() {
super();
}
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public Long getRoleKey() {
return roleKey;
}
public void setRoleKey(Long roleKey) {
this.roleKey = roleKey;
}
}
......@@ -11,6 +11,9 @@ public class RoleType {
//
private String position;
//
private Long typeKey;
public RoleType() {
......@@ -34,4 +37,12 @@ public class RoleType {
public void setPosition(String position) {
this.position = position;
}
public Long getTypeKey() {
return typeKey;
}
public void setTypeKey(Long typeKey) {
this.typeKey = typeKey;
}
}
......@@ -15,8 +15,11 @@ public class User {
private String password;
private String name;
private Long role;
private String roleName;
private Long roleType;
private String roleTypeName;
private String auth;
private Boolean status;
private Long modifyAccount;
private Long createAccount;
......@@ -124,6 +127,31 @@ public class User {
this.auth = auth;
}
public Boolean getStatus() {
return status;
}
public void setStatus(Boolean status) {
this.status = status;
}
public String getRoleTypeName() {
return roleTypeName;
}
public void setRoleTypeName(String roleTypeName) {
this.roleTypeName = roleTypeName;
}
public String getRoleName() {
return roleName;
}
public void setRoleName(String roleName) {
this.roleName = roleName;
}
@Override
public String toString() {
return "User{" +
......
......@@ -11,4 +11,5 @@ import java.util.List;
@Transactional
public interface AuthRepository extends JpaRepository<Auth, Long> {
Auth findByUser(Long user);
}
package common.repository;
import common.model.Role;
import common.model.RoleType;
import common.model.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
@Transactional
public interface RoleRepository extends JpaRepository<Role, Long> {
@Query(value="select role from role where role_key = ?1",nativeQuery=true)
String getName(Long key);
}
......@@ -2,9 +2,12 @@ package common.repository;
import common.model.RoleType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;
@Transactional
public interface RoleTypeRepository extends JpaRepository<RoleType, Long> {
@Query(value="select position from role_type where type_key = ?1",nativeQuery=true)
String getName(Long key);
}
......@@ -18,7 +18,7 @@ public interface UserRepository extends JpaRepository<User, Long> {
List<User> findOneDepartment(Long role);
@Query(value="select * from user where del_flag is not true",nativeQuery=true)
List<User> findAll();
List<User> findList();
@Query(value="select * from user where email = ?1 and del_flag is not true",nativeQuery=true)
User login(String email);
......
......@@ -10,6 +10,8 @@ import java.util.List;
*/
public interface UserService {
Boolean validEmail(String email);
User create(User login, User resource);
User update(User login, User resource);
......@@ -18,6 +20,10 @@ public interface UserService {
User delete(User login, Long id);
User enable(User login, Long id);
User forbiden(User login, Long id);
User updateName(User login, String name);
User updatePwd(User login, String pwd);
......
......@@ -14,6 +14,7 @@ import org.springframework.stereotype.Service;
import util.CharacterUtils;
import util.CipherUtil;
import util.MailUtils;
import util.ValidateUtil;
import java.util.*;
......@@ -32,15 +33,25 @@ public class UserServiceImpl implements UserService {
private CodeRepository codeRepository;
@Override
public Boolean validEmail(String email) {
User user = userRepository.login(email);
if(null == user){
return true;
}
return false;
}
@Override
public User create(User login, User resource) {
if(!login.getRole().equals(RoleEnum.MANAGER.getKey())){//非管理员只能创建本部门普通账户
resource.setRole(login.getRole());
resource.setRoleType(RoleTypeEnum.COMMON.getKey());
}
resource.setPassword(CipherUtil.generatePassword("111111"));
resource.setPassword(CipherUtil.generatePassword(resource.getPassword()));
resource.setCreateTime(new Date());
resource.setCreateAccount(login.getId());
resource.setStatus(true);
User save = userRepository.save(resource);
//auth
......@@ -55,18 +66,24 @@ public class UserServiceImpl implements UserService {
@Override
public User update(User login, User resource) {
User one = userRepository.findOne(resource.getId());
if(!login.getRole().equals(RoleEnum.MANAGER.getKey())){//非管理员只能创建本部门普通账户
resource.setRole(login.getRole());
resource.setRoleType(RoleTypeEnum.COMMON.getKey());
}
resource.setCreateTime(one.getCreateTime());
resource.setStatus(one.getStatus());
resource.setDelFlag(one.getDelFlag());
resource.setCreateAccount(one.getCreateAccount());
resource.setPassword(one.getPassword());
resource.setModifyTime(new Date());
resource.setModifyAccount(login.getId());
User save = userRepository.save(resource);
//auth
Auth auth = new Auth();
auth.setCreateTime(new Date());
auth.setCreateAccount(login.getId());
Auth auth = authRepository.findByUser(one.getId());
auth.setModifyTime(new Date());
auth.setModifyAccount(login.getId());
auth.setAuth(resource.getAuth());
auth.setUser(save.getId());
authRepository.save(auth);
......@@ -75,13 +92,29 @@ public class UserServiceImpl implements UserService {
@Override
public List<User> find(User login) {
List<User> userList = null;
if(!login.getRole().equals(RoleEnum.MANAGER.getKey())) {
userList = userRepository.findAll();
} else if(RoleTypeEnum.MANAGER.getKey().equals(login.getRoleType())){
List<Auth> authList = authRepository.findAll();
Map<Long, String> map = new HashMap<>();
if(ValidateUtil.isValid(authList)){
for(Auth a : authList){
map.put(a.getUser(), a.getAuth());
}
}
List<User> userList = new ArrayList<>();
List<User> result = new ArrayList<>();
if(login.getRole().equals(RoleEnum.MANAGER.getKey())) {
userList = userRepository.findList();
} else if(!RoleTypeEnum.MANAGER.getKey().equals(login.getRoleType())){
userList = userRepository.findOneDepartment(login.getRole());
}
return userList;
if(ValidateUtil.isValid(userList)){
for(User u : userList){
if(map.containsKey(u.getId())){
u.setAuth(map.get(u.getId()));
}
result.add(u);
}
}
return result;
}
@Override
......@@ -94,6 +127,24 @@ public class UserServiceImpl implements UserService {
}
@Override
public User enable(User login, Long id) {
User one = userRepository.findOne(id);
one.setModifyTime(new Date());
one.setModifyAccount(login.getId());
one.setStatus(true);
return userRepository.save(one);
}
@Override
public User forbiden(User login, Long id) {
User one = userRepository.findOne(id);
one.setModifyTime(new Date());
one.setModifyAccount(login.getId());
one.setStatus(false);
return userRepository.save(one);
}
@Override
public User updateName(User login, String name) {
User one = userRepository.findOne(login.getId());
one.setName(name);
......
......@@ -12,7 +12,7 @@
<bean id="tkioAccountTask" class="tkio.task.AccountTask"></bean>
<task:scheduled-tasks>
<!--//定时同步短链数据(每5分钟执行一次)-->
<task:scheduled ref="tkioAccountTask" method="task" cron="0 40 14 * * ?"/>
<task:scheduled ref="tkioAccountTask" method="task" cron="0 11 17 * * ?"/>
</task:scheduled-tasks>
<bean id="tkioNoticeTask" class="tkio.task.NoticeTask"></bean>
......
......@@ -10,11 +10,14 @@
<description>调度配置</description>
<bean id="tkioAccountTask" class="tkio.task.AccountTask"></bean>
<task:scheduled-tasks>
<!--//定时同步短链数据(每5分钟执行一次)-->
<task:scheduled ref="tkioAccountTask" method="task" cron="0 21 15 * * ?"/>
<task:scheduled ref="tkioAccountTask" method="task" cron="0 11 17 * * ?"/>
</task:scheduled-tasks>
<bean id="tkioNoticeTask" class="tkio.task.NoticeTask"></bean>
<task:scheduled-tasks>
<task:scheduled ref="tkioNoticeTask" method="task" cron="0 33 16 * * ?"/>
</task:scheduled-tasks>
<bean id="trackAccountTask" class="track.task.AccountTask"></bean>
......
......@@ -19,6 +19,7 @@ tkio\model\Account.class
common\task\ReportCallable.class
security\AbstractTokenManager.class
track\repository\TrackAccountRepository.class
common\model\Role.class
common\model\UserLog.class
security\exception\MethodNotSupportException.class
tkio\repository\SalesManLeaderRepository.class
......@@ -35,6 +36,7 @@ tkio\repository\IsNotifiedRepository.class
track\repository\TrackChannelRepository.class
tkio\service\impl\TkioAccountServiceImpl.class
util\DateUtil.class
common\repository\RoleRepository.class
common\model\AppCategory.class
tkio\repository\ChannelRepository.class
security\RedisLoginStatusManager.class
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment