Commit 356fe707 authored by chenhao's avatar chenhao

修改bug 2472

parent 12dd8fae
......@@ -37,7 +37,7 @@ public interface IDutyCommonService {
* @param endDate 结束日期
* @return ResponseModel
*/
List<Map<String, Object>> list(String beginDate, String endDate) throws ParseException;
List<Map<String, Object>> list(Long teamId,String beginDate, String endDate) throws ParseException;
/**
* 获取表单参数
......
......@@ -16,177 +16,184 @@ import java.util.Map;
* @date 2021-06-18
*/
public interface IOrgUsrService {
/**
* 查询上级单位
*
* @param parent_id
* @return
*/
String selectUpUnitByParam(String parent_id);
/**
* 获取父级
*
* @param topId
* @param entityList
* @param packageURL
* @param IDMethodName
* @param IDHierarchy
* @param NAMEMethodName
* @param PARENTIDMethodName
* @param OrgTypeMethodName
* @return
* @throws Exception
*/
List<OrgMenuDto> getTree(Long topId, Collection entityList, String packageURL, String IDMethodName, int IDHierarchy,
String NAMEMethodName, String PARENTIDMethodName, String OrgTypeMethodName) throws Exception;
/**
* 获取子数据集合
*
* @param topId
* @param entityList
* @param packageURL
* @param IDMethodName
* @param IDHierarchy
* @param NAMEMethodName
* @param PARENTIDMethodName
* @param OrgTypeMethodName
* @return
* @throws Exception
*/
List<OrgMenuDto> getSub(Long topId, Collection entityList, String packageURL, String IDMethodName, int IDHierarchy,
String NAMEMethodName, String PARENTIDMethodName, String OrgTypeMethodName) throws Exception;
/**
* 组装融合调度单位人员信息
*
* @param ids
* @return
* @throws Exception
*/
List<Map<String, Object>> returnCompanyPersonMsg(List<Long> ids) throws Exception;
/**
* 获取动态表单数据
*
* @param id
* @return
* @throws Exception
*/
List<FormValue> getFormValue(Long id) throws Exception;
/**
* 保存 机构/部门/人员基本信息
*
* @param
* @throws Exception
*/
void saveOrgUsr(OrgUsr orgUsr, OrgUsr oriOrgUsr) throws Exception;
/**
* 新增机构/部门/人员基本信息和动态表单数据
*
* @param orgUsr
* @param alertFromValuelist
*/
void saveOrgUsrDynamicFormInstance(OrgUsr orgUsr, List<DynamicFormInstance> alertFromValuelist) throws Exception;
/**
* 更新机构/部门/人员基本信息和动态表单数据
*
* @param instanceId 实例id
* @param fromValueList 动态表单数据列表
* @throws Exception
*/
void updateDynamicFormInstance(Long instanceId, List<DynamicFormInstance> fromValueList) throws Exception;
/**
* @param id
* @throws Exception
*/
Map<String, Object> selectForShowById(OrgUsr orgUsr, Long id) throws Exception;
List<OrgUsr> selectCompanyDepartmentMsg();
void saveOrgUsr(OrgUsrDto OrgUsrDto) throws Exception;
void saveOrgPerson(OrgPersonDto OrgPersonDto) throws Exception;
void updateByIdOrgUsr(OrgUsrDto OrgUsrDto, Long id) throws Exception;
void updateByIdOrgPerson(OrgPersonDto OrgPersonDto, Long id) throws Exception;
OrgUsrFormDto selectCompanyById(Long id) throws Exception;
IPage bizOrgTypeListPage(String pageNum, String pageSize, String bizOrgType) throws Exception;
void saveDepartment(List<OrgDepartmentDto> OrgDepartmentDto, Long id) throws Exception;
void saveCompany(List<OrgUsrDto> OrgUsrDto) throws Exception;
OrgPersonFormDto selectPersonById(Long id) throws Exception;
OrgPersonFormDto selectPersonByIdDetail(Long id) throws Exception;
List<OrgMenuDto> selectPersonTree() throws Exception;
void savePersonList(List<OrgPersonDto> OrgPersonDto) throws Exception;
void saveOrgDepartment(OrgDepartmentDto OrgDepartmentDto) throws Exception;
void updateByIdOrgDepartment(OrgDepartmentDto OrgDepartmentDto, Long id) throws Exception;
OrgDepartmentFormDto selectDepartmentById(Long id) throws Exception;
List<Map<String, Object>> selectForShowByListId(List<Long> ids) throws Exception;
/**
* * @param null
*
* @return <PRE>
* author tw
* date 2021/7/20
* </PRE>
* 列表
*/
List<CompanyDto> listContractDto(Integer pageNum, Integer pageSize, RequestData requestData);
/**
* 查询上级单位
*
* @param parent_id
* @return
*/
String selectUpUnitByParam(String parent_id);
/**
* * @param null
*
* @return <PRE>
* author tw
* date 2021/7/20
* </PRE>
* 统计
*/
Integer listContractDtoCount(RequestData par);
/**
* 获取父级
*
* @param topId
* @param entityList
* @param packageURL
* @param IDMethodName
* @param IDHierarchy
* @param NAMEMethodName
* @param PARENTIDMethodName
* @param OrgTypeMethodName
* @return
* @throws Exception
*/
List<OrgMenuDto> getTree(Long topId, Collection entityList, String packageURL, String IDMethodName, int IDHierarchy,
String NAMEMethodName, String PARENTIDMethodName, String OrgTypeMethodName) throws Exception;
/**
* * @param null
*
* @return <PRE>
* author tw
* date 2021/7/26
* </PRE>
*/
/**
* 获取子数据集合
*
* @param topId
* @param entityList
* @param packageURL
* @param IDMethodName
* @param IDHierarchy
* @param NAMEMethodName
* @param PARENTIDMethodName
* @param OrgTypeMethodName
* @return
* @throws Exception
*/
List<OrgMenuDto> getSub(Long topId, Collection entityList, String packageURL, String IDMethodName, int IDHierarchy,
String NAMEMethodName, String PARENTIDMethodName, String OrgTypeMethodName) throws Exception;
List<OrgUsrzhDto> getOrgUsrzhDto(String name);
/**
* 组装融合调度单位人员信息
*
* @param ids
* @return
* @throws Exception
*/
List<Map<String, Object>> returnCompanyPersonMsg(List<Long> ids) throws Exception;
List<ESOrgUsrDto> selectByIddata(String name);
/**
* 获取动态表单数据
*
* @param id
* @return
* @throws Exception
*/
List<FormValue> getFormValue(Long id) throws Exception;
List<Map<String, Object>> getparent();
/**
* 保存 机构/部门/人员基本信息
*
* @param
* @throws Exception
*/
void saveOrgUsr(OrgUsr orgUsr, OrgUsr oriOrgUsr) throws Exception;
List<OrgUsrExcelDto> exportToExcel();
/**
* 新增机构/部门/人员基本信息和动态表单数据
*
* @param orgUsr
* @param alertFromValuelist
*/
void saveOrgUsrDynamicFormInstance(OrgUsr orgUsr, List<DynamicFormInstance> alertFromValuelist) throws Exception;
UserUnitDto getUserUnit(String userId);
/**
* 更新机构/部门/人员基本信息和动态表单数据
*
* @param instanceId 实例id
* @param fromValueList 动态表单数据列表
* @throws Exception
*/
void updateDynamicFormInstance(Long instanceId, List<DynamicFormInstance> fromValueList) throws Exception;
/**
* @param id
* @throws Exception
*/
Map<String, Object> selectForShowById(OrgUsr orgUsr, Long id) throws Exception;
List<OrgUsr> selectCompanyDepartmentMsg();
void saveOrgUsr(OrgUsrDto OrgUsrDto) throws Exception;
void saveOrgPerson(OrgPersonDto OrgPersonDto) throws Exception;
void updateByIdOrgUsr(OrgUsrDto OrgUsrDto, Long id) throws Exception;
void updateByIdOrgPerson(OrgPersonDto OrgPersonDto, Long id) throws Exception;
OrgUsrFormDto selectCompanyById(Long id) throws Exception;
IPage bizOrgTypeListPage(String pageNum, String pageSize, String bizOrgType) throws Exception;
void saveDepartment(List<OrgDepartmentDto> OrgDepartmentDto, Long id) throws Exception;
void saveCompany(List<OrgUsrDto> OrgUsrDto) throws Exception;
OrgPersonFormDto selectPersonById(Long id) throws Exception;
OrgPersonFormDto selectPersonByIdDetail(Long id) throws Exception;
List<OrgMenuDto> selectPersonTree() throws Exception;
void savePersonList(List<OrgPersonDto> OrgPersonDto) throws Exception;
void saveOrgDepartment(OrgDepartmentDto OrgDepartmentDto) throws Exception;
void updateByIdOrgDepartment(OrgDepartmentDto OrgDepartmentDto, Long id) throws Exception;
OrgDepartmentFormDto selectDepartmentById(Long id) throws Exception;
List<Map<String, Object>> selectForShowByListId(List<Long> ids) throws Exception;
/**
* * @param null
*
* @return
*
* <PRE>
* author tw
* date 2021/7/20
* </PRE>
*
* 列表
*/
List<CompanyDto> listContractDto(Integer pageNum, Integer pageSize, RequestData requestData);
/**
* * @param null
*
* @return
*
* <PRE>
* author tw
* date 2021/7/20
* </PRE>
*
* 统计
*/
Integer listContractDtoCount(RequestData par);
/**
* * @param null
*
* @return
*
* <PRE>
* author tw
* date 2021/7/26
* </PRE>
*/
List<OrgUsrzhDto> getOrgUsrzhDto(String name);
List<ESOrgUsrDto> selectByIddata(String name);
List<Map<String, Object>> getparent();
List<OrgUsrExcelDto> exportToExcel();
UserUnitDto getUserUnit(String userId);
/**
* 根据登陆人获取公司部门人员树
*/
List<OrgMenuDto> companyUserTreeByUser (AgencyUserModel user);
List<OrgMenuDto> companyUserTreeByUser(AgencyUserModel user);
/**
* 根据登陆人获取公司部门树
......@@ -198,4 +205,6 @@ public interface IOrgUsrService {
*/
List<OrgUsrTreeDto> companyListByUser(AgencyUserModel user);
List<OrgUsr> getPersonListByParentId(Long id);
}
......@@ -61,8 +61,9 @@ public class DutyPersonController extends BaseController {
@GetMapping(value = "/list")
@ApiOperation(httpMethod = "GET", value = "值班列表视图-不分页", notes = "值班列表视图-不分页")
public ResponseModel list(@ApiParam(value = "开始日期", required = true) @RequestParam String beginDate,
@ApiParam(value = "结束日期", required = true) @RequestParam String endDate) throws ParseException {
return ResponseHelper.buildResponse(iDutyPersonService.list(beginDate, endDate));
@ApiParam(value = "结束日期", required = true) @RequestParam String endDate,
@RequestParam(required = false) Long teamId) throws ParseException {
return ResponseHelper.buildResponse(iDutyPersonService.list(teamId,beginDate, endDate));
}
......
......@@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Sequence;
import com.yeejoin.amos.boot.biz.common.entity.BaseEntity;
import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.module.common.api.dto.CompanyPerson;
import com.yeejoin.amos.boot.module.common.api.dto.DutyCarDto;
import com.yeejoin.amos.boot.module.common.api.dto.DutyPersonDto;
import com.yeejoin.amos.boot.module.common.api.dto.DutyPersonShiftDto;
......@@ -14,6 +15,7 @@ import com.yeejoin.amos.boot.module.common.api.entity.DutyPersonShift;
import com.yeejoin.amos.boot.module.common.api.entity.DutyShift;
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.OrgUsr;
import com.yeejoin.amos.boot.module.common.api.enums.DutyViewTypeEnum;
import com.yeejoin.amos.boot.module.common.api.service.IDutyCommonService;
......@@ -39,325 +41,342 @@ import java.util.stream.Collectors;
@Transactional(rollbackFor = Exception.class)
public class DutyCommonServiceImpl implements IDutyCommonService {
@Autowired
DynamicFormColumnServiceImpl dynamicFormColumnService;
@Autowired
DynamicFormColumnServiceImpl dynamicFormColumnService;
@Autowired
DynamicFormInstanceServiceImpl dynamicFormInstanceService;
@Autowired
DynamicFormInstanceServiceImpl dynamicFormInstanceService;
@Autowired
DutyPersonShiftServiceImpl dutyPersonShiftService;
@Autowired
DutyPersonShiftServiceImpl dutyPersonShiftService;
@Autowired
Sequence sequence;
@Autowired
Sequence sequence;
@Autowired
HttpServletRequest request;
@Autowired
HttpServletRequest request;
@Autowired
DutyShiftServiceImpl dutyShiftService;
@Autowired
DutyShiftServiceImpl dutyShiftService;
@Autowired
OrgUsrServiceImpl orgUsrService;
@Autowired
OrgUsrServiceImpl orgUsrService;
/**
* 每天单个班次执勤人数全部小于等于3人
*/
final int LIMIT_PERSON_NUMBER = 3;
/**
* 每天单个班次执勤人数全部小于等于3人
*/
final int LIMIT_PERSON_NUMBER = 3;
/**
* 班次小于等于2
*/
final int LIMIT_SHIFT_NUMBER = 2;
/**
* 班次小于等于2
*/
final int LIMIT_SHIFT_NUMBER = 2;
@Override
public IPage<Map<String, Object>> pageList(int current, int size, String beginDate, String endDate)
throws ParseException {
// 1.已column为准 进行返回
String groupCode = this.getGroupCode();
IPage<Map<String, Object>> iPage = dynamicFormInstanceService.pageList(current, size, groupCode);
for (Map<String, Object> m : iPage.getRecords()) {
this.fillDutyShiftData(beginDate, endDate, m);
}
return iPage;
}
@Override
public IPage<Map<String, Object>> pageList(int current, int size, String beginDate, String endDate) throws ParseException {
//1.已column为准 进行返回
String groupCode = this.getGroupCode();
IPage<Map<String, Object>> iPage = dynamicFormInstanceService.pageList(current, size, groupCode);
for (Map<String, Object> m : iPage.getRecords()) {
this.fillDutyShiftData(beginDate, endDate, m);
}
return iPage;
}
private void fillDutyShiftData(String beginDate, String endDate, Map<String, Object> m) throws ParseException {
String instanceId = m.get("instanceId").toString();
List<DutyShift> dutyShifts = dutyShiftService.list(new LambdaQueryWrapper<DutyShift>()
.eq(BaseEntity::getIsDelete, false).eq(DutyShift::getAppKey, RequestContext.getAppKey()));
Map<Long, DutyShift> keyNameMap = dutyShifts.stream()
.collect(Collectors.toMap(BaseEntity::getSequenceNbr, Function.identity()));
List<DutyPersonShiftDto> personShiftList = dutyPersonShiftService
.list(new LambdaQueryWrapper<DutyPersonShift>().eq(DutyPersonShift::getInstanceId, instanceId)
.ge(beginDate != null, DutyPersonShift::getDutyDate, beginDate)
.le(endDate != null, DutyPersonShift::getDutyDate, endDate))
.stream().map(e -> {
DutyPersonShiftDto dto = new DutyPersonShiftDto();
Bean.copyExistPropertis(e, dto);
// 没值班信息,默认休
DutyShift dutyShift = keyNameMap.get(e.getShiftId());
dto.setShiftName(dutyShift != null ? dutyShift.getName() : "休");
dto.setColor(dutyShift != null ? dutyShift.getColor() : "");
return dto;
}).collect(Collectors.toList());
m.put("dutyShift", personShiftList);
}
private void fillDutyShiftData(String beginDate, String endDate, Map<String, Object> m) throws ParseException {
String instanceId = m.get("instanceId").toString();
List<DutyShift> dutyShifts =
dutyShiftService.list(new LambdaQueryWrapper<DutyShift>().eq(BaseEntity::getIsDelete, false).eq(DutyShift::getAppKey, RequestContext.getAppKey()));
Map<Long, DutyShift> keyNameMap = dutyShifts.stream().collect(Collectors.toMap(BaseEntity::getSequenceNbr,
Function.identity()));
List<DutyPersonShiftDto> personShiftList = dutyPersonShiftService.list(new LambdaQueryWrapper<DutyPersonShift>()
.eq(DutyPersonShift::getInstanceId, instanceId)
.ge(beginDate != null, DutyPersonShift::getDutyDate, beginDate)
.le(endDate != null, DutyPersonShift::getDutyDate, endDate)).stream().map(e -> {
DutyPersonShiftDto dto = new DutyPersonShiftDto();
Bean.copyExistPropertis(e, dto);
//没值班信息,默认休
DutyShift dutyShift = keyNameMap.get(e.getShiftId());
dto.setShiftName(dutyShift != null ? dutyShift.getName() : "休");
dto.setColor(dutyShift != null ? dutyShift.getColor() : "");
return dto;
}).collect(Collectors.toList());
m.put("dutyShift", personShiftList);
}
@Override
public List<Map<String, Object>> statisticsDay(String beginDate, String endDate) throws ParseException {
DutyViewTypeEnum viewTypeEnum = this.inferView(beginDate, endDate, RequestContext.getAppKey());
List<Map<String, Object>> rangeDate = dutyPersonShiftService.getBaseMapper().genRangeDate(beginDate, endDate);
return rangeDate.stream().map(p -> {
Map<String, Object> result = new LinkedHashMap<>();
result.put("key", p.get("date"));
result.put("viewType", viewTypeEnum.getCode());
result.put("data", this.buildViewData(viewTypeEnum, p.get("date").toString(), RequestContext.getAppKey()));
return result;
}).collect(Collectors.toList());
}
@Override
public List<Map<String, Object>> statisticsDay(String beginDate, String endDate) throws ParseException {
DutyViewTypeEnum viewTypeEnum = this.inferView(beginDate, endDate, RequestContext.getAppKey());
List<Map<String, Object>> rangeDate = dutyPersonShiftService.getBaseMapper().genRangeDate(beginDate, endDate);
return rangeDate.stream().map(p -> {
Map<String, Object> result = new LinkedHashMap<>();
result.put("key", p.get("date"));
result.put("viewType", viewTypeEnum.getCode());
result.put("data", this.buildViewData(viewTypeEnum, p.get("date").toString(), RequestContext.getAppKey()));
return result;
}).collect(Collectors.toList());
}
private Object buildViewData(DutyViewTypeEnum viewTypeEnum, String dutyDate, String appKey) {
List<Map<String, Object>> result = new ArrayList<>();
switch (viewTypeEnum) {
case BANK:
result = dutyPersonShiftService.getBaseMapper().bankViewData(dutyDate, appKey, this.getGroupCode());
break;
case STATION:
result = dutyPersonShiftService.getBaseMapper().stationViewData(dutyDate, appKey, this.getGroupCode());
break;
default:
break;
}
return result;
}
private Object buildViewData(DutyViewTypeEnum viewTypeEnum, String dutyDate, String appKey) {
List<Map<String, Object>> result = new ArrayList<>();
switch (viewTypeEnum) {
case BANK:
result = dutyPersonShiftService.getBaseMapper().bankViewData(dutyDate, appKey, this.getGroupCode());
break;
case STATION:
result = dutyPersonShiftService.getBaseMapper().stationViewData(dutyDate, appKey, this.getGroupCode());
break;
default:
break;
}
return result;
}
private DutyViewTypeEnum inferView(String beginDate, String endDate, String appKey) {
Map<String, Long> result = dutyPersonShiftService.getBaseMapper().calMaxPersonAndShiftNum(beginDate, endDate,
appKey, this.getGroupCode());
// 计算班次最大执勤人数,时间区间内
Long maxDutyPersonNumDay = result.get("maxDutyPersonNumDay");
// 计算天的最大班次数量,时间区间内
Long maxShiftNumDay = result.get("maxShiftNumDay");
if (maxDutyPersonNumDay <= LIMIT_PERSON_NUMBER && maxShiftNumDay <= LIMIT_SHIFT_NUMBER) {
return DutyViewTypeEnum.BANK;
} else {
return DutyViewTypeEnum.STATION;
}
}
private DutyViewTypeEnum inferView(String beginDate, String endDate, String appKey) {
Map<String, Long> result = dutyPersonShiftService.getBaseMapper().calMaxPersonAndShiftNum(beginDate, endDate,
appKey, this.getGroupCode());
//计算班次最大执勤人数,时间区间内
Long maxDutyPersonNumDay = result.get("maxDutyPersonNumDay");
//计算天的最大班次数量,时间区间内
Long maxShiftNumDay = result.get("maxShiftNumDay");
if (maxDutyPersonNumDay <= LIMIT_PERSON_NUMBER && maxShiftNumDay <= LIMIT_SHIFT_NUMBER) {
return DutyViewTypeEnum.BANK;
} else {
return DutyViewTypeEnum.STATION;
}
}
@Override
public List<Map<String, Object>> list(Long teamId, String beginDate, String endDate) throws ParseException {
// 1.已column为准 进行返回
String groupCode = this.getGroupCode();
List<Map<String, Object>> list = dynamicFormInstanceService.listAll(groupCode);
// 2.组织值班数据
for (Map<String, Object> map : list) {
this.fillDutyShiftData(beginDate, endDate, map);
}
/*bug2472 添加根据部门id筛选数据的方法 陈浩 2021-08-21 开始 */
if(teamId!=null && teamId.intValue()!=0) {
List<OrgUsr> orgUsrList = orgUsrService.getPersonListByParentId(teamId);
List<Map<String, Object>> resultList= new ArrayList<Map<String, Object>>();
list.stream().forEach(i->{
orgUsrList.forEach(m->{
if(i.get("userId").toString().equals(m.getSequenceNbr().longValue()+"")) {
resultList.add(i);
}
});
});
return resultList;
}
/*bug2472 添加根据部门id筛选数据的方法 陈浩 2021-08-21 结束 */
return list;
}
@Override
public List<Map<String, Object>> list(String beginDate, String endDate) throws ParseException {
//1.已column为准 进行返回
String groupCode = this.getGroupCode();
List<Map<String, Object>> list = dynamicFormInstanceService.listAll(groupCode);
//2.组织值班数据
for (Map<String, Object> map : list) {
this.fillDutyShiftData(beginDate, endDate, map);
}
return list;
}
@Override
public String getGroupCode() {
return null;
}
@Override
public String getGroupCode() {
return null;
}
@Override
public List downloadList(String beginDate, String endDate) throws ParseException {
List<Map<String, Object>> maps = this.list(null,beginDate, endDate);
JSONArray jsonArray = new JSONArray();
jsonArray.addAll(maps);
List<?> list = new ArrayList<>();
String groupCode = this.getGroupCode();
String fileName;
if ("dutyCar".equals(groupCode)) {
list = jsonArray.toJavaList(DutyCarDto.class);
} else {
list = jsonArray.toJavaList(DutyPersonDto.class);
}
return list;
}
@Override
public List downloadList(String beginDate, String endDate) throws ParseException {
List<Map<String, Object>> maps = this.list(beginDate, endDate);
JSONArray jsonArray = new JSONArray();
jsonArray.addAll(maps);
List<?> list = new ArrayList<>();
String groupCode = this.getGroupCode();
String fileName;
if ("dutyCar".equals(groupCode)) {
list = jsonArray.toJavaList(DutyCarDto.class);
} else {
list = jsonArray.toJavaList(DutyPersonDto.class);
}
return list;
}
@Override
public void saveImportData(List<Map<String, Object>> dataList) {
List<DynamicFormInstance> formInstanceList = new ArrayList<>();
Set<DutyPersonShift> dutyPersonShifts = new HashSet<>();
dataList.forEach(d -> {
// TODO: 业务唯一索引,用户id
String userId = d.get("userId").toString();
List<DynamicFormInstance> instances = dynamicFormInstanceService
.list(new LambdaQueryWrapper<DynamicFormInstance>().eq(DynamicFormInstance::getFieldCode, "userId")
.eq(DynamicFormInstance::getFieldValue, userId)
.eq(DynamicFormInstance::getGroupCode, this.getGroupCode()));
Long instanceId = null;
List<DynamicFormColumn> columns = dynamicFormColumnService.list(new LambdaQueryWrapper<DynamicFormColumn>()
.eq(DynamicFormColumn::getGroupCode, this.getGroupCode()));
// 1.组装动态表单数据
if (!instances.isEmpty()) {
// 0.定位instanceId,准备进行更新操作
instanceId = instances.get(0).getInstanceId();
// 1.查询已有数据
List<DynamicFormInstance> instancesInDb = dynamicFormInstanceService
.list(new LambdaQueryWrapper<DynamicFormInstance>().eq(DynamicFormInstance::getInstanceId,
instanceId));
// 2.list 转 map
Map<Object, DynamicFormInstance> instanceMap = Bean.listToMap(instancesInDb, "fieldCode",
DynamicFormInstance.class);
// 3.待更新数据组装,待批量入库
this.updateFormValue(formInstanceList, d, instanceId, columns, instanceMap);
} else {
// 0.新数据,生成id
instanceId = sequence.nextId();
Long finalInstanceId1 = instanceId;
// 1.组装数据
List<DynamicFormInstance> newInstances = columns.stream().map(column -> {
DynamicFormInstance instance = new DynamicFormInstance();
buildFormInstanceData(finalInstanceId1, d, column, instance);
return instance;
}).collect(Collectors.toList());
// 2.待更新数据组装,待批量入库
formInstanceList.addAll(newInstances);
}
// 2.组装值班数据
List<DutyPersonShiftDto> shiftDtos = (List<DutyPersonShiftDto>) d.get("dutyShift");
Long finalInstanceId = instanceId;
// 按照业务唯一索引查询主键
List<DutyPersonShift> dutyPersonShiftsDb = dutyPersonShiftService
.list(new LambdaQueryWrapper<DutyPersonShift>().eq(DutyPersonShift::getInstanceId, instanceId));
Map<Date, Long> dutyPersonShiftMap = dutyPersonShiftsDb.stream()
.collect(Collectors.toMap(DutyPersonShift::getDutyDate, DutyPersonShift::getSequenceNbr));
// todo: 只更新当天及值班之后数据
Set<DutyPersonShift> needToDb = shiftDtos.stream()
.filter(s -> DateUtils.dateCompare(s.getDutyDate(), new Date()) >= 0).map(shiftDto -> {
DutyPersonShift dutyPersonShift = new DutyPersonShift();
Bean.copyExistPropertis(shiftDto, dutyPersonShift);
dutyPersonShift.setInstanceId(finalInstanceId);
dutyPersonShift.setAppKey(RequestContext.getAppKey());
dutyPersonShift.setSequenceNbr(dutyPersonShiftMap.get(dutyPersonShift.getDutyDate()));
return dutyPersonShift;
}).collect(Collectors.toSet());
dutyPersonShifts.addAll(needToDb);
});
if (!formInstanceList.isEmpty()) {
dynamicFormInstanceService.saveOrUpdateBatch(formInstanceList);
}
if (!dutyPersonShifts.isEmpty()) {
dutyPersonShiftService.saveOrUpdateBatch(dutyPersonShifts);
}
}
@Override
public void saveImportData(List<Map<String, Object>> dataList) {
List<DynamicFormInstance> formInstanceList = new ArrayList<>();
Set<DutyPersonShift> dutyPersonShifts = new HashSet<>();
dataList.forEach(d -> {
//TODO: 业务唯一索引,用户id
String userId = d.get("userId").toString();
List<DynamicFormInstance> instances =
dynamicFormInstanceService.list(new LambdaQueryWrapper<DynamicFormInstance>()
.eq(DynamicFormInstance::getFieldCode, "userId")
.eq(DynamicFormInstance::getFieldValue, userId)
.eq(DynamicFormInstance::getGroupCode, this.getGroupCode()));
Long instanceId = null;
List<DynamicFormColumn> columns =
dynamicFormColumnService.list(new LambdaQueryWrapper<DynamicFormColumn>().eq(DynamicFormColumn::getGroupCode, this.getGroupCode()));
//1.组装动态表单数据
if (!instances.isEmpty()) {
//0.定位instanceId,准备进行更新操作
instanceId = instances.get(0).getInstanceId();
//1.查询已有数据
List<DynamicFormInstance> instancesInDb =
dynamicFormInstanceService.list(new LambdaQueryWrapper<DynamicFormInstance>().eq(DynamicFormInstance::getInstanceId, instanceId));
//2.list 转 map
Map<Object, DynamicFormInstance> instanceMap = Bean.listToMap(instancesInDb, "fieldCode",
DynamicFormInstance.class);
//3.待更新数据组装,待批量入库
this.updateFormValue(formInstanceList, d, instanceId, columns, instanceMap);
} else {
//0.新数据,生成id
instanceId = sequence.nextId();
Long finalInstanceId1 = instanceId;
//1.组装数据
List<DynamicFormInstance> newInstances = columns.stream().map(column -> {
DynamicFormInstance instance = new DynamicFormInstance();
buildFormInstanceData(finalInstanceId1, d, column, instance);
return instance;
}).collect(Collectors.toList());
//2.待更新数据组装,待批量入库
formInstanceList.addAll(newInstances);
}
//2.组装值班数据
List<DutyPersonShiftDto> shiftDtos = (List<DutyPersonShiftDto>) d.get("dutyShift");
Long finalInstanceId = instanceId;
//按照业务唯一索引查询主键
List<DutyPersonShift> dutyPersonShiftsDb =
dutyPersonShiftService.list(new LambdaQueryWrapper<DutyPersonShift>().eq(DutyPersonShift::getInstanceId, instanceId));
Map<Date, Long> dutyPersonShiftMap =
dutyPersonShiftsDb.stream().collect(Collectors.toMap(DutyPersonShift::getDutyDate,
DutyPersonShift::getSequenceNbr));
//todo: 只更新当天及值班之后数据
Set<DutyPersonShift> needToDb = shiftDtos.stream().filter(s -> DateUtils.dateCompare(s.getDutyDate(),
new Date()) >= 0).map(shiftDto -> {
DutyPersonShift dutyPersonShift = new DutyPersonShift();
Bean.copyExistPropertis(shiftDto, dutyPersonShift);
dutyPersonShift.setInstanceId(finalInstanceId);
dutyPersonShift.setAppKey(RequestContext.getAppKey());
dutyPersonShift.setSequenceNbr(dutyPersonShiftMap.get(dutyPersonShift.getDutyDate()));
return dutyPersonShift;
}).collect(Collectors.toSet());
dutyPersonShifts.addAll(needToDb);
});
if (!formInstanceList.isEmpty()) {
dynamicFormInstanceService.saveOrUpdateBatch(formInstanceList);
}
if (!dutyPersonShifts.isEmpty()) {
dutyPersonShiftService.saveOrUpdateBatch(dutyPersonShifts);
}
}
public void updateFormValue(List<DynamicFormInstance> formInstanceList, Map<String, Object> d, Long instanceId,
List<DynamicFormColumn> columns, Map<Object, DynamicFormInstance> instanceMap) {
for (DynamicFormColumn column : columns) {
DynamicFormInstance formInstance = instanceMap.get(column.getFieldCode());
if (!ObjectUtils.isEmpty(formInstance)) {
// 有的更新
formInstance.setFieldValue(
d.get(column.getFieldCode()) != null ? d.get(column.getFieldCode()).toString() : "");
} else {
// 没有的新增
formInstance = new DynamicFormInstance();
buildFormInstanceData(instanceId, d, column, formInstance);
}
formInstanceList.add(formInstance);
}
}
public void updateFormValue(List<DynamicFormInstance> formInstanceList, Map<String, Object> d, Long instanceId,
List<DynamicFormColumn> columns, Map<Object, DynamicFormInstance> instanceMap) {
for (DynamicFormColumn column : columns) {
DynamicFormInstance formInstance = instanceMap.get(column.getFieldCode());
if (!ObjectUtils.isEmpty(formInstance)) {
//有的更新
formInstance.setFieldValue(d.get(column.getFieldCode()) != null ?
d.get(column.getFieldCode()).toString() : "");
} else {
//没有的新增
formInstance = new DynamicFormInstance();
buildFormInstanceData(instanceId, d, column, formInstance);
}
formInstanceList.add(formInstance);
}
}
private void buildFormInstanceData(Long instanceId, Map<String, Object> map, DynamicFormColumn column,
DynamicFormInstance formInstance) {
fillFormInstanceData(instanceId, map, column, formInstance, sequence.nextId());
}
private void buildFormInstanceData(Long instanceId, Map<String, Object> map, DynamicFormColumn column,
DynamicFormInstance formInstance) {
fillFormInstanceData(instanceId, map, column, formInstance, sequence.nextId());
}
static void fillFormInstanceData(Long instanceId, Map<String, Object> map, DynamicFormColumn column,
DynamicFormInstance formInstance, long l) {
Bean.copyExistPropertis(column, formInstance);
formInstance.setAppKey(RequestContext.getAppKey());
formInstance.setInstanceId(instanceId);
formInstance.setSequenceNbr(l);
formInstance.setFormColumnId(column.getSequenceNbr());
formInstance
.setFieldValue(map.get(column.getFieldCode()) != null ? map.get(column.getFieldCode()).toString() : "");
}
static void fillFormInstanceData(Long instanceId, Map<String, Object> map, DynamicFormColumn column,
DynamicFormInstance formInstance, long l) {
Bean.copyExistPropertis(column, formInstance);
formInstance.setAppKey(RequestContext.getAppKey());
formInstance.setInstanceId(instanceId);
formInstance.setSequenceNbr(l);
formInstance.setFormColumnId(column.getSequenceNbr());
formInstance.setFieldValue(map.get(column.getFieldCode()) != null ?
map.get(column.getFieldCode()).toString() : "");
}
@Override
public Boolean deleteDutyData(Long instanceId) {
dynamicFormInstanceService.remove(
new LambdaQueryWrapper<DynamicFormInstance>().eq(DynamicFormInstance::getInstanceId, instanceId));
dutyPersonShiftService
.remove(new LambdaQueryWrapper<DutyPersonShift>().eq(DutyPersonShift::getInstanceId, instanceId));
return true;
}
@Override
public Boolean deleteDutyData(Long instanceId) {
dynamicFormInstanceService.remove(new LambdaQueryWrapper<DynamicFormInstance>().eq(DynamicFormInstance::getInstanceId, instanceId));
dutyPersonShiftService.remove(new LambdaQueryWrapper<DutyPersonShift>().eq(DutyPersonShift::getInstanceId,
instanceId));
return true;
}
@Override
public List<Map<String, Object>> dayDutyPersonList(String dutyDay, Long shiftId, String postType) {
String groupCode = this.getGroupCode();
Map<String, String> params = new HashMap<>();
params.put("postType", postType);
List<DynamicFormColumn> columns = dynamicFormColumnService
.list(new LambdaQueryWrapper<DynamicFormColumn>().eq(DynamicFormColumn::getGroupCode, groupCode));
Map<String, Object> fieldCodes = Bean.listToMap(columns, "fieldCode", "queryStrategy", DynamicFormColumn.class);
return dynamicFormInstanceService.getBaseMapper().listOneDayDutyPerson(dutyDay, shiftId, fieldCodes,
RequestContext.getAppKey(), groupCode, params);
}
@Override
public List<Map<String, Object>> dayDutyPersonList(String dutyDay, Long shiftId, String postType) {
String groupCode = this.getGroupCode();
Map<String, String> params = new HashMap<>();
params.put("postType", postType);
List<DynamicFormColumn> columns =
dynamicFormColumnService.list(new LambdaQueryWrapper<DynamicFormColumn>().eq(DynamicFormColumn::getGroupCode, groupCode));
Map<String, Object> fieldCodes = Bean.listToMap(columns, "fieldCode", "queryStrategy", DynamicFormColumn.class);
return dynamicFormInstanceService.getBaseMapper().listOneDayDutyPerson(dutyDay, shiftId, fieldCodes,
RequestContext.getAppKey(), groupCode, params);
}
@Override
public List<Map<String, Object>> listOnDutyPerson() {
String groupCode = this.getGroupCode();
// 获取当前班次列表
DateTime now = new DateTime();
List<Long> shiftIdList = getOnDuty(now);
String shiftIds = StringUtils.join(shiftIdList.toArray(), ",");
String dutyDay = now.toString("yyyy-MM-dd");
// 获取当前值班人员
List<DynamicFormColumn> columns = dynamicFormColumnService
.list(new LambdaQueryWrapper<DynamicFormColumn>().eq(DynamicFormColumn::getGroupCode, groupCode));
Map<String, Object> fieldCodes = Bean.listToMap(columns, "fieldCode", "queryStrategy", DynamicFormColumn.class);
List<Map<String, Object>> maps = dynamicFormInstanceService.getBaseMapper().listOnDutyPerson(dutyDay, shiftIds,
fieldCodes, groupCode);
// 获取人员照片和电话
List<Long> ids = new ArrayList<>();
maps.forEach(item -> ids.add(Long.valueOf(String.valueOf(item.get("userId")))));
try {
List<Map<String, Object>> orgUsrList = orgUsrService.selectForShowByListId(ids);
maps.forEach(item -> {
String userId = String.valueOf(item.get("userId"));
for (Map<String, Object> usr : orgUsrList) {
if (userId.equals(String.valueOf(usr.get("sequenceNbr")))) {
item.put("personImg", usr.get("personImg"));
item.put("telephone", usr.get("telephone"));
break;
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
return maps;
}
@Override
public List<Map<String, Object>> listOnDutyPerson() {
String groupCode = this.getGroupCode();
// 获取当前班次列表
DateTime now = new DateTime();
List<Long> shiftIdList = getOnDuty(now);
String shiftIds = StringUtils.join(shiftIdList.toArray(), ",");
String dutyDay = now.toString("yyyy-MM-dd");
// 获取当前值班人员
List<DynamicFormColumn> columns =
dynamicFormColumnService.list(new LambdaQueryWrapper<DynamicFormColumn>().eq(DynamicFormColumn::getGroupCode, groupCode));
Map<String, Object> fieldCodes = Bean.listToMap(columns, "fieldCode", "queryStrategy", DynamicFormColumn.class);
List<Map<String, Object>> maps = dynamicFormInstanceService.getBaseMapper().listOnDutyPerson(dutyDay,
shiftIds, fieldCodes, groupCode);
// 获取人员照片和电话
List<Long> ids = new ArrayList<>();
maps.forEach(item -> ids.add(Long.valueOf(String.valueOf(item.get("userId")))));
try {
List<Map<String, Object>> orgUsrList = orgUsrService.selectForShowByListId(ids);
maps.forEach(item -> {
String userId = String.valueOf(item.get("userId"));
for (Map<String, Object> usr : orgUsrList) {
if (userId.equals(String.valueOf(usr.get("sequenceNbr")))) {
item.put("personImg", usr.get("personImg"));
item.put("telephone", usr.get("telephone"));
break;
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
return maps;
}
private List<Long> getOnDuty(DateTime now) {
List<DutyShiftDto> dutyShiftDtos = dutyShiftService.queryForDutyShiftList(false);
List<Long> shiftIds = new ArrayList<>();
int hour = now.getHourOfDay();
int minute = now.getMinuteOfHour();
dutyShiftDtos.forEach(item -> {
String[] start = item.getStartTime().split(": ");
String[] startTime = start[1].split(":");
Integer startHour = Integer.valueOf(startTime[0]);
Integer startMinute = Integer.valueOf(startTime[1]);
String[] end = item.getEndTime().split(": ");
String[] endTime = end[1].split(":");
Integer endHour = Integer.valueOf(endTime[0]);
Integer endMinute = Integer.valueOf(endTime[1]);
if ("当日".equals(start[0])) {
if (hour > startHour || hour == startHour && minute > startMinute) {
if ("次日".equals(end[0]) || "当日".equals(end[0]) && (hour < endHour || hour == endHour && minute < endMinute)) {
shiftIds.add(item.getSequenceNbr());
}
}
}
});
return shiftIds;
}
private List<Long> getOnDuty(DateTime now) {
List<DutyShiftDto> dutyShiftDtos = dutyShiftService.queryForDutyShiftList(false);
List<Long> shiftIds = new ArrayList<>();
int hour = now.getHourOfDay();
int minute = now.getMinuteOfHour();
dutyShiftDtos.forEach(item -> {
String[] start = item.getStartTime().split(": ");
String[] startTime = start[1].split(":");
Integer startHour = Integer.valueOf(startTime[0]);
Integer startMinute = Integer.valueOf(startTime[1]);
String[] end = item.getEndTime().split(": ");
String[] endTime = end[1].split(":");
Integer endHour = Integer.valueOf(endTime[0]);
Integer endMinute = Integer.valueOf(endTime[1]);
if ("当日".equals(start[0])) {
if (hour > startHour || hour == startHour && minute > startMinute) {
if ("次日".equals(end[0])
|| "当日".equals(end[0]) && (hour < endHour || hour == endHour && minute < endMinute)) {
shiftIds.add(item.getSequenceNbr());
}
}
}
});
return shiftIds;
}
}
......@@ -20,6 +20,9 @@ import com.yeejoin.amos.boot.module.common.api.service.IOrgUsrService;
import com.yeejoin.amos.feign.privilege.Privilege;
import com.yeejoin.amos.feign.privilege.model.AgencyUserModel;
import com.yeejoin.amos.feign.privilege.model.RoleModel;
import net.bytebuddy.asm.Advice.This;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -1294,6 +1297,22 @@ public class OrgUsrServiceImpl extends BaseService<OrgUsrDto, OrgUsr, OrgUsrMapp
return pid;
}
/**
* 查询组织机构下面的人员信息
* @param id
* @return
*/
public List<OrgUsr> getPersonListByParentId(Long id) {
LambdaQueryWrapper<OrgUsr> wrapper = new LambdaQueryWrapper<OrgUsr>();
wrapper.eq(OrgUsr::getIsDelete, false);
wrapper.eq(OrgUsr::getParentId,id);
wrapper.eq(OrgUsr::getBizOrgType, OrgPersonEnum.人员.getKey());
return this.baseMapper.selectList(wrapper);
}
}
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