// Path: src/main/java/org/myazure/weixin/domain/MaUser.java
// @Entity
// @Table(name = "myazure_weixin_user")
// public class MaUser extends BaseEntity {
// 
//     @Id
//     @GeneratedValue(strategy = GenerationType.AUTO)
//     @Column(name = "user_id")
//     private long id;
// 
//     @Column(name = "username", nullable = false, unique = true)
//     private String userName;
// 
//     @Column(name = "password", nullable = false)
//     private String password;
// 
//     @Column(name = "role", nullable = false)
//     @Enumerated(EnumType.STRING)
//     private MaRole role;
// 
//     @Column(name = "active", columnDefinition = "BIT", length = 1)
//     private boolean active = false;
//     
//     public MaUser() {
// 
//     }
// 
//     public MaUser(String userName, String password, MaRole role) {
//         this.userName = userName;
//         this.password = password;
//         this.role = role;
//     }
// 
//     public long getId() {
//         return id;
//     }
// 
//     public void setId(long id) {
//         this.id = id;
//     }
// 
//     public String getUserName() {
//         return userName;
//     }
// 
//     public void setUserName(String userName) {
//         this.userName = userName;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// 
//     public MaRole getRole() {
//         return role;
//     }
// 
//     public void setRole(MaRole role) {
//         this.role = role;
//     }
// 
// 	public boolean isActive() {
// 		return active;
// 	}
// 
// 	public void setActive(boolean active) {
// 		this.active = active;
// 	}
// }
// 
// Path: src/main/java/org/myazure/weixin/domain/entity/MaUserEntity.java
// public class MaUserEntity {
// 
// 	@NotEmpty
//     private Long id;
// 	
//     @NotEmpty
//     private String userName = "";
// 
//     private String password = "";
// 
//     private String passwordRepeated = "";
// 
//     @NotNull
//     private MaRole role = MaRole.USER;
// 
//     public String getUserName() {
//         return userName;
//     }
// 
//     public void setUserName(String userName) {
//         this.userName = userName;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// 
//     public String getPasswordRepeated() {
//         return passwordRepeated;
//     }
// 
//     public void setPasswordRepeated(String passwordRepeated) {
//         this.passwordRepeated = passwordRepeated;
//     }
// 
//     public MaRole getRole() {
//         return role;
//     }
// 
//     public void setRole(MaRole role) {
//         this.role = role;
//     }
// 
// 	public Long getId() {
// 		return id;
// 	}
// 
// 	public void setId(Long id) {
// 		this.id = id;
// 	}
// }
// 
// Path: src/main/java/org/myazure/weixin/repository/MaUserRepository.java
// public interface MaUserRepository extends PagingAndSortingRepository<MaUser, Long> {
// 
//     MaUser findOneByUserName(String userName);
// }


import java.util.Collection;
import org.myazure.weixin.domain.MaUser;
import org.myazure.weixin.domain.entity.MaUserEntity;
import org.myazure.weixin.repository.MaUserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Sort;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
package org.myazure.weixin.service;



/**
 * 
 * @author WangZhen
 *
 */
@Service
public class MaUserServiceImpl implements MaUserService {

    private static final Logger LOGGER = LoggerFactory.getLogger(MaUserServiceImpl.class);

    @Autowired
    private BCryptPasswordEncoder passwordEncoder;

    private final MaUserRepository userRepository;

    @Autowired
    public MaUserServiceImpl(MaUserRepository userRepository) {
        this.userRepository = userRepository;
    }

    @Override
    @Cacheable(value = "userCache",keyGenerator = "wiselyKeyGenerator")
    public MaUser getMaUserById(long id) {
    	LOGGER.info("[Myazure Weixin]: getMaUserById()");
        return userRepository.findOne(id);
    }

    @Override
    public MaUser getMaUserByName(String name) {
        return userRepository.findOneByUserName(name);
    }

    @Override
    @Cacheable(value = "userCache",keyGenerator = "wiselyKeyGenerator")
    public Collection<MaUser> getAllMaUsers() {
    	LOGGER.info("[Myazure Weixin]: getAllAdUsers()");
        return (Collection<MaUser>) userRepository.findAll(new Sort("userName"));
    }

