Browse Source

排班第三版接口增加

master
walton 4 months ago
parent
commit
df689228b3
  1. 7
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/duty/entity/ImsDutyMainEntity.java
  2. 42
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/duty/vo/ImsSchedulingNewVo.java
  3. 51
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/controller/ImsDutyMainController.java
  4. 2
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/IImsDutyMainService.java
  5. 237
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyMainServiceImpl.java

7
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/duty/entity/ImsDutyMainEntity.java

@ -37,7 +37,9 @@ public class ImsDutyMainEntity extends TenantEntity {
@ApiModelProperty(value = "值班组id")
private Long dutyGroupId;
@TableField(exist = false)
@ApiModelProperty(value = "值班组名称")
private String dutyGroupName;
/**
* 值班人IDS, ID之间用^隔开
*/
@ -72,4 +74,7 @@ public class ImsDutyMainEntity extends TenantEntity {
@ApiModelProperty(value = "备注")
private String remark;
@TableField(exist = false)
private Long manageId;//值班长id
}

42
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/duty/vo/ImsSchedulingNewVo.java

@ -0,0 +1,42 @@
package com.hnac.hzims.operational.duty.vo;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.NullSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
@Data
public class ImsSchedulingNewVo implements Serializable {
@ApiModelProperty(value = "班组ID 通过^隔开",required = true)
private String groupIds;
// @ApiModelProperty(value = "班组名称 通过^隔开",required = true)
// private String groupNames;
@ApiModelProperty(value = "班次ID 通过^隔开",required = true)
private String classIds;
@ApiModelProperty(value = "班次名称 通过^隔开",required = true)
private String classNames;
@ApiModelProperty(value = "开始时间",required = true)
private String startDate;
@ApiModelProperty(value = "结束时间",required = true)
private String endDate;
private Long deptId;//机构id
@ApiModelProperty("人员类型: 1、班组 2 、人员")
private Integer personType;
//人员组
List<Map<String,String>> personIds; //人员用 managerId 值长id personIds 人员ids 多个^隔开(不包含值长id)
@ApiModelProperty("班次类型ID")
@JsonSerialize(nullsUsing = NullSerializer.class)
private Long dutyClassTypeId;
}

51
hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/controller/ImsDutyMainController.java

@ -11,10 +11,7 @@ import com.hnac.hzims.operational.duty.entity.ImsDutyMainReportExcel;
import com.hnac.hzims.operational.duty.service.IImsDutyMainService;
import com.hnac.hzims.operational.duty.utils.ExcelMergeHandler;
import com.hnac.hzims.operational.duty.utils.ExcelTool;
import com.hnac.hzims.operational.duty.vo.ChangeDutyMainVo;
import com.hnac.hzims.operational.duty.vo.ExchangeGroupLeader;
import com.hnac.hzims.operational.duty.vo.HomePageDutyMainInfoVo;
import com.hnac.hzims.operational.duty.vo.ImsSchedulingVo;
import com.hnac.hzims.operational.duty.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@ -122,36 +119,36 @@ public class ImsDutyMainController extends BladeController {
return imsDutyMainService.getSchedulingV2(imsSchedulingVo);
}
/**
* 导入排班
*/
@PostMapping("/importScheduling")
@PostMapping("/schedulingNew")
@ApiOperationSupport(order = 8)
@ApiOperation(value = "导入排班管理(适用一天一班的情况)", notes = "")
public R importScheduling(@RequestParam("file")MultipartFile file,
@RequestParam("yearMonth") String yearMonth,////yearMonth格式 yyyy-MM
@RequestParam("deptId") Long deptId
) {
if(StringUtils.isBlank(yearMonth)){
return R.fail("请选择年月");
@ApiOperation(value = "排班管理", notes = "")
public R schedulingNew(@Valid @RequestBody ImsSchedulingNewVo vo) {
if (null == vo.getDeptId()) {
return R.fail("请选择机构");
}
if(deptId == null){
return R.fail("请选择部门");
if (null == AuthUtil.getTenantId()) {
return R.fail("请登录");
}
return imsDutyMainService.importScheduling(file,yearMonth,deptId);
return imsDutyMainService.getSchedulingV3(vo);
}
// /**
// * 排班管理
// */
// @PostMapping("/scheduling")
/**
* 导入排班
*/
// @PostMapping("/importScheduling")
// @ApiOperationSupport(order = 8)
// @ApiOperation(value = "排班管理", notes = "")
// public R schedulingV2(@Valid @RequestBody ImsSchedulingVo imsSchedulingVo) {
// if (null == imsSchedulingVo.getCreateDept()) {
// imsSchedulingVo.setCreateDept(Long.valueOf(AuthUtil.getDeptId()));
// @ApiOperation(value = "导入排班管理(适用一天一班的情况)", notes = "")
// public R importScheduling(@RequestParam("file")MultipartFile file,
// @RequestParam("yearMonth") String yearMonth,////yearMonth格式 yyyy-MM
// @RequestParam("deptId") Long deptId
// ) {
// if(StringUtils.isBlank(yearMonth)){
// return R.fail("请选择年月");
// }
// if(deptId == null){
// return R.fail("请选择部门");
// }
// return imsDutyMainService.getScheduling(imsSchedulingVo);
// return imsDutyMainService.importScheduling(file,yearMonth,deptId);
// }
/**

2
hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/IImsDutyMainService.java

@ -62,6 +62,8 @@ public interface IImsDutyMainService extends BaseService<ImsDutyMainEntity> {
R getSchedulingV2(ImsSchedulingVo imsSchedulingVo);
R getSchedulingV3(ImsSchedulingNewVo vo);
R importScheduling(MultipartFile file,String yearMonth,Long deptId);
R getSchedulingList(int year, int month, Long deptId);

237
hzims-service/operational/src/main/java/com/hnac/hzims/operational/duty/service/impl/ImsDutyMainServiceImpl.java

@ -45,6 +45,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.sql.Time;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
@ -303,6 +304,242 @@ public class ImsDutyMainServiceImpl extends BaseServiceImpl<ImsDutyMainMapper, I
}
@Override
public R getSchedulingV3(ImsSchedulingNewVo vo) {
String startDate=vo.getStartDate();
String endDate=vo.getEndDate();
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
try {
Date start=sdf.parse(startDate);
Date end=sdf.parse(endDate);
Date now=new Date();
if(start.compareTo(now) <= 0){
return R.fail("开始时间应从明天开始");
}
if(end.compareTo(now) <= 0){
return R.fail("结束时间应从明天开始");
}
}catch (Exception e){
return R.fail("开始时间格式不对");
}
//判断是否符合排班规则。
String[] start = startDate.split("-");
String[] end = endDate.split("-");
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH) + 1;//获取月份
int day = cal.get(Calendar.DAY_OF_MONTH);
String date1 = getDate(year, month, day);
String date2 = DateUtils.dayStringDate(date1, 1, true);
if (!vo.getStartDate().equals(date2)) {
String minusOnedDay = DateUtils.dayStringDate(vo.getStartDate(), 1, false);
log.info("--------------Auth:" + AuthUtil.getDeptId() + "--------createDept:" + vo.getDeptId());
List<ImsDutyMainEntity> imsDutyMainEntities = this.baseMapper.selectByDateAndDept(minusOnedDay, vo.getDeptId());
if (CollectionUtil.isEmpty(imsDutyMainEntities)) {
return R.fail("所选日期之前存在未排班情况,请重新选择日期区间!");
}
}
List<String> dates = getTwoPeriodsAll(Integer.valueOf(start[0]), Integer.valueOf(start[1]), Integer.valueOf(start[2]), Integer.valueOf(end[0]), Integer.valueOf(end[1]), Integer.valueOf(end[2]));
if (Integer.valueOf(start[0]) < year) {
return R.fail("年份必须大于或等于当前年份!");
}
if (Integer.valueOf(start[0]) == year && Integer.valueOf(start[1]) < month) {
return R.fail("时间必须大于或等于当前时间");
}
List<ImsDutyMainEntity> imsDutyMainEntities2 = this.baseMapper.selectList(new LambdaQueryWrapper<ImsDutyMainEntity>() {{
ge(ImsDutyMainEntity::getDutyDate, vo.getStartDate());
le(ImsDutyMainEntity::getDutyDate, vo.getEndDate());
eq(ImsDutyMainEntity::getCreateDept, vo.getDeptId());
}});
List<ImsDutyMainPersonEntity> imsDutyMainPersonEntities = imsDutyMainPersonMapper.selectList(new LambdaQueryWrapper<ImsDutyMainPersonEntity>() {{
ge(ImsDutyMainPersonEntity::getDutyDate, vo.getStartDate());
le(ImsDutyMainPersonEntity::getDutyDate, vo.getEndDate());
eq(ImsDutyMainPersonEntity::getCreateDept, vo.getDeptId());
}});
if (CollectionUtil.isNotEmpty(imsDutyMainPersonEntities) || CollectionUtil.isNotEmpty(imsDutyMainEntities2)) {
if (CollectionUtil.isNotEmpty(dates)) {
//重新修改已有的排版,先删除,在添加
this.baseMapper.delete(new LambdaQueryWrapper<ImsDutyMainEntity>() {{
eq(ImsDutyMainEntity::getCreateDept, vo.getDeptId());
in(ImsDutyMainEntity::getDutyDate, dates);
}});
imsDutyMainPersonMapper.delete(new LambdaQueryWrapper<ImsDutyMainPersonEntity>() {{
in(ImsDutyMainPersonEntity::getDutyDate, dates);
eq(ImsDutyMainPersonEntity::getCreateDept, vo.getDeptId());
}});
}
}
String subDayDate = DateUtils.dayDate(DateUtil.parse(vo.getStartDate(), DateUtil.PATTERN_DATE), -1, DateUtil.PATTERN_DATE);
//获取最后一个排班的信息
ImsDutyMainEntity preDutyMain = this.baseMapper.selectOne(new LambdaQueryWrapper<ImsDutyMainEntity>() {{
eq(ImsDutyMainEntity::getDutyDate, subDayDate);
eq(ImsDutyMainEntity::getCreateDept, vo.getDeptId());
ne(ImsDutyMainEntity::getStatus, "-1");
orderByDesc(ImsDutyMainEntity::getId).last("LIMIT 1");
}});
String proDutyMainId=null;
List<ImsDutyMainEntity> imsDutyMainEntityList=getImsDutyMainEntityList(vo,dates);
if(imsDutyMainEntityList!=null && !imsDutyMainEntityList.isEmpty()){
ImsDutyMainEntity entity=imsDutyMainEntityList.get(0);
if(preDutyMain!=null) {
Long dutyMainId = preDutyMain.getId();
proDutyMainId =String.valueOf(dutyMainId);
entity.setPreDutyId(dutyMainId);
}
dealCreator(entity,vo.getDeptId());
}else{
return R.fail("排班失败");
}
//统一处理preDutyId
for(int i=1,count=imsDutyMainEntityList.size();i<count;i++){
ImsDutyMainEntity entity=imsDutyMainEntityList.get(i);
dealCreator(entity,vo.getDeptId());
ImsDutyMainEntity preEntity=imsDutyMainEntityList.get(i-1);
entity.setPreDutyId(preEntity.getId());
}
// this.saveBatch(imsDutyMainEntityList);
List<ImsDutyMainPersonEntity> mainPersonEntityList=new ArrayList<>();
for(ImsDutyMainEntity imsDutyMainEntity:imsDutyMainEntityList) {
String[] personIds=imsDutyMainEntity.getDutyPersonIds().split("\\^");
List<Long> collect=Arrays.asList(personIds).stream().map(e->Long.valueOf(e)).collect(Collectors.toList());
//每个人员对应一条排班-人员计划
for (Long personId : collect) {
ImsDutyMainPersonEntity imsDutyMainPersonEntity = new ImsDutyMainPersonEntity();
imsDutyMainPersonEntity.setClassId(imsDutyMainEntity.getClassId());
imsDutyMainPersonEntity.setCreateDept(imsDutyMainEntity.getCreateDept());
imsDutyMainPersonEntity.setDutyGroupName(imsDutyMainEntity.getDutyGroupName());
imsDutyMainPersonEntity.setDutyGroupId(imsDutyMainEntity.getDutyGroupId());
imsDutyMainPersonEntity.setDutyDate(imsDutyMainEntity.getDutyDate());
imsDutyMainPersonEntity.setStatus(imsDutyMainEntity.getStatus());
imsDutyMainPersonEntity.setCreateTime(imsDutyMainEntity.getCreateTime());
imsDutyMainPersonEntity.setDutyMainId(imsDutyMainEntity.getId());
imsDutyMainPersonEntity.setCreateUser(imsDutyMainEntity.getCreateUser());
imsDutyMainPersonEntity.setUpdateUser(imsDutyMainEntity.getUpdateUser());
imsDutyMainPersonEntity.setTenantId(imsDutyMainEntity.getTenantId());
imsDutyMainPersonEntity.setDutyPerson(personId);
long id1 = IdWorker.getId(imsDutyMainPersonEntity);
imsDutyMainPersonEntity.setId(id1);
imsDutyMainPersonEntity.setDutyChargePerson(imsDutyMainEntity.getManageId());
mainPersonEntityList.add(imsDutyMainPersonEntity);
}
}
log.error("=排班====imsDutyMainEntityList{}====mainPersonEntityList:{}",imsDutyMainEntityList,mainPersonEntityList);
ThreadTask.dutyTask(imsDutyMainEntityList, mainPersonEntityList, vo.getEndDate(), proDutyMainId, vo.getDeptId(), vo.getDutyClassTypeId());
return R.success("排班成功");
}
private void dealCreator(ImsDutyMainEntity entity,Long deptId){
entity.setCreateDept(deptId);
entity.setCreateUser(AuthUtil.getUserId());
entity.setCreateTime(new Date());
entity.setTenantId(AuthUtil.getTenantId());
entity.setIsDeleted(0);
entity.setStatus(0);
entity.setUpdateUser(AuthUtil.getUserId());
entity.setUpdateTime(new Date());
}
private List<ImsDutyMainEntity> getImsDutyMainEntityList(ImsSchedulingNewVo vo,List<String> dates){
List<ImsDutyMainEntity> list=new ArrayList<>();
////班次信息
String[] classIdArr=vo.getClassIds().split("\\^");
List<Long> classIds=Arrays.asList(classIdArr).stream().map(e->Long.valueOf(e)).collect(Collectors.toList());
String[] classNameArr=vo.getClassNames().split("\\^");
Map<Long,String> classMap=new HashMap<>();
for(int i=0;i<classIds.size();i++){
classMap.put(classIds.get(i),classNameArr[i]);
}
if(vo.getPersonType().intValue() == 1){//班组
String[] groupIdsArr=vo.getGroupIds().split("\\^");
List<Long> groupIds=Arrays.asList(groupIdsArr).stream().map(e->Long.valueOf(e)).collect(Collectors.toList());
LambdaQueryWrapper<ImsDutyGroupEntity> groupWrapper=new LambdaQueryWrapper<>();
groupWrapper.in(ImsDutyGroupEntity::getId,groupIds);
List<ImsDutyGroupEntity> groupEntities=dutyGroupMapper.selectList(groupWrapper);
Map<Long,ImsDutyGroupEntity> groupMap=groupEntities.stream().collect(Collectors.toMap(ImsDutyGroupEntity::getId,Function.identity()));
List<ImsDutyGroupPEntity> groupPEntities = imsDutyGroupPService.selectByGroupIds(groupIds);
Map<Long,List<ImsDutyGroupPEntity>> personMap=groupPEntities.stream().collect(Collectors.groupingBy(ImsDutyGroupPEntity::getGroupId));
//班组信息
List<Map<String,String>> groups=new ArrayList<>();
for(Long groupId :groupIds){
Map<String,String> map=new HashMap<>();
map.put("groupId",String.valueOf(groupId));
ImsDutyGroupEntity groupEntity=groupMap.get(groupId);
map.put("groupName",groupEntity.getGroupName());
map.put("managerId",String.valueOf(groupEntity.getManagerId()));
List<ImsDutyGroupPEntity> groupPList=personMap.get(groupId);
List<String> personIds=groupPList.stream().map(e->String.valueOf(e.getPersonId())).collect(Collectors.toList());
String personStrIds=personIds.stream().collect(Collectors.joining("^"));
map.put("personIds",personStrIds);//包含了值长id
groups.add(map);
}
dealImsDutyMainEntityList(list,dates,classIds,groups,classMap);
}else if(vo.getPersonType().intValue() == 2){//人员
List<Map<String,String>> persons=vo.getPersonIds();
for(Map<String,String> person:persons){
String personIds=person.get("personIds");
person.put("personIds",person.get("managerId")+"^"+personIds);
}
dealImsDutyMainEntityList(list,dates,classIds,persons,classMap);
}
return list;
}
private void dealImsDutyMainEntityList(List<ImsDutyMainEntity> list,List<String> dates,
List<Long> classIds,
List<Map<String,String>> persons,Map<Long,String> classMap){
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
int dateCount=dates.size();
int classCount=classIds.size();
int count=dateCount * classCount;//总工共排多少个
List<Map<String,String>> allPerson=new ArrayList<>();//总数队列
while (allPerson.size() < count){
for(Map<String,String> person:persons){
allPerson.add(person);
}
}
try {
for (int i = 0; i < dateCount; i++) {
String ts = dates.get(i);
for (int j = 0; j < classCount; j++) {
int personIndex = (i * classCount) + j;
Map<String, String> person = allPerson.get(personIndex);
Long classId = classIds.get(j);
ImsDutyMainEntity res = new ImsDutyMainEntity();
res.setId(IdWorker.getId());
if (person.get("groupId") != null) {
res.setDutyGroupId(Long.valueOf(person.get("groupId").toString()));
}
if (person.get("groupName") != null) {
res.setDutyGroupName(person.get("groupName").toString());
}
res.setDutyPersonIds(person.get("personIds"));
res.setDutyDate(sdf.parse(ts));
res.setClassId(classId);
res.setClassName(classMap.get(classId));
res.setManageId(Long.valueOf(person.get("managerId")));
list.add(res);
}
}
}catch (ParseException e){
log.error("日期格式不对");
}
}
@Override
public R importScheduling(MultipartFile file,String yearMonth,Long deptId) {
String filename = file.getOriginalFilename();
ExcelToolListener excelToolListener = new ExcelToolListener();

Loading…
Cancel
Save