@Entity
//±íÃûÓëÀàÃû²»ÏàÍ¬Ê±ÖØÐÂ¶¨Òå±íÃû.
@Table(name = "ACCT_USER")
//Ä¬ÈÏµÄ»º´æ²ßÂÔ.
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class AcctUser implements java.io.Serializable {

	private Long id;
	private String email;
	//javascriptÑéÖ¤
	private String loginName;
	//Èç¹ûÖØ¸´ÔÚêÇ³ÆºóÃæ¼ÓÉÏ#Êý×Ö ±ÈÈç#3366
	private String name;
	private String password;
	
	private String avatar;
	private Long login_count;
	private Date create_time;
	
	private Date outDate;
	private String validataCode;
	
	private Long experience;
	private int user_level;
	
	
	private Set<Comment> comments = new HashSet<Comment>(0);
	
	private Set<AcctUserInfo> acctUserInfo = new HashSet<AcctUserInfo>(0);
	
	private Set<Badge> badges = new HashSet<Badge>(0);

	@Column(name="avatar")
	public String getAvatar() {
		return avatar;
	}

	public void setAvatar(String avatar) {
		this.avatar = avatar;
	}

	@Column(name="login_count")
	public Long getLogin_count() {
		return login_count;
	}

	public void setLogin_count(Long login_count) {
		this.login_count = login_count;
	}

	@Column(name="create_time")
	public Date getCreate_time() {
		return create_time;
	}

	public void setCreate_time(Date create_time) {
		this.create_time = create_time;
	}

	@Column(name="out_date")
	public Date getOutDate() {
		return outDate;
	}

	public void setOutDate(Date outDate) {
		this.outDate = outDate;
	}

	@Column(name="validata_code")
	public String getValidataCode() {
		return validataCode;
	}

	public void setValidataCode(String validataCode) {
		this.validataCode = validataCode;
	}

	@Column(name="experience")
	public Long getExperience() {
		return experience;
	}

	//¼ì²â¾­Ñé
	public void setExperience(Long experience) {
		if(experience<0){
			this.experience = 0L;
		}else if(experience>9999){
			this.experience = 9999L;
		}else{
			this.experience = experience;
		}
		
	}

	@Column(name="user_level")
	public int getUser_level() {
		return user_level;
	}

	//¼ì²âµÈ¼¶
	public void setUser_level(int user_level) {
		this.user_level = user_level;
		
		if(user_level<1){
			this.user_level = 1;
		}else if(user_level>9){
			this.user_level = 9;
		}else{
			this.user_level = user_level;
		}
	}

	private List<AcctRole> roleList = Lists.newArrayList();//ÓÐÐòµÄ¹ØÁª¶ÔÏó¼¯ºÏ
	

	public AcctUser() {
	}
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(unique = true,nullable = false)
	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	//×Ö¶Î·Ç¿ÕÇÒÎ¨Ò», ÓÃÓÚÌáÐÑEntityÊ¹ÓÃÕß¼°Éú³ÉDDL.
	@Column(name="login_name",nullable = false, unique = true)
	public String getLoginName() {
		return this.loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	@OneToMany(mappedBy = "acctuser")
	public Set<Comment> getComments() {
		return comments;
	}

	public void setComments(Set<Comment> comments) {
		this.comments = comments;
	}
	
	//---
	@OneToMany(mappedBy="acctUser",cascade = { CascadeType.PERSIST ,CascadeType.ALL})
	public Set<AcctUserInfo> getAcctUserInfo() {
		return acctUserInfo;
	}

	public void setAcctUserInfo(Set<AcctUserInfo> acctUserInfo) {
		this.acctUserInfo = acctUserInfo;
	}

	@ManyToMany
	@JoinTable(name = "user_badge", joinColumns = { @JoinColumn(name = "user_id") }, inverseJoinColumns = { @JoinColumn(name = "badge_id") })
	@Fetch(FetchMode.SUBSELECT)
	@OrderBy("id")
	@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
	public Set<Badge> getBadges() {
		return badges;
	}

	public void setBadges(Set<Badge> badges) {
		this.badges = badges;
	}

		//¶à¶Ô¶à¶¨Òå
		@ManyToMany
		//ÖÐ¼ä±í¶¨Òå,±íÃû²ÉÓÃÄ¬ÈÏÃüÃû¹æÔò
		@JoinTable(name = "ACCT_USER_ROLE", joinColumns = { @JoinColumn(name = "USER_ID") }, inverseJoinColumns = { @JoinColumn(name = "ROLE_ID") })
		//Fecth²ßÂÔ¶¨Òå
		@Fetch(FetchMode.SUBSELECT)
		//¼¯ºÏ°´idÅÅÐò.
		@OrderBy("id")
		//¼¯ºÏÖÐ¶ÔÏóidµÄ»º´æ.
		@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
		public List<AcctRole> getRoleList() {
			return roleList;
		}

		public void setRoleList(List<AcctRole> roleList) {
			this.roleList = roleList;
		}

		//·Ç³Ö¾Ã»¯ÊôÐÔ.
		@Transient
		public String getRoleNames() {
			return ConvertUtils.convertElementPropertyToString(roleList, "name", ", ");
		}
		
		/**
		 * ÓÃ»§ÓµÓÐµÄ½ÇÉ«id×Ö·û´®, ¶à¸ö½ÇÉ«idÓÃ','·Ö¸ô.
		 */
		//·Ç³Ö¾Ã»¯ÊôÐÔ.
		@Transient
		@SuppressWarnings("unchecked")
		public List<Long> getRoleIds() {
			return ConvertUtils.convertElementPropertyToList(roleList, "id");
		}

		@Override
		public String toString() {
			return ToStringBuilder.reflectionToString(this);
		}
		
		//·Ç³Ö¾Ã»¯ÊôÐÔ.
		@Transient
		public String createTimeToString(){
			return create_time.toLocaleString();
		}
		
		//´¦Àí¹ýÊ±µÄtoLocaleString()
		@Transient
		public String createTimeToString2(){
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			return sdf.format(create_time);
		}
	
} public class MyUserDetails extends User{

	private String userNameAlias;
	
	public MyUserDetails(String username, String password, boolean enabled, boolean accountNonExpired,
            boolean credentialsNonExpired, boolean accountNonLocked, Collection<GrantedAuthority> authorities)
            throws IllegalArgumentException {
        super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
    }
	
	public String getUserNameAlias() {
		return userNameAlias;
	}

	public void setUserNameAlias(String userNameAlias) {
		this.userNameAlias = userNameAlias;
	}
} @Entity
@Table(name = "badge")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Badge implements java.io.Serializable {

	private Long id;
	private String name;
	private String url;
	private String alt;
	private String full_url;

	public Badge() {
	}

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public synchronized String getName() {
		return name;
	}

	public synchronized void setName(String name) {
		this.name = name;
	}

	public synchronized String getUrl() {
		return url;
	}

	public synchronized void setUrl(String url) {
		this.url = url;
	}

	public synchronized String getAlt() {
		return alt;
	}

	public synchronized void setAlt(String alt) {
		this.alt = alt;
	}

	@Column(name="full_url")
	public String getFull_url() {
		return full_url;
	}

	public void setFull_url(String full_url) {
		this.full_url = full_url;
	}

} @Entity
@Table(name = "badge_show")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class BadgeShow implements java.io.Serializable {

	private Long id;
	private Long userId;
	private Long badgeId;
	private Integer show_control;

	public BadgeShow() {
	}

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name="user_id")
	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	@Column(name="badge_id")
	public Long getBadgeId() {
		return badgeId;
	}

	public void setBadgeId(Long badgeId) {
		this.badgeId = badgeId;
	}

	@Column(name="show_control")
	public Integer getShow_control() {
		return show_control;
	}

	public void setShow_control(Integer show_control) {
		this.show_control = show_control;
	}

} @Entity
@Table(name = "check_topic_ad")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class CheckTopicAd implements java.io.Serializable {

	private Long id;
	private long userId;
	private long topicId;

	public CheckTopicAd() {
	}

	public CheckTopicAd(long userId, long topicId) {
		this.userId = userId;
		this.topicId = topicId;
	}

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name="user_id")
	public long getUserId() {
		return this.userId;
	}

	public void setUserId(long userId) {
		this.userId = userId;
	}

	@Column(name="topic_id")
	public long getTopicId() {
		return this.topicId;
	}

	public void setTopicId(long topicId) {
		this.topicId = topicId;
	}

} @Entity
@Table(name = "Comment")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Comment implements java.io.Serializable {

	private Long id;
	private Topic topic;
	private String content;
	private Date createTime;
	private int status;
	
	//comment_ad
	private CommentAd commentAd;

	private AcctUser acctuser;

	public Comment() {
	}

	public Comment(Topic topic, String content, Date createTime, int status) {
		this.topic = topic;
		this.content = content;
		this.createTime = createTime;
		this.status = status;
	}

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "topic_id")
	public Topic getTopic() {
		return this.topic;
	}

	public void setTopic(Topic topic) {
		this.topic = topic;
	}

	@Column(nullable=false)
	public String getContent() {
		return this.content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Column(name="create_time")
	public Date getCreateTime() {
		return this.createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}
	
	@Transient
	public String createTimeToString(){
		return createTime.toLocaleString();
	}
	
	//´¦Àí¹ýÊ±µÄtoLocaleString()
	@Transient
	public String createTimeToString2(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(createTime);
	}

	public int getStatus() {
		return this.status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "user_id", nullable = false)
	public AcctUser getAcctuser() {
		return acctuser;
	}

	public void setAcctuser(AcctUser acctuser) {
		this.acctuser = acctuser;
	}
	
	@OneToOne(fetch = FetchType.EAGER,mappedBy="comment")
	public CommentAd getCommentAd() {
		return commentAd;
	}

	public void setCommentAd(CommentAd commentAd) {
		this.commentAd = commentAd;
	}
} @Entity
@Table(name = "community_level")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class CommunityLevel implements java.io.Serializable {

	private Long id;
	private long experience;
	private int levels;
	private byte[] img;

	public CommunityLevel() {
	}

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name="experience")
	public long getExperience() {
		return this.experience;
	}

	public void setExperience(long experience) {
		this.experience = experience;
	}

	@Column(name="levels")
	public int getLevels() {
		return this.levels;
	}

	public void setLevels(int levels) {
		this.levels = levels;
	}

	@Lob 
	@Basic(fetch=FetchType.LAZY) 
	@Column(name="img", columnDefinition="BLOB", nullable=true)
	public byte[] getImg() {
		return img;
	}

	public void setImg(byte[] img) {
		this.img = img;
	}

} @Entity
//±íÃûÓëÀàÃû²»ÏàÍ¬Ê±ÖØÐÂ¶¨Òå±íÃû.
@Table(name = "node")
//Ä¬ÈÏµÄ»º´æ²ßÂÔ.
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Node implements java.io.Serializable {

	private Long id;
	private Section section;
	private String description;
	private Long topicCount;
	private String name;
	private int status;
	private Set<Topic> topics = new HashSet<Topic>(0);

	public Node() {
	}

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name="section_id")
	public Section getSection() {
		return this.section;
	}

	public void setSection(Section section) {
		this.section = section;
	}

	@Column(name="description")
	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	@Column(name="topic_count")
	public Long getTopicCount() {
		return this.topicCount;
	}

	public void setTopicCount(Long topicCount) {
		this.topicCount = topicCount;
	}

	@Column(name="name",nullable = false)
	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name="status")
	public int getStatus() {
		return this.status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	@OneToMany(mappedBy = "node")
	public Set<Topic> getTopics() {
		return topics;
	}

	public void setTopics(Set<Topic> topics) {
		this.topics = topics;
	}

} @Entity
@Table(name = "topic")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class Topic implements java.io.Serializable {

	private Long id;
	private Node node;
	private Long commentCount;
	private String content;
	private Date createTime;
	private Date lastCommentAt;
	private Long lastCommentUserId;
	private int status;
	private String title;
	private Date updateTime;
	private Long viewCount;
	private int isTop;
	//×÷Õß
	private AcctUser acctuser;
	//×îºó»Ø¸´
	private AcctUser lastacctuser;
	
	//topic_ad
	private Set<TopicAd> topicAd = new HashSet<TopicAd>(0);

	private Set<Comment> comments = new HashSet(0);

	public Topic() {
	}

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "node_id")
	public Node getNode() {
		return node;
	}

	public void setNode(Node node) {
		this.node = node;
	}

	@Column(name="comment_count")
	public Long getCommentCount() {
		return this.commentCount;
	}

	public void setCommentCount(Long commentCount) {
		this.commentCount = commentCount;
	}

	@Column(name="content",nullable = false)
	public String getContent() {
		return this.content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Column(name="create_time")
	public Date getCreateTime() {
		return this.createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name="last_comment_at")
	public Date getLastCommentAt() {
		return this.lastCommentAt;
	}

	public void setLastCommentAt(Date lastCommentAt) {
		this.lastCommentAt = lastCommentAt;
	}

	@Column(name="last_comment_user_id")
	public Long getLastCommentUserId() {
		return lastCommentUserId;
	}

	public void setLastCommentUserId(Long lastCommentUserId) {
		this.lastCommentUserId = lastCommentUserId;
	}

	public int getStatus() {
		return this.status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	@Column(nullable=false)
	public String getTitle() {
		return this.title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(name="update_time")
	public Date getUpdateTime() {
		return this.updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	@Column(name="view_count")
	public Long getViewCount() {
		return this.viewCount;
	}

	public void setViewCount(Long viewCount) {
		this.viewCount = viewCount;
	}

	@OneToMany(mappedBy = "topic")
	public Set<Comment> getComments() {
		return comments;
	}

	public void setComments(Set<Comment> comments) {
		this.comments = comments;
	}
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "user_id", nullable = false)
	public AcctUser getAcctuser() {
		return acctuser;
	}

	public void setAcctuser(AcctUser acctuser) {
		this.acctuser = acctuser;
	}
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "last_user_id")
	public AcctUser getLastacctuser() {
		return lastacctuser;
	}

	public void setLastacctuser(AcctUser lastacctuser) {
		this.lastacctuser = lastacctuser;
	}
	
	@OneToMany(mappedBy="topic",cascade = { CascadeType.PERSIST ,CascadeType.ALL})
	public Set<TopicAd> getTopicAd() {
		return topicAd;
	}

	public void setTopicAd(Set<TopicAd> topicAd) {
		this.topicAd = topicAd;
	}

	@Column(name="istop")
	public int getIsTop() {
		return isTop;
	}

	public void setIsTop(int isTop) {
		this.isTop = isTop;
	}

	@Transient
	public String titleFormat(){
		if(title.length()<=32){
			return title;
		}else{
			return title.substring(0,32).concat("...");
		}
	}
	
	@Transient
	public String createTimeToString(){
		return createTime.toLocaleString();
	}
	
	@Transient
	public String lastCommentAtToString(){
		return lastCommentAt.toLocaleString();
	}

	@Transient
	public String updateTimeToString(){
		return updateTime.toLocaleString();
	}
	
	//´¦Àí¹ýÊ±µÄtoLocaleString()
	@Transient
	public String createTimeToString2(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(createTime);
	}
	
	@Transient
	public String lastCommentAtToString2(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(lastCommentAt);
	}
	
	@Transient
	public String updateTimeToString2(){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		return sdf.format(updateTime);
	}

} @Entity
@Table(name = "topic_ad")
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class TopicAd implements java.io.Serializable {

	private Long id;
	//private long topicId;
	private long agreeCount;
	private long dsagreeCount;
	private Topic topic;

	public TopicAd() {
	}

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return this.id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name="agree_count")
	public long getAgreeCount() {
		return this.agreeCount;
	}

	public void setAgreeCount(long agreeCount) {
		this.agreeCount = agreeCount;
	}

	@Column(name="dsagree_count")
	public long getDsagreeCount() {
		return this.dsagreeCount;
	}

	public void setDsagreeCount(long dsagreeCount) {
		this.dsagreeCount = dsagreeCount;
	}
	
	@ManyToOne
	@JoinColumn(name="topic_id",unique=true)
	public Topic getTopic() {
		return topic;
	}

	public void setTopic(Topic topic) {
		this.topic = topic;
	}

} @Component
//Ä¬ÈÏ½«ÀàÖÐµÄËùÓÐº¯ÊýÄÉÈëÊÂÎñ¹ÜÀí.
@Transactional
public class AccountManager {
	
