Commit 5d52e8dc authored by 付培阳's avatar 付培阳

今日值班列表查询接口

parent 1f1b440f
spring.application.name=JCS spring.application.name=JCS_FPY
server.servlet.context-path=/jcs server.servlet.context-path=/jcs
server.port=11100 server.port=11100
spring.profiles.active=dev spring.profiles.active=dev
......
...@@ -70,4 +70,20 @@ public interface DynamicFormInstanceMapper extends BaseMapper<DynamicFormInstanc ...@@ -70,4 +70,20 @@ public interface DynamicFormInstanceMapper extends BaseMapper<DynamicFormInstanc
@Param("appKey") String appKey, @Param("appKey") String appKey,
@Param("groupCode") String groupCode, @Param("groupCode") String groupCode,
@Param("params") Map<String, String> params); @Param("params") Map<String, String> params);
/**
* 查询当前值班信息
* @param dutyDay 值班日期
* @param shiftIds 班次id
* @param fieldCodes 动态列
* @param appKey 应用标识
* @param groupCode 表单类型
* @return List<Map < String, Object>>
*/
List<Map<String, Object>> listOnDutyPerson(
@Param("dutyDate") String dutyDay,
@Param("shiftId") String shiftIds,
@Param("fieldCodes") Map<String, Object> fieldCodes,
@Param("appKey") String appKey,
@Param("groupCode") String groupCode);
} }
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.yeejoin.amos.boot.module.common.api.mapper.DynamicFormInstanceMapper"> <mapper namespace="com.yeejoin.amos.boot.module.common.api.mapper.DynamicFormInstanceMapper">
<select id="selectListByCalledId" resultType="com.yeejoin.amos.boot.module.common.api.dto.DynamicFormInstanceDto"> <select id="selectListByCalledId" resultType="com.yeejoin.amos.boot.module.common.api.dto.DynamicFormInstanceDto">
SELECT SELECT v.sequence_nbr sequenceNbr,
v.sequence_nbr sequenceNbr, v.form_column_id formColumnId,
v.form_column_id formColumnId, v.instance_id instanceId,
v.instance_id instanceId, v.group_code groupCode,
v.group_code groupCode, v.field_name fieldName,
v.field_name fieldName, v.field_code fieldCode,
v.field_code fieldCode, v.field_value fieldValue,
v.field_value fieldValue, v.field_value_label fieldValueLabel,
v.field_value_label fieldValueLabel, v.rec_user_name recUserName,
v.rec_user_name recUserName, v.rec_user_id recUserId,
v.rec_user_id recUserId, v.rec_date recDate,
v.rec_date recDate, v.is_delete isDelete,
v.is_delete isDelete, v.block block,
v.block block, f.field_type fieldType
f.field_type fieldType FROM cb_dynamic_form_instance v
FROM LEFT JOIN cb_dynamic_form_column f ON f.sequence_nbr = v.form_column_id
cb_dynamic_form_instance v WHERE v.instance_id = #{id}
LEFT JOIN cb_dynamic_form_column f ON f.sequence_nbr = v.form_column_id </select>
WHERE v.instance_id=#{id} <select id="listAll" resultType="java.util.Map">
</select> select
<select id="listAll" resultType="java.util.Map"> d.*
select from
d.* (
from select
( i.INSTANCE_ID instanceId,
select i.GROUP_CODE groupCode,
i.INSTANCE_ID instanceId, <foreach collection="fieldCodes" item="value" index="key" separator=",">
i.GROUP_CODE groupCode, MAX(CASE WHEN i.FIELD_CODE = #{key} THEN i.FIELD_VALUE END) as ${key}
<foreach collection="fieldCodes" item="value" index="key" separator=","> </foreach>
MAX(CASE WHEN i.FIELD_CODE = #{key} THEN i.FIELD_VALUE END) as ${key} from
</foreach> cb_dynamic_form_instance i
from where i.GROUP_CODE = #{groupCode}
cb_dynamic_form_instance i and i.APP_KEY = #{appKey}
where i.GROUP_CODE = #{groupCode} GROUP by
and i.APP_KEY = #{appKey} i.INSTANCE_ID)d
GROUP by <if test="params != null and params.size() > 0">
i.INSTANCE_ID)d where
<if test="params != null and params.size() > 0"> 1=1
where <foreach collection="params" index="key" item="value" separator="">
1=1 <choose>
<foreach collection="params" index="key" item="value" separator=""> <when test="fieldCodes[key] == 'like' and value !=null and value !=''">
<choose> and d.${key} like concat('%',#{value},'%')
<when test="fieldCodes[key] == 'like' and value !=null and value !=''"> </when>
and d.${key} like concat('%',#{value},'%') <when test="fieldCodes[key] == 'eq' and value !=null and value !=''">
</when> and d.${key} = #{value}
<when test="fieldCodes[key] == 'eq' and value !=null and value !=''"> </when>
and d.${key} = #{value} </choose>
</when> </foreach>
</choose> </if>
</foreach> order by instanceId desc
</if> </select>
order by instanceId desc <select id="pageList" resultType="java.util.Map">
</select> select
<select id="pageList" resultType="java.util.Map"> d.*
select from
d.* (
from select
( i.INSTANCE_ID instanceId,
select i.GROUP_CODE groupCode,
i.INSTANCE_ID instanceId, <foreach collection="fieldCodes" item="value" index="key" separator=",">
i.GROUP_CODE groupCode, MAX(CASE WHEN i.FIELD_CODE = #{key} THEN i.FIELD_VALUE END) as ${key}
<foreach collection="fieldCodes" item="value" index="key" separator=","> </foreach>
MAX(CASE WHEN i.FIELD_CODE = #{key} THEN i.FIELD_VALUE END) as ${key} from
</foreach> cb_dynamic_form_instance i
from where
cb_dynamic_form_instance i i.GROUP_CODE = #{groupCode}
where <if test="appKey != null and appKey !=''">
i.GROUP_CODE = #{groupCode} and i.APP_KEY = #{appKey}
<if test="appKey != null and appKey !=''"> </if>
and i.APP_KEY = #{appKey} GROUP by
</if> i.INSTANCE_ID)d
GROUP by <if test="params != null and params.size() > 0">
i.INSTANCE_ID)d where
<if test="params != null and params.size() > 0"> 1=1
where <foreach collection="params" index="key" item="value" separator="">
1=1 <choose>
<foreach collection="params" index="key" item="value" separator=""> <when test="fieldCodes[key] == 'like' and value !=null and value !=''">
<choose> and d.${key} like concat('%',#{value},'%')
<when test="fieldCodes[key] == 'like' and value !=null and value !=''"> </when>
and d.${key} like concat('%',#{value},'%') <when test="fieldCodes[key] == 'eq' and value !=null and value !=''">
</when> and d.${key} = #{value}
<when test="fieldCodes[key] == 'eq' and value !=null and value !=''"> </when>
and d.${key} = #{value} </choose>
</when> </foreach>
</choose> </if>
</foreach> order by instanceId desc
</if> </select>
order by instanceId desc <select id="listOneDayDutyPerson" resultType="java.util.Map">
</select> select
<select id="listOneDayDutyPerson" resultType="java.util.Map"> d.*,
select ps.shift_id as shiftId,
d.*, ps.duty_date as dutyDate,
ps.shift_id as shiftId, ds.name as shiftName
ps.duty_date as dutyDate, from
ds.name as shiftName (
from select
( i.INSTANCE_ID instanceId,
select i.GROUP_CODE groupCode,
i.INSTANCE_ID instanceId, <foreach collection="fieldCodes" item="value" index="key" separator=",">
i.GROUP_CODE groupCode, MAX(CASE WHEN i.FIELD_CODE = #{key} THEN i.FIELD_VALUE END) as ${key}
<foreach collection="fieldCodes" item="value" index="key" separator=","> </foreach>
MAX(CASE WHEN i.FIELD_CODE = #{key} THEN i.FIELD_VALUE END) as ${key} from
</foreach> cb_dynamic_form_instance i
from where i.GROUP_CODE = #{groupCode}
cb_dynamic_form_instance i and i.APP_KEY = #{appKey}
where i.GROUP_CODE = #{groupCode} GROUP by
and i.APP_KEY = #{appKey} i.INSTANCE_ID ) d,
GROUP by cb_duty_person_shift ps,
i.INSTANCE_ID ) d, cb_duty_shift ds
cb_duty_person_shift ps, where
cb_duty_shift ds d.instanceId = ps.instance_id
where and ps.shift_id = ds.sequence_nbr
d.instanceId = ps.instance_id and ps.duty_date = #{dutyDate}
and ps.shift_id = ds.sequence_nbr <if test="shiftId != null and shiftId != ''">
and ps.duty_date = #{dutyDate} and ps.shift_id = #{shiftId}
<if test="shiftId != null and shiftId != ''"> </if>
and ps.shift_id = #{shiftId} <if test="params != null and params.size() > 0">
</if> <foreach collection="params" index="key" item="value" separator="">
<if test="params != null and params.size() > 0"> <choose>
<foreach collection="params" index="key" item="value" separator=""> <when test="fieldCodes[key] == 'like' and value !=null and value !=''">
<choose> and d.${key} like concat('%',#{value},'%')
<when test="fieldCodes[key] == 'like' and value !=null and value !=''"> </when>
and d.${key} like concat('%',#{value},'%') <when test="fieldCodes[key] == 'eq' and value !=null and value !=''">
</when> and d.${key} = #{value}
<when test="fieldCodes[key] == 'eq' and value !=null and value !=''"> </when>
and d.${key} = #{value} </choose>
</when> </foreach>
</choose> </if>
</foreach> order by instanceId desc
</if> </select>
order by instanceId desc <select id="listOnDutyPerson" resultType="java.util.Map">
</select> select
d.*,
ps.shift_id as shiftId,
ps.duty_date as dutyDate,
ds.name as shiftName
from
(
select
i.INSTANCE_ID instanceId,
i.GROUP_CODE groupCode,
<foreach collection="fieldCodes" item="value" index="key" separator=",">
MAX(CASE WHEN i.FIELD_CODE = #{key} THEN i.FIELD_VALUE END) as ${key}
</foreach>
from
cb_dynamic_form_instance i
where i.GROUP_CODE = #{groupCode}
and i.APP_KEY = #{appKey}
GROUP by
i.INSTANCE_ID ) d,
cb_duty_person_shift ps,
cb_duty_shift ds
where
d.instanceId = ps.instance_id
and ps.shift_id = ds.sequence_nbr
and ps.duty_date = #{dutyDate}
<if test="shiftId != null and shiftId != ''">
and ps.shift_id in (#{shiftId})
</if>
order by instanceId desc
</select>
</mapper> </mapper>
...@@ -14,6 +14,7 @@ import org.typroject.tyboot.core.restful.doc.TycloudOperation; ...@@ -14,6 +14,7 @@ import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper; import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.text.ParseException; import java.text.ParseException;
import java.util.List; import java.util.List;
...@@ -111,6 +112,7 @@ public class DutyPersonController extends BaseController { ...@@ -111,6 +112,7 @@ public class DutyPersonController extends BaseController {
/** /**
* 值班数据删除 * 值班数据删除
*
* @param instanceId 实例id * @param instanceId 实例id
* @return ResponseModel * @return ResponseModel
*/ */
...@@ -129,7 +131,8 @@ public class DutyPersonController extends BaseController { ...@@ -129,7 +131,8 @@ public class DutyPersonController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY) @TycloudOperation(ApiLevel = UserType.AGENCY)
@GetMapping("/exportExcel") @GetMapping("/exportExcel")
@ApiOperation(httpMethod = "GET", value = "人员执勤导出", notes = "人员执勤导出") @ApiOperation(httpMethod = "GET", value = "人员执勤导出", notes = "人员执勤导出")
public ResponseModel exportExcel(HttpServletResponse response, @ApiParam(value = "开始日期", required = true) @RequestParam String beginDate, public ResponseModel exportExcel(HttpServletResponse response,
@ApiParam(value = "开始日期", required = true) @RequestParam String beginDate,
@ApiParam(value = "结束日期", required = true) @RequestParam String endDate) throws ParseException { @ApiParam(value = "结束日期", required = true) @RequestParam String endDate) throws ParseException {
return ResponseHelper.buildResponse(iDutyPersonService.downloadList(beginDate, endDate)); return ResponseHelper.buildResponse(iDutyPersonService.downloadList(beginDate, endDate));
} }
...@@ -137,9 +140,19 @@ public class DutyPersonController extends BaseController { ...@@ -137,9 +140,19 @@ public class DutyPersonController extends BaseController {
@TycloudOperation(ApiLevel = UserType.AGENCY) @TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation("查询指定日期值班人信息列表") @ApiOperation("查询指定日期值班人信息列表")
@GetMapping("/person/{dutyDay}/list") @GetMapping("/person/{dutyDay}/list")
public ResponseModel listDutyPerson(@ApiParam(value = "值班日期",required = true) @PathVariable String dutyDay, public ResponseModel listDutyPerson(@ApiParam(value = "值班日期", required = true) @PathVariable String dutyDay,
@ApiParam(value = "班次id") @RequestParam(required = false) Long shiftId, @ApiParam(value = "班次id") @RequestParam(required = false) Long shiftId,
@ApiParam(value = "岗位") @RequestParam(required = false) String postType) { @ApiParam(value = "岗位") @RequestParam(required = false) String postType) {
return ResponseHelper.buildResponse(iDutyPersonService.dayDutyPersonList(dutyDay, shiftId, postType)); return ResponseHelper.buildResponse(iDutyPersonService.dayDutyPersonList(dutyDay, shiftId, postType));
} }
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation("查询当前值班人信息列表")
@GetMapping("/person/on_duty/list")
public ResponseModel listOnDutyPerson(HttpServletRequest request) {
String appKey = request.getHeader("appKey");
return ResponseHelper.buildResponse(iDutyPersonService.listOnDutyPerson(appKey));
}
} }
...@@ -57,6 +57,7 @@ public interface IDutyCommonService { ...@@ -57,6 +57,7 @@ public interface IDutyCommonService {
/** /**
* 删除值班数据 * 删除值班数据
*
* @param instanceId 实例id * @param instanceId 实例id
* @return Boolean * @return Boolean
*/ */
...@@ -64,10 +65,18 @@ public interface IDutyCommonService { ...@@ -64,10 +65,18 @@ public interface IDutyCommonService {
/** /**
* 查询指定条件的值班人信息 * 查询指定条件的值班人信息
* @param dutyDay 查询条件 *
* @param shiftId 班次 * @param dutyDay 查询条件
* @param shiftId 班次
* @param postType 岗位 * @param postType 岗位
* @return List<Map<String, Object>> * @return List<Map < String, Object>>
*/
List<Map<String, Object>> dayDutyPersonList(String dutyDay, Long shiftId, String postType);
/**
* 查询当前值班人信息
*
* @return List<Map < String, Object>>
*/ */
List<Map<String, Object>> dayDutyPersonList(String dutyDay,Long shiftId,String postType); List<Map<String, Object>> listOnDutyPerson(String appKey);
} }
...@@ -9,12 +9,15 @@ import com.yeejoin.amos.boot.biz.common.utils.DateUtils; ...@@ -9,12 +9,15 @@ import com.yeejoin.amos.boot.biz.common.utils.DateUtils;
import com.yeejoin.amos.boot.module.common.api.dto.DutyCarDto; 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.DutyPersonDto;
import com.yeejoin.amos.boot.module.common.api.dto.DutyPersonShiftDto; import com.yeejoin.amos.boot.module.common.api.dto.DutyPersonShiftDto;
import com.yeejoin.amos.boot.module.common.api.dto.DutyShiftDto;
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.DutyShift; 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.DynamicFormColumn;
import com.yeejoin.amos.boot.module.common.api.entity.DynamicFormInstance; import com.yeejoin.amos.boot.module.common.api.entity.DynamicFormInstance;
import com.yeejoin.amos.boot.module.common.api.enums.DutyViewTypeEnum; import com.yeejoin.amos.boot.module.common.api.enums.DutyViewTypeEnum;
import com.yeejoin.amos.boot.module.common.biz.service.IDutyCommonService; import com.yeejoin.amos.boot.module.common.biz.service.IDutyCommonService;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.DateTime;
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.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
...@@ -53,6 +56,9 @@ public class DutyCommonServiceImpl implements IDutyCommonService { ...@@ -53,6 +56,9 @@ public class DutyCommonServiceImpl implements IDutyCommonService {
@Autowired @Autowired
DutyShiftServiceImpl dutyShiftService; DutyShiftServiceImpl dutyShiftService;
@Autowired
OrgUsrServiceImpl orgUsrService;
/** /**
* 每天单个班次执勤人数全部小于等于3人 * 每天单个班次执勤人数全部小于等于3人
*/ */
...@@ -68,7 +74,7 @@ public class DutyCommonServiceImpl implements IDutyCommonService { ...@@ -68,7 +74,7 @@ public class DutyCommonServiceImpl implements IDutyCommonService {
public IPage<Map<String, Object>> pageList(int current, int size, String beginDate, String endDate) throws ParseException { public IPage<Map<String, Object>> pageList(int current, int size, String beginDate, String endDate) throws ParseException {
//1.已column为准 进行返回 //1.已column为准 进行返回
String groupCode = this.getGroupCode(); String groupCode = this.getGroupCode();
IPage<Map<String, Object>> iPage = dynamicFormInstanceService.pageList(current,size,groupCode); IPage<Map<String, Object>> iPage = dynamicFormInstanceService.pageList(current, size, groupCode);
for (Map<String, Object> m : iPage.getRecords()) { for (Map<String, Object> m : iPage.getRecords()) {
this.fillDutyShiftData(beginDate, endDate, m); this.fillDutyShiftData(beginDate, endDate, m);
} }
...@@ -77,8 +83,10 @@ public class DutyCommonServiceImpl implements IDutyCommonService { ...@@ -77,8 +83,10 @@ public class DutyCommonServiceImpl implements IDutyCommonService {
private void fillDutyShiftData(String beginDate, String endDate, Map<String, Object> m) throws ParseException { private void fillDutyShiftData(String beginDate, String endDate, Map<String, Object> m) throws ParseException {
String instanceId = m.get("instanceId").toString(); String instanceId = m.get("instanceId").toString();
List<DutyShift> dutyShifts = dutyShiftService.list(new LambdaQueryWrapper<DutyShift>().eq(BaseEntity::getIsDelete, false).eq(DutyShift::getAppKey, RequestContext.getAppKey())); List<DutyShift> dutyShifts =
Map<Long, DutyShift> keyNameMap = dutyShifts.stream().collect(Collectors.toMap(BaseEntity::getSequenceNbr, Function.identity())); 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>() List<DutyPersonShiftDto> personShiftList = dutyPersonShiftService.list(new LambdaQueryWrapper<DutyPersonShift>()
.eq(DutyPersonShift::getInstanceId, instanceId) .eq(DutyPersonShift::getInstanceId, instanceId)
.ge(beginDate != null, DutyPersonShift::getDutyDate, beginDate) .ge(beginDate != null, DutyPersonShift::getDutyDate, beginDate)
...@@ -123,7 +131,8 @@ public class DutyCommonServiceImpl implements IDutyCommonService { ...@@ -123,7 +131,8 @@ public class DutyCommonServiceImpl implements IDutyCommonService {
} }
private DutyViewTypeEnum inferView(String beginDate, String endDate, String appKey) { private DutyViewTypeEnum inferView(String beginDate, String endDate, String appKey) {
Map<String, Long> result = dutyPersonShiftService.getBaseMapper().calMaxPersonAndShiftNum(beginDate, endDate, appKey, this.getGroupCode()); Map<String, Long> result = dutyPersonShiftService.getBaseMapper().calMaxPersonAndShiftNum(beginDate, endDate,
appKey, this.getGroupCode());
//计算班次最大执勤人数,时间区间内 //计算班次最大执勤人数,时间区间内
Long maxDutyPersonNumDay = result.get("maxDutyPersonNumDay"); Long maxDutyPersonNumDay = result.get("maxDutyPersonNumDay");
//计算天的最大班次数量,时间区间内 //计算天的最大班次数量,时间区间内
...@@ -175,20 +184,24 @@ public class DutyCommonServiceImpl implements IDutyCommonService { ...@@ -175,20 +184,24 @@ public class DutyCommonServiceImpl implements IDutyCommonService {
dataList.forEach(d -> { dataList.forEach(d -> {
//TODO: 业务唯一索引,用户id //TODO: 业务唯一索引,用户id
String userId = d.get("userId").toString(); String userId = d.get("userId").toString();
List<DynamicFormInstance> instances = dynamicFormInstanceService.list(new LambdaQueryWrapper<DynamicFormInstance>() List<DynamicFormInstance> instances =
dynamicFormInstanceService.list(new LambdaQueryWrapper<DynamicFormInstance>()
.eq(DynamicFormInstance::getFieldCode, "userId") .eq(DynamicFormInstance::getFieldCode, "userId")
.eq(DynamicFormInstance::getFieldValue, userId) .eq(DynamicFormInstance::getFieldValue, userId)
.eq(DynamicFormInstance::getGroupCode, this.getGroupCode())); .eq(DynamicFormInstance::getGroupCode, this.getGroupCode()));
Long instanceId = null; Long instanceId = null;
List<DynamicFormColumn> columns = dynamicFormColumnService.list(new LambdaQueryWrapper<DynamicFormColumn>().eq(DynamicFormColumn::getGroupCode, this.getGroupCode())); List<DynamicFormColumn> columns =
dynamicFormColumnService.list(new LambdaQueryWrapper<DynamicFormColumn>().eq(DynamicFormColumn::getGroupCode, this.getGroupCode()));
//1.组装动态表单数据 //1.组装动态表单数据
if (!instances.isEmpty()) { if (!instances.isEmpty()) {
//0.定位instanceId,准备进行更新操作 //0.定位instanceId,准备进行更新操作
instanceId = instances.get(0).getInstanceId(); instanceId = instances.get(0).getInstanceId();
//1.查询已有数据 //1.查询已有数据
List<DynamicFormInstance> instancesInDb = dynamicFormInstanceService.list(new LambdaQueryWrapper<DynamicFormInstance>().eq(DynamicFormInstance::getInstanceId, instanceId)); List<DynamicFormInstance> instancesInDb =
dynamicFormInstanceService.list(new LambdaQueryWrapper<DynamicFormInstance>().eq(DynamicFormInstance::getInstanceId, instanceId));
//2.list 转 map //2.list 转 map
Map<Object, DynamicFormInstance> instanceMap = Bean.listToMap(instancesInDb, "fieldCode", DynamicFormInstance.class); Map<Object, DynamicFormInstance> instanceMap = Bean.listToMap(instancesInDb, "fieldCode",
DynamicFormInstance.class);
//3.待更新数据组装,待批量入库 //3.待更新数据组装,待批量入库
this.updateFormValue(formInstanceList, d, instanceId, columns, instanceMap); this.updateFormValue(formInstanceList, d, instanceId, columns, instanceMap);
} else { } else {
...@@ -208,10 +221,14 @@ public class DutyCommonServiceImpl implements IDutyCommonService { ...@@ -208,10 +221,14 @@ public class DutyCommonServiceImpl implements IDutyCommonService {
List<DutyPersonShiftDto> shiftDtos = (List<DutyPersonShiftDto>) d.get("dutyShift"); List<DutyPersonShiftDto> shiftDtos = (List<DutyPersonShiftDto>) d.get("dutyShift");
Long finalInstanceId = instanceId; Long finalInstanceId = instanceId;
//按照业务唯一索引查询主键 //按照业务唯一索引查询主键
List<DutyPersonShift> dutyPersonShiftsDb = dutyPersonShiftService.list(new LambdaQueryWrapper<DutyPersonShift>().eq(DutyPersonShift::getInstanceId, instanceId)); List<DutyPersonShift> dutyPersonShiftsDb =
Map<Date, Long> dutyPersonShiftMap = dutyPersonShiftsDb.stream().collect(Collectors.toMap(DutyPersonShift::getDutyDate, DutyPersonShift::getSequenceNbr)); dutyPersonShiftService.list(new LambdaQueryWrapper<DutyPersonShift>().eq(DutyPersonShift::getInstanceId, instanceId));
Map<Date, Long> dutyPersonShiftMap =
dutyPersonShiftsDb.stream().collect(Collectors.toMap(DutyPersonShift::getDutyDate,
DutyPersonShift::getSequenceNbr));
//todo: 只更新当天及值班之后数据 //todo: 只更新当天及值班之后数据
Set<DutyPersonShift> needToDb = shiftDtos.stream().filter(s -> DateUtils.dateCompare(s.getDutyDate(), new Date()) >= 0).map(shiftDto -> { Set<DutyPersonShift> needToDb = shiftDtos.stream().filter(s -> DateUtils.dateCompare(s.getDutyDate(),
new Date()) >= 0).map(shiftDto -> {
DutyPersonShift dutyPersonShift = new DutyPersonShift(); DutyPersonShift dutyPersonShift = new DutyPersonShift();
Bean.copyExistPropertis(shiftDto, dutyPersonShift); Bean.copyExistPropertis(shiftDto, dutyPersonShift);
dutyPersonShift.setInstanceId(finalInstanceId); dutyPersonShift.setInstanceId(finalInstanceId);
...@@ -229,12 +246,14 @@ public class DutyCommonServiceImpl implements IDutyCommonService { ...@@ -229,12 +246,14 @@ public class DutyCommonServiceImpl implements IDutyCommonService {
} }
} }
public void updateFormValue(List<DynamicFormInstance> formInstanceList, Map<String, Object> d, Long instanceId, List<DynamicFormColumn> columns, Map<Object, DynamicFormInstance> instanceMap) { public void updateFormValue(List<DynamicFormInstance> formInstanceList, Map<String, Object> d, Long instanceId,
List<DynamicFormColumn> columns, Map<Object, DynamicFormInstance> instanceMap) {
for (DynamicFormColumn column : columns) { for (DynamicFormColumn column : columns) {
DynamicFormInstance formInstance = instanceMap.get(column.getFieldCode()); DynamicFormInstance formInstance = instanceMap.get(column.getFieldCode());
if (!ObjectUtils.isEmpty(formInstance)) { if (!ObjectUtils.isEmpty(formInstance)) {
//有的更新 //有的更新
formInstance.setFieldValue(d.get(column.getFieldCode()) != null ? d.get(column.getFieldCode()).toString() : ""); formInstance.setFieldValue(d.get(column.getFieldCode()) != null ?
d.get(column.getFieldCode()).toString() : "");
} else { } else {
//没有的新增 //没有的新增
formInstance = new DynamicFormInstance(); formInstance = new DynamicFormInstance();
...@@ -244,23 +263,27 @@ public class DutyCommonServiceImpl implements IDutyCommonService { ...@@ -244,23 +263,27 @@ public class DutyCommonServiceImpl implements IDutyCommonService {
} }
} }
private void buildFormInstanceData(Long instanceId, Map<String, Object> map, DynamicFormColumn column, DynamicFormInstance formInstance) { private void buildFormInstanceData(Long instanceId, Map<String, Object> map, DynamicFormColumn column,
DynamicFormInstance formInstance) {
fillFormInstanceData(instanceId, map, column, formInstance, sequence.nextId()); fillFormInstanceData(instanceId, map, column, formInstance, sequence.nextId());
} }
static void fillFormInstanceData(Long instanceId, Map<String, Object> map, DynamicFormColumn column, DynamicFormInstance formInstance, long l) { static void fillFormInstanceData(Long instanceId, Map<String, Object> map, DynamicFormColumn column,
DynamicFormInstance formInstance, long l) {
Bean.copyExistPropertis(column, formInstance); Bean.copyExistPropertis(column, formInstance);
formInstance.setAppKey(RequestContext.getAppKey()); formInstance.setAppKey(RequestContext.getAppKey());
formInstance.setInstanceId(instanceId); formInstance.setInstanceId(instanceId);
formInstance.setSequenceNbr(l); formInstance.setSequenceNbr(l);
formInstance.setFormColumnId(column.getSequenceNbr()); formInstance.setFormColumnId(column.getSequenceNbr());
formInstance.setFieldValue(map.get(column.getFieldCode()) != null ? map.get(column.getFieldCode()).toString() : ""); formInstance.setFieldValue(map.get(column.getFieldCode()) != null ?
map.get(column.getFieldCode()).toString() : "");
} }
@Override @Override
public Boolean deleteDutyData(Long instanceId) { public Boolean deleteDutyData(Long instanceId) {
dynamicFormInstanceService.remove(new LambdaQueryWrapper<DynamicFormInstance>().eq(DynamicFormInstance::getInstanceId, instanceId)); dynamicFormInstanceService.remove(new LambdaQueryWrapper<DynamicFormInstance>().eq(DynamicFormInstance::getInstanceId, instanceId));
dutyPersonShiftService.remove(new LambdaQueryWrapper<DutyPersonShift>().eq(DutyPersonShift::getInstanceId, instanceId)); dutyPersonShiftService.remove(new LambdaQueryWrapper<DutyPersonShift>().eq(DutyPersonShift::getInstanceId,
instanceId));
return true; return true;
} }
...@@ -269,10 +292,71 @@ public class DutyCommonServiceImpl implements IDutyCommonService { ...@@ -269,10 +292,71 @@ public class DutyCommonServiceImpl implements IDutyCommonService {
String groupCode = this.getGroupCode(); String groupCode = this.getGroupCode();
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
params.put("postType", postType); params.put("postType", postType);
List<DynamicFormColumn> columns = dynamicFormColumnService.list(new LambdaQueryWrapper<DynamicFormColumn>().eq(DynamicFormColumn::getGroupCode, groupCode)); List<DynamicFormColumn> columns =
dynamicFormColumnService.list(new LambdaQueryWrapper<DynamicFormColumn>().eq(DynamicFormColumn::getGroupCode, groupCode));
Map<String, Object> fieldCodes = Bean.listToMap(columns, "fieldCode", "queryStrategy", DynamicFormColumn.class); Map<String, Object> fieldCodes = Bean.listToMap(columns, "fieldCode", "queryStrategy", DynamicFormColumn.class);
return dynamicFormInstanceService.getBaseMapper().listOneDayDutyPerson(dutyDay, shiftId, fieldCodes, RequestContext.getAppKey(), groupCode, params); return dynamicFormInstanceService.getBaseMapper().listOneDayDutyPerson(dutyDay, shiftId, fieldCodes,
RequestContext.getAppKey(), groupCode, params);
} }
@Override
public List<Map<String, Object>> listOnDutyPerson(String appKey) {
String groupCode = this.getGroupCode();
// 获取当前班次列表
DateTime now = new DateTime();
List<Long> shiftIdList = getOnDuty(now, appKey);
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, RequestContext.getAppKey(), 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"));
orgUsrList.remove(usr);
}
}
});
} catch (Exception e) {
e.printStackTrace();
}
return maps;
}
private List<Long> getOnDuty(DateTime now, String appKey) {
List<DutyShiftDto> dutyShiftDtos = dutyShiftService.queryForDutyShiftList(appKey, 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;
}
} }
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