@Autowired
private ComplaintMapper complaintMapper;
//注入service
@Autowired
private PersonnelServiceImpl personnelService;
//分页搜索总记录数
//下面这个是注解切换数据源的方式,如果你发现切换没有效果那你把你的事务给拿掉吧
@DataSource(value = "druid")
@Override
public RestResult selectComplaint(Map params) throws Exception {
//查询的条件,我有点冗余,你们可以不要按照我这样写
Integer pageNum = Integer.valueOf(String.valueOf(params.get("pageNum")));
Integer pagesize = Integer.valueOf(String.valueOf(params.get("pagesize")));
String keyword = String.valueOf(params.get("keyword"));
String startTime = String.valueOf(params.get("startTime"));
String endTime = String.valueOf(params.get("endTime"));
Integer status = Integer.valueOf(String.valueOf(params.get("status")));
Integer channels = Integer.valueOf(String.valueOf(params.get("channel")));
String frequency = String.valueOf(params.get("frequency"));
String TScustomer = String.valueOf(params.get("TScustomer"));
Integer TechnologyRecruitmentID =Integer.valueOf(String.valueOf(params.get("TechnologyRecruitmentID")));
Integer PersonnelID = Integer.valueOf(String.valueOf(params.get("PersonnelID")));
Integer TeamID = Integer.valueOf(String.valueOf(params.get("TeamID")));
String TeamName = String.valueOf(params.get("TeamName"));
if (pagesize>=10){
pagesize = 10;
}if (pageNum == 1){
pageNum = 0;
}else {
pageNum=(pageNum-1)*pagesize;
}
params.put("pageNum",pageNum);
params.put("pageSize",pagesize);
params.put("keyword",keyword);
params.put("status",status);
if (Strings.isEmpty(startTime)){
params.put("startTime",startTime);
}
if (Strings.isEmpty(endTime)) {
params.put("endTime", endTime);
}
if (channels !=-1){
params.put("channels",channels);
}
if (frequency.isEmpty()) {
params.put("frequencys", frequency);
}
if (Strings.isEmpty(TScustomer)){
params.put("TScustomer",TScustomer);
}
if (Strings.isEmpty(TeamName)){
params.put("TeamName",TeamName);
}
if (TeamID !=-1){
params.put("TeamID",TeamID);
}
if (TechnologyRecruitmentID != -1){
params.put("TechnologyRecruitmentID",TechnologyRecruitmentID);
}
if (PersonnelID != -1 ){
params.put("PersonnelID",PersonnelID);
}
//调用dao层
List list = complaintMapper.selectComplaintList(params);
List result = new ArrayList<>();
for (ComplaintVo vo:list){
String wangwangnum = vo.getWangwangnum();
params.put("wangwangnum",wangwangnum);
ComplaintVo complaintVos = personnelService.selectComplaintListOver(params);
ComplaintVo complaintVo = new ComplaintVo();
complaintVo.setScenerestoration(vo.getScenerestoration());
complaintVo.setStatus(vo.getStatus());
complaintVo.setCreateTime(vo.getCreateTime());
complaintVo.setId(vo.getId());
complaintVo.setChannel(vo.getChannel());
complaintVo.setComplaintdate(vo.getComplaintdate());
complaintVo.setDepartment(vo.getDepartment());
complaintVo.setWorktype(vo.getWorktype());
complaintVo.setRemarks(vo.getRemarks());
complaintVo.setPkId(vo.getPkId());
complaintVo.setIsStop(vo.getIsStop());
complaintVo.setIsDelete(vo.getIsDelete());
complaintVo.setFrequency(vo.getFrequency());
complaintVo.setContent(vo.getContent());
complaintVo.setWangwangnum(vo.getWangwangnum());
//判断第二个接口是否有数据,有数据则set进去没有就不执行
if (complaintVos !=null) {
complaintVo.setTechnologyrecruitmentid(complaintVos.getTechnologyrecruitmentid());
complaintVo.setShopptype(complaintVos.getShopptype());
complaintVo.setPersonnelid(complaintVos.getPersonnelid());
complaintVo.setTscustomer(complaintVos.getTscustomer());
complaintVo.setTeamid(complaintVos.getTeamid());
complaintVo.setTeamname(complaintVos.getTeamname());
complaintVo.setUsername(complaintVos.getUsername());
complaintVo.setPname(complaintVos.getPname());
complaintVo.setTename(complaintVos.getTename());
result.add(complaintVo);
}
}
//总数量
Integer total = complaintMapper.selectComplaintCount(params);
Map map = new HashMap();
map.put("list",result);
map.put("total",total);
return new RestResultBuilder().setCode(0).setMsg("请求成功").setData(map).build();
}
我这是sqlserver的查询!sqlserver好像不支持动态查询,我这是mybatis,是支持的!为了避免不采坑,我建议动态查询的条件你们全部写成字段名!
//切换数据源,这个接口的数据全是从sqlserver出来的,至于怎么切换数据源,看我另外的博客吧!
@DataSource(value = "slave1")
@Override
public ComplaintVo selectComplaintListOver(Map map) {
return personnelMapper.selectComplaintListOver(map);
}
代码就这样,不明白的联系博主simon