    @Override
// Path: src/main/java/org/myazure/weixin/domain/MaUser.java
// @Entity
// @Table(name = "myazure_weixin_user")
// public class MaUser extends BaseEntity {
// 
//     @Id
//     @GeneratedValue(strategy = GenerationType.AUTO)
//     @Column(name = "user_id")
//     private long id;
// 
//     @Column(name = "username", nullable = false, unique = true)
//     private String userName;
// 
//     @Column(name = "password", nullable = false)
//     private String password;
// 
//     @Column(name = "role", nullable = false)
//     @Enumerated(EnumType.STRING)
//     private MaRole role;
// 
//     @Column(name = "active", columnDefinition = "BIT", length = 1)
//     private boolean active = false;
//     
//     public MaUser() {
// 
//     }
// 
//     public MaUser(String userName, String password, MaRole role) {
//         this.userName = userName;
//         this.password = password;
//         this.role = role;
//     }
// 
//     public long getId() {
//         return id;
//     }
// 
//     public void setId(long id) {
//         this.id = id;
//     }
// 
//     public String getUserName() {
//         return userName;
//     }
// 
//     public void setUserName(String userName) {
//         this.userName = userName;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// 
//     public MaRole getRole() {
//         return role;
//     }
// 
//     public void setRole(MaRole role) {
//         this.role = role;
//     }
// 
// 	public boolean isActive() {
// 		return active;
// 	}
// 
// 	public void setActive(boolean active) {
// 		this.active = active;
// 	}
// }
// 
// Path: src/main/java/org/myazure/weixin/domain/entity/MaUserEntity.java
// public class MaUserEntity {
// 
// 	@NotEmpty
//     private Long id;
// 	
//     @NotEmpty
//     private String userName = "";
// 
//     private String password = "";
// 
//     private String passwordRepeated = "";
// 
//     @NotNull
//     private MaRole role = MaRole.USER;
// 
//     public String getUserName() {
//         return userName;
//     }
// 
//     public void setUserName(String userName) {
//         this.userName = userName;
//     }
// 
//     public String getPassword() {
//         return password;
//     }
// 
//     public void setPassword(String password) {
//         this.password = password;
//     }
// 
//     public String getPasswordRepeated() {
//         return passwordRepeated;
//     }
// 
//     public void setPasswordRepeated(String passwordRepeated) {
//         this.passwordRepeated = passwordRepeated;
//     }
// 
//     public MaRole getRole() {
//         return role;
//     }
// 
//     public void setRole(MaRole role) {
//         this.role = role;
//     }
// 
// 	public Long getId() {
// 		return id;
// 	}
// 
// 	public void setId(Long id) {
// 		this.id = id;
// 	}
// }
// 
// Path: src/main/java/org/myazure/weixin/repository/MaUserRepository.java
// public interface MaUserRepository extends PagingAndSortingRepository<MaUser, Long> {
// 
//     MaUser findOneByUserName(String userName);
// }


// Path: src/main/java/org/myazure/weixin/service/MaUserServiceImpl.java
import java.util.Collection;
import org.myazure.weixin.domain.MaUser;
import org.myazure.weixin.domain.entity.MaUserEntity;
import org.myazure.weixin.repository.MaUserRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Sort;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

package org.myazure.weixin.service;



/**
 * 
 * @author WangZhen
 *
 */
@Service
public class MaUserServiceImpl implements MaUserService {

    private static final Logger LOGGER = LoggerFactory.getLogger(MaUserServiceImpl.class);

    @Autowired
    private BCryptPasswordEncoder passwordEncoder;

    private final MaUserRepository userRepository;

    @Autowired
    public MaUserServiceImpl(MaUserRepository userRepository) {
        this.userRepository = userRepository;
    }

    @Override
    @Cacheable(value = "userCache",keyGenerator = "wiselyKeyGenerator")
    public MaUser getMaUserById(long id) {
    	LOGGER.info("[Myazure Weixin]: getMaUserById()");
        return userRepository.findOne(id);
    }

    @Override
    public MaUser getMaUserByName(String name) {
        return userRepository.findOneByUserName(name);
    }

    @Override
    @Cacheable(value = "userCache",keyGenerator = "wiselyKeyGenerator")
    public Collection<MaUser> getAllMaUsers() {
    	LOGGER.info("[Myazure Weixin]: getAllAdUsers()");
        return (Collection<MaUser>) userRepository.findAll(new Sort("userName"));
    }

    @Override
    public MaUser create(MaUserEntity form) {