Commit 2dabf1ed by 王力

Merge branch 'feature_mvp616_wangl' into 'develop'

修改

See merge request !70
2 parents 09ca9ff5 eeda320f
......@@ -22,7 +22,7 @@ public class EngineerController {
try {
res = engineerService.getEngineerInfoList(page, size);
} catch (BusinessException e) {
Result.failed(e.getMessage());
return Result.failed(e.getMessage());
}
return res;
}
......@@ -34,7 +34,7 @@ public class EngineerController {
try {
res = engineerService.getEngineerInfoDetail(engineerCode);
} catch (BusinessException e) {
Result.failed(e.getMessage());
return Result.failed(e.getMessage());
}
return res;
}
......@@ -46,7 +46,7 @@ public class EngineerController {
try {
res = engineerService.getEngineerSkillList(page, size);
} catch (BusinessException e) {
Result.failed(e.getMessage());
return Result.failed(e.getMessage());
}
return res;
}
......@@ -58,7 +58,7 @@ public class EngineerController {
try {
res = engineerService.getEngineerSkillDetail(engineerCode);
} catch (BusinessException e) {
Result.failed(e.getMessage());
return Result.failed(e.getMessage());
}
return res;
}
......@@ -69,7 +69,7 @@ public class EngineerController {
try {
engineerService.engineerSkillUpdate(req.getEngineerCode(), req.getCategoryIds());
} catch (BusinessException e) {
Result.failed(e.getMessage());
return Result.failed(e.getMessage());
}
return Result.success(null);
}
......@@ -81,7 +81,7 @@ public class EngineerController {
try {
res = engineerService.getEngineerBusinessList(page, size);
} catch (BusinessException e) {
Result.failed(e.getMessage());
return Result.failed(e.getMessage());
}
return res;
}
......@@ -93,7 +93,7 @@ public class EngineerController {
try {
res = engineerService.getEngineerBusinessDetail(engineerCode);
} catch (BusinessException e) {
Result.failed(e.getMessage());
return Result.failed(e.getMessage());
}
return res;
}
......@@ -107,7 +107,7 @@ public class EngineerController {
req.getEngineerCode(), req.getMaxNum(), req.getMaxMinute(),
req.getDeparture(), req.getPriority());
} catch (BusinessException e) {
Result.failed(e.getMessage());
return Result.failed(e.getMessage());
}
return res;
}
......
package com.alibaba.cloud.integration.order.service.impl;
import com.alibaba.cloud.integration.common.BusinessException;
import com.alibaba.cloud.integration.common.Result;
import com.alibaba.cloud.integration.order.dao.*;
import com.alibaba.cloud.integration.order.dao.EngineerBusinessMPDao;
import com.alibaba.cloud.integration.order.dao.EngineerInfoMPDao;
import com.alibaba.cloud.integration.order.dao.EngineerSkillMPDao;
import com.alibaba.cloud.integration.order.dao.OrgGroupMPDao;
import com.alibaba.cloud.integration.order.dto.EngineerBusinessListResp;
import com.alibaba.cloud.integration.order.dto.EngineerInfoListResp;
import com.alibaba.cloud.integration.order.dto.EngineerSkillListResp;
import com.alibaba.cloud.integration.order.entity.*;
import com.alibaba.cloud.integration.order.entity.EngineerBusiness;
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.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
......@@ -28,7 +34,7 @@ import java.util.stream.Collectors;
@Service
public class EngineerServiceImpl implements EngineerService {
private Logger logger = LoggerFactory.getLogger(getClass());
private final Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
private EngineerInfoMPDao engineerInfoMPDao;
......@@ -58,7 +64,7 @@ public class EngineerServiceImpl implements EngineerService {
// 设置返回值
EngineerInfoListResp res = new EngineerInfoListResp();
res.setContent(this.packEngineerInfo(records, groupNames));
res.setContent(this.packEngineerInfos(records, groupNames));
res.setTotal(pg.getTotal());
res.setPages(pg.getPages());
res.setPageCurrent(pg.getCurrent());
......@@ -68,23 +74,21 @@ public class EngineerServiceImpl implements EngineerService {
}
@Override
public Result<?> getEngineerInfoDetail(String engineerCode) {
public Result<?> getEngineerInfoDetail(String engineerCode) throws BusinessException {
// 获取技术员基础信息详情
EngineerInfoListResp.EngineerInfo empty = new EngineerInfoListResp.EngineerInfo();
// 获取技术员列表
List<EngineerInfo> records = this.queryEngineerInfos(engineerCode);
if (records.isEmpty()){
return Result.success(empty);
if (records.isEmpty()) {
throw new BusinessException("技术员不存在");
}
List<String> groupIds = records.stream().map(EngineerInfo::getGroupId).collect(Collectors.toList());
HashMap<String, String> groupNames = this.queryGroupNames(groupIds);
List<EngineerInfoListResp.EngineerInfo> items = this.packEngineerInfo(records, groupNames);
List<EngineerInfoListResp.EngineerInfo> items = this.packEngineerInfos(records, groupNames);
if (items.isEmpty()) {
return Result.success(empty);
throw new BusinessException("技术员不存在");
}
return Result.success(items.get(0));
}
......@@ -93,49 +97,30 @@ public class EngineerServiceImpl implements EngineerService {
@Override
public Result<?> getEngineerSkillList(long page, long size) {
// 获取技术员技能列表
IPage<EngineerInfo> pg = this.queryEngineerInfoIPage(page, size);
List<EngineerInfo> engineers = pg.getRecords();
// 获取groupId类表
List<String> groupIds = engineers.stream().map(EngineerInfo::getGroupId).collect(Collectors.toList());
HashMap<String, String> groupNames = this.queryGroupNames(groupIds);
// 获取技术员code列表
List<String> engineerCodes = engineers.stream().map(EngineerInfo::getEngineerCode).collect(Collectors.toList());
// 获取技术员的可用技能列表
List<Integer> statuses = new ArrayList<Integer>(Arrays.asList(1));
HashMap<String, List<String>> engineerSkills = this.queryEngineerSkills(engineerCodes, statuses);
List<String> emptySkills = Collections.emptyList();
List<EngineerSkillListResp.EngineerSkill> items = new ArrayList<>();
for(EngineerInfo e: engineers) {
EngineerSkillListResp.EngineerSkill skill = new EngineerSkillListResp.EngineerSkill();
skill.setEngineerCode(e.getEngineerCode());
skill.setEngineerName(e.getName());
skill.setGroupName(groupNames.getOrDefault(e.getGroupId(), ""));
skill.setUpdateTime(this.Timestamp2Datetime(e.getUpdateTime(), "yyyy-MM-dd hh:mm:ss"));
// 获取一个工程师的技能列表
skill.setCategoryIds(engineerSkills.getOrDefault(e.getEngineerCode(), emptySkills));
items.add(skill);
}
EngineerSkillListResp res = new EngineerSkillListResp();
res.setTotal(pg.getTotal());
res.setPages(pg.getPages());
res.setPageCurrent(pg.getCurrent());
res.setPageSize(pg.getSize());
res.setContent(items);
res.setContent(this.packEngineerSkills(engineers));
return Result.success(res);
}
@Override
public Result<?> getEngineerSkillDetail(String engineerCode) {
public Result<?> getEngineerSkillDetail(String engineerCode) throws BusinessException {
// 获取工程师技能详情
return null;
List<EngineerInfo> engineers = this.queryEngineerInfos(engineerCode);
if (engineers.isEmpty()) {
throw new BusinessException("技术员不存在");
}
List<EngineerSkillListResp.EngineerSkill> items = this.packEngineerSkills(engineers);
if (items.isEmpty()) {
throw new BusinessException("技术员不存在");
}
return Result.success(items.get(0));
}
@Transactional
......@@ -147,7 +132,7 @@ public class EngineerServiceImpl implements EngineerService {
LambdaUpdateWrapper<EngineerSkill> wrapper = new LambdaUpdateWrapper<>();
wrapper.eq(EngineerSkill::getEngineerCode, engineerCode).set(EngineerSkill::getStatus, 0);
engineerSkillMPDao.update(null, wrapper);
if (categoryIds.isEmpty()){
if (categoryIds.isEmpty()) {
return null;
}
......@@ -163,13 +148,13 @@ public class EngineerServiceImpl implements EngineerService {
// 可能存在engineerSkill表不存在的记录,需要补充录入
List<Integer> statuses = new ArrayList<Integer>(Arrays.asList(1, 0));
List<String> engineerCodes = new ArrayList<>(Arrays.asList(engineerCode));
List<String> engineerCodes = new ArrayList<>(Collections.singletonList(engineerCode));
HashMap<String, List<String>> engineerSkills = this.queryEngineerSkills(engineerCodes, statuses);
Set<String> sInput = new HashSet<>(categoryIds);
Set<String> sDB = new HashSet<>(engineerSkills.get(engineerCode));
sInput.removeAll(sDB);
for(String categoryId: sInput) {
for (String categoryId : sInput) {
EngineerSkill e = new EngineerSkill();
e.setEngineerCode(engineerCode);
e.setCategoryId(categoryId);
......@@ -186,50 +171,7 @@ public class EngineerServiceImpl implements EngineerService {
// 查询技术员列表
IPage<EngineerInfo> pg = this.queryEngineerInfoIPage(page, size);
List<EngineerInfo> records = pg.getRecords();
// 获取技术员code列表
List<String> engineerCodes = records.stream().map(EngineerInfo::getEngineerCode).collect(Collectors.toList());
HashMap<String, EngineerBusiness> buss = this.queryEngineerBusiness(engineerCodes);
List<EngineerBusinessListResp.EngineerBusiness> items = new ArrayList<>();
EngineerBusiness b;
for(EngineerInfo e: records) {
EngineerBusinessListResp.EngineerBusiness item = new EngineerBusinessListResp.EngineerBusiness();
item.setEngineerCode(e.getEngineerCode());
item.setEngineerName(e.getName());
item.setKind((e.getKind() == 1) ? "fullJob": "partJob");
b = buss.getOrDefault(e.getEngineerCode(), null);
if (b == null) {
item.setAddress("");
item.setLocation("");
item.setDeparture("");
item.setMaxMinute(0);
item.setMaxNum(0);
item.setPriority("低");
} else {
item.setAddress(b.getAddress());
item.setLocation(String.format("%s,%s", b.getX(), b.getY()));
item.setDeparture((b.getDeparture() == 1) ? "配件仓" : "住址");
item.setMaxMinute(b.getMaxMinute());
item.setMaxNum(b.getMaxNum());
String priority;
if (b.getPriority() == 3) {
priority = "高";
} else if (b.getPriority() == 2) {
priority = "中";
} else {
priority = "低";
}
item.setPriority(priority);
}
items.add(item);
}
List<EngineerInfo> engineers = pg.getRecords();
// 查询技术员业务属性
EngineerBusinessListResp res = new EngineerBusinessListResp();
......@@ -237,14 +179,22 @@ public class EngineerServiceImpl implements EngineerService {
res.setPages(pg.getPages());
res.setPageCurrent(pg.getCurrent());
res.setPageSize(pg.getSize());
res.setContent(items);
res.setContent(this.packEngineerBusinesses(engineers));
return Result.success(res);
}
@Override
public Result<?> getEngineerBusinessDetail(String engineerCode) {
// 获取技术员业务熟悉详情
return null;
List<EngineerInfo> engineers = this.queryEngineerInfos(engineerCode);
if (engineers.isEmpty()) {
throw new BusinessException("技术员不存在");
}
List<?> items = this.packEngineerBusinesses(engineers);
if (items.isEmpty()) {
throw new BusinessException("技术员不存在");
}
return Result.success(items.get(0));
}
@Transactional
......@@ -304,8 +254,8 @@ public class EngineerServiceImpl implements EngineerService {
LambdaQueryWrapper<OrgGroup> lqw = new LambdaQueryWrapper<>();
lqw.select(OrgGroup::getGroupId, OrgGroup::getGroupName);
lqw.in(OrgGroup::getGroupId, groupIds);
List<OrgGroup> groups= orgGroupMPDao.selectList(lqw);
for(OrgGroup g: groups) {
List<OrgGroup> groups = orgGroupMPDao.selectList(lqw);
for (OrgGroup g : groups) {
map.put(g.getGroupId(), g.getGroupName());
}
return map;
......@@ -329,7 +279,7 @@ public class EngineerServiceImpl implements EngineerService {
// 根据engineerCode分组
Map<String, List<EngineerSkill>> g = results.stream().collect(Collectors.groupingBy(EngineerSkill::getEngineerCode));
for(String engineerCode: g.keySet()) {
for (String engineerCode : g.keySet()) {
// 技术员技能ID列表
List<String> skillIds = g.get(engineerCode).stream().map(EngineerSkill::getCategoryId).collect(Collectors.toList());
map.put(engineerCode, skillIds);
......@@ -345,18 +295,18 @@ public class EngineerServiceImpl implements EngineerService {
LambdaQueryWrapper<EngineerBusiness> lqw = new LambdaQueryWrapper<>();
lqw.in(EngineerBusiness::getEngineerCode, engineerCodes);
List<EngineerBusiness> records = engineerBusinessDao.selectList(lqw);
for(EngineerBusiness r: records) {
for (EngineerBusiness r : records) {
map.put(r.getEngineerCode(), r);
}
return map;
}
private List<EngineerInfoListResp.EngineerInfo> packEngineerInfo(List<EngineerInfo> engineers, HashMap<String, String> groups) {
private List<EngineerInfoListResp.EngineerInfo> packEngineerInfos(List<EngineerInfo> engineers, HashMap<String, String> groups) {
String groupName, age, kind;
List<EngineerInfoListResp.EngineerInfo> items = new ArrayList<>();
for(EngineerInfo e: engineers) {
for (EngineerInfo e : engineers) {
EngineerInfoListResp.EngineerInfo item = new EngineerInfoListResp.EngineerInfo();
item.setEngineerCode(e.getEngineerCode());
item.setNumber(e.getEngineerCode());
......@@ -375,19 +325,19 @@ public class EngineerServiceImpl implements EngineerService {
item.setAge(age);
// 工作类型:全职/兼职
kind = (e.getKind() == 1) ? "fullJob": "partJob";
kind = (e.getKind() == 1) ? "fullJob" : "partJob";
item.setKind(kind);
if(e.getCredentials() != null){
if (e.getCredentials() != null) {
item.setCredentials(Arrays.asList(e.getCredentials().split("、")));
} else{
} else {
item.setCredentials(new ArrayList<String>());
}
// 标签
List<String> tags = new ArrayList<>();
if (e.getTags() != null && e.getTags().isEmpty()) {
for(JSONObject.Entry<String, Object> entry: e.getTags().entrySet()){
for (JSONObject.Entry<String, Object> entry : e.getTags().entrySet()) {
tags.add(String.format("%s+%s", entry.getKey(), entry.getValue().toString()));
}
} else {
......@@ -398,9 +348,83 @@ public class EngineerServiceImpl implements EngineerService {
return items;
}
private List<EngineerSkillListResp.EngineerSkill> packEngineerSkills(List<EngineerInfo> engineers) {
// 获取groupId类表
List<String> groupIds = engineers.stream().map(EngineerInfo::getGroupId).collect(Collectors.toList());
HashMap<String, String> groupNames = this.queryGroupNames(groupIds);
// 获取技术员code列表
List<String> engineerCodes = engineers.stream().map(EngineerInfo::getEngineerCode).collect(Collectors.toList());
// 获取技术员的可用技能列表
List<Integer> statuses = new ArrayList<Integer>(List.of(1));
HashMap<String, List<String>> engineerSkills = this.queryEngineerSkills(engineerCodes, statuses);
List<String> emptySkills = Collections.emptyList();
List<EngineerSkillListResp.EngineerSkill> items = new ArrayList<>();
for (EngineerInfo e : engineers) {
EngineerSkillListResp.EngineerSkill skill = new EngineerSkillListResp.EngineerSkill();
skill.setEngineerCode(e.getEngineerCode());
skill.setEngineerName(e.getName());
skill.setGroupName(groupNames.getOrDefault(e.getGroupId(), ""));
skill.setUpdateTime(this.Timestamp2Datetime(e.getUpdateTime(), "yyyy-MM-dd hh:mm:ss"));
// 获取一个工程师的技能列表
skill.setCategoryIds(engineerSkills.getOrDefault(e.getEngineerCode(), emptySkills));
items.add(skill);
}
return items;
}
private List<EngineerBusinessListResp.EngineerBusiness> packEngineerBusinesses(List<EngineerInfo> engineers) {
// 获取技术员code列表
List<String> engineerCodes = engineers.stream().map(EngineerInfo::getEngineerCode).collect(Collectors.toList());
HashMap<String, EngineerBusiness> buss = this.queryEngineerBusiness(engineerCodes);
List<EngineerBusinessListResp.EngineerBusiness> items = new ArrayList<>();
for (EngineerInfo e : engineers) {
EngineerBusinessListResp.EngineerBusiness item = new EngineerBusinessListResp.EngineerBusiness();
item.setEngineerCode(e.getEngineerCode());
item.setEngineerName(e.getName());
item.setKind((e.getKind() == 1) ? "fullJob" : "partJob");
EngineerBusiness b = buss.getOrDefault(e.getEngineerCode(), null);
if (b == null) {
item.setAddress("");
item.setLocation("");
item.setDeparture("");
item.setMaxMinute(0);
item.setMaxNum(0);
item.setPriority("低");
} else {
item.setAddress(b.getAddress());
item.setLocation(String.format("%s,%s", b.getX(), b.getY()));
item.setDeparture((b.getDeparture() == 1) ? "配件仓" : "住址");
item.setMaxMinute(b.getMaxMinute());
item.setMaxNum(b.getMaxNum());
String priority;
if (b.getPriority() == 3) {
priority = "高";
} else if (b.getPriority() == 2) {
priority = "中";
} else {
priority = "低";
}
item.setPriority(priority);
}
items.add(item);
}
return items;
}
private HashMap<String, Integer> getEngineerSkillIds(List<String> skillIds, HashMap<String, Integer> engineerSkillIds) {
HashMap<String, Integer> map = new HashMap<>();
for(String skillId: skillIds) {
for (String skillId : skillIds) {
map.put(skillId, engineerSkillIds.getOrDefault(skillId, 0));
}
return map;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!