Commit 7217b709 by 丁伟峰

技术员日历实现

1 parent a07b5a5d
package com.dituhui.pea.order.common;
import com.dituhui.pea.order.dao.EngineerInfoDao;
import com.dituhui.pea.order.dao.OrgGroupDao;
import com.dituhui.pea.order.dao.OrgTeamEngineerDao;
import com.dituhui.pea.order.entity.EngineerInfoEntity;
import com.dituhui.pea.order.entity.OrgGroupEntity;
import com.dituhui.pea.order.entity.OrgTeamEngineerEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.stream.Collectors;
@Component
public class EngineerUtil {
@Autowired
private OrgTeamEngineerDao orgTeamEngineerDao;
@Autowired
private EngineerInfoDao engineerInfoDao;
@Autowired
private OrgGroupDao orgGroupDao;
public List<EngineerInfoEntity> getEngineesByLevel(String levelType, String levelValue){
List<EngineerInfoEntity> engineers = null;
List<String> groupIds = null;
switch (levelType) {
case "team":
List<String> engineerCodes = orgTeamEngineerDao.findAllByTeamId(levelValue).stream()
.map(OrgTeamEngineerEntity::getEngineerCode).collect(Collectors.toList());
engineers = engineerInfoDao.findByEngineerCodeIn(engineerCodes);
break;
case "group":
engineers = engineerInfoDao.findByGroupId(levelValue);
break;
case "branch":
groupIds = orgGroupDao.findAllByBranchId(levelValue).stream()
.map(OrgGroupEntity::getGroupId).collect(Collectors.toList());
engineers = engineerInfoDao.findByGroupIdIn(groupIds);
break;
default:
// "cluster".equals(levelType)
groupIds = orgGroupDao.findAllByClusterId(levelValue).stream()
.map(OrgGroupEntity::getGroupId).collect(Collectors.toList());
engineers = engineerInfoDao.findByGroupIdIn(groupIds);
break;
}
return engineers;
}
}
......@@ -3,6 +3,7 @@ package com.dituhui.pea.order.controller;
import com.dituhui.pea.common.BusinessException;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.dto.EngineerBusinessUpdateReqDTO;
import com.dituhui.pea.order.dto.EngineerCalendarDTO;
import com.dituhui.pea.order.dto.EngineerSkillUpdateReqDTO;
import com.dituhui.pea.order.dto.EngineersGanttReqDTO;
import com.dituhui.pea.order.service.EngineerService;
......@@ -116,7 +117,7 @@ public class EngineerController {
return res;
}
@PostMapping(value = "/engineer/schedule/gantt")
@PostMapping("/engineer/schedule/gantt")
public Result<?> getEngineersGanttList(@Validated @RequestBody EngineersGanttReqDTO reqDTO) {
log.info("getEngineersGanttList: {}", reqDTO);
Result<?> res = null;
......@@ -127,4 +128,15 @@ public class EngineerController {
}
return res;
}
@GetMapping("/engineer/calendar")
public Result<?> getEngineerCalendar(@Validated EngineerCalendarDTO.Request reqDTO) {
Result<?> res = null;
try {
res = engineerService.getEngineersCalendar(reqDTO);
} catch (BusinessException e) {
return Result.failed(e.getMessage());
}
return res;
}
}
package com.dituhui.pea.order.dao;
import com.dituhui.pea.order.entity.CapacityEngineerCalendarEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
public interface CapacityEngineerCalendarDao extends JpaRepository<CapacityEngineerCalendarEntity, Long> {
@Query("select a from CapacityEngineerCalendarEntity a where a.engineerCode=:engineerCode and a.workday between :beginDate and :endDate")
List<CapacityEngineerCalendarEntity> findCalendarByEngineerCodeAndDateBetween(String engineerCode, String beginDate, String endDate);
}
......@@ -21,6 +21,9 @@ public interface OrgTeamEngineerDao extends JpaRepository<OrgTeamEngineerEntity,
List<OrgTeamEngineerEntity> findByTeamId(String teamId);
@Query("select a.teamId from OrgTeamEngineerEntity a where a.engineerCode=:engineerCode")
List<String> getTeamIdsByEngineerCode(String engineerCode);
@Modifying
@Query("UPDATE OrgTeamEngineerEntity tt SET tt.status = :status WHERE tt.teamId = :teamId")
void updateStatusAllEngineers(String teamId, int status);
......
package com.dituhui.pea.order.entity;
import lombok.Data;
import javax.persistence.*;
import java.sql.Timestamp;
import java.time.LocalDateTime;
@Entity
@Table(name = "capacity_engineer_calendar")
@Data
public class CapacityEngineerCalendarEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(nullable = false)
private String workday;
@Column(name = "engineer_code", nullable = false, columnDefinition = "varchar(50) default '0'")
private String engineerCode;
@Column(name = "start_time", nullable = false)
private LocalDateTime startTime;
@Column(name = "end_time", nullable = false)
private LocalDateTime endTime;
@Column(nullable = false)
private String type;
@Column(nullable = false)
private String memo;
@Column(name = "create_time", nullable = false, updatable = false, columnDefinition = "timestamp default current_timestamp")
private Timestamp createTime;
@Column(name = "update_time", nullable = false, columnDefinition = "timestamp default current_timestamp on update current_timestamp")
private Timestamp updateTime;
// 其他字段和关联关系的定义
// ...
}
package com.dituhui.pea.order.service;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.dto.EngineerCalendarDTO;
import com.dituhui.pea.order.dto.EngineersGanttReqDTO;
import java.util.List;
......@@ -24,4 +25,6 @@ public interface EngineerService {
Result<?> engineerBusinessUpdate(String engineerCode, Integer maxNum, Integer maxMutine, String departure, String priority);
Result<?> getEngineersGanttList(EngineersGanttReqDTO ganttReqDTO);
Result<?> getEngineersCalendar(EngineerCalendarDTO.Request engineerCalendarReq);
}
package com.dituhui.pea.order.service.impl;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.date.Week;
import com.dituhui.pea.common.BusinessException;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.EngineerUtil;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.*;
import com.dituhui.pea.order.entity.*;
......@@ -18,9 +21,18 @@ import org.springframework.transaction.annotation.Transactional;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.dituhui.pea.order.config.OrderConfig.PATTERN_DATE;
import static com.dituhui.pea.order.config.OrderConfig.PATTERN_DATETIME;
@Slf4j
@Service
......@@ -50,6 +62,17 @@ public class EngineerServiceImpl implements EngineerService {
@Autowired
private CapacityEngineerStatDao capacityEngineerStatDao;
@Autowired
private CapacityEngineerCalendarDao capacityEngineerCalendarDao;
@Autowired
private OrgTeamDao orgTeamDao;
@Autowired
private OrgTeamEngineerDao orgTeamEngineerDao;
@Autowired
private EngineerUtil engineerUtil;
@Transactional
@Override
public Result<?> getEngineerInfoList(long page, long size) {
......@@ -506,7 +529,7 @@ public class EngineerServiceImpl implements EngineerService {
} else {
engineer.setCapTotal(capacityEngineerStat.getCapTotal().toString()).setCapUsed(capacityEngineerStat.getCapUsed().toString());
}
if (mapEngineers.containsKey(engineerCode)){
if (mapEngineers.containsKey(engineerCode)) {
engineer.setOrders(mapEngineers.get(engineerCode));
}
// engineer.setErrorTip(); todo
......@@ -516,6 +539,25 @@ public class EngineerServiceImpl implements EngineerService {
return Result.success(data);
}
@Override
public Result<?> getEngineersCalendar(EngineerCalendarDTO.Request req) {
// 技术员日历,查询 capacity_engineer_calendar表,如果当日有各种事项,进行显示;否则显示正常上班;
List<EngineerCalendarDTO.Engineer> engineers = new ArrayList<>();
List<EngineerInfoEntity> entities = engineerUtil.getEngineesByLevel(req.getLevelType(), req.getLevelValue());
String edate = LocalDate.parse(req.getDate()).plusDays(14).toString();
for (EngineerInfoEntity e : entities) {
EngineerCalendarDTO.Engineer engineer = new EngineerCalendarDTO.Engineer();
engineer.setEngineerCode(e.getEngineerCode());
engineer.setName(e.getName());
engineer.setCalendar(getOneEngineerCalendars(e.getEngineerCode(), req.getDate(), edate));
engineers.add(engineer);
}
EngineerCalendarDTO.Result rs = new EngineerCalendarDTO.Result();
rs.setEngineers(engineers);
return Result.success(rs);
}
public Map<String, OrderRequestEntity> getOrdersByOrderIds(List<String> orderIds) {
List<OrderRequestEntity> orders = orderRequestDao.findAllByOrderIdIn(orderIds);
......@@ -540,4 +582,90 @@ public class EngineerServiceImpl implements EngineerService {
tips.add(new LabelValueDTO().setLabel("标签").setValue(order.getTags()));
return tips;
}
private List<EngineerCalendarDTO.Calendar> getOneEngineerCalendars(String engineerCode, String bdate, String edate) {
// 返回某一个技术员,日期范围内的日历列表
List<EngineerCalendarDTO.Calendar> calendars = null;
List<String> teamIds = orgTeamEngineerDao.getTeamIdsByEngineerCode(engineerCode);
if (teamIds == null || teamIds.size() == 0) {
return new ArrayList<>();
}
LocalDate startDate = LocalDate.parse(bdate);
LocalDate endDate = LocalDate.parse(edate);
List<LocalDate> datesInRange = Stream.iterate(startDate, date -> date.plusDays(1))
.limit(ChronoUnit.DAYS.between(startDate, endDate.plusDays(1)))
.collect(Collectors.toList());
Map<String, List<CapacityEngineerCalendarEntity>> configs = capacityEngineerCalendarDao.findCalendarByEngineerCodeAndDateBetween(engineerCode, bdate, edate).stream()
.collect(Collectors.groupingBy(CapacityEngineerCalendarEntity::getWorkday));
for (LocalDate date : datesInRange) {
String sDate = LocalDateTimeUtil.format(date, PATTERN_DATE);
EngineerCalendarDTO.Calendar calander = null;
if (!configs.containsKey(sDate)) {
calander = getEmptyCalendar(teamIds.get(0), sDate);
} else {
calander = new EngineerCalendarDTO.Calendar();
calander.setDate(sDate);
int week = LocalDate.parse(sDate).getDayOfWeek().getValue();
calander.setWeek(Week.of(week).toChinese("周"));
List<EngineerCalendarDTO.Content> contents = new ArrayList<>();
// 有配置
for (CapacityEngineerCalendarEntity e : configs.get(sDate)) {
EngineerCalendarDTO.Content content = new EngineerCalendarDTO.Content();
content.setType("rest");
content.setTitle(e.getType());
content.setValue(getCalendarDuration(e.getStartTime(), e.getEndTime()));
}
calander.setContent(contents);
}
calendars.add(calander);
}
return calendars;
}
private String getCalendarDuration(LocalDateTime btime, LocalDateTime etime) {
String b2 = LocalDateTimeUtil.format(btime, PATTERN_DATETIME);
String e2 = LocalDateTimeUtil.format(etime, PATTERN_DATETIME);
return getCalendarDuration(b2, e2);
}
private String getCalendarDuration(String btime, String etime) {
LocalTime t1 = LocalTime.parse(btime);
LocalTime t2 = LocalTime.parse(etime);
Duration duration = Duration.between(t1, t2);
long hours = duration.toHours();
long minutes = duration.toMinutesPart();
if (minutes > 0 && hours == 0) {
return String.format("%d分钟", minutes);
} else if (minutes == 0 && hours > 0) {
return String.format("%d小时", hours);
} else {
return String.format("%d小时%d分钟", hours, minutes);
}
}
private EngineerCalendarDTO.Calendar getEmptyCalendar(String teamId, String date) {
// 初始化一天的日历
OrgTeamEntity e = orgTeamDao.getByTeamId(teamId);
EngineerCalendarDTO.Calendar calendar = new EngineerCalendarDTO.Calendar();
calendar.setDate(date);
int week = LocalDate.parse(date).getDayOfWeek().getValue();
EngineerCalendarDTO.Content content = new EngineerCalendarDTO.Content();
List<String> workdays = Arrays.asList(e.getWorkdays().split(","));
if (workdays.contains(String.valueOf(week))) {
content.setType("woring");
content.setTitle(String.format("日常出勤 %s-%s", e.getWorkOn(), e.getWorkOff()));
content.setValue(getCalendarDuration(e.getWorkOn(), e.getWorkOff()));
} else {
content.setType("rest");
content.setTitle("休息");
}
calendar.setContent(Collections.singletonList(content));
return calendar;
}
}
package com.dituhui.pea.order.service.impl;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.EngineerUtil;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.*;
import com.dituhui.pea.order.entity.*;
......@@ -31,6 +32,9 @@ public class OrganizationServiceImpl implements OrganizationService {
@Autowired
private OrgTeamDao orgTeamDao;
@Autowired
private EngineerUtil engineerUtil;
@Override
public Result<?> getOrganizationTree(String levelType, String levelValue) {
// 如果传递了精确的id,只返回对应的tree内容;如果没有传递,返回所有tree内容
......@@ -111,30 +115,7 @@ public class OrganizationServiceImpl implements OrganizationService {
@Override
public Result<?> getEngineersByLevel(String levelType, String levelValue) {
List<EngineerInfoEntity> engineers = null;
List<String> groupIds = null;
assert "team".equals(levelType) || "group".equals(levelType) || "branch".equals(levelType) || "cluster".equals(levelType);
switch (levelType) {
case "team":
List<String> engineerCodes = orgTeamEngineerDao.findAllByTeamId(levelValue).stream()
.map(OrgTeamEngineerEntity::getEngineerCode).collect(Collectors.toList());
engineers = engineerInfoDao.findByEngineerCodeIn(engineerCodes);
break;
case "group":
engineers = engineerInfoDao.findByGroupId(levelValue);
break;
case "branch":
groupIds = orgGroupDao.findAllByBranchId(levelValue).stream()
.map(OrgGroupEntity::getGroupId).collect(Collectors.toList());
engineers = engineerInfoDao.findByGroupIdIn(groupIds);
break;
default:
// "cluster".equals(levelType)
groupIds = orgGroupDao.findAllByClusterId(levelValue).stream()
.map(OrgGroupEntity::getGroupId).collect(Collectors.toList());
engineers = engineerInfoDao.findByGroupIdIn(groupIds);
break;
}
List<EngineerInfoEntity> engineers = engineerUtil.getEngineesByLevel(levelType, levelValue);
List<OrganizationEngineersDTO.Engineer> engineers1 = engineers.stream().map(entity -> {
return new OrganizationEngineersDTO.Engineer()
.setEngineerCode(entity.getEngineerCode())
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!