Commit 98883a6c by 王力

Merge branch 'feature_OrderServiceList_wangl' into 'develop'

Feature order service list wangl

See merge request !18
2 parents 1fb62751 8a279a61
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.dao;
import com.alibaba.cloud.integration.order.entity.OrgBranch;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface OrgBranchDao extends BaseMapper<OrgBranch> {
}
package com.alibaba.cloud.integration.order.dao;
import com.alibaba.cloud.integration.order.entity.OrgCluster;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface OrgClusterDao extends BaseMapper<OrgCluster> {
}
package com.alibaba.cloud.integration.order.dao;
import com.alibaba.cloud.integration.order.entity.OrgGroup;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface OrgGroupDao extends BaseMapper<OrgGroup> {
}
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,13 +8,13 @@ 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;
private String phone;
private String addr;
private String address;
private Integer kind;
private String grade;
private String credentials;
......
package com.alibaba.cloud.integration.order.entity;
import lombok.Data;
import java.sql.Timestamp;
@Data
public class OrgBranch {
private Integer id;
private String branchId;
private String branchName;
private String clusterId;
private String address;
private String x;
private String y;
private Integer kind;
private String layerId;
private String memo;
private Timestamp createTime;
private Timestamp updateTime;
}
\ No newline at end of file
package com.alibaba.cloud.integration.order.entity;
import lombok.Data;
import java.sql.Timestamp;
@Data
public class OrgCluster {
private Integer id;
private String clusterId;
private String name;
private String address;
private String cityName;
private Integer status;
private String updateUser;
private Timestamp createTime;
private Timestamp updateTime;
}
\ No newline at end of file
package com.alibaba.cloud.integration.order.entity;
import lombok.Data;
import java.sql.Timestamp;
@Data
public class OrgGroup {
private Integer id;
private String groupId;
private String groupName;
private String clusterId;
private String branchId;
private String address;
private String x;
private String y;
private String cityCode;
private Integer kind;
private Integer category;
private Integer warehouseId;
private String memo;
private Timestamp createTime;
private Timestamp updateTime;
}
\ No newline at end of file
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!