	private static Logger logger = LoggerFactory.getLogger(AccountManager.class);
	
	private UserDao userDao;
	private RoleDao roleDao;
	private UserInfoDao userInfoDao;
	
	@Transactional(readOnly = true)
	public AcctRole getRole(String name) {
		return roleDao.findUniqueBy("name", name);
	}

	@Transactional(readOnly = true)
	public AcctUser getUser(Long id) {
		return userDao.get(id);
	}
	
	@Transactional(readOnly = true)
	public int getUserRankBySql(Long id) {
		return userDao.getUserRankBySql(id);
	}
	
	public void saveUser(AcctUser entity) {
		userDao.save(entity);
	}
	
	public void saveUserInfo(AcctUserInfo entity) {
		userInfoDao.save(entity);
	}
	
	@Transactional(readOnly = true)
	public AcctUser getUserByEmail(String email){
		return userDao.findUniqueBy("email",email);
	}
	
	/**
	 * É¾³ýÓÃ»§,Èç¹û³¢ÊÔÉ¾³ý³¬¼¶¹ÜÀíÔ±½«Å×³öÒì³£.
	 */
	public void deleteUser(Long id) {
		if (isSupervisor(id)) {
			logger.warn("²Ù×÷Ô±{}³¢ÊÔÉ¾³ý³¬¼¶¹ÜÀíÔ±ÓÃ»§", SpringSecurityUtils.getCurrentUserName());
			try {
				throw new Exception();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		userDao.delete(id);
	}
	
	/**
	 * ÅÐ¶ÏÊÇ·ñ³¬¼¶¹ÜÀíÔ±.
	 */
	private boolean isSupervisor(Long id) {
		return id == 1;
	}
	
	/**
	 * Ê¹ÓÃÊôÐÔ¹ýÂËÌõ¼þ²éÑ¯ÓÃ»§.
	 */
	@Transactional(readOnly = true)
	public Page<AcctUser> searchUser(final Page<AcctUser> page, final List<PropertyFilter> filters) {
		return userDao.findPage(page, filters);
	}
	
	@Transactional(readOnly = true)
	public AcctUser findUserByLoginName(String loginName) {
		return userDao.findUniqueBy("loginName", loginName);
	}
	
	@Transactional(readOnly = true)
	public AcctUser findUserByUserNameAndEmail(String loginName,String email) {
		return userDao.findUserByUserNameAndEmail(loginName, email);
	}
	
	@Transactional(readOnly = true)
	public AcctUser findUserByUserNameAndPassword(String loginName,String password) {
		return userDao.findUserByUserNameAndPassword(loginName, password);
	}
	
	@Transactional(readOnly = true)
	public AcctUser findUserByLoginNameOrEmail(String loginName_email) {
		AcctUser acctUser=userDao.findUniqueBy("loginName", loginName_email);
		if(acctUser!=null){
			return acctUser;
		}else{
			acctUser=userDao.findUniqueBy("email", loginName_email);
		}
		return userDao.findUniqueBy("email", loginName_email);
	}
	
	//¸ù¾ÝId²éÕÒUser
	@Transactional(readOnly = true)
	public AcctUser findUserById(Long id) {
		return userDao.get(id);
	}

	//¸ù¾ÝId²éÕÒUserInfo
	@Transactional(readOnly = true)
	public AcctUserInfo findUserInfoById(Long id) {
		return userInfoDao.get(id);
	}

	public UserDao getUserDao() {
		return userDao;
	}

	@Autowired
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	
	public RoleDao getRoleDao() {
		return roleDao;
	}

	@Autowired
	public void setRoleDao(RoleDao roleDao) {
		this.roleDao = roleDao;
	}

	public UserInfoDao getUserInfoDao() {
		return userInfoDao;
	}

	@Autowired
	public void setUserInfoDao(UserInfoDao userInfoDao) {
		this.userInfoDao = userInfoDao;
	}

} @Component
//Ä¬ÈÏ½«ÀàÖÐµÄËùÓÐº¯ÊýÄÉÈëÊÂÎñ¹ÜÀí.
@Transactional
public class BbsManager {

	private static Logger logger = LoggerFactory.getLogger(BbsManager.class);
	
	private TopicDao topicDao;

	private NodeDao nodeDao;
	
	private CommentDao commentDao;
	
	private TopicAdDao topicAdDao;
	
	private CheckTopicAdDao checkTopicAdDao;
	
	private CommentAdDao commentAdDao;
	
	private CheckCommentAdDao checkCommentAdDao;
	
	private CommunityLevelDao communityLevelDao;
	
	private BadgeDao badgeDao;
	
	private BadgeShowDao badgeShowDao;

	// ·ÖÒ³²éÑ¯Ê×Ò³Ìû×Ó
	@Transactional(readOnly = true)
	public Page<Topic> getIndexTopics(final Page<Topic> page) {
		return topicDao.findPageTopic(page);
	}
	
	// ·ÖÒ³²éÑ¯×ÓÀàÌû×Ó new
	@Transactional(readOnly = true)
	public Page<Topic> getNodeTopics(final Page<Topic> page,Long nodeValue) {
		return topicDao.findPageNodeTopic(page,nodeValue);
	}
	
	//·ÖÒ³²éÑ¯»Ø¸´
	@Transactional(readOnly = true)
	public Page<Comment> getComments(final Page<Comment> page,List<PropertyFilter> filters) {
		return commentDao.findPage(page, filters).orderBy("id");
	}
	
	//¹ýÂË·µ»ØËùÓÐ»Ø¸´
	@Transactional(readOnly = true)
	public List<Comment> getAllCommentsByFitler(List<PropertyFilter> filters){
		return commentDao.find(filters);
	}
	
	public void deleteComment(Long id){
		commentDao.delete(id);
	}
	
	//ÓÐÐò²éÑ¯ËùÓÐµÈ¼¶
	@Transactional(readOnly = true)
	public List<CommunityLevel> getAllCommunityLevels() {
		return communityLevelDao.getAll("levels",true);
	}
	
	//²éÑ¯µÈ¼¶byId
	@Transactional(readOnly = true)
	public CommunityLevel getCommunityLevelById(Long id) {
		return communityLevelDao.get(id);
	}
	
	//²éÑ¯µÈ¼¶byLevel
	@Transactional(readOnly = true)
	public CommunityLevel getCommunityLevelByLevel(int level) {
		return communityLevelDao.findUniqueBy("levels", level);
	}
	
	//²éÑ¯»ÕÕÂ
	@Transactional(readOnly = true)
	public Badge getBadgeById(Long id) {
		return badgeDao.get(id);
	}
	
	//²éÑ¯ËùÓÐ»ÕÕÂ
	@Transactional(readOnly = true)
	public List<Badge> getAllBadges() {
		return badgeDao.getAll();
	}
	
	//Í¨¹ýUserIdºÍBadge²éÑ¯ÓÃ»§ÏÔÊ¾µÄ»ÕÕÂ
	@Transactional(readOnly = true)
	public BadgeShow getBadgeShowByUserIdAndBadgeId(Long userId,Long badgeId) {
		return badgeShowDao.findBadgeShowByUserIdAndBadgeId(userId,badgeId);
	}
	
	public void saveBadgeShow(BadgeShow badgeShow){
		badgeShowDao.save(badgeShow);
	}
	
	public void saveBadge(Badge badge){
		badgeDao.save(badge);
	}
	
	public void saveTopic(Topic topic){
		topicDao.save(topic);
	}
	
	public void deleteTopic(Long id){
		topicDao.delete(id);
	}
	
	public void saveTopicAd(TopicAd topicAd){
		topicAdDao.save(topicAd);
	}
	
	public void saveCommentAd(CommentAd commentAd){
		commentAdDao.save(commentAd);
	}
	
	public void deleteCommentAd(Long id){
		commentAdDao.delete(id);
	}
	
	public void saveComment(Comment comment){
		commentDao.save(comment);
	}
	
	public void saveCheckTopicAd(CheckTopicAd checkTopicAd){
		checkTopicAdDao.save(checkTopicAd);
	}
	
	public void saveCheckCommentAd(CheckCommentAd checkCommentAd){
		checkCommentAdDao.save(checkCommentAd);
	}
	
	public void deleteCheckCommentAd(Long id){
		checkCommentAdDao.delete(id);
	}
	
	@Transactional(readOnly = true)
	public Topic getTopic(Long topicId){
		return topicDao.get(topicId);
	}
	
	@Transactional(readOnly = true)
	public Comment getComment(Long commentId){
		return commentDao.get(commentId);
	}
	
	@Transactional(readOnly = true)
	public TopicAd getTopicAd(Long id){
		return topicAdDao.get(id);
	}
	
	@Transactional(readOnly = true)
	public TopicAd getTopicAdByTopicId(Long topicId){
		return topicAdDao.findUniqueBy("topic.id", topicId);
	}
	
	public void deleteTopicAd(Long id){
		topicAdDao.delete(id);
	}
	
	@Transactional(readOnly = true)
	public CommentAd getCommentAd(Long id){
		return commentAdDao.get(id);
	}
	
	@Transactional(readOnly = true)
	public CommentAd getCommentAdByCommentId(Long CommentId){
		return commentAdDao.findUniqueBy("comment.id", CommentId);
	}
	
	@Transactional(readOnly = true)
	public List<Node> findAllNodesByFitler(List<PropertyFilter> filters){
		return nodeDao.find(filters);
	}
	
	@Transactional(readOnly = true)
	public CheckTopicAd findCheckTopicAd(Long UserId,Long topicId){
		return checkTopicAdDao.getCheckTopicAd(UserId,topicId);
	}
	
	@Transactional(readOnly = true)
	public CheckTopicAd findCheckTopicAdByTopicId(Long topicId){
		return checkTopicAdDao.findUniqueBy("topicId", topicId);
	}
	
	@Transactional(readOnly = true)
	public List<CheckTopicAd> findCheckTopicAdsByTopicId(Long topicId){
		return checkTopicAdDao.findBy("topicId", topicId);
	}
	
	public void deleteCheckTopicAd(Long id){
		checkTopicAdDao.delete(id);
	}
	
	@Transactional(readOnly = true)
	public CheckCommentAd findCheckCommentAd(Long UserId,Long commentId){
		return checkCommentAdDao.getCheckCommentAd(UserId,commentId);
	}
	
	@Transactional(readOnly = true)
	public CheckCommentAd findCheckCommentAdByCommentId(Long commentId){
		return checkCommentAdDao.findUniqueBy("commentId", commentId);
	}
	
	@Transactional(readOnly = true)
	public List<CheckCommentAd> findCheckCommentAdsByCommentId(Long commentId){
		return checkCommentAdDao.findBy("commentId", commentId);
	}
	
	@Transactional(readOnly = true)
	public Node getNode(Long id){
		return nodeDao.get(id);
	}
	
	public TopicDao getTopicDao() {
		return topicDao;
	}
	
	@Autowired
	public void setTopicDao(TopicDao topicDao) {
		this.topicDao = topicDao;
	}
	
	public NodeDao getNodeDao() {
		return nodeDao;
	}

	@Autowired
	public void setNodeDao(NodeDao nodeDao) {
		this.nodeDao = nodeDao;
	}
	
	public CommentDao getCommentDao() {
		return commentDao;
	}

	@Autowired
	public void setCommentDao(CommentDao commentDao) {
		this.commentDao = commentDao;
	}
	
	public TopicAdDao getTopicAdDao() {
		return topicAdDao;
	}

	@Autowired
	public void setTopicAdDao(TopicAdDao topicAdDao) {
		this.topicAdDao = topicAdDao;
	}
	
	public CheckTopicAdDao getCheckTopicAdDao() {
		return checkTopicAdDao;
	}

	@Autowired
	public void setCheckTopicAdDao(CheckTopicAdDao checkTopicAdDao) {
		this.checkTopicAdDao = checkTopicAdDao;
	}

	public CommentAdDao getCommentAdDao() {
		return commentAdDao;
	}

	@Autowired
	public void setCommentAdDao(CommentAdDao commentAdDao) {
		this.commentAdDao = commentAdDao;
	}

	public CheckCommentAdDao getCheckCommentAdDao() {
		return checkCommentAdDao;
	}

	@Autowired
	public void setCheckCommentAdDao(CheckCommentAdDao checkCommentAdDao) {
		this.checkCommentAdDao = checkCommentAdDao;
	}

	public CommunityLevelDao getCommunityLevelDao() {
		return communityLevelDao;
	}

	@Autowired
	public void setCommunityLevelDao(CommunityLevelDao communityLevelDao) {
		this.communityLevelDao = communityLevelDao;
	}

	public BadgeDao getBadgeDao() {
		return badgeDao;
	}

	@Autowired
	public void setBadgeDao(BadgeDao badgeDao) {
		this.badgeDao = badgeDao;
	}

	public BadgeShowDao getBadgeShowDao() {
		return badgeShowDao;
	}

	@Autowired
	public void setBadgeShowDao(BadgeShowDao badgeShowDao) {
		this.badgeShowDao = badgeShowDao;
	}

} public class LevelUtil {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		try {
			CommunityLevel bbsLevel1=new CommunityLevel();
			bbsLevel1.setId(1L);
			bbsLevel1.setExperience(0L);
			
			CommunityLevel bbsLevel2=new CommunityLevel();
			bbsLevel2.setId(2L);
			bbsLevel2.setExperience(30L);
			
			CommunityLevel bbsLevel3=new CommunityLevel();
			bbsLevel3.setId(3L);
			bbsLevel3.setExperience(100L);
			
			CommunityLevel bbsLevel4=new CommunityLevel();
			bbsLevel4.setId(4L);
			bbsLevel4.setExperience(290L);
			
			CommunityLevel bbsLevel5=new CommunityLevel();
			bbsLevel5.setId(5L);
			bbsLevel5.setExperience(600L);
			
			CommunityLevel bbsLevel6=new CommunityLevel();
			bbsLevel6.setId(6L);
			bbsLevel6.setExperience(1050L);
			
			CommunityLevel bbsLevel7=new CommunityLevel();
			bbsLevel7.setId(7L);
			bbsLevel7.setExperience(1650L);
			
			CommunityLevel bbsLevel8=new CommunityLevel();
			bbsLevel8.setId(8L);
			bbsLevel8.setExperience(2650L);
			
			CommunityLevel bbsLevel9=new CommunityLevel();
			bbsLevel9.setId(9L);
			bbsLevel9.setExperience(7650L);
			
			ArrayList<CommunityLevel> list=new ArrayList<CommunityLevel>();
			list.add(bbsLevel1);
			list.add(bbsLevel2);
			list.add(bbsLevel3);
			list.add(bbsLevel4);
			list.add(bbsLevel5);
			list.add(bbsLevel6);
			list.add(bbsLevel7);
			list.add(bbsLevel8);
			list.add(bbsLevel9);
			
			
			getNewLevel(list,30L);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public static CommunityLevel getNewLevel(List<CommunityLevel> bbsLevels,long experience) throws Exception{
		if(bbsLevels.size()!=9){
			throw new Exception("Êý×é´«Èë´íÎó");
		}
		int index=0;
		CommunityLevel bbsLevelResult=null;
		
		long[] level=new long[9];
		int levelIndex=0;
		Iterator<CommunityLevel> it=bbsLevels.iterator();
		while(it.hasNext()){
			CommunityLevel temp=it.next();
			System.out.println("id="+temp.getId());
			level[levelIndex++]=temp.getExperience();
		}
		
		/*level[0]=0;
		level[1]=30;
		level[2]=100;
		level[3]=290;
		level[4]=600;
		level[5]=1050;
		level[6]=1650;
		level[7]=2650;
		level[8]=7650;*/
		
		//set ¼ì²â ¸ºÊýÐÞ¸ÄÎª0 ÕûÊý²»ÄÜ´ó¹ý9999
		
		display(level);
		
		if(experience<0){
			index=0;
			bbsLevelResult=bbsLevels.get(index++);
			System.out.println(bbsLevelResult.getId()+" "+bbsLevelResult.getExperience());
			return bbsLevelResult;
		}else if(experience==0){
			index=0;
			bbsLevelResult=bbsLevels.get(index++);
			System.out.println(bbsLevelResult.getId()+" "+bbsLevelResult.getExperience());
			return bbsLevelResult;
		}else{
			for(int i=0;i<level.length-1;i++){
				if(level[i]>=experience){
					index=i;
					break;
				}
			}
			
			if(index==0){
				index=level.length-1;
			}
			
			if(experience<level[index]){
				System.out.println("index="+(--index));
			}else if(experience==level[index]){
				System.out.println("index="+index);
			}else{
				System.out.println("index="+index);
			}
			
			bbsLevelResult=bbsLevels.get(index++);
			System.out.println(bbsLevelResult.getId()+" "+bbsLevelResult.getExperience());
			return bbsLevelResult;
		}

	}
	
	public static void display(long[] a){
		for(int i=0;i<a.length;i++){
			System.out.print(a[i]+" ");
		}
		System.out.println();
	}

} public class MyStringUtil {

	public static String strReplaces(String str, String... replaceStr) {

		if (str.indexOf("<code>") != 0) {
			if (replaceStr != null) {
				for (int i = 0; i < replaceStr.length; i++) {
					if (replaceStr[i].equals("<p>")) {
						str = str.replaceAll(replaceStr[i], "");
					}
					if (replaceStr[i].equals("</p>")) {
						str = str.replaceAll(replaceStr[i], "<br/>");
					}
					
					if (replaceStr[i].equals("<pre>")) {
						str = str.replaceAll(replaceStr[i], "");
					}
					
					if (replaceStr[i].equals("</pre>")) {
						str = str.replaceAll(replaceStr[i], "");
					}
					
					if (replaceStr[i].equals("<code>")) {
						str = str.replaceAll(replaceStr[i], "<code class=\"brush:java\" data-lang=\"java\"><br/>");
					}
					if (replaceStr[i].equals("<code class=\"lang-java\">")) {
						str = str.replaceAll(replaceStr[i], "<code class=\"brush:java\" data-lang=\"java\"><br/>");
					}
				}
				System.out.println(str);
			}
			return str;
		}

		return null;
	}
	
	//´¦Àí´æÈ¡ÉúÈÕ
	public static String[] getBirthdayYMD(String birthday){
		
		String[] birthdays=new String[3];
		
		birthdays=birthday.split("-");
		
		for(String s:birthdays){
			System.out.println(s);
		}
		
		return birthdays;
	}
	
	public static String getFullBirthday(String[] birthdays){
		
		String birthday="";
		
		for(String s:birthdays){
			birthday=birthday+s+"-";
		}
		
		birthday=birthday.substring(0, birthday.length()-1);

		System.out.println(birthday);
		
		return birthday;
	}
	
	//´¦Àí´æÈ¡µØÇø
		public static String[] getAddressSCQ(String address){
			
			String[] addresses=new String[3];
			
			addresses=address.split("-");
			
			for(String s:addresses){
				System.out.println(s);
			}
			
			return addresses;
		}

		public static String getFullAddress(String[] addresses){
			
			String address="";
			
			for(String s:addresses){
				address=address+s+"-";
			}
			
			address=address.substring(0, address.length()-1);

			System.out.println(address);
			
			return address;
		}
		
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//getBirthdayYMD("1987-3-11");
		getFullBirthday(null);
	}

}
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletResponse;
import javax.swing.plaf.synth.SynthSeparatorUI;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import cn.tiger.entity.account.AcctUser;
import cn.tiger.entity.account.UserDetails.MyUserDetails;
import cn.tiger.entity.bbs.Badge;
import cn.tiger.entity.bbs.BadgeShow;
import cn.tiger.entity.bbs.CheckTopicAd;
import cn.tiger.entity.bbs.Comment;
import cn.tiger.entity.bbs.CommunityLevel;
import cn.tiger.entity.bbs.Node;
import cn.tiger.entity.bbs.Topic;
import cn.tiger.entity.bbs.TopicAd;
import cn.tiger.service.account.AccountManager;
import cn.tiger.service.bbs.BbsManager;
import cn.tiger.utils.level.LevelUtil;
import cn.tiger.utils.zstring.MyStringUtil;
package cn.tiger.web.mypace.bbs;






@Namespace("/mypace/bbs")
@Results( { @Result(name = "index", location = "/WEB-INF/zz7/mypace/index.jsp", type = "dispatcher"),
	@Result(name = "nodeIndex", location = "/WEB-INF/zz7/mypace/bbs/nodeIndex.jsp", type = "dispatcher"),
	@Result(name = "createNewTopic", location = "/WEB-INF/zz7/mypace/bbs/createTopic.jsp", type = "dispatcher"),
	@Result(name = "login", location = "/WEB-INF/zz7/mypace/login.jsp", type = "dispatcher"),
	@Result(name = "save_ok", location = "topic.action", type = "redirect"),
	@Result(name = "showTopic", location = "/WEB-INF/zz7/mypace/bbs/showTopic.jsp", type = "dispatcher")

})
public class TopicAction extends ActionSupport{
	
	private BbsManager bbsManager;
	
	private AccountManager accountManager;
	
	private List<Node> nodes;
	
	private Topic topic;
	
	//²é¿´Ìû×ÓµÄId
	private Long viewTopicId;
	
	//ÔÞÓë²ÈµÄÌû×ÓId
	private Long adTopicId;
	
	//zan or cai
	private String zanOrcai;

	//Ñ¡ÔñµÄ½Úµã
	private String nodeValue;

	private Page<Topic> page = new Page<Topic>(9);
	
	private Page<Comment> commontPage = new Page<Comment>(9);
	
	//»ÕÕÂÏà¹Ø

	//Ñ¡Ôñ·ÖÀà
	public static final String SECTIONID="1";

	public String execute(){
		
		page=bbsManager.getIndexTopics(page);
	    
		List filters = new ArrayList();
		PropertyFilter filter = new PropertyFilter("EQL_section.id", SECTIONID);
        filters.add(filter);
        nodes = bbsManager.findAllNodesByFitler(filters);
		
		return "index";
	}
	
	//²é¿´Ìû×Ó
	public String showTopic(){
		
		topic=bbsManager.getTopic(viewTopicId);
		
		//showBadges
		Set<Badge> userBadges=topic.getAcctuser().getBadges();
		
		Iterator<Badge> it_user_badge=userBadges.iterator();
		
		//·¢ÌûÓÃ»§ÅÅ³ýÒþ²ØµÄÑ«ÕÂ
		while(it_user_badge.hasNext()){
			Badge badgeTemp=it_user_badge.next();
			BadgeShow badgeShowTemp=bbsManager.getBadgeShowByUserIdAndBadgeId(topic.getAcctuser().getId(), badgeTemp.getId());