Commit 8a279a61 by wangli

新增获取技术与基础信息列表接口

1 parent dc020f0b
package com.alibaba.cloud.integration.order.controller;
import com.alibaba.cloud.integration.common.BusinessException;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.service.EngineerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class EngineerController {
@Autowired
private EngineerService engineerService;
@GetMapping("/engineer/info/list")
public Result<?> getEngineerInfoList(@RequestParam Integer page, @RequestParam Integer size){
// 获取工程师基础信息列表
Result<?> res = null;
try {
res = engineerService.getEngineerInfoList(page, size);
} catch (BusinessException e) {
Result.failed(e.getMessage());
}
return res;
}
@GetMapping("/engineer/skill/list")
public Result<?> getEngineerSkillList(@RequestParam Integer page, @RequestParam Integer size) {
// 获取工程师技能信息列表
Result<?> res = null;
try {
res = engineerService.getEngineerSkillList(page, size);
} catch (BusinessException e) {
Result.failed(e.getMessage());
}
return res;
}
}
package com.alibaba.cloud.integration.order.dto;
import lombok.Data;
import java.util.List;
@Data
public class EngineerInfoListResp {
private long total;
private long pages;
private long pageCurrent;
private long pageSize;
private List<EngineerInfo> content;
@Data
public static class EngineerInfo{
private String engineerCode;
private String number;
private String name;
private String group;
private String sex;
private String age;
private String phone;
private String address;
private String workType;
}
}
......@@ -8,8 +8,8 @@ import java.sql.Timestamp;
public class EngineerInfo {
private Integer id;
private String engineerCode;
private String branchId;
private String name;
private String groupId;
private String cosmosId;
private String gender;
private String birth;
......
package com.alibaba.cloud.integration.order.service;
import com.alibaba.cloud.integration.common.Result;
public interface EngineerService {
// 获取公司列表
Result<?> getEngineerInfoList(Integer page, Integer size);
//获取工程师技能列表
Result<?> getEngineerSkillList(Integer page, Integer size);
}
package com.alibaba.cloud.integration.order.service.impl;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.dao.EngineerInfoDao;
import com.alibaba.cloud.integration.order.dao.EngineerSkillDao;
import com.alibaba.cloud.integration.order.dao.OrgGroupDao;
import com.alibaba.cloud.integration.order.dto.EngineerInfoListResp;
import com.alibaba.cloud.integration.order.entity.EngineerInfo;
import com.alibaba.cloud.integration.order.entity.EngineerSkill;
import com.alibaba.cloud.integration.order.entity.OrgGroup;
import com.alibaba.cloud.integration.order.service.EngineerService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.text.SimpleDateFormat;
import java.util.*;
@Service
public class EngineerServiceImpl implements EngineerService {
@Autowired
private EngineerInfoDao engineerInfoDao;
@Autowired
private EngineerSkillDao engineerSkillDao;
@Autowired
private OrgGroupDao orgGroupDao;
@Transactional
@Override
public Result<?> getEngineerInfoList(Integer page, Integer size) {
// 查询工程师信息
IPage<EngineerInfo> pg = this.queryEngineerInfo(page, size);
List<EngineerInfo> records = pg.getRecords();
// 获取groupIds
List<String> groupIds = new ArrayList<>();
for(EngineerInfo e: records){
groupIds.add(e.getGroupId());
}
// 获取Map<groupId, groupName>
HashMap<String, String> groupNames = this.queryGroupNames(groupIds);
// 设置返回值
EngineerInfoListResp res = new EngineerInfoListResp();
res.setContent(this.packEngineerInfo(records, groupNames));
res.setTotal(pg.getTotal());
res.setPages(pg.getPages());
res.setPageCurrent(pg.getCurrent());
res.setPageSize(pg.getSize());
return Result.success(res);
}
@Transactional
@Override
public Result<?> getEngineerSkillList(Integer page, Integer size) {
return null;
}
private IPage<EngineerInfo> queryEngineerInfo(Integer page, Integer size) {
// 分页查询工程师基础信息
LambdaQueryWrapper<EngineerInfo> lqw = new LambdaQueryWrapper<>();
lqw.orderByAsc(EngineerInfo::getGroupId);
lqw.orderByAsc(EngineerInfo::getEngineerCode);
IPage<EngineerInfo> pg = new Page(page, size);
engineerInfoDao.selectPage(pg, lqw);
return pg;
}
private HashMap<String, String> queryGroupNames(List<String> groupIds) {
//查询小组名称映射关系
HashMap<String, String> map = new HashMap<>();
if (groupIds.isEmpty() || groupIds == null) {
return map;
}
LambdaQueryWrapper<OrgGroup> lqw = new LambdaQueryWrapper<>();
lqw.select(OrgGroup::getGroupId, OrgGroup::getGroupName);
lqw.in(OrgGroup::getGroupId, groupIds);
List<OrgGroup> groups= orgGroupDao.selectList(lqw);
for(OrgGroup g: groups) {
map.put(g.getGroupId(), g.getGroupName());
}
return map;
}
private List<EngineerInfoListResp.EngineerInfo> packEngineerInfo(List<EngineerInfo> engineers, HashMap<String, String> groups) {
String groupName, age, workType;
List<EngineerInfoListResp.EngineerInfo> items = new ArrayList<>();
for(EngineerInfo e: engineers) {
EngineerInfoListResp.EngineerInfo item = new EngineerInfoListResp.EngineerInfo();
item.setEngineerCode(e.getEngineerCode());
item.setNumber(e.getEngineerCode());
item.setName(e.getName());
item.setSex(e.getGender());
item.setPhone(e.getPhone());
item.setAddress(e.getAddress());
groupName = groups.getOrDefault(e.getGroupId(), "");
item.setGroup(groupName);
age = this.getEngineerAge(e.getBirth());
item.setAge(age);
workType = (e.getKind() == 1) ? "fullJob": "partJob";
item.setWorkType(workType);
items.add(item);
}
return items;
}
private String getEngineerAge(String birth) {
// 获取工程师年龄
if (birth.isEmpty() || birth == null) {
return "";
}
int age = 0;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
try {
Date birthDate = dateFormat.parse(birth);
Calendar birthCalendar = Calendar.getInstance();
birthCalendar.setTime(birthDate);
Calendar nowCalendar = Calendar.getInstance();
age = nowCalendar.get(Calendar.YEAR) - birthCalendar.get(Calendar.YEAR);
if (nowCalendar.get(Calendar.DAY_OF_YEAR) < birthCalendar.get(Calendar.DAY_OF_YEAR)) {
age--;
}
} catch (Exception e) {
return "";
}
return (age <= 0) ? "" : Integer.toString(age);
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!