|
@ -0,0 +1,228 @@
|
|
|
|
package com.yihu.wlyy.service.manager.user;
|
|
|
|
|
|
|
|
import com.yihu.wlyy.entity.*;
|
|
|
|
import com.yihu.wlyy.repository.*;
|
|
|
|
import com.yihu.wlyy.util.Envelop;
|
|
|
|
import com.yihu.wlyy.util.MD5;
|
|
|
|
import com.yihu.wlyy.util.query.BaseJpaService;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
import org.springframework.data.domain.PageImpl;
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
|
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import javax.persistence.criteria.CriteriaBuilder;
|
|
|
|
import javax.persistence.criteria.CriteriaQuery;
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
|
|
import javax.persistence.criteria.Root;
|
|
|
|
import java.util.*;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Created by Reece on 2018/1/16.
|
|
|
|
*/
|
|
|
|
@Service
|
|
|
|
public class ManageRangeService extends BaseJpaService<Doctor, DoctorDao> {
|
|
|
|
@Autowired
|
|
|
|
private WlyyUserRoleDao userRoleDao;
|
|
|
|
@Autowired
|
|
|
|
private DoctorDao doctorDao;
|
|
|
|
@Autowired
|
|
|
|
private WlyyRoleDao roleDao;
|
|
|
|
@Autowired
|
|
|
|
private JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wlyy_user_role 列表展示及页面搜索医生信息
|
|
|
|
*
|
|
|
|
* @param name
|
|
|
|
* @param idcard
|
|
|
|
* @param page
|
|
|
|
* @param pageSize
|
|
|
|
* @return
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public List<Doctor> searchList(String name, String idcard, Integer page, Integer pageSize) throws Exception {
|
|
|
|
if (page == null) {
|
|
|
|
page = 1;
|
|
|
|
}
|
|
|
|
if (page == null) {
|
|
|
|
pageSize = 15;
|
|
|
|
}
|
|
|
|
// 展示状态排序
|
|
|
|
Sort sort = new Sort(Sort.Direction.ASC, "id");
|
|
|
|
PageRequest pageRequest = new PageRequest(page - 1, pageSize, sort);
|
|
|
|
List<Doctor> userList = null;
|
|
|
|
|
|
|
|
/*if (StringUtils.isNotEmpty(name) && StringUtils.isNotEmpty(idcard)) {
|
|
|
|
userList = doctorDao.findByFilter(name, idcard, pageRequest);
|
|
|
|
} else if (StringUtils.isEmpty(name) && StringUtils.isNotEmpty(idcard)) {
|
|
|
|
userList = doctorDao.findByIdcard(idcard, pageRequest);
|
|
|
|
} else if (StringUtils.isNotEmpty(name) && StringUtils.isEmpty(idcard)) {
|
|
|
|
userList = doctorDao.findByName(name, pageRequest);
|
|
|
|
} else {
|
|
|
|
userList = doctorDao.findByFilterAll(pageRequest);
|
|
|
|
}*/
|
|
|
|
String sql = "SELECT p.code,p.name,p.sex,p.idCard,p.mobile,ro.code hospital,ro.name hospitalName " +
|
|
|
|
" FROM wlyy_doctor p, wlyy_user_role r, wlyy_role ro " +
|
|
|
|
" WHERE r.user = p.code AND r.role = ro.code AND p.status = 1 ";
|
|
|
|
if (StringUtils.isNotEmpty(name) && StringUtils.isNotEmpty(idcard)) {
|
|
|
|
sql += " AND p.name = " + name + " AND p.idcard = " + idcard;
|
|
|
|
} else if (StringUtils.isEmpty(name) && StringUtils.isNotEmpty(idcard)) {
|
|
|
|
sql += " AND p.idcard = " + idcard;;
|
|
|
|
} else if (StringUtils.isNotEmpty(name) && StringUtils.isEmpty(idcard)) {
|
|
|
|
sql += " AND p.name = " + name;
|
|
|
|
}
|
|
|
|
sql += " ORDER BY p.id ASC limit "+ (page-1) +"," +pageSize;
|
|
|
|
userList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(Doctor.class));
|
|
|
|
|
|
|
|
return userList;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wlyy_user_role 列表展示及页面搜索医生信息
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public List<Doctor> searchList(String name, String idcard) throws Exception {
|
|
|
|
|
|
|
|
List<Doctor> userList = null;
|
|
|
|
|
|
|
|
String sql = "SELECT p.code,p.name,p.sex,p.idcard,p.mobile,ro.code hospital,ro.name hospitalName " +
|
|
|
|
" FROM wlyy_doctor p, wlyy_user_role r, wlyy_role ro " +
|
|
|
|
" WHERE r.user = p.code AND r.role = ro.code AND p.status = 1 ";
|
|
|
|
if (StringUtils.isNotEmpty(name) && StringUtils.isNotEmpty(idcard)) {
|
|
|
|
sql += " AND p.name = " + name + " AND p.idcard = " + idcard;
|
|
|
|
} else if (StringUtils.isEmpty(name) && StringUtils.isNotEmpty(idcard)) {
|
|
|
|
sql += " AND p.idcard = " + idcard;;
|
|
|
|
} else if (StringUtils.isNotEmpty(name) && StringUtils.isEmpty(idcard)) {
|
|
|
|
sql += " AND p.name = " + name;
|
|
|
|
}
|
|
|
|
sql += " ORDER BY p.id ASC ";
|
|
|
|
userList = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(Doctor.class));
|
|
|
|
|
|
|
|
return userList;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 查询所有的医院信息
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public List<WlyyRole> getHostpitalList() throws Exception {
|
|
|
|
// 展示状态排序
|
|
|
|
List<WlyyRole> roleList = roleDao.findAll();
|
|
|
|
return roleList;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* wlyy_user_role 列表展示及页面搜索医生信息
|
|
|
|
* @return
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public List<Doctor> getDoctorList(String name, String idcard) throws Exception {
|
|
|
|
// 展示状态排序
|
|
|
|
List<Doctor> userList = null;
|
|
|
|
|
|
|
|
if (StringUtils.isNotEmpty(name) && StringUtils.isNotEmpty(idcard)) {
|
|
|
|
userList = doctorDao.findDoctorByFilter(name, idcard);
|
|
|
|
} else if (StringUtils.isEmpty(name) && StringUtils.isNotEmpty(idcard)) {
|
|
|
|
userList = doctorDao.findDoctorByIdcard(idcard);
|
|
|
|
} else if (StringUtils.isNotEmpty(name) && StringUtils.isEmpty(idcard)) {
|
|
|
|
userList = doctorDao.findDoctorByName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return userList;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 用户删除
|
|
|
|
* @param doc
|
|
|
|
* @param hospital
|
|
|
|
* @return
|
|
|
|
* @throws Exception
|
|
|
|
*/
|
|
|
|
public boolean deleteUserRole(String doc,String hospital) throws Exception {
|
|
|
|
Boolean flag = false;
|
|
|
|
try {
|
|
|
|
WlyyUserRole role = userRoleDao.findByUserAndRole(doc,hospital);
|
|
|
|
userRoleDao.delete(role);
|
|
|
|
flag = true;
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
//保存先判断wlyy_role是否存在在新增
|
|
|
|
public int saveUserRole(String doc, String hospital) throws Exception {
|
|
|
|
int flag = 200;
|
|
|
|
try {
|
|
|
|
Doctor doctor = doctorDao.findByCode(doc);
|
|
|
|
if (doctor != null) {
|
|
|
|
WlyyUserRole wlyyUserRole = userRoleDao.findByUserAndRole(doc, hospital);
|
|
|
|
if (wlyyUserRole == null) {
|
|
|
|
WlyyUserRole userRole = new WlyyUserRole();
|
|
|
|
userRole.setUser(doc);
|
|
|
|
userRole.setRole(hospital);
|
|
|
|
userRole.setCzrq(new Date());
|
|
|
|
userRole.setCzy("1");
|
|
|
|
userRoleDao.save(userRole);
|
|
|
|
} else {
|
|
|
|
flag = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
flag = -2;
|
|
|
|
}
|
|
|
|
return flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 列表页查询医生详情
|
|
|
|
*
|
|
|
|
* @param doc
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public List<Doctor> getUser(String doc,String hospital) throws Exception{
|
|
|
|
List<Doctor> doctor = null;
|
|
|
|
try {
|
|
|
|
String sql = "SELECT p.code,p.name,p.sex,p.idcard,p.mobile,ro.code hospital,ro.name hospitalName " +
|
|
|
|
" FROM wlyy_doctor p, wlyy_user_role r, wlyy_role ro " +
|
|
|
|
" WHERE r.user = p.code AND r.role = ro.code AND p.status = 1 " +
|
|
|
|
" and r.user = "+ doc +" and ro.code = "+ hospital;
|
|
|
|
doctor = jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(Doctor.class));
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
return doctor;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 编辑医生相关信息
|
|
|
|
*
|
|
|
|
* @param doc 编辑医生code(批量添加逗号分隔)
|
|
|
|
* @param oldHospital 修改前的医生权限code
|
|
|
|
* @param hospital 修改后的医生权限code
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public void updateUserRole(String doc, String oldHospital, String hospital) throws Exception {
|
|
|
|
try {
|
|
|
|
WlyyUserRole userRole = userRoleDao.findByUserAndRole(doc,oldHospital);
|
|
|
|
userRole.setRole(hospital);
|
|
|
|
userRoleDao.save(userRole);
|
|
|
|
} catch (Exception e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|