Skip to content

Commit

Permalink
dicionary mgmt added
Browse files Browse the repository at this point in the history
  • Loading branch information
DanneLeung committed Mar 21, 2017
1 parent c8b982c commit 0821a77
Show file tree
Hide file tree
Showing 30 changed files with 1,189 additions and 487 deletions.

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions src/main/java/com/xcesys/extras/framework/entity/Dict.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.datatables.mapping.DataTablesOutput;

import com.fasterxml.jackson.annotation.JsonView;
import com.xcesys.extras.framework.core.model.IdAuditableEntity;

import lombok.Getter;
Expand All @@ -23,16 +25,20 @@
@NoArgsConstructor
@Getter
@Setter
public class Dict extends IdAuditableEntity implements java.io.Serializable {
public class Dict extends IdAuditableEntity {

private static final long serialVersionUID = -8572522105499245114L;
private String description;
private Long id;
private String name;
private Integer seq;
@JsonView(DataTablesOutput.View.class)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn
private DictType type;
@JsonView(DataTablesOutput.View.class)
private String name;
@JsonView(DataTablesOutput.View.class)
private String value;
@JsonView(DataTablesOutput.View.class)
private Integer sort;
@JsonView(DataTablesOutput.View.class)
private String description;

}
18 changes: 13 additions & 5 deletions src/main/java/com/xcesys/extras/framework/entity/DictType.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.datatables.mapping.DataTablesOutput;

import com.fasterxml.jackson.annotation.JsonView;
import com.xcesys.extras.framework.core.model.IEditable;
import com.xcesys.extras.framework.core.model.IdAuditableEntity;

import lombok.Getter;
Expand All @@ -26,14 +29,19 @@
@DynamicUpdate
@Getter
@Setter
public class DictType extends IdAuditableEntity {

private static final long serialVersionUID = -4470144171936304544L;
public class DictType extends IdAuditableEntity implements IEditable{
private static final long serialVersionUID = -2334286394502372010L;
@JsonView(DataTablesOutput.View.class)
private String name;
@JsonView(DataTablesOutput.View.class)
private String description;
private Integer length;
@JsonView(DataTablesOutput.View.class)
private int length = 1;
@JsonView(DataTablesOutput.View.class)
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn
private Set<Dict> dicts = new HashSet<Dict>(0);
private Boolean editable;
@JsonView(DataTablesOutput.View.class)
private boolean editable = true;

}
175 changes: 87 additions & 88 deletions src/main/java/com/xcesys/extras/framework/entity/User.java
Original file line number Diff line number Diff line change
@@ -1,88 +1,87 @@
package com.xcesys.extras.framework.entity;

import static javax.persistence.FetchType.EAGER;

import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Locale;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.datatables.mapping.DataTablesOutput;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.fasterxml.jackson.annotation.JsonView;
import com.xcesys.extras.framework.core.model.IEditable;
import com.xcesys.extras.framework.core.model.IdAuditableEntity;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

@Entity
@DynamicInsert
@DynamicUpdate
@NoArgsConstructor
@RequiredArgsConstructor
@Getter
@Setter
public class User extends IdAuditableEntity implements UserDetails, IEditable {
private static final long serialVersionUID = -6943871074854331138L;
@JsonView(DataTablesOutput.View.class)
private boolean accountNonExpired = true;
@JsonView(DataTablesOutput.View.class)
private boolean accountNonLocked = true;
@JsonView(DataTablesOutput.View.class)
private boolean admin = false;
@JsonView(DataTablesOutput.View.class)
private boolean credentialsNonExpired = true;
@JsonView(DataTablesOutput.View.class)
private boolean editable = true;
@JsonView(DataTablesOutput.View.class)
private String email;
@JsonView(DataTablesOutput.View.class)
private boolean enabled = true;
@JsonView(DataTablesOutput.View.class)
private String fullname;
@JsonView(DataTablesOutput.View.class)
private String mobile;
@NonNull
@JsonView(DataTablesOutput.View.class)
private String password;
@JsonView(DataTablesOutput.View.class)
@OneToMany(fetch = EAGER)
private Set<PreferenceValue> preferenceValues = new HashSet<PreferenceValue>();

@JsonView(DataTablesOutput.View.class)
@ManyToMany(fetch = EAGER)
@JoinTable(name = "user_roles", joinColumns = {
@JoinColumn(name = "users_id", nullable = false, updatable = false) }, inverseJoinColumns = {
@JoinColumn(name = "roles_id", nullable = false, updatable = false) })
private Set<Role> roles = new HashSet<Role>();
@Column(unique = true)
@NonNull
@JsonView(DataTablesOutput.View.class)
private String username;

@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
Set<GrantedAuthority> grantedAuthorities = new LinkedHashSet<>();
for (Role role : getRoles()) {
grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
}
return grantedAuthorities;
}
}
package com.xcesys.extras.framework.entity;

import static javax.persistence.FetchType.EAGER;

import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;

import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.datatables.mapping.DataTablesOutput;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.fasterxml.jackson.annotation.JsonView;
import com.xcesys.extras.framework.core.model.IEditable;
import com.xcesys.extras.framework.core.model.IdAuditableEntity;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

@Entity
@DynamicInsert
@DynamicUpdate
@NoArgsConstructor
@RequiredArgsConstructor
@Getter
@Setter
public class User extends IdAuditableEntity implements UserDetails, IEditable {
private static final long serialVersionUID = -6943871074854331138L;
@JsonView(DataTablesOutput.View.class)
private boolean accountNonExpired = true;
@JsonView(DataTablesOutput.View.class)
private boolean accountNonLocked = true;
@JsonView(DataTablesOutput.View.class)
private boolean admin = false;
@JsonView(DataTablesOutput.View.class)
private boolean credentialsNonExpired = true;
@JsonView(DataTablesOutput.View.class)
private boolean editable = true;
@JsonView(DataTablesOutput.View.class)
private String email;
@JsonView(DataTablesOutput.View.class)
private boolean enabled = true;
@JsonView(DataTablesOutput.View.class)
private String fullname;
@JsonView(DataTablesOutput.View.class)
private String mobile;
@NonNull
@JsonView(DataTablesOutput.View.class)
private String password;
@JsonView(DataTablesOutput.View.class)
@OneToMany(fetch = EAGER)
private Set<PreferenceValue> preferenceValues = new HashSet<PreferenceValue>();

@JsonView(DataTablesOutput.View.class)
@ManyToMany(fetch = EAGER)
@JoinTable(name = "user_roles", joinColumns = {
@JoinColumn(name = "users_id", nullable = false, updatable = false) }, inverseJoinColumns = {
@JoinColumn(name = "roles_id", nullable = false, updatable = false) })
private Set<Role> roles = new HashSet<Role>();
@Column(unique = true)
@NonNull
@JsonView(DataTablesOutput.View.class)
private String username;

@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
Set<GrantedAuthority> grantedAuthorities = new LinkedHashSet<>();
for (Role role : getRoles()) {
grantedAuthorities.add(new SimpleGrantedAuthority(role.getName()));
}
return grantedAuthorities;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.xcesys.extras.framework.repository;

import com.xcesys.extras.framework.core.repository.IBaseRepository;
import com.xcesys.extras.framework.entity.Dict;

public interface DictRepository extends IBaseRepository<Dict, Long> {

Dict findByName(String name);

int countByTypeIdAndName(Long typeId, String name);

Iterable<Dict> findByTypeId(Long id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.xcesys.extras.framework.repository;

import com.xcesys.extras.framework.core.repository.IBaseRepository;
import com.xcesys.extras.framework.entity.DictType;

public interface DictTypeRepository extends IBaseRepository<DictType, Long> {

DictType findByName(String name);

int countByName(String name);
}
36 changes: 36 additions & 0 deletions src/main/java/com/xcesys/extras/framework/service/DictService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.xcesys.extras.framework.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xcesys.extras.framework.core.repository.IBaseRepository;
import com.xcesys.extras.framework.core.service.impl.BaseCrudService;
import com.xcesys.extras.framework.entity.Dict;
import com.xcesys.extras.framework.repository.DictRepository;

@Service
@Transactional
public class DictService extends BaseCrudService<Dict, Long> {
@Autowired
private DictRepository reposity;

public Dict findByName(String Dictname) {
return reposity.findByName(Dictname);
}

@Override
public IBaseRepository<Dict, Long> getRepository() {
return reposity;
}

public int countByTypeIdAndName(Long typeId, String name) {
return reposity.countByTypeIdAndName(typeId, name);
}

public Iterable<Dict> findByTypeId(@Param("typeId") Long typeId) {
return reposity.findByTypeId(typeId);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.xcesys.extras.framework.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xcesys.extras.framework.core.repository.IBaseRepository;
import com.xcesys.extras.framework.core.service.impl.BaseCrudService;
import com.xcesys.extras.framework.entity.DictType;
import com.xcesys.extras.framework.repository.DictTypeRepository;

@Service
@Transactional
public class DictTypeService extends BaseCrudService<DictType, Long> {
@Autowired
private DictTypeRepository reposity;

public DictType findByName(String DictTypename) {
return reposity.findByName(DictTypename);
}

@Override
public IBaseRepository<DictType, Long> getRepository() {
return reposity;
}

public int countByName(String name) {
return reposity.countByName(name);
}

}
17 changes: 5 additions & 12 deletions src/main/java/com/xcesys/extras/framework/service/RoleService.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,26 @@
import com.xcesys.extras.framework.entity.Role;
import com.xcesys.extras.framework.repository.RoleRepository;

import lombok.extern.slf4j.Slf4j;

@Service
@Transactional
@Slf4j
public class RoleService extends BaseCrudService<Role, Long> {
@Autowired
private RoleRepository roleRepository;

public int countByname(String username) {
return roleRepository.countByName(username);
}
private RoleRepository repository;

public Role findByName(String Rolename) {
return roleRepository.findByName(Rolename);
return repository.findByName(Rolename);
}

@Override
public IBaseRepository<Role, Long> getRepository() {
return roleRepository;
return repository;
}

public int countByName(String name) {
return roleRepository.countByName(name);
return repository.countByName(name);
}

public Role usersInRole(Long id) {
return roleRepository.findUsersById(id);
return repository.findUsersById(id);
}
}
Loading

0 comments on commit 0821a77

Please sign in to comment.