| | |
| | | import cn.hutool.json.JSONUtil; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.ruoyi.basic.pojo.IfsInventoryQuantity; |
| | | import com.ruoyi.common.config.mes.MesConfig; |
| | | import com.ruoyi.common.config.mes.MesProperties; |
| | | import com.ruoyi.common.numgen.NumberGenerator; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.api.MesApiUtils; |
| | | import com.ruoyi.common.utils.api.mes.MesApiUtils; |
| | | import com.ruoyi.inspect.pojo.IfsSplitOrderRecord; |
| | | import com.ruoyi.inspect.service.IfsSplitOrderRecordService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | import com.ruoyi.inspect.pojo.StaffAttendanceTrackingRecord; |
| | | import com.ruoyi.inspect.service.StaffAttendanceTrackingRecordService; |
| | | import com.ruoyi.inspect.util.HourDiffCalculator; |
| | | import com.ruoyi.inspect.util.TimeDiffCalculator; |
| | | import com.ruoyi.inspect.vo.StaffAttendanceVO; |
| | | import com.ruoyi.inspect.vo.StaffClockInVO; |
| | | import com.ruoyi.performance.dto.PerformanceShiftMapDto; |
| | |
| | | private final static List<String> syncDeviceCode = Arrays.asList("1001538", "1001539", "1001540", "1001541", |
| | | "1001626", "1001627", "1001628", "1001629"); |
| | | |
| | | /** |
| | | * ä¸çæ¶é´å¤å®è¾¹çå°æ¶æ° |
| | | */ |
| | | private final static long WORK_TIME_BOUNDARY = 2L; |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean syncAttendanceRecord(LocalDateTime startDate, LocalDateTime endDate) { |
| | |
| | | public IPage<StaffAttendanceVO> pageAttendanceRecord(Page<StaffAttendanceTrackingRecord> page, |
| | | StaffAttendanceDTO staffAttendanceDTO) { |
| | | // æ¥è¯¢æå¡è®°å½ |
| | | System.out.println(staffAttendanceDTO.getStartDate()); |
| | | System.out.println(staffAttendanceDTO.getEndDate()); |
| | | System.out.println(ObjectUtils.allNotNull(staffAttendanceDTO.getStartDate(),staffAttendanceDTO.getEndDate())); |
| | | Wrapper<StaffAttendanceTrackingRecord> queryWrapper = Wrappers.<StaffAttendanceTrackingRecord>lambdaQuery() |
| | | .eq(StaffAttendanceTrackingRecord::getEnableReport, Boolean.TRUE) |
| | | .between(ObjectUtils.allNotNull(staffAttendanceDTO.getStartDate(),staffAttendanceDTO.getEndDate()), |
| | |
| | | LocalTime currentShiftStartTime = LocalTime.parse(p.getStartTime(), HHmm); |
| | | LocalDateTime currentShiftStartDateTime = LocalDateTime.of(p.getWorkTime().toLocalDate(), |
| | | currentShiftStartTime); |
| | | // å½åçæ¬¡ç»ææ¶é´ |
| | | LocalTime currentShiftEndTime = LocalTime.parse(p.getEndTime(), HHmm); |
| | | LocalDateTime currentShiftEndDateTime = LocalDateTime.of(endDateTime.toLocalDate(), |
| | | currentShiftEndTime); |
| | | // ä¸ä¸ç次å¼å§æ¶é´ |
| | | LocalDateTime nextShiftStartDateTime = getShiftStartDateTime(i + 1, performanceShifts, |
| | | startDateTime.plusDays(1L)); |
| | |
| | | // 妿尿¶å·®ä¸ºè´æ°ï¼è¡¨ç¤ºè·¨å¤©ï¼ç»ææ¶é´éå ä¸ |
| | | endDateTime = endDateTime.plusDays(1L); |
| | | } |
| | | // å½åçæ¬¡ç»ææ¶é´ |
| | | LocalTime currentShiftEndTime = LocalTime.parse(p.getEndTime(), HHmm); |
| | | LocalDateTime currentShiftEndDateTime = LocalDateTime.of(endDateTime.toLocalDate(), |
| | | currentShiftEndTime); |
| | | // è¿æ»¤åºå½å人åå½åçæ¬¡çè¿/åºè®°å½ |
| | | LocalDateTime workDateTime = null; |
| | | LocalDateTime offWorkDateTime = null; |
| | | List<StaffAttendanceTrackingRecord> enterRecords = filterAttendanceRecord(p.getPersonCode(), |
| | | EnterOrExitType.ENTER.getValue(), startDateTime, endDateTime, recordList); |
| | | //ä¸çæ¶é´å¤å®è¾¹ç |
| | | LocalDateTime boundaryTime = currentShiftStartDateTime.minusHours(WORK_TIME_BOUNDARY); |
| | | if (!enterRecords.isEmpty()) { |
| | | // ä¸çæ¶é´åç¶æ |
| | | StaffAttendanceTrackingRecord enterRecord = enterRecords.stream() |
| | | .filter(s -> !s.getSwingTime().isAfter(currentShiftStartDateTime)) |
| | | .filter(s -> !s.getSwingTime().isAfter(currentShiftStartDateTime) && !s.getSwingTime().isBefore(boundaryTime)) |
| | | .max(Comparator.comparing(StaffAttendanceTrackingRecord::getSwingTime)) |
| | | .orElse(new StaffAttendanceTrackingRecord()); |
| | | if (BeanUtil.isEmpty(enterRecord)) { |
| | |
| | | |
| | | } |
| | | if (ObjectUtils.allNotNull(workDateTime, offWorkDateTime)) { |
| | | vo.setActualWorkHours(HourDiffCalculator.getHourDiff(workDateTime.toLocalTime().format(HHmm), |
| | | offWorkDateTime.toLocalTime().format(HHmm))); |
| | | vo.setActualWorkHours(TimeDiffCalculator.getHourDiff(workDateTime, |
| | | offWorkDateTime)); |
| | | } |
| | | // èµå¼ |
| | | vo.setShiftId(p.getShift()); |
| | | vo.setPersonCode(p.getPersonCode()); |
| | | vo.setPersonName(p.getUserName()); |
| | | vo.setPlannedWorkHours(hourDiff); |
| | | //åºå¤æ¶é¿ |
| | | double plannedWorkHours = Math.abs(hourDiff); |
| | | vo.setPlannedWorkHours(plannedWorkHours); |
| | | vo.setSwingDate(startDateTime); |
| | | vo.setWorkDateTime(workDateTime); |
| | | vo.setOffWorkDateTime(offWorkDateTime); |
| | |
| | | private StaffAttendanceTrackingRecordService trackingRecordService; |
| | | |
| | | |
| | | @Scheduled(cron = "0 0 1 * * ?") |
| | | @Scheduled(cron = "0 0 */12 * * ?") |
| | | public void sync() { |
| | | log.info("--------忥èå¤è®°å½å®æ¶ä»»å¡å¼å§--------"); |
| | | LocalDate yesterday = LocalDate.now(ZoneId.of("Asia/Shanghai")).minusDays(1L); |
| | | LocalDate now = LocalDate.now(ZoneId.of("Asia/Shanghai")); |
| | | LocalDateTime startTime = LocalDateTime.of(yesterday, LocalTime.MIN); |
| | | LocalDateTime endTime = LocalDateTime.of(yesterday, LocalTime.MAX); |
| | | LocalDateTime endTime = LocalDateTime.of(now, LocalTime.MAX); |
| | | trackingRecordService.syncAttendanceRecord(startTime,endTime); |
| | | log.info("--------忥èå¤è®°å½å®æ¶ä»»å¡ç»æ--------"); |
| | | } |
| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.LocalDateTime; |
| | | import java.time.temporal.ChronoUnit; |
| | | import java.util.Objects; |
| | | import java.util.regex.Pattern; |
| | | |
| | |
| | | return hourDiff.doubleValue(); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | System.out.println(getHourDiff("07:38","19:26")); |
| | | LocalDateTime localDateTime = LocalDateTime.of(2026, 3, 30, 7, 38); |
| | | LocalDateTime localDateTime2 = LocalDateTime.of(2026, 3, 30, 19, 26); |
| | | System.out.println(getTimeDifference(localDateTime,localDateTime2)); |
| | | } |
| | | |
| | | /** |
| | | * 计ç®ä¸¤ä¸ªæ¶é´çå·®å¼ï¼è¿å 天:æ¶:å:ç§ï¼æ¯ä½ä¸¤ä½æ°ï¼æ¯æè·¨å¤©ï¼ |
| | | * @param startTime å¼å§æ¶é´ |
| | | * @param endTime ç»ææ¶é´ |
| | | * @return æ ¼å¼ååçæ¶é´å·®ï¼ä¾ï¼01天 01æ¶ 30å 05ç§ï¼ |
| | | */ |
| | | public static String getTimeDifference(LocalDateTime startTime, LocalDateTime endTime) { |
| | | // 1. 计ç®ä¸¤ä¸ªæ¶é´ç**æ»æ¯«ç§å·®**ï¼ç»å¯¹å¼ï¼é¿å
æ¶é´é¡ºåºé®é¢ï¼ |
| | | long totalMillis = Math.abs(ChronoUnit.MILLIS.between(startTime, endTime)); |
| | | |
| | | // 2. å®ä¹æ¶é´åä½å¸¸éï¼æ¯«ç§ï¼ |
| | | final long MILLIS_PER_DAY = 24 * 60 * 60 * 1000; // 1天 |
| | | final long MILLIS_PER_HOUR = 60 * 60 * 1000; // 1å°æ¶ |
| | | final long MILLIS_PER_MINUTE = 60 * 1000; // 1åé |
| | | final long MILLIS_PER_SECOND = 1000; // 1ç§ |
| | | |
| | | // 3. æå å¤©ãæ¶ãåãç§ |
| | | long days = totalMillis / MILLIS_PER_DAY; |
| | | long remainingMillis = totalMillis % MILLIS_PER_DAY; |
| | | long hours = remainingMillis / MILLIS_PER_HOUR; |
| | | remainingMillis %= MILLIS_PER_HOUR; |
| | | long minutes = remainingMillis / MILLIS_PER_MINUTE; |
| | | long seconds = remainingMillis / MILLIS_PER_SECOND; |
| | | |
| | | // 4. æ ¼å¼åï¼%02d = æ´æ°è¡¥é¶å°ä¸¤ä½æ°ï¼æ ¸å¿ï¼æ»¡è¶³ç²¾ç¡®å°ä¸¤ä½æ°è¦æ±ï¼ |
| | | return String.format("%02d天 %02dæ¶ %02då %02dç§", days, hours, minutes, seconds); |
| | | } |
| | | |
| | | /** |
| | | * æ ¡éªæ¶é´æ ¼å¼æ¯å¦ä¸ºHH:mm |
| | | */ |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.inspect.util; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.time.Duration; |
| | | import java.time.LocalDateTime; |
| | | |
| | | /** |
| | | * LocalDateTime æ¶é´å·®è®¡ç®å·¥å
· |
| | | * åè½ï¼ä¼ å
¥ä¸¤ä¸ªæ¶é´ï¼è¿åä¿ç两ä½å°æ°çæ¶é´å·®ï¼å¤©/å°æ¶/åé/ç§ï¼ |
| | | */ |
| | | public class TimeDiffCalculator { |
| | | |
| | | // çº³ç§æ¢ç®å¸¸éï¼æç²¾ç¡®çæ¶é´åä½ï¼æ ç²¾åº¦ä¸¢å¤±ï¼ |
| | | private static final long NANOS_PER_DAY = 24L * 60 * 60 * 1000000000; |
| | | private static final long NANOS_PER_HOUR = 60L * 60 * 1000000000; |
| | | private static final long NANOS_PER_MINUTE = 60L * 1000000000; |
| | | private static final long NANOS_PER_SECOND = 1000000000L; |
| | | |
| | | /** |
| | | * è®¡ç® å¤©æ° å·®ï¼ä¿ç两ä½å°æ° |
| | | */ |
| | | public static double getDayDiff(LocalDateTime start, LocalDateTime end) { |
| | | return calculateDiff(start, end, NANOS_PER_DAY); |
| | | } |
| | | |
| | | /** |
| | | * è®¡ç® å°æ¶ å·®ï¼ä¿ç两ä½å°æ° |
| | | */ |
| | | public static double getHourDiff(LocalDateTime start, LocalDateTime end) { |
| | | return calculateDiff(start, end, NANOS_PER_HOUR); |
| | | } |
| | | |
| | | /** |
| | | * è®¡ç® åé å·®ï¼ä¿ç两ä½å°æ° |
| | | */ |
| | | public static double getMinuteDiff(LocalDateTime start, LocalDateTime end) { |
| | | return calculateDiff(start, end, NANOS_PER_MINUTE); |
| | | } |
| | | |
| | | /** |
| | | * è®¡ç® ç§ å·®ï¼ä¿ç两ä½å°æ° |
| | | */ |
| | | public static double getSecondDiff(LocalDateTime start, LocalDateTime end) { |
| | | return calculateDiff(start, end, NANOS_PER_SECOND); |
| | | } |
| | | |
| | | /** |
| | | * ç»ä¸è®¡ç®é»è¾ï¼æ½ç¦»å
Œ
±ä»£ç ï¼ |
| | | * @param unitNanos ç®æ åä½å¯¹åºççº³ç§æ° |
| | | */ |
| | | private static double calculateDiff(LocalDateTime start, LocalDateTime end, long unitNanos) { |
| | | // 1. è®¡ç®æ¶é´å·®ï¼åç»å¯¹å¼ |
| | | Duration duration = Duration.between(start, end).abs(); |
| | | // 2. 纳ç§è½¬BigDecimalï¼ç²¾ç¡®è®¡ç® |
| | | BigDecimal totalNanos = new BigDecimal(duration.toNanos()); |
| | | BigDecimal unit = new BigDecimal(unitNanos); |
| | | // 3. 餿³è¿ç®ï¼ä¿ç2ä½å°æ°ï¼åèäºå
¥ |
| | | return totalNanos.divide(unit, 2, RoundingMode.HALF_UP).doubleValue(); |
| | | } |
| | | |
| | | } |
| | |
| | | public Result selectAuxiliaryAllByMonth(AuxiliaryOriginalHoursLookDto dto){ |
| | | return Result.success(auxiliaryOriginalHoursService.selectAuxiliaryAllByMonth(dto)); |
| | | } |
| | | |
| | | @ApiOperation(value = "导åºå·¥æ¶æ±æ»") |
| | | @GetMapping("/exportWorkHoursTotal") |
| | | public void exportWorkHoursTotal(HttpServletResponse response,AuxiliaryOriginalHoursLookDto dto){ |
| | | auxiliaryOriginalHoursService.exportWorkHoursTotal(response,dto); |
| | | } |
| | | |
| | | } |
| | |
| | | package com.ruoyi.performance.dto; |
| | | |
| | | import com.alibaba.excel.annotation.ExcelIgnore; |
| | | import com.alibaba.excel.annotation.ExcelProperty; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Data; |
| | |
| | | @NoArgsConstructor |
| | | public class AuxiliaryAllDto { |
| | | |
| | | @ApiModelProperty("产éå·¥æ¶") |
| | | private BigDecimal yieldHour; |
| | | |
| | | @ApiModelProperty("è¾
å©å·¥æ¶") |
| | | private BigDecimal subsidiaryHour; |
| | | |
| | | @ApiModelProperty("æ»å·¥æ¶") |
| | | private BigDecimal totalHour; |
| | | |
| | | @ExcelIgnore |
| | | @ApiModelProperty("人åid") |
| | | private Integer userId; |
| | | |
| | | @ApiModelProperty("å§å") |
| | | private String userName; |
| | | |
| | | @ExcelIgnore |
| | | @ApiModelProperty("æä»½") |
| | | private String month; |
| | | |
| | | @ExcelProperty(value = {"åºå·","åºå·"},index = 0) |
| | | @ApiModelProperty("导åºåºå·") |
| | | private Integer excelIndex; |
| | | |
| | | @ExcelProperty(value = {"å§å","å§å"},index = 1) |
| | | @ApiModelProperty("å§å") |
| | | private String userName; |
| | | |
| | | @ExcelProperty(value = {"èä¸åMES","å·¥åºç»©æ"},index = 2) |
| | | @ApiModelProperty("å·¥åºç»©æ-èä¸å") |
| | | private BigDecimal operationPerformanceByNS = BigDecimal.ZERO; |
| | | |
| | | @ExcelProperty(value = {"èä¸åMES","æå绩æ"},index = 3) |
| | | @ApiModelProperty("æå绩æ-èä¸å") |
| | | private BigDecimal productPerformanceByNS = BigDecimal.ZERO; |
| | | |
| | | @ExcelProperty(value = {"èä¸åMES","å·¡æ£ç»©æ"},index = 4) |
| | | @ApiModelProperty("å·¡æ£ç»©æ-èä¸å") |
| | | private BigDecimal onsiteInspWageByNS = BigDecimal.ZERO; |
| | | |
| | | @ExcelProperty(value = {"èä¸åMES","æå·¥å·¥èµ"},index = 5) |
| | | @ApiModelProperty("æå·¥å·¥èµ-èä¸å") |
| | | private BigDecimal handymanWageByNS = BigDecimal.ZERO; |
| | | |
| | | @ExcelProperty(value = {"ç§æåMES","å·¥åºç»©æ"},index = 6) |
| | | @ApiModelProperty("å·¥åºç»©æ-ç§æå") |
| | | private BigDecimal operationPerformanceByKJ = BigDecimal.ZERO; |
| | | |
| | | @ExcelProperty(value = {"ç§æåMES","æå绩æ"},index = 7) |
| | | @ApiModelProperty("æå绩æ-ç§æå") |
| | | private BigDecimal productPerformanceByKJ = BigDecimal.ZERO; |
| | | |
| | | @ExcelProperty(value = {"ç§æåMES","å·¡æ£ç»©æ"},index = 8) |
| | | @ApiModelProperty("å·¡æ£ç»©æ-ç§æå") |
| | | private BigDecimal onsiteInspWageByKJ = BigDecimal.ZERO; |
| | | |
| | | @ExcelProperty(value = {"ç§æåMES","æå·¥å·¥èµ"},index = 9) |
| | | @ApiModelProperty("æå·¥å·¥èµ-ç§æå") |
| | | private BigDecimal handymanWageByKJ = BigDecimal.ZERO; |
| | | |
| | | @ExcelProperty(value = {"MESæ±æ»","å·¥åºç»©æ"},index = 10) |
| | | @ApiModelProperty("å·¥åºç»©æ-ç§æå") |
| | | private BigDecimal operationPerformance = BigDecimal.ZERO; |
| | | |
| | | @ExcelProperty(value = {"MESæ±æ»","æå绩æ"},index = 11) |
| | | @ApiModelProperty("æå绩æ-ç§æå") |
| | | private BigDecimal productPerformance = BigDecimal.ZERO; |
| | | |
| | | @ExcelProperty(value = {"MESæ±æ»","å·¡æ£ç»©æ"},index = 12) |
| | | @ApiModelProperty("å·¡æ£ç»©æ-ç§æå") |
| | | private BigDecimal onsiteInspWage = BigDecimal.ZERO; |
| | | |
| | | @ExcelProperty(value = {"MESæ±æ»","æå·¥å·¥èµ"},index = 13) |
| | | @ApiModelProperty("æå·¥å·¥èµ-ç§æå") |
| | | private BigDecimal handymanWage = BigDecimal.ZERO; |
| | | |
| | | @ExcelProperty(value = {"LIMS","产éå·¥æ¶"},index = 14) |
| | | @ApiModelProperty("产éå·¥æ¶") |
| | | private BigDecimal yieldHour; |
| | | |
| | | @ExcelProperty(value = {"LIMS","è¾
å©å·¥æ¶"},index = 15) |
| | | @ApiModelProperty("è¾
å©å·¥æ¶") |
| | | private BigDecimal subsidiaryHour; |
| | | |
| | | @ExcelProperty(value = {"LIMS","æ»å·¥æ¶"},index = 16) |
| | | @ApiModelProperty("æ»å·¥æ¶") |
| | | private BigDecimal totalHour; |
| | | |
| | | public AuxiliaryAllDto(BigDecimal yieldHour, BigDecimal subsidiaryHour, BigDecimal totalHour, Integer userId, String userName, String month) { |
| | | this.yieldHour = yieldHour; |
| | | this.subsidiaryHour = subsidiaryHour; |
| | | this.totalHour = totalHour; |
| | | this.userId = userId; |
| | | this.userName = userName; |
| | | this.month = month; |
| | | } |
| | | } |
| | |
| | | * @return |
| | | */ |
| | | List<AuxiliaryAllDto> selectAuxiliaryAllByMonth(AuxiliaryOriginalHoursLookDto dto); |
| | | |
| | | void exportWorkHoursTotal(HttpServletResponse response, AuxiliaryOriginalHoursLookDto dto); |
| | | } |
| | |
| | | |
| | | import com.alibaba.excel.EasyExcel; |
| | | import com.alibaba.excel.ExcelWriter; |
| | | import com.alibaba.excel.support.ExcelTypeEnum; |
| | | import com.alibaba.excel.write.metadata.WriteSheet; |
| | | import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.core.domain.entity.User; |
| | | import com.ruoyi.common.enums.ContractType; |
| | | import com.ruoyi.common.enums.StaffSkillLevelType; |
| | | import com.ruoyi.common.exception.base.BaseException; |
| | | import com.ruoyi.common.utils.api.mes.MesApiUtils; |
| | | import com.ruoyi.common.utils.api.mes.model.WorkingHoursRecordSumVO; |
| | | import com.ruoyi.common.utils.api.mes.model.WorkingHoursRecordTotalVO; |
| | | import com.ruoyi.common.utils.excel.EasyExcelUtils; |
| | | import com.ruoyi.common.utils.excel.FullCustomAutoWidthHandler; |
| | | import com.ruoyi.common.utils.excel.HeaderContentRowHeightHandler; |
| | | import com.ruoyi.performance.dto.AuxiliaryAllDto; |
| | | import com.ruoyi.performance.dto.AuxiliaryCorrectionHoursDto; |
| | | import com.ruoyi.performance.dto.AuxiliaryOriginalHoursDto; |
| | | import com.ruoyi.performance.dto.AuxiliaryOriginalHoursLookDto; |
| | | import com.ruoyi.performance.mapper.AuxiliaryCorrectionHoursMapper; |
| | |
| | | import com.ruoyi.performance.pojo.AuxiliaryCorrectionHours; |
| | | import com.ruoyi.performance.service.AuxiliaryOriginalHoursService; |
| | | import com.ruoyi.system.mapper.UserMapper; |
| | | import org.apache.commons.math3.analysis.function.Power; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.poi.ss.usermodel.IndexedColors; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.net.URLEncoder; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | | @Service |
| | | public class AuxiliaryOriginalHoursServiceImpl implements AuxiliaryOriginalHoursService { |
| | | |
| | |
| | | |
| | | @Resource |
| | | AuxiliaryCorrectionHoursMapper auxiliaryCorrectionHoursMapper; |
| | | |
| | | @Autowired |
| | | private MesApiUtils mesApiUtils; |
| | | |
| | | @Override |
| | | public IPage<AuxiliaryOriginalHoursDto> selectAuxiliaryOriginalHours(Page page, AuxiliaryOriginalHoursLookDto auxiliaryOriginalHoursLookDto) { |
| | |
| | | dto.setAssistBeginDate(beginDate); |
| | | dto.setAssistEndDate(endDate); |
| | | |
| | | |
| | | //æ¥è¯¢KJNSåZTNSåçMESç»©ææ°æ® |
| | | Map<String, Object> params = new HashMap<>(); |
| | | params.put("year",date.getYear()); |
| | | params.put("month",date.getMonthValue()); |
| | | List<WorkingHoursRecordTotalVO> hoursRecordSumByNS = new ArrayList<>(); |
| | | List<WorkingHoursRecordTotalVO> hoursRecordSumByKJ = new ArrayList<>(); |
| | | try { |
| | | hoursRecordSumByNS = mesApiUtils.getCheckWorkingHoursRecordSum(ContractType.ZTNS.getValue(), params); |
| | | hoursRecordSumByKJ = mesApiUtils.getCheckWorkingHoursRecordSum(ContractType.KJNS.getValue(), params); |
| | | }catch (Exception e){ |
| | | log.error("å·¥æ¶æ±æ»æ¥è¯¢å¼å¸¸ï¼{}",e.getMessage()); |
| | | } |
| | | // æ¥è¯¢äº§éå·¥æ¶ |
| | | List<AuxiliaryAllDto> auxiliaryAllDtos = auxiliaryOutputWorkingHoursMapper.selectAuxiliaryAllByMonth(dto, userIds); |
| | | |
| | |
| | | BigDecimal total = (auxiliaryAllDto.getYieldHour() != null ? auxiliaryAllDto.getYieldHour() : BigDecimal.ZERO) |
| | | .add(auxiliaryAllDto.getSubsidiaryHour() != null ? auxiliaryAllDto.getSubsidiaryHour() : BigDecimal.ZERO); |
| | | auxiliaryAllDto.setTotalHour(total); |
| | | if(!hoursRecordSumByNS.isEmpty()){ |
| | | WorkingHoursRecordTotalVO totalVOByNS = hoursRecordSumByNS.stream().filter(f -> StringUtils.equals(f.getChecker(), auxiliaryAllDto.getUserName())).findFirst().orElse(null); |
| | | if(ObjectUtils.isNotNull(totalVOByNS)){ |
| | | auxiliaryAllDto.setHandymanWageByNS(totalVOByNS.getHandymanWage()); |
| | | auxiliaryAllDto.setOnsiteInspWageByNS(totalVOByNS.getOnsiteInspWage()); |
| | | auxiliaryAllDto.setOperationPerformanceByNS(totalVOByNS.getOperationPerformance()); |
| | | auxiliaryAllDto.setProductPerformanceByNS(totalVOByNS.getProductPerformance()); |
| | | } |
| | | } |
| | | if(!hoursRecordSumByKJ.isEmpty()){ |
| | | WorkingHoursRecordTotalVO totalVOByKJ = hoursRecordSumByKJ.stream().filter(f -> StringUtils.equals(f.getChecker(), auxiliaryAllDto.getUserName())).findFirst().orElse(null); |
| | | if(ObjectUtils.isNotNull(totalVOByKJ)){ |
| | | auxiliaryAllDto.setHandymanWageByKJ(totalVOByKJ.getHandymanWage()); |
| | | auxiliaryAllDto.setOnsiteInspWageByKJ(totalVOByKJ.getOnsiteInspWage()); |
| | | auxiliaryAllDto.setOperationPerformanceByKJ(totalVOByKJ.getOperationPerformance()); |
| | | auxiliaryAllDto.setProductPerformanceByKJ(totalVOByKJ.getProductPerformance()); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return auxiliaryAllDtos; |
| | | } |
| | | |
| | | @Override |
| | | public void exportWorkHoursTotal(HttpServletResponse response, AuxiliaryOriginalHoursLookDto dto) { |
| | | response.reset(); |
| | | try { |
| | | //1.ç»è£
æ°æ® |
| | | AtomicInteger excelIndex = new AtomicInteger(1); |
| | | List<AuxiliaryAllDto> auxiliaryAllDtos = selectAuxiliaryAllByMonth(dto); |
| | | auxiliaryAllDtos.forEach(a->{ |
| | | a.setExcelIndex(excelIndex.getAndIncrement()); |
| | | a.setOperationPerformance(a.getOperationPerformanceByKJ().add(a.getOperationPerformanceByNS()));//å·¥åºç»©ææ±æ» |
| | | a.setOnsiteInspWage(a.getOnsiteInspWageByKJ().add(a.getOnsiteInspWageByNS()));//å·¡æ£ç»©ææ±æ» |
| | | a.setProductPerformance(a.getProductPerformanceByKJ().add(a.getProductPerformanceByNS()));//æåç»©ææ±æ» |
| | | a.setHandymanWage(a.getHandymanWageByKJ().add(a.getHandymanWageByNS()));//æå·¥å·¥èµ |
| | | }); |
| | | //2.å¯¼åº |
| | | String fileName = "ä¸å¤©èä¸è´¨éé¨å·¥æ¶æ±æ»"+ ExcelTypeEnum.XLSX; |
| | | fileName = URLEncoder.encode(fileName, StandardCharsets.UTF_8.toString()); |
| | | response.setContentType("application/vnd.ms-excel"); |
| | | response.setHeader("Cache-Control", "no-cache"); |
| | | response.setHeader("Content-Disposition", "attachment;filename=" + fileName); |
| | | response.setHeader("Access-Control-Expose-Headers", "Content-Disposition"); |
| | | EasyExcel.write(response.getOutputStream()) |
| | | .head(AuxiliaryAllDto.class) |
| | | .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()) |
| | | .sheet("Sheet 1") |
| | | .doWrite(auxiliaryAllDtos); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | private Map<String, AuxiliaryOriginalHoursDto> getData(List<Map<String, Object>> objectMaps, String type) { |
| | | Map<String, AuxiliaryOriginalHoursDto> dtoMap = new HashMap<>(); |
| | | for (Map<String, Object> objectMap : objectMaps) { |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.common.utils.api.mes; |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.http.HttpRequest; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.fasterxml.jackson.core.type.TypeReference; |
| | | import com.ruoyi.common.config.mes.MesConfig; |
| | | import com.ruoyi.common.config.mes.MesProperties; |
| | | import com.ruoyi.common.utils.api.mes.model.WorkingHoursRecordSumVO; |
| | | import com.ruoyi.common.utils.api.mes.model.WorkingHoursRecordTotalVO; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | public class MesApiUtils { |
| | | |
| | | @Autowired |
| | | private MesConfig mesConfig; |
| | | |
| | | /** |
| | | * æ ¹æ®å·¥åååå»mesé
ç½® |
| | | * @param contract |
| | | * @return |
| | | */ |
| | | public MesProperties getMesPropertiesByContract(String contract){ |
| | | return mesConfig.getProps().stream().filter(f-> org.apache.commons.lang3.StringUtils.equals(f.getContract(),contract)).findFirst().orElse(new MesProperties()); |
| | | } |
| | | |
| | | /** |
| | | * è·åtoken请æ±é¾æ¥ |
| | | * @return |
| | | */ |
| | | private String getAuthTokenUrl(String ip) { |
| | | return ip + "/auth/oauth/token?randomStr=blockPuzzle&grant_type=password"; |
| | | } |
| | | |
| | | /** |
| | | * æ°å¢å®æ¶åºå请æ±é¾æ¥ |
| | | * @return |
| | | */ |
| | | private String getBatchAddStockUrl(String ip){ |
| | | return ip + "/mes/stock/batchAddStock"; |
| | | } |
| | | |
| | | /** |
| | | * æ£æµå·¥æ¶ç»è®¡æ¥è¯¢è¯·æ±é¾æ¥ |
| | | * @return |
| | | */ |
| | | private String getCheckWorkingHoursRecordSumUrl(String ip){ |
| | | return ip + "/mes/checkWorkingHoursRecord/getCheckWorkingHoursRecordSum"; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * è·åmesç³»ç»token |
| | | * @return æ¥å£ååºç»æ |
| | | */ |
| | | public String getToken(MesProperties mesProperties){ |
| | | try{ |
| | | String bodyStr = "username="+mesProperties.getUser()+"&password="+mesProperties.getPassword(); |
| | | String response = HttpRequest.post(getAuthTokenUrl(mesProperties.getIp())) |
| | | .header("Authorization", "Basic cGlnOnBpZw==") |
| | | .header("Content-Type", "application/x-www-form-urlencoded") |
| | | .body(bodyStr,"application/x-www-form-urlencoded").execute().body(); |
| | | JSONObject responseObj = JSONObject.parseObject(response); |
| | | if(Objects.nonNull(responseObj.getString("access_token"))){ |
| | | return "Bearer " + responseObj.getString("access_token"); |
| | | }else{ |
| | | throw new RuntimeException(responseObj.getString("msg")); |
| | | } |
| | | }catch (Exception e){ |
| | | throw new RuntimeException("è·åMESç³»ç»tokenæ¥å£å¼å¸¸:"+e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * mesæ°å¢å®æ¶åºåæ¥å£ |
| | | * @param contract å·¥åå |
| | | * @param requestJsonStr 请æ±åæ°jsonå符串 |
| | | * @return æ¥å£ååºç»æ |
| | | */ |
| | | public boolean batchAddStock(String contract,String requestJsonStr){ |
| | | try{ |
| | | MesProperties mesProperties = getMesPropertiesByContract(contract); |
| | | String response = HttpRequest.post(getBatchAddStockUrl(mesProperties.getIp())) |
| | | .header("Authorization", getToken(mesProperties)) |
| | | .header("Content-Type", "application/json") |
| | | .body(requestJsonStr) |
| | | .execute() |
| | | .body(); |
| | | JSONObject entries = JSONObject.parseObject(response); |
| | | if(entries.getInteger("code")==0){ |
| | | return true; |
| | | }else{ |
| | | throw new RuntimeException("ã"+contract+"ã忥å°MES失败ï¼"+entries.getString("msg")); |
| | | } |
| | | }catch (Exception e){ |
| | | throw new RuntimeException("ã"+contract+"ã忥MES宿¶åºåæ¥å£å¼å¸¸:"+e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * æ£æµå·¥æ¶ç»è®¡æ¥è¯¢ |
| | | * @return |
| | | */ |
| | | public List<WorkingHoursRecordTotalVO> getCheckWorkingHoursRecordSum(String contract,Map<String,Object> params){ |
| | | try { |
| | | MesProperties mesProperties = getMesPropertiesByContract(contract); |
| | | String response = HttpRequest.get(getCheckWorkingHoursRecordSumUrl(mesProperties.getIp())) |
| | | .header("Authorization", getToken(mesProperties)) |
| | | .header("Content-Type", "application/x-www-form-urlencoded") |
| | | .form(params) |
| | | .execute() |
| | | .body(); |
| | | JSONObject entries = JSONObject.parseObject(response); |
| | | if(entries.getInteger("code")==0){ |
| | | List<WorkingHoursRecordTotalVO> totalVOS = new ArrayList<>(); |
| | | List<WorkingHoursRecordSumVO> parseObject = JSONObject.parseObject(entries.getString("data"), new TypeReference<List<WorkingHoursRecordSumVO>>() {}.getType()); |
| | | parseObject.forEach(p->{ |
| | | WorkingHoursRecordSumVO.WorkHoursVO monthTotal = p.getWorkingHours().stream().filter(f -> StringUtils.equals(f.getDutyDate(), "æåº¦æ±æ»")).findFirst().orElse(null); |
| | | WorkingHoursRecordTotalVO totalVO = new WorkingHoursRecordTotalVO(); |
| | | if(ObjectUtils.isNotEmpty(monthTotal)){ |
| | | BeanUtil.copyProperties(monthTotal,totalVO); |
| | | } |
| | | totalVO.setYear(p.getYear()); |
| | | totalVO.setMonth(p.getMonth()); |
| | | totalVO.setChecker(p.getChecker()); |
| | | totalVOS.add(totalVO); |
| | | }); |
| | | return totalVOS; |
| | | }else{ |
| | | throw new RuntimeException("ã"+contract+"ãæåMESæ£æµå·¥æ¶å¤±è´¥ï¼"+entries.getString("msg")); |
| | | } |
| | | }catch (Exception e){ |
| | | throw new RuntimeException("ã"+contract+"ãæåMESæ£æµå·¥æ¶æ¥å£å¼å¸¸ï¼"+e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.common.utils.api.mes.model; |
| | | |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 忥mesæ£æµå·¥æ¶ååºå¯¹è±¡ |
| | | */ |
| | | @Data |
| | | public class WorkingHoursRecordSumVO { |
| | | |
| | | /** |
| | | * 年份 |
| | | */ |
| | | @ApiModelProperty("年份") |
| | | private Integer year; |
| | | |
| | | /** |
| | | * æä»½ |
| | | */ |
| | | @ApiModelProperty("æä»½") |
| | | private Integer month; |
| | | |
| | | /** |
| | | * æ£æµäºº |
| | | */ |
| | | @ApiModelProperty("æ£æµäºº") |
| | | private String checker; |
| | | |
| | | /** |
| | | * æ£æµäººid |
| | | */ |
| | | @ApiModelProperty("æ£æµäººid") |
| | | private Long staffId; |
| | | |
| | | /** |
| | | * å·¥æ¶å表 |
| | | */ |
| | | @ApiModelProperty("å·¥æ¶å表") |
| | | private List<WorkHoursVO> workingHours; |
| | | |
| | | @Data |
| | | public static class WorkHoursVO { |
| | | |
| | | /** |
| | | * æ¥æ |
| | | */ |
| | | @ApiModelProperty("æ¥æ") |
| | | private String dutyDate; |
| | | |
| | | /** |
| | | * å·¥åºåå¼ |
| | | */ |
| | | @ApiModelProperty("å·¥åºåå¼") |
| | | private BigDecimal operationScore; |
| | | |
| | | /** |
| | | * å·¥åºç»©æ |
| | | */ |
| | | @ApiModelProperty("å·¥åºç»©æ") |
| | | private BigDecimal operationPerformance; |
| | | |
| | | /** |
| | | * æååå¼ |
| | | */ |
| | | @ApiModelProperty("æååå¼") |
| | | private BigDecimal productScore; |
| | | |
| | | /** |
| | | * æå绩æ |
| | | */ |
| | | @ApiModelProperty("æå绩æ") |
| | | private BigDecimal productPerformance; |
| | | |
| | | /** |
| | | * æå·¥å·¥æ¶ |
| | | */ |
| | | @ApiModelProperty("æå·¥å·¥æ¶") |
| | | private BigDecimal handymanHours; |
| | | |
| | | /** |
| | | * æå·¥å·¥èµ |
| | | */ |
| | | @ApiModelProperty("æå·¥å·¥èµ") |
| | | private BigDecimal handymanWage; |
| | | |
| | | /** |
| | | * å·¡æ£å·¥èµ |
| | | */ |
| | | @ApiModelProperty("å·¡æ£å·¥èµ") |
| | | private BigDecimal onsiteInspWage; |
| | | |
| | | /** |
| | | * æ±æ» |
| | | */ |
| | | @ApiModelProperty("æ±æ»") |
| | | private BigDecimal total; |
| | | } |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.common.utils.api.mes.model; |
| | | |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | |
| | | import java.math.BigDecimal; |
| | | |
| | | @Data |
| | | public class WorkingHoursRecordTotalVO { |
| | | |
| | | |
| | | /** |
| | | * 年份 |
| | | */ |
| | | @ApiModelProperty("年份") |
| | | private Integer year; |
| | | |
| | | /** |
| | | * æä»½ |
| | | */ |
| | | @ApiModelProperty("æä»½") |
| | | private Integer month; |
| | | |
| | | /** |
| | | * æ£æµäºº |
| | | */ |
| | | @ApiModelProperty("æ£æµäºº") |
| | | private String checker; |
| | | |
| | | /** |
| | | * æ¥æ |
| | | */ |
| | | @ApiModelProperty("æ¥æ") |
| | | private String dutyDate; |
| | | |
| | | /** |
| | | * å·¥åºåå¼ |
| | | */ |
| | | @ApiModelProperty("å·¥åºåå¼") |
| | | private BigDecimal operationScore; |
| | | |
| | | /** |
| | | * å·¥åºç»©æ |
| | | */ |
| | | @ApiModelProperty("å·¥åºç»©æ") |
| | | private BigDecimal operationPerformance; |
| | | |
| | | /** |
| | | * æååå¼ |
| | | */ |
| | | @ApiModelProperty("æååå¼") |
| | | private BigDecimal productScore; |
| | | |
| | | /** |
| | | * æå绩æ |
| | | */ |
| | | @ApiModelProperty("æå绩æ") |
| | | private BigDecimal productPerformance; |
| | | |
| | | /** |
| | | * æå·¥å·¥æ¶ |
| | | */ |
| | | @ApiModelProperty("æå·¥å·¥æ¶") |
| | | private BigDecimal handymanHours; |
| | | |
| | | /** |
| | | * æå·¥å·¥èµ |
| | | */ |
| | | @ApiModelProperty("æå·¥å·¥èµ") |
| | | private BigDecimal handymanWage; |
| | | |
| | | /** |
| | | * å·¡æ£å·¥èµ |
| | | */ |
| | | @ApiModelProperty("å·¡æ£å·¥èµ") |
| | | private BigDecimal onsiteInspWage; |
| | | |
| | | /** |
| | | * æ±æ» |
| | | */ |
| | | @ApiModelProperty("æ±æ»") |
| | | private BigDecimal total; |
| | | |
| | | } |