lius
2023-08-08 3f7774efde865b52797089fcdde621d7ae1e1a4a
设备工作日历配置接口更新
已修改7个文件
157 ■■■■ 文件已修改
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcDeviceCalendarController.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/MdcDeviceCalendar.java 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcDeviceCalendarMapper.xml 11 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcDeviceCalendarServiceImpl.java 104 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcVacationManagementServiceImpl.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/EquipmentCalendarVo.java 24 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcDeviceCalendarVo.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/controller/MdcDeviceCalendarController.java
@@ -70,8 +70,8 @@
    @ApiOperation(value = "设备工作日历表-配置", notes = "设备工作日历表-配置")
    @PostMapping(value = "/add")
    public Result add(@RequestBody EquipmentCalendarVo calendarVo) {
        if (StringUtils.isBlank(calendarVo.getEquipmentId())) {
            return Result.error("未选择设备");
        if (StringUtils.isBlank(calendarVo.getEquipmentId()) || calendarVo.getDateList().isEmpty()) {
            return Result.error("请选择有效参数!");
        }
        boolean result = mdcDeviceCalendarService.saveCalendar(calendarVo);
        if(result){
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/entity/MdcDeviceCalendar.java
@@ -42,7 +42,7 @@
     */
    @Excel(name = "设备编号", width = 15)
    @ApiModelProperty(value = "设备编号")
    private String equmentId;
    private String equipmentId;
    /**
     * 班次ID
@@ -50,11 +50,5 @@
    @Excel(name = "班次ID", width = 15)
    @ApiModelProperty(value = "班次ID")
    private String shiftSubId;
    /**
     * 星期标识
     */
    @Excel(name = "星期标识", width = 15)
    @ApiModelProperty(value = "星期标识")
    @Dict(dicCode = "week_number_type")
    private String weekNumber;
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/mapper/xml/MdcDeviceCalendarMapper.xml
@@ -13,19 +13,18 @@
            t3.sleep_start_date,
            t3.sleep_end_date,
            t3.is_day_span,
            t4.equipment_name,
            t4.equipment_id
            t4.equipment_name
        FROM
            mdc_device_calendar t1
            LEFT JOIN mdc_shift t2 ON t1.shift_id = t2.id
            LEFT JOIN mdc_shift_sub t3 ON t1.shift_sub_id = t3.id
            LEFT JOIN mdc_equipment t4 ON t1.equment_id = t4.equipment_id
            LEFT JOIN mdc_equipment t4 ON t1.equipment_id = t4.equipment_id
        WHERE 1=1
        <if test="deviceCalendar.effectiveDate != null and deviceCalendar.effectiveDate != ''">
            AND t1.effective_date LIKE CONCAT('%',#{ deviceCalendar.effectiveDate },'%')
        </if>
        <if test="deviceCalendar.equipmentId != null and deviceCalendar.equipmentId != ''">
            AND t1.equment_id = #{ deviceCalendar.equipmentId }
            AND t1.equipment_id = #{ deviceCalendar.equipmentId }
        </if>
        <if test="deviceCalendar.startTime != null and deviceCalendar.startTime != ''">
            AND t1.effective_date &gt;= #{ deviceCalendar.startTime }
@@ -34,7 +33,7 @@
            AND t1.effective_date &lt;= #{ deviceCalendar.endTime }
        </if>
        <if test="deviceCalendar.equipmentIdList != null and deviceCalendar.equipmentIdList.size() > 0 ">
            AND t1.equment_id IN
            AND t1.equipment_id IN
            <foreach collection="deviceCalendar.equipmentIdList" item="id" index="index" open="(" close=")" separator=",">
                #{ id }
            </foreach>
@@ -59,7 +58,7 @@
            mdc_device_calendar t1
            LEFT JOIN mdc_shift t2 ON t1.shift_id = t2.id
            LEFT JOIN mdc_shift_sub t3 ON t1.shift_sub_id = t3.id
            LEFT JOIN mdc_equipment t4 ON t1.equment_id = t4.equipment_id
            LEFT JOIN mdc_equipment t4 ON t1.equipment_id = t4.equipment_id
        <where>
            <if test="equipmentid != null and equipmentid != ''">
                AND t4.equipment_id = #{ equipmentid }
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcDeviceCalendarServiceImpl.java
@@ -83,50 +83,21 @@
    @Override
    public boolean saveCalendar(EquipmentCalendarVo calendarVo) {
        String[] equipmentIdList = calendarVo.getEquipmentId().split(",");
        //生效时间
        LocalDate takeEffectDate = calendarVo.getTakeEffectDate();
        //失效时间
        LocalDate invalidDate = calendarVo.getInvalidDate();
        //处理星期
        Map<String, String> map = new HashMap<>();
        if (org.apache.commons.lang.StringUtils.isNotBlank(calendarVo.getMonShiftId())) {
            map.put("1", calendarVo.getMonShiftId());
        }
        if (org.apache.commons.lang.StringUtils.isNotBlank(calendarVo.getTueShiftId())) {
            map.put("2", calendarVo.getTueShiftId());
        }
        if (org.apache.commons.lang.StringUtils.isNotBlank(calendarVo.getWedShiftId())) {
            map.put("3", calendarVo.getWedShiftId());
        }
        if (org.apache.commons.lang.StringUtils.isNotBlank(calendarVo.getThuShiftId())) {
            map.put("4", calendarVo.getThuShiftId());
        }
        if (org.apache.commons.lang.StringUtils.isNotBlank(calendarVo.getFriShiftId())) {
            map.put("5", calendarVo.getFriShiftId());
        }
        if (org.apache.commons.lang.StringUtils.isNotBlank(calendarVo.getSatShiftId())) {
            map.put("6", calendarVo.getSatShiftId());
        }
        if (org.apache.commons.lang.StringUtils.isNotBlank(calendarVo.getSunShiftId())) {
            map.put("7", calendarVo.getSunShiftId());
        }
        if (map.isEmpty()) {
            return false;
        }
        List<String> dateList = calendarVo.getDateList();
        List<MdcShiftSub> mdcShiftSubList = mdcShiftSubService.list(new LambdaQueryWrapper<MdcShiftSub>().eq(MdcShiftSub::getShiftId, calendarVo.getShiftId()).eq(MdcShiftSub::getShiftSubStatus, "1"));
        List<MdcDeviceCalendar> calendarList = new ArrayList<>();
        map.forEach((key, value) -> {
            List<MdcShiftSub> mdcShiftSubList = mdcShiftSubService.list(new LambdaQueryWrapper
                    <MdcShiftSub>().eq(MdcShiftSub::getShiftId, value).eq(MdcShiftSub::getShiftSubStatus, "1"));
            List<LocalDate> meetDayOfWeekLocalDates = getMeetDayOfWeekLocalDates(takeEffectDate, invalidDate, key);
            if (!meetDayOfWeekLocalDates.isEmpty()) {
                List<String> dates = meetDayOfWeekLocalDates.stream().map(localDate -> localDate.format(DateTimeFormatter.BASIC_ISO_DATE)).collect(Collectors.toList());
                LambdaUpdateChainWrapper<MdcDeviceCalendar> lambdaUpdate = this.lambdaUpdate();
                lambdaUpdate.in(MdcDeviceCalendar::getEffectiveDate, dates).in(MdcDeviceCalendar::getEqumentId, Arrays.asList(equipmentIdList));
                lambdaUpdate.remove();
                List<MdcDeviceCalendar> calendars = handleMdcDeviceCalendar(dates, equipmentIdList, mdcShiftSubList, key);
                calendarList.addAll(calendars);
        for (String equipmentId : equipmentIdList) {
            for (String date : dateList) {
                for (MdcShiftSub mdcShiftSub : mdcShiftSubList) {
                    MdcDeviceCalendar mdcDeviceCalendar = new MdcDeviceCalendar();
                    mdcDeviceCalendar.setEffectiveDate(date);
                    mdcDeviceCalendar.setEquipmentId(equipmentId);
                    mdcDeviceCalendar.setShiftId(mdcShiftSub.getShiftId());
                    mdcDeviceCalendar.setShiftSubId(mdcShiftSub.getId());
                    calendarList.add(mdcDeviceCalendar);
                }
            }
        });
        }
        this.saveBatch(calendarList);
        return true;
    }
@@ -134,24 +105,24 @@
    /**
     * 查询班制数据
     *
     * @param equipmentid
     * @param equipmentId
     * @param stringDates
     * @return
     */
    @Override
    public List<MdcDeviceCalendarVo> listByEquipmentAndDate(String equipmentid, List<String> stringDates) {
    public List<MdcDeviceCalendarVo> listByEquipmentAndDate(String equipmentId, List<String> stringDates) {
        List<MdcDeviceCalendarVo> result = new ArrayList<>();
        try {
            //查询默认班制
            List<MdcDeviceCalendarVo> acquiesceShift = this.baseMapper.findAcquiesceShift();
            for (String stringDate : stringDates) {
                List<MdcDeviceCalendarVo> mdcDeviceCalendarVos = this.baseMapper.listByEquipmentAndDate(equipmentid, stringDate);
                List<MdcDeviceCalendarVo> mdcDeviceCalendarVos = this.baseMapper.listByEquipmentAndDate(equipmentId, stringDate);
                if (mdcDeviceCalendarVos != null && !mdcDeviceCalendarVos.isEmpty()) {
                    result.addAll(mdcDeviceCalendarVos);
                } else {
                    acquiesceShift.forEach(mdcDeviceCalendarVo -> {
                        mdcDeviceCalendarVo.setEquipmentId(equipmentid);
                        mdcDeviceCalendarVo.setEquipmentId(equipmentId);
                        mdcDeviceCalendarVo.setEffectiveDate(stringDate);
                    });
                    // 设置默认班制
@@ -165,45 +136,4 @@
        return result;
    }
    /**
     * 获取一段时间范围内符合星期几的日期集合
     *
     * @param startDate 开始时间
     * @param endDate   结束时间
     * @param workDate  周几 1,2,3,4
     */
    public static List<LocalDate> getMeetDayOfWeekLocalDates(LocalDate startDate, LocalDate endDate, String workDate) {
        List<DayOfWeek> dayOfWeeks = Stream.of(workDate.split(","))
                .map(Integer::valueOf)
                .map(DayOfWeek::of)
                .collect(Collectors.toList());
        long distance = ChronoUnit.DAYS.between(startDate, endDate);
        return Stream.iterate(startDate, d -> d.plusDays(1))
                .limit(distance + 1)
                .filter(localDate -> dayOfWeeks.contains(localDate.getDayOfWeek()))
                .collect(Collectors.toList());
    }
    public List<MdcDeviceCalendar> handleMdcDeviceCalendar(List<String> dates, String[] equipment, List<MdcShiftSub> mdcShiftSubList, String weekNumber) {
        List<MdcDeviceCalendar> ds = new ArrayList<>();
        for (String date : dates) {
            for (String equipmentId : equipment) {
                for (MdcShiftSub temp : mdcShiftSubList) {
                    MdcDeviceCalendar mdcDeviceCalendar = new MdcDeviceCalendar();
                    if (org.apache.commons.lang.StringUtils.isNotEmpty(equipmentId)) {
                        mdcDeviceCalendar.setEqumentId(equipmentId);
                    }
                    mdcDeviceCalendar.setShiftId(temp.getShiftId());
                    mdcDeviceCalendar.setShiftSubId(temp.getId());
                    mdcDeviceCalendar.setEffectiveDate(date);
                    mdcDeviceCalendar.setWeekNumber(weekNumber);
                    ds.add(mdcDeviceCalendar);
                }
            }
        }
        return ds;
    }
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/service/impl/MdcVacationManagementServiceImpl.java
@@ -112,6 +112,8 @@
     */
    @Override
    public void generateWeekDays() {
        List<String> alist = new ArrayList<>();
        String s = alist.get(10);
        MdcVacationManagement mdcVacationManagement = this.baseMapper.selectLastWeekDays();
        // 获取生成开始时间和结束时间
        LocalDate startDate;
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/EquipmentCalendarVo.java
@@ -4,6 +4,7 @@
import lombok.Data;
import java.time.LocalDate;
import java.util.List;
/**
 * @author: LiuS
@@ -13,28 +14,9 @@
public class EquipmentCalendarVo {
    private String equipmentId;
    /**
     * 开始时间
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
    private LocalDate takeEffectDate;
    /**
     * 结束时间
     */
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
    private LocalDate invalidDate;
    private String monShiftId;
    private List<String> dateList;
    private String tueShiftId;
    private String shiftId;
    private String wedShiftId;
    private String thuShiftId;
    private String friShiftId;
    private String satShiftId;
    private String sunShiftId;
}
lxzn-module-mdc/src/main/java/org/jeecg/modules/mdc/vo/MdcDeviceCalendarVo.java
@@ -17,5 +17,5 @@
    private String sleepEndDate;
    private String isDaySpan;
    private String equipmentName;
    private String equipmentId;
//    private String equipmentId;
}