Commit a5c106de authored by kongfm's avatar kongfm

BUG 2807 更新人员车辆排版值班的保存逻辑 如果没有填写数据则保存空数据 。 同步修改 查询 导出相关逻辑 by kongfm 2021-09-14

parent 62698a38
...@@ -46,4 +46,10 @@ public class DutyCarDto implements Serializable { ...@@ -46,4 +46,10 @@ public class DutyCarDto implements Serializable {
@ApiModelProperty(value = "值班信息") @ApiModelProperty(value = "值班信息")
private List<DutyPersonShiftDto> dutyShift = new ArrayList<>(); private List<DutyPersonShiftDto> dutyShift = new ArrayList<>();
// BUG 2807 更新人员车辆排版值班的保存逻辑 如果没有填写数据则保存空数据 。 同步修改 查询 导出相关逻辑 by kongfm 2021-09-14
@ApiModelProperty(value = "值班开始时间")
private String startTime;
@ApiModelProperty(value = "值班结束时间")
private String endTime;
} }
...@@ -39,4 +39,10 @@ public class DutyPersonDto implements Serializable { ...@@ -39,4 +39,10 @@ public class DutyPersonDto implements Serializable {
@ApiModelProperty(value = "值班信息") @ApiModelProperty(value = "值班信息")
private List<DutyPersonShiftDto> dutyShift; private List<DutyPersonShiftDto> dutyShift;
// BUG 2807 更新人员车辆排版值班的保存逻辑 如果没有填写数据则保存空数据 。 同步修改 查询 导出相关逻辑 by kongfm 2021-09-14
@ApiModelProperty(value = "值班开始时间")
private String startTime;
@ApiModelProperty(value = "值班结束时间")
private String endTime;
} }
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
AND i.field_code = 'userId' AND i.field_code = 'userId'
and s.duty_date >= #{beginDate} and s.duty_date >= #{beginDate}
and s.duty_date <![CDATA[<=]]> #{endDate} and s.duty_date <![CDATA[<=]]> #{endDate}
AND s.shift_id is not null <!--// BUG 2807 更新人员车辆排版值班的保存逻辑 如果没有填写数据则保存空数据 。 同步修改 查询 导出相关逻辑 by kongfm 2021-09-14-->
and s.app_Key = #{appKey} and s.app_Key = #{appKey}
GROUP BY s.duty_date,s.shift_id <!--增添分组条件 根据班次分组技术 --> GROUP BY s.duty_date,s.shift_id <!--增添分组条件 根据班次分组技术 -->
) a) as maxDutyPersonNumDay, ) a) as maxDutyPersonNumDay,
...@@ -56,6 +57,7 @@ ...@@ -56,6 +57,7 @@
AND ds.sequence_nbr = s.shift_id AND ds.sequence_nbr = s.shift_id
AND i.field_code = 'userName' AND i.field_code = 'userName'
AND s.duty_date = #{dutyDate} AND s.duty_date = #{dutyDate}
AND s.shift_id is not null
AND s.app_key = #{appKey} AND s.app_key = #{appKey}
and i.group_code =#{groupCode} and i.group_code =#{groupCode}
GROUP BY GROUP BY
...@@ -76,6 +78,7 @@ ...@@ -76,6 +78,7 @@
s.instance_id = i.instance_id s.instance_id = i.instance_id
and i.field_code = 'postTypeName' and i.field_code = 'postTypeName'
AND s.duty_date = #{dutyDate} AND s.duty_date = #{dutyDate}
AND s.shift_id is not null
AND s.app_key = #{appKey} AND s.app_key = #{appKey}
and i.group_code =#{groupCode} and i.group_code =#{groupCode}
GROUP BY i.field_value GROUP BY i.field_value
......
...@@ -134,7 +134,7 @@ public class DutyCarController extends BaseController { ...@@ -134,7 +134,7 @@ public class DutyCarController extends BaseController {
* @return ResponseModel * @return ResponseModel
*/ */
@TycloudOperation(ApiLevel = UserType.AGENCY) @TycloudOperation(ApiLevel = UserType.AGENCY)
@DeleteMapping("/{instanceId}") @DeleteMapping("/{instanceId}/{startTime}/{endTime}")
@ApiOperation(httpMethod = "DELETE", value = "值班数据删除", notes = "值班数据删除") @ApiOperation(httpMethod = "DELETE", value = "值班数据删除", notes = "值班数据删除")
public ResponseModel deleteDutyData(@PathVariable Long instanceId,@PathVariable String startTime,@PathVariable String endTime) { public ResponseModel deleteDutyData(@PathVariable Long instanceId,@PathVariable String startTime,@PathVariable String endTime) {
if (ValidationUtil.isEmpty(instanceId) if (ValidationUtil.isEmpty(instanceId)
......
...@@ -14,12 +14,14 @@ import com.yeejoin.amos.boot.module.common.api.service.IDutyCarService; ...@@ -14,12 +14,14 @@ import com.yeejoin.amos.boot.module.common.api.service.IDutyCarService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.core.foundation.context.RequestContext; import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.utils.Bean; import org.typroject.tyboot.core.foundation.utils.Bean;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil; import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -49,14 +51,71 @@ public class DutyCarServiceImpl extends DutyCommonServiceImpl implements IDutyCa ...@@ -49,14 +51,71 @@ public class DutyCarServiceImpl extends DutyCommonServiceImpl implements IDutyCa
@Override @Override
public DutyCarDto save(DutyCarDto dutyCarDto) { public DutyCarDto save(DutyCarDto dutyCarDto) {
// BUG 2807 更新人员车辆排版值班的保存逻辑 如果没有填写数据则保存空数据 。 同步修改 查询 导出相关逻辑 by kongfm 2021-09-14
//1.保存行数据 //1.保存行数据
String groupCode = this.getGroupCode(); String groupCode = this.getGroupCode();
String userId = dutyCarDto.getUserId();
List<DynamicFormInstance> instances = dynamicFormInstanceService
.list(new LambdaQueryWrapper<DynamicFormInstance>().eq(DynamicFormInstance::getFieldCode, "userId")
.eq(DynamicFormInstance::getFieldValue, userId)
.eq(DynamicFormInstance::getGroupCode, this.getGroupCode()));
Long instanceId = null;
Map<String, Object> map = Bean.BeantoMap(dutyCarDto); Map<String, Object> map = Bean.BeantoMap(dutyCarDto);
Long instanceId = dynamicFormInstanceService.commonSave(groupCode,map); if (!instances.isEmpty()) {
// 0.定位instanceId,准备进行更新操作
instanceId = instances.get(0).getInstanceId(); // 已经有了走更新方法
//1.查询已有数据
List<DynamicFormInstance> hasInstances = dynamicFormInstanceService.list(new LambdaQueryWrapper<DynamicFormInstance>().eq(DynamicFormInstance::getInstanceId, instanceId));
//2.list 转 map
Map<Object, DynamicFormInstance> instanceMap = Bean.listToMap(hasInstances, "fieldCode", DynamicFormInstance.class);
//3.查询列数据,已列为主
List<DynamicFormColumn> columns = dynamicFormColumnService.list(new LambdaQueryWrapper<DynamicFormColumn>().eq(DynamicFormColumn::getGroupCode, groupCode));
//4.已列为主 填充动态表单数据
List<DynamicFormInstance> entrys = new ArrayList<>();
for (DynamicFormColumn column : columns) {
DynamicFormInstance formInstance = instanceMap.get(column.getFieldCode());
if (!ObjectUtils.isEmpty(formInstance)) {
//有的更新
formInstance.setFieldValue(map.get(column.getFieldCode()) != null ? map.get(column.getFieldCode()).toString() : "");
} else {
//没有的新增
formInstance = new DynamicFormInstance();
buildFormInstanceData(instanceId, map, column, formInstance);
}
entrys.add(formInstance);
}
if(!entrys.isEmpty()){
dynamicFormInstanceService.saveOrUpdateBatch(entrys);
}
} else {
instanceId = dynamicFormInstanceService.commonSave(groupCode,map);
}
if(dutyCarDto.getDutyShift() != null && dutyCarDto.getDutyShift().size() == 0) {
Calendar startDate = Calendar.getInstance();
startDate.setTime(DateUtils.longStr2Date(dutyCarDto.getStartTime()));
int dates = startDate.getActualMaximum(Calendar.DAY_OF_MONTH);
startDate.set(Calendar.DAY_OF_MONTH, 1);
List<DutyPersonShift> dutyShift = new ArrayList<>(dates);
for (int i = 0 ; i < dates ; i ++) {
DutyPersonShift temp = new DutyPersonShift();
temp.setAppKey(RequestContext.getAppKey());
temp.setDutyDate(startDate.getTime());
temp.setIsDelete(false);
temp.setInstanceId(instanceId);
dutyShift.add(temp);
startDate.add(Calendar.DAY_OF_YEAR,1);
}
dutyPersonShiftService.saveOrUpdateBatch(dutyShift);
}
//2.保存值班信息 //2.保存值班信息
insertPersonShift(instanceId, dutyCarDto); insertPersonShift(instanceId, dutyCarDto);
//3.返回保存后的数据 //3.返回保存后的数据
return dutyCarDto; return dutyCarDto;
} }
@Override @Override
...@@ -83,7 +142,12 @@ public class DutyCarServiceImpl extends DutyCommonServiceImpl implements IDutyCa ...@@ -83,7 +142,12 @@ public class DutyCarServiceImpl extends DutyCommonServiceImpl implements IDutyCa
private void insertPersonShift(Long instanceId, DutyCarDto dutyCarDto) { private void insertPersonShift(Long instanceId, DutyCarDto dutyCarDto) {
Set<DutyPersonShift> personShiftList = dutyCarDto.getDutyShift().stream().map(dto -> { Set<DutyPersonShift> personShiftList = dutyCarDto.getDutyShift().stream().map(dto -> {
DutyPersonShift dutyPersonShift = new DutyPersonShift(); // BUG 2807 修改时发现BUG 车辆保存有问题 by kongfm 2021-09-14
// 根据instanceId 和 日期查找 如果有则更新
DutyPersonShift dutyPersonShift = dutyPersonShiftService.getOne(new LambdaQueryWrapper<DutyPersonShift>().eq(DutyPersonShift::getInstanceId,instanceId).eq(DutyPersonShift::getDutyDate,dto.getDutyDate()));
if(dutyPersonShift == null) {
dutyPersonShift = new DutyPersonShift();
}
dto.setInstanceId(instanceId); dto.setInstanceId(instanceId);
Bean.copyExistPropertis(dto, dutyPersonShift); Bean.copyExistPropertis(dto, dutyPersonShift);
dutyPersonShift.setAppKey(RequestContext.getAppKey()); dutyPersonShift.setAppKey(RequestContext.getAppKey());
......
...@@ -81,6 +81,13 @@ public class DutyCommonServiceImpl implements IDutyCommonService { ...@@ -81,6 +81,13 @@ public class DutyCommonServiceImpl implements IDutyCommonService {
for (Map<String, Object> m : iPage.getRecords()) { for (Map<String, Object> m : iPage.getRecords()) {
this.fillDutyShiftData(beginDate, endDate, m); this.fillDutyShiftData(beginDate, endDate, m);
} }
// BUG 2807 如果不存在值班数据则不显示
List<Map<String, Object>> list = iPage.getRecords();
list = list.stream().filter(m ->
m.get("dutyShift") != null && ((List<DutyPersonShiftDto>) m.get("dutyShift")).size() > 0
).collect(Collectors.toList());
iPage.setTotal(list.size());
iPage.setRecords(list);
return iPage; return iPage;
} }
...@@ -126,7 +133,7 @@ public class DutyCommonServiceImpl implements IDutyCommonService { ...@@ -126,7 +133,7 @@ public class DutyCommonServiceImpl implements IDutyCommonService {
Bean.copyExistPropertis(e, dto); Bean.copyExistPropertis(e, dto);
// 没值班信息,默认休 // 没值班信息,默认休
DutyShift dutyShift = keyNameMap.get(e.getShiftId()); DutyShift dutyShift = keyNameMap.get(e.getShiftId());
dto.setShiftName(dutyShift != null ? dutyShift.getName() : "休"); dto.setShiftName(dutyShift != null ? dutyShift.getName() : "休");
dto.setColor(dutyShift != null ? dutyShift.getColor() : ""); dto.setColor(dutyShift != null ? dutyShift.getColor() : "");
return dto; return dto;
}).collect(Collectors.toList()); }).collect(Collectors.toList());
...@@ -186,6 +193,11 @@ public class DutyCommonServiceImpl implements IDutyCommonService { ...@@ -186,6 +193,11 @@ public class DutyCommonServiceImpl implements IDutyCommonService {
for (Map<String, Object> map : list) { for (Map<String, Object> map : list) {
this.fillDutyShiftData(beginDate, endDate, map); this.fillDutyShiftData(beginDate, endDate, map);
} }
// BUG 2807 更新人员车辆排版值班的保存逻辑 如果没有填写数据则保存空数据 。 同步修改 查询 导出相关逻辑 by kongfm 2021-09-14
list = list.stream().filter(m ->
m.get("dutyShift") != null && ((List<DutyPersonShiftDto>) m.get("dutyShift")).size() > 0
).collect(Collectors.toList());
/*bug2472 添加根据部门id筛选数据的方法 陈浩 2021-08-21 开始 */ /*bug2472 添加根据部门id筛选数据的方法 陈浩 2021-08-21 开始 */
if(teamId!=null && teamId.intValue()!=0) { if(teamId!=null && teamId.intValue()!=0) {
List<OrgUsr> orgUsrList = orgUsrService.getPersonListByParentId(teamId); List<OrgUsr> orgUsrList = orgUsrService.getPersonListByParentId(teamId);
...@@ -211,6 +223,11 @@ public class DutyCommonServiceImpl implements IDutyCommonService { ...@@ -211,6 +223,11 @@ public class DutyCommonServiceImpl implements IDutyCommonService {
@Override @Override
public List downloadList(String beginDate, String endDate) throws ParseException { public List downloadList(String beginDate, String endDate) throws ParseException {
List<Map<String, Object>> maps = this.list(null,beginDate, endDate); List<Map<String, Object>> maps = this.list(null,beginDate, endDate);
// BUG 2807 如果不存在值班数据则不显示
maps = maps.stream().filter(m ->
m.get("dutyShift") != null && ((List<DutyPersonShiftDto>) m.get("dutyShift")).size() > 0
).collect(Collectors.toList());
JSONArray jsonArray = new JSONArray(); JSONArray jsonArray = new JSONArray();
jsonArray.addAll(maps); jsonArray.addAll(maps);
List<?> list = new ArrayList<>(); List<?> list = new ArrayList<>();
......
package com.yeejoin.amos.boot.module.common.biz.service.impl; package com.yeejoin.amos.boot.module.common.biz.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.module.common.api.dto.DutyPersonDto; import com.yeejoin.amos.boot.module.common.api.dto.DutyPersonDto;
import com.yeejoin.amos.boot.module.common.api.dto.DutyPersonShiftDto;
import com.yeejoin.amos.boot.module.common.api.entity.DutyPersonShift; import com.yeejoin.amos.boot.module.common.api.entity.DutyPersonShift;
import com.yeejoin.amos.boot.module.common.api.entity.DynamicFormColumn; import com.yeejoin.amos.boot.module.common.api.entity.DynamicFormColumn;
import com.yeejoin.amos.boot.module.common.api.entity.DynamicFormInstance; import com.yeejoin.amos.boot.module.common.api.entity.DynamicFormInstance;
...@@ -13,6 +15,7 @@ import org.typroject.tyboot.core.foundation.context.RequestContext; ...@@ -13,6 +15,7 @@ import org.typroject.tyboot.core.foundation.context.RequestContext;
import org.typroject.tyboot.core.foundation.utils.Bean; import org.typroject.tyboot.core.foundation.utils.Bean;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -31,14 +34,74 @@ public class DutyPersonServiceImpl extends DutyCommonServiceImpl implements IDut ...@@ -31,14 +34,74 @@ public class DutyPersonServiceImpl extends DutyCommonServiceImpl implements IDut
@Override @Override
public DutyPersonDto save(DutyPersonDto dutyPersonDto) { public DutyPersonDto save(DutyPersonDto dutyPersonDto) {
// BUG 2807 更新人员车辆排版值班的保存逻辑 如果没有填写数据则保存空数据 。 同步修改 查询 导出相关逻辑 by kongfm 2021-09-14
//1.保存行数据 //1.保存行数据
String groupCode = this.getGroupCode(); String groupCode = this.getGroupCode();
String userId = dutyPersonDto.getUserId();
List<DynamicFormInstance> instances = dynamicFormInstanceService
.list(new LambdaQueryWrapper<DynamicFormInstance>().eq(DynamicFormInstance::getFieldCode, "userId")
.eq(DynamicFormInstance::getFieldValue, userId)
.eq(DynamicFormInstance::getGroupCode, this.getGroupCode()));
Long instanceId = null;
Map<String, Object> map = Bean.BeantoMap(dutyPersonDto); Map<String, Object> map = Bean.BeantoMap(dutyPersonDto);
Long instanceId = dynamicFormInstanceService.commonSave(groupCode,map);
if (!instances.isEmpty()) {
// 0.定位instanceId,准备进行更新操作
instanceId = instances.get(0).getInstanceId(); // 已经有了走更新方法
//1.查询已有数据
List<DynamicFormInstance> hasInstances = dynamicFormInstanceService.list(new LambdaQueryWrapper<DynamicFormInstance>().eq(DynamicFormInstance::getInstanceId, instanceId));
//2.list 转 map
Map<Object, DynamicFormInstance> instanceMap = Bean.listToMap(hasInstances, "fieldCode", DynamicFormInstance.class);
//3.查询列数据,已列为主
List<DynamicFormColumn> columns = dynamicFormColumnService.list(new LambdaQueryWrapper<DynamicFormColumn>().eq(DynamicFormColumn::getGroupCode, groupCode));
//4.已列为主 填充动态表单数据
List<DynamicFormInstance> entrys = new ArrayList<>();
for (DynamicFormColumn column : columns) {
DynamicFormInstance formInstance = instanceMap.get(column.getFieldCode());
if (!ObjectUtils.isEmpty(formInstance)) {
//有的更新
formInstance.setFieldValue(map.get(column.getFieldCode()) != null ? map.get(column.getFieldCode()).toString() : "");
} else {
//没有的新增
formInstance = new DynamicFormInstance();
buildFormInstanceData(instanceId, map, column, formInstance);
}
entrys.add(formInstance);
}
if(!entrys.isEmpty()){
dynamicFormInstanceService.saveOrUpdateBatch(entrys);
}
} else {
instanceId = dynamicFormInstanceService.commonSave(groupCode,map);
}
// 如果当前保存没有保存调班记录 需要默认保存一个月的空数据
if(dutyPersonDto.getDutyShift() != null && dutyPersonDto.getDutyShift().size() == 0) {
Calendar startDate = Calendar.getInstance();
startDate.setTime(DateUtils.longStr2Date(dutyPersonDto.getStartTime()));
int dates = startDate.getActualMaximum(Calendar.DAY_OF_MONTH);
startDate.set(Calendar.DAY_OF_MONTH, 1);
List<DutyPersonShift> dutyShift = new ArrayList<>(dates);
for (int i = 0 ; i < dates ; i ++) {
DutyPersonShift temp = new DutyPersonShift();
temp.setAppKey(RequestContext.getAppKey());
temp.setDutyDate(startDate.getTime());
temp.setIsDelete(false);
temp.setInstanceId(instanceId);
dutyShift.add(temp);
startDate.add(Calendar.DAY_OF_YEAR,1);
}
dutyPersonShiftService.saveOrUpdateBatch(dutyShift);
}
//2.保存值班信息 //2.保存值班信息
insertPersonShift(instanceId, dutyPersonDto); insertPersonShift(instanceId, dutyPersonDto);
//3.返回保存后的数据 //3.返回保存后的数据
return dutyPersonDto; return dutyPersonDto;
} }
@Override @Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment