Commit b70d223b authored by 刘文胜's avatar 刘文胜

封装了AbstractBaseServiceImpl 增删改查 分页等 不用写service

parent 76d3136d
package com.hdp.customerservice.model;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* (pi_customerservice_history)
*
* @author bianj
* @version 1.0.0 2015-06-17
*/
@Entity
@Table(name = "pi_customerservice_history")
public class HistoryEntity implements java.io.Serializable {
/** 版本号 */
private static final long serialVersionUID = 5661580036137274390L;
/** */
@Id
@Column(name = "id", unique = true, nullable = false, length = 19)
private Long id;
/** */
@Column(name = "ent_code", nullable = false, length = 10)
private Integer entCode;
/** */
@Column(name = "openid", nullable = false, length = 64)
private String openid;
/** */
@Column(name = "workid", nullable = false, length = 19)
private Long workid;
/** */
@Column(name = "content", nullable = true, length = 65535)
private String content;
/** */
@Column(name = "type", nullable = false, length = 10)
private Integer type;
/** */
@Column(name = "year", nullable = false, length = 10)
private Integer year;
/** */
@Column(name = "month", nullable = false, length = 10)
private Integer month;
/** */
@Column(name = "day", nullable = false, length = 10)
private Integer day;
/** */
@Column(name = "createat", nullable = false)
private Date createat;
/**
* 获取
*
* @return
*/
public Long getId() {
return this.id;
}
/**
* 设置
*
* @param id
*
*/
public void setId(Long id) {
this.id = id;
}
/**
* 获取
*
* @return
*/
public Integer getEntCode() {
return this.entCode;
}
/**
* 设置
*
* @param entCode
*
*/
public void setEntCode(Integer entCode) {
this.entCode = entCode;
}
/**
* 获取
*
* @return
*/
public String getOpenid() {
return this.openid;
}
/**
* 设置
*
* @param openid
*
*/
public void setOpenid(String openid) {
this.openid = openid;
}
/**
* 获取
*
* @return
*/
public Long getWorkid() {
return this.workid;
}
/**
* 设置
*
* @param workid
*
*/
public void setWorkid(Long workid) {
this.workid = workid;
}
/**
* 获取
*
* @return
*/
public String getContent() {
return this.content;
}
/**
* 设置
*
* @param content
*
*/
public void setContent(String content) {
this.content = content;
}
/**
* 获取
*
* @return
*/
public Integer getType() {
return this.type;
}
/**
* 设置
*
* @param type
*
*/
public void setType(Integer type) {
this.type = type;
}
/**
* 获取
*
* @return
*/
public Integer getYear() {
return this.year;
}
/**
* 设置
*
* @param year
*
*/
public void setYear(Integer year) {
this.year = year;
}
/**
* 获取
*
* @return
*/
public Integer getMonth() {
return this.month;
}
/**
* 设置
*
* @param month
*
*/
public void setMonth(Integer month) {
this.month = month;
}
/**
* 获取
*
* @return
*/
public Integer getDay() {
return this.day;
}
/**
* 设置
*
* @param day
*
*/
public void setDay(Integer day) {
this.day = day;
}
/**
* 获取
*
* @return
*/
public Date getCreateat() {
return this.createat;
}
/**
* 设置
*
* @param createat
*
*/
public void setCreateat(Date createat) {
this.createat = createat;
}
}
\ No newline at end of file
package com.hdp.customerservice.model;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* (pi_customerservice_member)
*
* @author bianj
* @version 1.0.0 2015-06-17
*/
@Entity
@Table(name = "pi_customerservice_member")
public class MemberEntity implements java.io.Serializable {
/** 版本号 */
private static final long serialVersionUID = 8542190028198354606L;
/** */
@Id
@Column(name = "id", unique = true, nullable = false, length = 19)
private Long id;
/** */
@Column(name = "appid", nullable = false, length = 128)
private String appid;
/** */
@Column(name = "ent_code", nullable = false, length = 10)
private Integer entCode;
/** */
@Column(name = "openid", nullable = false, length = 32)
private String openid;
/** */
@Column(name = "headimg", nullable = true, length = 512)
private String headimg;
/** */
@Column(name = "nickname", nullable = true, length = 128)
private String nickname;
/** */
@Column(name = "country", nullable = true, length = 64)
private String country;
/** */
@Column(name = "province", nullable = true, length = 64)
private String province;
/** */
@Column(name = "city", nullable = true, length = 64)
private String city;
/** */
@Column(name = "groupid", nullable = true, length = 10)
private Integer groupid;
/** */
@Column(name = "language", nullable = true, length = 32)
private String language;
/** */
@Column(name = "sex", nullable = true, length = 10)
private Integer sex;
/** */
@Column(name = "subscribe", nullable = true, length = 10)
private Integer subscribe;
/** */
@Column(name = "subscribe_time", nullable = true)
private Date subscribeTime;
/**
* 获取
*
* @return
*/
public Long getId() {
return this.id;
}
/**
* 设置
*
* @param id
*
*/
public void setId(Long id) {
this.id = id;
}
/**
* 获取
*
* @return
*/
public String getAppid() {
return this.appid;
}
/**
* 设置
*
* @param appid
*
*/
public void setAppid(String appid) {
this.appid = appid;
}
/**
* 获取
*
* @return
*/
public Integer getEntCode() {
return this.entCode;
}
/**
* 设置
*
* @param entCode
*
*/
public void setEntCode(Integer entCode) {
this.entCode = entCode;
}
/**
* 获取
*
* @return
*/
public String getOpenid() {
return this.openid;
}
/**
* 设置
*
* @param openid
*
*/
public void setOpenid(String openid) {
this.openid = openid;
}
/**
* 获取
*
* @return
*/
public String getHeadimg() {
return this.headimg;
}
/**
* 设置
*
* @param headimg
*
*/
public void setHeadimg(String headimg) {
this.headimg = headimg;
}
/**
* 获取
*
* @return
*/
public String getNickname() {
return this.nickname;
}
/**
* 设置
*
* @param nickname
*
*/
public void setNickname(String nickname) {
this.nickname = nickname;
}
/**
* 获取
*
* @return
*/
public String getCountry() {
return this.country;
}
/**
* 设置
*
* @param country
*
*/
public void setCountry(String country) {
this.country = country;
}
/**
* 获取
*
* @return
*/
public String getProvince() {
return this.province;
}
/**
* 设置
*
* @param province
*
*/
public void setProvince(String province) {
this.province = province;
}
/**
* 获取
*
* @return
*/
public String getCity() {
return this.city;
}
/**
* 设置
*
* @param city
*
*/
public void setCity(String city) {
this.city = city;
}
/**
* 获取
*
* @return
*/
public Integer getGroupid() {
return this.groupid;
}
/**
* 设置
*
* @param groupid
*
*/
public void setGroupid(Integer groupid) {
this.groupid = groupid;
}
/**
* 获取
*
* @return
*/
public String getLanguage() {
return this.language;
}
/**
* 设置
*
* @param language
*
*/
public void setLanguage(String language) {
this.language = language;
}
/**
* 获取
*
* @return
*/
public Integer getSex() {
return this.sex;
}
/**
* 设置
*
* @param sex
*
*/
public void setSex(Integer sex) {
this.sex = sex;
}
/**
* 获取
*
* @return
*/
public Integer getSubscribe() {
return this.subscribe;
}
/**
* 设置
*
* @param subscribe
*
*/
public void setSubscribe(Integer subscribe) {
this.subscribe = subscribe;
}
/**
* 获取
*
* @return
*/
public Date getSubscribeTime() {
return this.subscribeTime;
}
/**
* 设置
*
* @param subscribeTime
*
*/
public void setSubscribeTime(Date subscribeTime) {
this.subscribeTime = subscribeTime;
}
}
\ No newline at end of file
package com.hdp.customerservice.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* (pi_customerservice_member_tag)
*
* @author bianj
* @version 1.0.0 2015-06-17
*/
@Entity
@Table(name = "pi_customerservice_member_tag")
public class MemberTagEntity implements java.io.Serializable {
/** 版本号 */
private static final long serialVersionUID = -7307927505285788223L;
/** */
@Id
@Column(name = "id", unique = true, nullable = false, length = 19)
private Long id;
/** */
@Column(name = "ent_code", nullable = false, length = 10)
private Integer entCode;
/** */
@Column(name = "workid", nullable = false, length = 19)
private Long workid;
/** */
@Column(name = "mid", nullable = false, length = 19)
private Long mid;
/** */
@Column(name = "tag", nullable = false, length = 16)
private String tag;
/**
* 获取
*
* @return
*/
public Long getId() {
return this.id;
}
/**
* 设置
*
* @param id
*
*/
public void setId(Long id) {
this.id = id;
}
/**
* 获取
*
* @return
*/
public Integer getEntCode() {
return this.entCode;
}
/**
* 设置
*
* @param entCode
*
*/
public void setEntCode(Integer entCode) {
this.entCode = entCode;
}
/**
* 获取
*
* @return
*/
public Long getWorkid() {
return this.workid;
}
/**
* 设置
*
* @param workid
*
*/
public void setWorkid(Long workid) {
this.workid = workid;
}
/**
* 获取
*
* @return
*/
public Long getMid() {
return this.mid;
}
/**
* 设置
*
* @param mid
*
*/
public void setMid(Long mid) {
this.mid = mid;
}
/**
* 获取
*
* @return
*/
public String getTag() {
return this.tag;
}
/**
* 设置
*
* @param tag
*
*/
public void setTag(String tag) {
this.tag = tag;
}
}
\ No newline at end of file
package com.hdp.customerservice.model;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* (pi_customerservice_reception_history)
*
* @author bianj
* @version 1.0.0 2015-06-17
*/
@Entity
@Table(name = "pi_customerservice_reception_history")
public class ReceptionHistoryEntity implements java.io.Serializable {
/** 版本号 */
private static final long serialVersionUID = 5982802693241785248L;
/** */
@Id
@Column(name = "id", unique = true, nullable = false, length = 19)
private Long id;
/** */
@Column(name = "ent_code", nullable = false, length = 10)
private Integer entCode;
/** */
@Column(name = "workid", nullable = false, length = 19)
private Long workid;
/** */
@Column(name = "mid", nullable = false, length = 19)
private Long mid;
/** */
@Column(name = "year", nullable = false, length = 10)
private Integer year;
/** */
@Column(name = "month", nullable = false, length = 10)
private Integer month;
/** */
@Column(name = "day", nullable = false, length = 10)
private Integer day;
/** */
@Column(name = "createat", nullable = false)
private Date createat;
/**
* 获取
*
* @return
*/
public Long getId() {
return this.id;
}
/**
* 设置
*
* @param id
*
*/
public void setId(Long id) {
this.id = id;
}
/**
* 获取
*
* @return
*/
public Integer getEntCode() {
return this.entCode;
}
/**
* 设置
*
* @param entCode
*
*/
public void setEntCode(Integer entCode) {
this.entCode = entCode;
}
/**
* 获取
*
* @return
*/
public Long getWorkid() {
return this.workid;
}
/**
* 设置
*
* @param workid
*
*/
public void setWorkid(Long workid) {
this.workid = workid;
}
/**
* 获取
*
* @return
*/
public Long getMid() {
return this.mid;
}
/**
* 设置
*
* @param mid
*
*/
public void setMid(Long mid) {
this.mid = mid;
}
/**
* 获取
*
* @return
*/
public Integer getYear() {
return this.year;
}
/**
* 设置
*
* @param year
*
*/
public void setYear(Integer year) {
this.year = year;
}
/**
* 获取
*
* @return
*/
public Integer getMonth() {
return this.month;
}
/**
* 设置
*
* @param month
*
*/
public void setMonth(Integer month) {
this.month = month;
}
/**
* 获取
*
* @return
*/
public Integer getDay() {
return this.day;
}
/**
* 设置
*
* @param day
*
*/
public void setDay(Integer day) {
this.day = day;
}
/**
* 获取
*
* @return
*/
public Date getCreateat() {
return this.createat;
}
/**
* 设置
*
* @param createat
*
*/
public void setCreateat(Date createat) {
this.createat = createat;
}
}
\ No newline at end of file
package com.hdp.customerservice.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* (pi_customerservice_reception_setting)
*
* @author bianj
* @version 1.0.0 2015-06-17
*/
@Entity
@Table(name = "pi_customerservice_reception_setting")
public class ReceptionSettingEntity implements java.io.Serializable {
/** 版本号 */
private static final long serialVersionUID = 1243504005972485759L;
/** */
@Id
@Column(name = "id", unique = true, nullable = false, length = 19)
private Long id;
/** */
@Column(name = "ent_code", nullable = false, length = 10)
private Integer entCode;
/** */
@Column(name = "workid", nullable = false, length = 19)
private Long workid;
/** */
@Column(name = "mid", nullable = false, length = 19)
private Long mid;
/**
* 获取
*
* @return
*/
public Long getId() {
return this.id;
}
/**
* 设置
*
* @param id
*
*/
public void setId(Long id) {
this.id = id;
}
/**
* 获取
*
* @return
*/
public Integer getEntCode() {
return this.entCode;
}
/**
* 设置
*
* @param entCode
*
*/
public void setEntCode(Integer entCode) {
this.entCode = entCode;
}
/**
* 获取
*
* @return
*/
public Long getWorkid() {
return this.workid;
}
/**
* 设置
*
* @param workid
*
*/
public void setWorkid(Long workid) {
this.workid = workid;
}
/**
* 获取
*
* @return
*/
public Long getMid() {
return this.mid;
}
/**
* 设置
*
* @param mid
*
*/
public void setMid(Long mid) {
this.mid = mid;
}
}
\ No newline at end of file
package com.hdp.customerservice.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* (pi_customerservice_work_weight_setting)
*
* @author bianj
* @version 1.0.0 2015-06-17
*/
@Entity
@Table(name = "pi_customerservice_work_weight_setting")
public class WorkWeightSettingEntity implements java.io.Serializable {
/** 版本号 */
private static final long serialVersionUID = 3070612323274430771L;
/** */
@Id
@Column(name = "id", unique = true, nullable = false, length = 19)
private Long id;
/** */
@Column(name = "ent_code", nullable = false, length = 10)
private Integer entCode;
/** */
@Column(name = "workid", nullable = false, length = 19)
private Long workid;
/** */
@Column(name = "weight", nullable = false, length = 10)
private Integer weight;
/**
* 获取
*
* @return
*/
public Long getId() {
return this.id;
}
/**
* 设置
*
* @param id
*
*/
public void setId(Long id) {
this.id = id;
}
/**
* 获取
*
* @return
*/
public Integer getEntCode() {
return this.entCode;
}
/**
* 设置
*
* @param entCode
*
*/
public void setEntCode(Integer entCode) {
this.entCode = entCode;
}
/**
* 获取
*
* @return
*/
public Long getWorkid() {
return this.workid;
}
/**
* 设置
*
* @param workid
*
*/
public void setWorkid(Long workid) {
this.workid = workid;
}
/**
* 获取
*
* @return
*/
public Integer getWeight() {
return this.weight;
}
/**
* 设置
*
* @param weight
*
*/
public void setWeight(Integer weight) {
this.weight = weight;
}
}
\ No newline at end of file
package com.hdp.customerservice.model;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
/**
* (pi_customerservice_works)
*
* @author bianj
* @version 1.0.0 2015-06-17
*/
@Entity
@Table(name = "pi_customerservice_works")
public class WorksEntity implements java.io.Serializable {
/** 版本号 */
private static final long serialVersionUID = 2024136148468682445L;
/** */
@Id
@Column(name = "id", unique = true, nullable = false, length = 19)
private Long id;
/** */
@Column(name = "ent_code", nullable = false, length = 10)
private Integer entCode;
/** */
@Column(name = "username", nullable = false, length = 128)
private String username;
/** */
@Column(name = "pwd", nullable = false, length = 128)
private String pwd;
/** */
@Column(name = "nickname", nullable = true, length = 128)
private String nickname;
/** */
@Column(name = "headimg", nullable = true, length = 512)
private String headimg;
/** */
@Column(name = "status", nullable = false, length = 10)
private Integer status;
/**
* 获取
*
* @return
*/
public Long getId() {
return this.id;
}
/**
* 设置
*
* @param id
*
*/
public void setId(Long id) {
this.id = id;
}
/**
* 获取
*
* @return
*/
public Integer getEntCode() {
return this.entCode;
}
/**
* 设置
*
* @param entCode
*
*/
public void setEntCode(Integer entCode) {
this.entCode = entCode;
}
/**
* 获取
*
* @return
*/
public String getUsername() {
return this.username;
}
/**
* 设置
*
* @param username
*
*/
public void setUsername(String username) {
this.username = username;
}
/**
* 获取
*
* @return
*/
public String getPwd() {
return this.pwd;
}
/**
* 设置
*
* @param pwd
*
*/
public void setPwd(String pwd) {
this.pwd = pwd;
}
/**
* 获取
*
* @return
*/
public String getNickname() {
return this.nickname;
}
/**
* 设置
*
* @param nickname
*
*/
public void setNickname(String nickname) {
this.nickname = nickname;
}
/**
* 获取
*
* @return
*/
public String getHeadimg() {
return this.headimg;
}
/**
* 设置
*
* @param headimg
*
*/
public void setHeadimg(String headimg) {
this.headimg = headimg;
}
/**
* 获取
*
* @return
*/
public Integer getStatus() {
return this.status;
}
/**
* 设置
*
* @param status
*
*/
public void setStatus(Integer status) {
this.status = status;
}
}
\ No newline at end of file
/**
* @Title: BaseRepository.java
* @Package com.hdp.customerservice.repository
* @Description: TODO
* @author new12304508_163_com
* @date 2015年6月17日 下午2:12:56
* @version V1.0
*/
package com.hdp.customerservice.repository;
import java.io.Serializable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.stereotype.Repository;
@NoRepositoryBean
public interface BaseRepository <E, PK extends Serializable> extends JpaRepository<E, PK>,JpaSpecificationExecutor<E>{
}
/**
* @Title: SurveyTopicRepository.java
* @Package com.hdp.pi.repository
* @Description: TODO
* @author new12304508_163_com
* @date 2015年5月27日 下午2:42:35
* @version V1.0
*/
package com.hdp.customerservice.repository;
import org.springframework.stereotype.Repository;
import com.hdp.customerservice.model.MemberEntity;
@Repository
public interface MemberRepository extends BaseRepository<MemberEntity, Long>{
}
/**
* @Title: AbstractBaseServiceImpl.java
* @Package com.hdp.customerservice.service
* @Description: TODO
* @author new12304508_163_com
* @date 2015年6月17日 下午2:07:07
* @version V1.0
*/
package com.hdp.customerservice.service;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.mockito.internal.util.collections.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import com.hdp.customerservice.repository.BaseRepository;
public abstract class AbstractBaseServiceImpl<E, PK extends Serializable> implements BaseService<E, PK> {
protected BaseRepository<E, PK> repository;
@Override
public E get(PK id) {
return repository.findOne(id);
}
@Override
public List<E> getAllList() {
return repository.findAll();
}
@Override
public Long getTotalCount() {
return repository.count();
}
@Override
public E save(E entity) {
return repository.save(entity);
}
@Override
public E update(E entity) {
return repository.save(entity);
}
@Override
public E saveOrUpdate(E entity) {
return repository.save(entity);
}
@Override
public boolean existById(PK id) {
return repository.exists(id);
}
@Override
public void delete(PK id) {
repository.delete(id);
}
@Override
public void deleteByIds(List<PK> ids) {
repository.delete(repository.findAll(ids));
}
@Override
public Page<E> findPage(int page, int size) {
return findPage(page, size, null, null);
}
@Override
public Page<E> findPage(int page, int size,Sort sort) {
return findPage(page, size, sort);
}
@Override
public Page<E> findPage(int page, int size,Specification<E> spec) {
return findPage(page, size, spec);
}
@Override
public Page<E> findPage(int page, int size,Sort sort,Specification<E> spec) {
PageRequest pageRequest = null;
if(sort != null){
pageRequest = new PageRequest(page-1, size, sort);
}else{
pageRequest = new PageRequest(page-1, size);
}
if(spec != null){
return repository.findAll(spec, pageRequest);
}
return repository.findAll(pageRequest);
}
}
/**
* @Title: BaseService.java
* @Package com.hdp.customerservice.service
* @Description: TODO
* @author new12304508_163_com
* @date 2015年6月17日 下午1:56:36
* @version V1.0
*/
package com.hdp.customerservice.service;
import java.io.Serializable;
import java.util.List;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
public interface BaseService <E, PK extends Serializable> {
/**
* 根据id获取对象
* @param id
* @return Entity
*/
public E get(PK id);
/**
* 取得所有Entity
* @return List<E>
*/
public List<E> getAllList();
/**
* 取得对象总数量
* @return
* @throws DataAccessException
*/
public Long getTotalCount();
/**
* 新增Entity
* @param entity
*/
public E save(E entity);
/**
* 保存修改Entity
* @param entity
*/
public E update(E entity);
/**
* 新增或者保存修改Entity
* @param entity
*/
public E saveOrUpdate(E entity);
/**
* 根据属性值判断对象是否存在
* @param entity
* @return 存在-true, 不存在-false
*/
public boolean existById(PK id);
/**
* 根据id删除对象
* @param id
* @throws DataAccessException
*/
public void delete(PK id);
/**
* 根据多个id删除
* @param ids
* @throws DataAccessException
*/
public void deleteByIds(List<PK> ids);
public Page<E> findPage(int page, int size);
public Page<E> findPage(int page, int size,Specification<E> spec);
public Page<E> findPage(int page, int size,Sort sort);
public Page<E> findPage(int page, int size,Sort sort,Specification<E> spec);
}
/**
* @Title: MemberService.java
* @Package com.hdp.customerservice.service
* @Description: TODO
* @author new12304508_163_com
* @date 2015年6月17日 下午1:45:31
* @version V1.0
*/
package com.hdp.customerservice.service;
import com.hdp.customerservice.model.MemberEntity;
public interface MemberService extends BaseService<MemberEntity, Long>{
}
/**
* @Title: MemberServiceImpl.java
* @Package com.hdp.customerservice.service
* @Description: TODO
* @author new12304508_163_com
* @date 2015年6月17日 下午1:46:27
* @version V1.0
*/
package com.hdp.customerservice.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.hdp.customerservice.model.MemberEntity;
import com.hdp.customerservice.repository.MemberRepository;
@Service
@Transactional(readOnly = true)
public class MemberServiceImpl extends AbstractBaseServiceImpl<MemberEntity, Long> implements MemberService{
@Autowired
public void setUserRepository(MemberRepository memberRepository) {
super.repository=memberRepository;
}
}
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