packagecom.payease.scfordermis.service.impl;importcom.payease.scfordermis.bo.ResultBo;importcom.payease.scfordermis.bo.requestBo.ReqEmpAccNumBean;importcom.payease.scfordermis.bo.responseBo.PageResponseCommBean;importcom.payease.scfordermis.bo.responseBo.RespEmpAccNumBean;importcom.payease.scfordermis.dao.DepartmentInfoDao;importcom.payease.scfordermis.dao.EmployeeInfoDao;importcom.payease.scfordermis.entity.TDepartmentInfoEntity;importcom.payease.scfordermis.entity.TEmployeeInfoEntity;importcom.payease.scfordermis.service.EmpAccNumService;importcom.payease.scfordermis.utils.MapUtil;importorg.apache.commons.lang.StringUtils;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.data.domain.Page;importorg.springframework.data.domain.PageRequest;importorg.springframework.data.domain.Pageable;importorg.springframework.data.domain.Sort;importorg.springframework.data.jpa.domain.Specification;importorg.springframework.stereotype.Service;importjavax.persistence.criteria.CriteriaBuilder;importjavax.persistence.criteria.CriteriaQuery;importjavax.persistence.criteria.Predicate;importjavax.persistence.criteria.Root;importjava.util.ArrayList;importjava.util.List;importjava.util.Map;/*** @Created By liuxiaoming
* @CreateTime 2018/1/15 下午1:55
**/@Servicepublic class EmpAccNumServiceImpl implementsEmpAccNumService {
@Autowired
EmployeeInfoDao employeeInfoDao;
@Autowired
DepartmentInfoDao departmentInfoDao;/*** 员工列表查询
*@param*@return
*/@OverridepublicResultBo getEmpAccNumList(ReqEmpAccNumBean req) {
ResultBo result=ResultBo.build();//入参
/*** json.put("depParentId",depParentId);
json.put("departmentId", departmentId);
json.put("other", other);
json.put("page",super.page);
json.put("size",super.size);*/Map map1 =req.getMap();
MapUtil map= newMapUtil(map1);//todo
Page page = this.pageTEmp(map);//todo
PageResponseCommBean resp =this.pageToResp(page);
System.out.println("=========resp.getTotalPages():"+resp.getTotalPages());
System.out.println("=========resp.getTotalElements():"+resp.getTotalElements());
System.out.println("=========resp.getContent():"+resp.getContent());//======================================================
result.setResultBody(resp);returnresult;
}/*** 从数据库中查询数据
*@parammap
*@return
*/
public PagepageTEmp(MapUtil map){
Integer depParentId= map.getInteger("depParentId");
Integer departmentId= map.getInteger("departmentId");
String other= map.getString("other");//分页 当前页 每页显示条数 按照字段排序
Pageable pageable = new PageRequest(map.getInteger("page") - 1, map.getInteger("size"), new Sort(Sort.Direction.DESC, "fId"));
Page page =employeeInfoDao.findAll(new Specification() {public Predicate toPredicate(Rootroot,
CriteriaQuery>query, CriteriaBuilder cb) {
List lstPredicates = new ArrayList();//部门-1 全查//部门非-1//看 父ID 0 根节点//子节点
if (departmentId != 0){if(departmentId != -1){if(depParentId == 0) {//映射实体类字段 请求入参字段
lstPredicates.add(cb.equal(root.get("fDepartIdOne").as(Integer.class), departmentId));
}else{
lstPredicates.add(cb.equal(root.get("fDepartIdTwo").as(Integer.class), departmentId));
}
}
}if(StringUtils.isNotBlank(other)) {
lstPredicates.add(cb.like(root.get("fSearchKey").as(String.class), "%"+ other +"%"));
}
lstPredicates.add(cb.notEqual(root.get("fIsDelete").as(String.class), "yes"));
Predicate[] arrayPredicates= newPredicate[lstPredicates.size()];returncb.and(lstPredicates.toArray(arrayPredicates));
}
}, pageable);returnpage;
}public PageResponseCommBean pageToResp(Pagepage){
List list =page.getContent();
PageResponseCommBean bean= newPageResponseCommBean();
List respList = new ArrayList<>();for(TEmployeeInfoEntity entity : list){
RespEmpAccNumBean resp= newRespEmpAccNumBean();
resp.setfId(entity.getfId());if(StringUtils.isNotBlank(String.valueOf(entity.getfAccount()))){
resp.setfAccount(entity.getfAccount());
}if(StringUtils.isNotBlank(String.valueOf(entity.getfName()))){
resp.setfName(entity.getfName());
}if(StringUtils.isNotBlank(String.valueOf(entity.getfPosition()))){
resp.setfPosition(entity.getfPosition());
}if(StringUtils.isNotBlank(String.valueOf(entity.getfDepartIdTwo()))){
TDepartmentInfoEntity one=departmentInfoDao.findOne(entity.getfDepartIdTwo());if(one == null){
resp.setfDepartIdTwo("");
}else{
resp.setfDepartIdTwo(one.getfName());
}
}if(StringUtils.isNotBlank(entity.getfMobile())){
resp.setfMobile(entity.getfMobile());
}if(StringUtils.isNotBlank(entity.getfEmail())){
resp.setfEmail(entity.getfEmail());
}if(StringUtils.isNotBlank(entity.getfStatus())){
resp.setfStatus(entity.getfStatus());
}
respList.add(resp);
}
bean.setContent(respList);
bean.setNumber(page.getNumber());
bean.setSize(page.getSize());
bean.setTotalElements(Integer.valueOf(String.valueOf(page.getTotalElements())));
bean.setTotalPages(page.getTotalPages());returnbean;
}//public Boolean cheackMap(Map map) {//boolean bo = true;//Iterator> it = map.entrySet().iterator();//while (it.hasNext()) {//Map.Entry entry = it.next();//System.out.println("key= " + entry.getKey() + " and value= " + entry.getValue());//if(map.get(entry.getKey())==null){//return false;//}//}//return true;//}
}