Compare commits

...

3 Commits

Author SHA1 Message Date
HuangHuiKang a8fb7cd262 feat:完成生产计划报表相关接口 4 weeks ago
HuangHuiKang ead8061756 feat:完成app统计报表 4 weeks ago
HuangHuiKang 6923984f8f feat:完成app统计报表 4 weeks ago

@ -0,0 +1,26 @@
package cn.iocoder.yudao.module.erp.controller.admin.product.vo.product;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Schema(description = "管理后台 - ERP 产品列表 Request VO")
@Data
public class ErpProductListReqVO {
@Schema(description = "产品名称", example = "零件A")
private String name;
@Schema(description = "产品分类编号", example = "11161")
private Long categoryId;
@Schema(description = "产品编号", example = "11161")
private String code;
@Schema(description = "产品规格", example = "红色")
private String standard;
@Schema(description = "产品 id 集合")
private List<Long> ids;
}

@ -105,4 +105,4 @@ public class ErpProductRespVO extends ErpProductDO {
@Schema(description = "关联模具列表")
private List<ProductRelationRespVO> molds;
}
}

@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductListReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductRelationRespVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
@ -35,6 +36,16 @@ public interface ErpProductMapper extends BaseMapperX<ErpProductDO> {
.orderByDesc(ErpProductDO::getId));
}
default List<ErpProductDO> selectList(ErpProductListReqVO reqVO) {
return selectList(new LambdaQueryWrapperX<ErpProductDO>()
.inIfPresent(ErpProductDO::getId, reqVO.getIds())
.likeIfPresent(ErpProductDO::getName, reqVO.getName())
.likeIfPresent(ErpProductDO::getBarCode, reqVO.getCode())
.eqIfPresent(ErpProductDO::getCategoryId, reqVO.getCategoryId())
.likeIfPresent(ErpProductDO::getStandard, reqVO.getStandard())
.orderByDesc(ErpProductDO::getId));
}
default PageResult<ErpProductDO> selectProductCodeExist(ErpProductPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ErpProductDO>()
.eqIfPresent(ErpProductDO::getName, reqVO.getName())
@ -92,4 +103,4 @@ public interface ErpProductMapper extends BaseMapperX<ErpProductDO> {
List<ProductRelationRespVO> selectMoldsByProductId(@Param("productId") Long productId);
}
}

@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.erp.service.product;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductImportExcelVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductImportRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductListReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductPageReqVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductSaveReqVO;

@ -26,7 +26,6 @@ import cn.iocoder.yudao.module.erp.dal.mysql.productdevicerel.ProductDeviceRelMa
import cn.iocoder.yudao.module.erp.dal.mysql.productmoldrel.ProductMoldRelMapper;
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockMapper;
import cn.iocoder.yudao.module.erp.service.stock.ErpStockService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.extern.slf4j.Slf4j;

@ -52,6 +52,7 @@ public interface ErrorCodeConstants {
ErrorCode DEVICE_ATTRIBUTE_NOT_EXISTS = new ErrorCode(1_003_000_006, "设备属性不存在");
ErrorCode DEVICE_ATTRIBUTE_TYPE_NOT_EXISTS = new ErrorCode(1_003_000_007, "采集点分类不存在");
ErrorCode DEVICE_CODE_EXISTS = new ErrorCode(1_003_000_000, "采集点编码已存在");
ErrorCode DEVICE_RATE_TREND_PERIOD_INVALID = new ErrorCode(1_003_000_100, "设备趋势查询时间区间参数不正确");
ErrorCode DEVICE_ATTRIBUTE_TYPE_REFERENCES_EXISTS = new ErrorCode(1_003_000_008, "存在采集点类型已被引用,请先删除对应引用");
ErrorCode ENDPOINT_DOES_NOT_EXIS = new ErrorCode(1_003_000_009, "暂未设置设备端点");
ErrorCode DEVICE_DOES_NOT_EXIST= new ErrorCode(1_003_000_010, "该采集设备不存在");
@ -85,6 +86,4 @@ public interface ErrorCodeConstants {
ErrorCode TABLE_CREATION_FAILED = new ErrorCode(1_004_000_008, "TDengine 表创建失败");
ErrorCode COLOUMN_CREATION_FAILED = new ErrorCode(1_004_000_008, "TDengine 列创建失败");
ErrorCode COLUMN_RENAME_FAILED = new ErrorCode(1_004_000_008, "列名修改失败");
}

@ -256,6 +256,12 @@ public class DeviceController {
return success(deviceOperationalStatus);
}
@GetMapping("/deviceRateTrend")
@Operation(summary = "按天查询设备整体开机率和稼动率趋势")
public CommonResult<List<DeviceRateTrendPointRespVO>> getDeviceRateTrend(@Valid DeviceRateTrendReqVO reqVO) {
return success(deviceService.getDeviceRateTrend(reqVO));
}
@GetMapping("/getDeviceOverview")
@Operation(summary = "获取设备概况")
public CommonResult<DeviceOverviewRespVO> getDeviceOverview() {

@ -0,0 +1,71 @@
package cn.iocoder.yudao.module.iot.controller.admin.device.enums;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.iot.enums.ErrorCodeConstants.DEVICE_RATE_TREND_PERIOD_INVALID;
@Getter
@AllArgsConstructor
public enum DeviceRateTrendPeriodEnum {
LAST_WEEK("LAST_WEEK", "上周") {
@Override
public DateRange resolve(LocalDate today) {
LocalDate start = today.minusWeeks(1).with(java.time.DayOfWeek.MONDAY);
return new DateRange(start, start.plusDays(6));
}
},
THIS_WEEK("THIS_WEEK", "本周") {
@Override
public DateRange resolve(LocalDate today) {
LocalDate start = today.with(java.time.DayOfWeek.MONDAY);
return new DateRange(start, today.minusDays(1));
}
},
LAST_7_DAYS("LAST_7_DAYS", "近7日") {
@Override
public DateRange resolve(LocalDate today) {
return new DateRange(today.minusDays(7), today.minusDays(1));
}
},
LAST_MONTH("LAST_MONTH", "上月") {
@Override
public DateRange resolve(LocalDate today) {
LocalDate start = today.minusMonths(1).withDayOfMonth(1);
return new DateRange(start, start.with(TemporalAdjusters.lastDayOfMonth()));
}
},
THIS_MONTH("THIS_MONTH", "本月") {
@Override
public DateRange resolve(LocalDate today) {
LocalDate start = today.withDayOfMonth(1);
return new DateRange(start, today.minusDays(1));
}
};
private final String code;
private final String name;
public abstract DateRange resolve(LocalDate today);
public static DeviceRateTrendPeriodEnum valueOfCode(String code) {
for (DeviceRateTrendPeriodEnum value : values()) {
if (value.code.equalsIgnoreCase(code)) {
return value;
}
}
throw exception(DEVICE_RATE_TREND_PERIOD_INVALID);
}
@Getter
@AllArgsConstructor
public static class DateRange {
private final LocalDate start;
private final LocalDate end;
}
}

@ -0,0 +1,21 @@
package cn.iocoder.yudao.module.iot.controller.admin.device.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@Schema(description = "管理后台 - 设备开机率/稼动率趋势点 Response VO")
public class DeviceRateTrendPointRespVO {
@Schema(description = "日期")
private String day;
@Schema(description = "当天整体开机率")
private String powerOnRate;
@Schema(description = "当天整体稼动率")
private String utilizationRate;
@Schema(description = "当天参与统计设备数")
private Integer deviceCount;
}

@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.iot.controller.admin.device.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@Schema(description = "管理后台 - 设备开机率/稼动率趋势 Request VO")
public class DeviceRateTrendReqVO {
@Schema(description = "设备编码")
private String deviceCode;
@Schema(description = "设备名称")
private String deviceName;
@Schema(description = "设备ID集合逗号分隔")
private String ids;
@Schema(description = "时间区间LAST_WEEK/THIS_WEEK/LAST_7_DAYS/LAST_MONTH/THIS_MONTH")
private String period;
@Schema(description = "是否只统计排产设备,默认 true")
private Boolean onlyScheduled;
@Schema(description = "是否跳过节假日,默认 false")
private Boolean skipHoliday;
}

@ -103,10 +103,24 @@ public class DeviceOperationRecordController {
return success(pageResult);
}
@GetMapping("/deviceOperationPageList")
@Operation(summary = "设备运行报表列表")
@PreAuthorize("@ss.hasPermission('iot:device-operation-record:query')")
public CommonResult<List<DeviceTotalTimeRecordRespVO>> deviceOperationPageList(@Valid DeviceTotalTimeRecordReqVO pageReqVO) {
return success(deviceOperationRecordService.deviceOperationPageList(pageReqVO));
}
@GetMapping("/deviceRateTrendByDeviceId")
@Operation(summary = "根据设备ID查询某个设备近7日开机率和稼动率")
@PreAuthorize("@ss.hasPermission('iot:device-operation-record:query')")
public CommonResult<List<DeviceOperationRateTrendRespVO>> getDeviceRateTrendByDeviceId(@RequestParam("deviceId") Long deviceId) {
return success(deviceOperationRecordService.getDeviceRateTrendByDeviceId(deviceId));
}
@GetMapping("/deviceOperationList")
@Operation(summary = "产线设备运行开机率/稼动率-大屏")
// @PreAuthorize("@ss.hasPermission('iot:device-operation-record:query')")
@PreAuthorize("@ss.hasPermission('iot:device-operation-record:query')")
public CommonResult<List<DeviceTotalTimeRecordRespVO>> deviceOperationList(@Valid DeviceTotalTimeRecordReqVO pageReqVO) {
List<DeviceTotalTimeRecordRespVO> deviceTotalTimeRecordRespVOList = deviceOperationRecordService.deviceOperationList(pageReqVO);
return success(deviceTotalTimeRecordRespVOList);
@ -130,4 +144,4 @@ public class DeviceOperationRecordController {
// 导出 Excel
ExcelUtils.write(response, fileName, "数据", DeviceTotalTimeRecordRespVO.class,pageResult.getList());
}
}
}

@ -0,0 +1,18 @@
package cn.iocoder.yudao.module.iot.controller.admin.deviceoperationrecord.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
@Schema(description = "管理后台 - 单设备近7日开机率/稼动率趋势 Response VO")
public class DeviceOperationRateTrendRespVO {
@Schema(description = "日期")
private String day;
@Schema(description = "当天开机率")
private String powerOnRate;
@Schema(description = "当天稼动率")
private String utilizationRate;
}

@ -15,6 +15,7 @@ import org.apache.ibatis.annotations.Select;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -135,6 +136,10 @@ public interface DeviceMapper extends BaseMapperX<DeviceDO> {
List<DeviceDO> selectListIncludeDeletedByIds(@Param("ids") Collection<Long> ids);
List<Long> selectScheduledDvIds(@Param("requestIds") Collection<Long> requestIds);
List<Date> selectHolidayDays(@Param("startDay") Date startDay, @Param("endDay") Date endDay);
}

@ -138,6 +138,8 @@ public interface DeviceService {
DeviceOverviewRespVO getDeviceOverview();
List<DeviceRateTrendPointRespVO> getDeviceRateTrend(DeviceRateTrendReqVO reqVO);
List<Map<String, Object>> getMultiDeviceAttributes(Long goviewId);
List<DeviceContactModelDO> getDeviceAttributeList(Long deviceId);

@ -5,14 +5,18 @@ import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.enums.DeviceConnectionStatusEnum;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.common.util.opc.OpcUtils;
import cn.iocoder.yudao.module.iot.controller.admin.device.enums.DeviceRateTrendPeriodEnum;
import cn.iocoder.yudao.module.iot.controller.admin.device.enums.DeviceStatusEnum;
import cn.iocoder.yudao.module.iot.controller.admin.device.scheduled.utils.CronExpressionUtils;
import cn.iocoder.yudao.module.iot.controller.admin.device.scheduled.scheduler.TaskSchedulerManager;
import cn.iocoder.yudao.module.iot.controller.admin.device.utils.DataTypeParseUtil;
import cn.iocoder.yudao.module.iot.controller.admin.device.vo.*;
import cn.iocoder.yudao.module.iot.controller.admin.devicecontactmodel.vo.DeviceContactModelPageReqVO;
import cn.iocoder.yudao.module.iot.controller.admin.deviceoperationrecord.vo.DeviceTotalTimeRecordReqVO;
import cn.iocoder.yudao.module.iot.controller.admin.deviceoperationrecord.vo.DeviceTotalTimeRecordRespVO;
import cn.iocoder.yudao.module.iot.controller.admin.mqttdatarecord.vo.MqttDataRecordPageReqVO;
import cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO;
import cn.iocoder.yudao.module.iot.dal.dataobject.deviceattributetype.DeviceAttributeTypeDO;
@ -31,6 +35,8 @@ import cn.iocoder.yudao.module.iot.dal.mysql.devicemodel.DeviceModelMapper;
import cn.iocoder.yudao.module.iot.dal.mysql.devicemodelattribute.DeviceModelAttributeMapper;
import cn.iocoder.yudao.module.iot.dal.mysql.devicemodelrules.DeviceModelRulesMapper;
import cn.iocoder.yudao.module.iot.dal.mysql.deviceoperationrecord.DeviceOperationRecordMapper;
import cn.iocoder.yudao.module.iot.service.deviceoperationrecord.DeviceOperationRecordService;
import cn.iocoder.yudao.module.iot.dal.mysql.devicepointrules.DevicePointRulesMapper;
import cn.iocoder.yudao.module.iot.dal.mysql.gateway.GatewayMapper;
import cn.iocoder.yudao.module.iot.dal.mysql.mqttdatarecord.MqttDataRecordMapper;
@ -57,7 +63,10 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.function.Function;
@ -114,6 +123,8 @@ public class DeviceServiceImpl implements DeviceService {
@Resource
private DeviceOperationRecordMapper deviceOperationRecordMapper;
@Resource
private DeviceOperationRecordService deviceOperationRecordService;
@Resource
private IMqttservice mqttService;
@ -1279,7 +1290,7 @@ public class DeviceServiceImpl implements DeviceService {
standbyCount++;
} else if ("3".equals(status)) {
faultCount++;
} else if ("0".equals(status)){
} else {
offlineCount++;
}
}
@ -1725,6 +1736,124 @@ public class DeviceServiceImpl implements DeviceService {
));
}
/**
*
* deviceOperationPage
*/
@Override
public List<DeviceRateTrendPointRespVO> getDeviceRateTrend(DeviceRateTrendReqVO reqVO) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND);
// 根据 period 解析查询日期范围,不包含当天
DeviceRateTrendPeriodEnum.DateRange dateRange = DeviceRateTrendPeriodEnum.valueOfCode(reqVO.getPeriod()).resolve(LocalDate.now());
LocalDateTime startDateTime = dateRange.getStart().atStartOfDay();
LocalDateTime endDateTime = dateRange.getEnd().atTime(LocalTime.MAX).withNano(0);
// 默认只统计排产设备,这里先得到最终参与统计的设备集合
String filteredIds = buildFilteredDeviceIds(reqVO);
List<DeviceRateTrendPointRespVO> result = new ArrayList<>();
for (LocalDate day = startDateTime.toLocalDate(); !day.isAfter(endDateTime.toLocalDate()); day = day.plusDays(1)) {
// 跳过节假日时,这一天不查询,也不返回
if (Boolean.TRUE.equals(reqVO.getSkipHoliday()) && isHoliday(day)) {
continue;
}
LocalDateTime dayStart = day.atStartOfDay();
LocalDateTime dayEnd = day.atTime(LocalTime.MAX).withNano(0);
// 复用现有 deviceOperationPage查出当天每台设备的开机率、稼动率基础数据
List<DeviceTotalTimeRecordRespVO> deviceDayList = queryDeviceDayList(reqVO, filteredIds, dayStart.format(formatter), dayEnd.format(formatter));
double powerOnRateSum = 0D;
double utilizationRateSum = 0D;
int deviceCount = deviceDayList.size();
for (DeviceTotalTimeRecordRespVO record : deviceDayList) {
powerOnRateSum += parsePercentValue(record.getPowerOnRate());
utilizationRateSum += parsePercentValue(record.getUtilizationRate());
}
DeviceRateTrendPointRespVO point = new DeviceRateTrendPointRespVO();
point.setDay(day.toString());
point.setDeviceCount(deviceCount);
point.setPowerOnRate(formatPercentValue(deviceCount > 0 ? powerOnRateSum / deviceCount : 0D));
point.setUtilizationRate(formatPercentValue(deviceCount > 0 ? utilizationRateSum / deviceCount : 0D));
result.add(point);
}
return result;
}
private double parsePercentValue(String percent) {
if (StringUtils.isBlank(percent)) {
return 0D;
}
String value = percent.trim();
if (value.endsWith("%")) {
value = value.substring(0, value.length() - 1);
}
if (StringUtils.isBlank(value)) {
return 0D;
}
return Double.parseDouble(value);
}
private String formatPercentValue(double value) {
return String.format("%.2f%%", value);
}
private List<DeviceTotalTimeRecordRespVO> queryDeviceDayList(DeviceRateTrendReqVO reqVO, String ids, String startTime, String endTime) {
DeviceTotalTimeRecordReqVO pageReqVO =
new DeviceTotalTimeRecordReqVO();
pageReqVO.setDeviceCode(reqVO.getDeviceCode());
pageReqVO.setDeviceName(reqVO.getDeviceName());
pageReqVO.setIds(ids);
pageReqVO.setStartTime(startTime);
pageReqVO.setEndTime(endTime);
return deviceOperationRecordService.deviceOperationPageList(pageReqVO);
}
private String buildFilteredDeviceIds(DeviceRateTrendReqVO reqVO) {
boolean onlyScheduled = reqVO.getOnlyScheduled() == null || reqVO.getOnlyScheduled();
if (!onlyScheduled) {
return reqVO.getIds();
}
Collection<Long> requestIds = parseIds(reqVO.getIds());
List<Long> filteredDvIds = deviceMapper.selectScheduledDvIds(requestIds);
if (StringUtils.isNotBlank(reqVO.getIds())) {
Set<Long> requestIdSet = new HashSet<>(requestIds);
filteredDvIds = filteredDvIds.stream().filter(requestIdSet::contains).collect(Collectors.toList());
}
if (filteredDvIds.isEmpty()) {
return "-1";
}
return filteredDvIds.stream().map(String::valueOf).collect(Collectors.joining(","));
}
private boolean isHoliday(LocalDate day) {
List<Date> holidays = deviceMapper.selectHolidayDays(java.sql.Date.valueOf(day), java.sql.Date.valueOf(day.plusDays(1)));
return !CollectionUtils.isEmpty(holidays);
}
private String toPercent(double value) {
return String.format("%.2f%%", value * 100);
}
private Collection<Long> parseIds(String ids) {
if (StringUtils.isBlank(ids)) {
return Collections.emptyList();
}
return Arrays.stream(ids.split(","))
.map(String::trim)
.filter(StringUtils::isNotBlank)
.map(Long::valueOf)
.collect(Collectors.toList());
}
}

@ -54,5 +54,9 @@ public interface DeviceOperationRecordService {
PageResult<DeviceTotalTimeRecordRespVO> deviceOperationPage(@Valid DeviceTotalTimeRecordReqVO pageReqVO);
List<DeviceTotalTimeRecordRespVO> deviceOperationPageList(@Valid DeviceTotalTimeRecordReqVO pageReqVO);
List<DeviceOperationRateTrendRespVO> getDeviceRateTrendByDeviceId(Long deviceId);
List<DeviceTotalTimeRecordRespVO> deviceOperationList(@Valid DeviceTotalTimeRecordReqVO pageReqVO);
}
}

@ -13,6 +13,7 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.time.Duration;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
@ -144,6 +145,79 @@ public class DeviceOperationRecordServiceImpl implements DeviceOperationRecordSe
}
@Override
public List<DeviceTotalTimeRecordRespVO> deviceOperationPageList(DeviceTotalTimeRecordReqVO pageReqVO) {
List<DeviceTotalTimeRecordRespVO> deviceList =
deviceOperationRecordMapper.selectDeviceListFromMySQL(pageReqVO);
if (CollectionUtils.isEmpty(deviceList)) {
return Collections.emptyList();
}
List<Long> deviceIds = deviceList.stream()
.map(DeviceTotalTimeRecordRespVO::getId)
.collect(Collectors.toList());
List<Map<String, Object>> statsList =
deviceOperationRecordMapper.selectDeviceStatsFromTD(
deviceIds,
pageReqVO.getStartTime(),
pageReqVO.getEndTime()
);
Map<Long, DeviceTotalTimeRecordRespVO> tdStatsMap = convertStatsListToMap(statsList);
List<DeviceTotalTimeRecordRespVO> result = new ArrayList<>();
for (DeviceTotalTimeRecordRespVO device : deviceList) {
DeviceTotalTimeRecordRespVO stats = tdStatsMap.get(device.getId());
if (stats != null) {
device.setTotalOfflineTime(stats.getTotalOfflineTime());
device.setTotalRunningTime(stats.getTotalRunningTime());
device.setTotalStandbyTime(stats.getTotalStandbyTime());
device.setTotalFaultTime(stats.getTotalFaultTime());
} else {
device.setTotalOfflineTime(0);
device.setTotalRunningTime(0);
device.setTotalStandbyTime(0);
device.setTotalFaultTime(0);
}
result.add(device);
}
calculateAndSetConvertedValues(result, pageReqVO);
result.sort(Comparator.comparingDouble(this::parsePercentValue).reversed());
return result;
}
@Override
public List<DeviceOperationRateTrendRespVO> getDeviceRateTrendByDeviceId(Long deviceId) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
List<DeviceOperationRateTrendRespVO> result = new ArrayList<>();
for (int offset = 6; offset >= 0; offset--) {
LocalDate day = LocalDate.now().minusDays(offset);
LocalDateTime dayStart = day.atStartOfDay();
LocalDateTime dayEnd = day.atTime(LocalTime.MAX).withNano(0);
DeviceTotalTimeRecordReqVO reqVO = new DeviceTotalTimeRecordReqVO();
reqVO.setIds(String.valueOf(deviceId));
reqVO.setStartTime(dayStart.format(formatter));
reqVO.setEndTime(dayEnd.format(formatter));
List<DeviceTotalTimeRecordRespVO> dayList = deviceOperationPageList(reqVO);
DeviceTotalTimeRecordRespVO record = CollectionUtils.isNotEmpty(dayList) ? dayList.get(0) : null;
DeviceOperationRateTrendRespVO trend = new DeviceOperationRateTrendRespVO();
trend.setDay(day.toString());
trend.setPowerOnRate(record != null ? record.getPowerOnRate() : "0%");
trend.setUtilizationRate(record != null ? record.getUtilizationRate() : "0%");
result.add(trend);
}
return result;
}
@Override
public List<DeviceTotalTimeRecordRespVO> deviceOperationList(DeviceTotalTimeRecordReqVO deviceTotalTimeRecordReqVO) {
@ -242,6 +316,13 @@ public class DeviceOperationRecordServiceImpl implements DeviceOperationRecordSe
return lineList;
}
private double parsePercentValue(DeviceTotalTimeRecordRespVO record) {
if (record == null || StringUtils.isBlank(record.getUtilizationRate())) {
return 0D;
}
return Double.parseDouble(record.getUtilizationRate().replace("%", "").trim());
}
private void calculateAndSetConvertedValues(
List<DeviceTotalTimeRecordRespVO> records,
DeviceTotalTimeRecordReqVO reqVO) {
@ -269,19 +350,19 @@ public class DeviceOperationRecordServiceImpl implements DeviceOperationRecordSe
// 在线时间 = 运行 + 待机 + 故障
double onlineSec = runningSec + standbySec + faultSec;
double totalSec = offlineSec + onlineSec;
// 计算总时间(根据筛选时间)
double totalSec = 0;
if (StringUtils.isNotBlank(startTimeStr) && StringUtils.isNotBlank(endTimeStr)) {
DateTimeFormatter formatter =
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime start = LocalDateTime.parse(startTimeStr, formatter);
LocalDateTime end = LocalDateTime.parse(endTimeStr, formatter);
totalSec = Duration.between(start, end).getSeconds();
}
// double totalSec = 0;
// if (StringUtils.isNotBlank(startTimeStr) && StringUtils.isNotBlank(endTimeStr)) {
//
// DateTimeFormatter formatter =
// DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//
// LocalDateTime start = LocalDateTime.parse(startTimeStr, formatter);
// LocalDateTime end = LocalDateTime.parse(endTimeStr, formatter);
//
// totalSec = Duration.between(start, end).getSeconds();
// }
// 防止负数或异常
if (totalSec < 0) {
@ -393,4 +474,4 @@ public class DeviceOperationRecordServiceImpl implements DeviceOperationRecordSe
return 0;
}
}
}

@ -246,5 +246,31 @@
</foreach>
</select>
<select id="selectScheduledDvIds" resultType="java.lang.Long">
SELECT DISTINCT mo.dv_id
FROM mes_organization mo
INNER JOIN mes_device_ledger mdl ON mdl.id = mo.machine_id
WHERE mo.deleted = 0
AND mo.machine_id IS NOT NULL
AND mo.dv_id IS NOT NULL
AND mdl.deleted = 0
AND mdl.is_scheduled = 1
<if test="requestIds != null and requestIds.size() > 0">
AND mo.dv_id IN
<foreach collection="requestIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</select>
<select id="selectHolidayDays" resultType="java.util.Date">
SELECT the_day
FROM mes_cal_holiday
WHERE deleted = 0
AND holiday_type = 'HOLIDAY'
AND the_day &gt;= #{startDay}
AND the_day &lt; #{endDay}
</select>
</mapper>

@ -193,7 +193,7 @@ public interface ErrorCodeConstants {
ErrorCode SCHEDULE_TIME_RANGE_INVALID = new ErrorCode(100_301_0013, "排产时间范围非法start={}, end={},结束时间必须晚于开始时间");
ErrorCode SCHEDULE_WORK_HOURS_INVALID = new ErrorCode(100_301_0014, "排产工时非法start={}, end={}可用工时必须大于0");
ErrorCode WAREHOUSE_NOT_EXISTS= new ErrorCode(100_301_0014, "仓库Id不能为空");
ErrorCode PLAN_RECORD_NOT_EXISTS = new ErrorCode(100_301_0015, "生产计划操作记录不存在");

@ -19,6 +19,9 @@ public class BaogongRecordPageReqVO extends PageParam {
@Schema(description = "关联计划id", example = "3326")
private Long planId;
@Schema(description = "任务单ID", example = "18331")
private Long taskId;
@Schema(description = "派工数量")
private Long num;
@ -38,4 +41,4 @@ public class BaogongRecordPageReqVO extends PageParam {
@Schema(description = "原因")
private String remark;
}
}

@ -27,4 +27,7 @@ public class BaogongRecordStatPageReqVO extends PageParam {
@Schema(description = "报工记录ID集合用于多选导出")
private List<Long> ids;
@Schema(description = "任务单Id")
private Long taskId ;
}

@ -83,9 +83,8 @@ public class BomController {
@Operation(summary = "获得产品BOM")
@Parameter(name = "productId", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('mes:bom:query')")
public CommonResult<BomRespVO> getByProductId(@RequestParam("id") Long id) {
BomDO bom = bomService.getBom(id);
return success(BeanUtils.toBean(bom, BomRespVO.class));
public CommonResult<List<BomDetailRespVO>> getByProductId(@RequestParam("productId") Long productId) {
return success(bomService.getBomDetailRespListByProductId(productId));
}
@GetMapping("/page")
@ -119,4 +118,4 @@ public class BomController {
return success(bomService.getBomDetailListByBomId(bomId));
}
}
}

@ -14,6 +14,7 @@ import cn.iocoder.yudao.module.mes.controller.admin.dashboard.vo.*;
import cn.iocoder.yudao.module.mes.controller.admin.dashboard.vo.dashboard.EventStatisticsVO;
import cn.iocoder.yudao.module.mes.controller.admin.dashboard.vo.dashboard.TaskVO;
import cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.task.vo.TaskStatusEnum;
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger.DeviceLedgerDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.dvrepair.DvRepairDO;
import cn.iocoder.yudao.module.common.dal.dataobject.moldrepair.MoldRepairDO;
@ -54,6 +55,7 @@ import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
@ -126,6 +128,10 @@ public class DashboardController {
TaskRespVO taskRespVO = new TaskRespVO();
List<TaskRespVO.Item> taskItems = new ArrayList<>();
List<TaskRespVO.Item> planItems = new ArrayList<>();
Map<Integer, Long> taskStatusCountMap = taskMapper.selectList(new LambdaQueryWrapperX<TaskDO>()
.betweenIfPresent(TaskDO::getOrderDate, taskReqVO.getStartTime()))
.stream()
.collect(Collectors.groupingBy(TaskDO::getStatus, Collectors.counting()));
// 生产任务总数
TaskRespVO.Item item = new TaskRespVO.Item();
item.setKey("1");
@ -166,6 +172,8 @@ public class DashboardController {
.in(TaskDO::getStatus, count3)
.betweenIfPresent(TaskDO::getOrderDate, taskReqVO.getStartTime())));
taskItems.add(item);
// 生产计划总数
item = new TaskRespVO.Item();
item.setKey("5");
@ -233,6 +241,14 @@ public class DashboardController {
item.setValue(passRate);
planItems.add(item);
for (TaskStatusEnum taskStatusEnum : TaskStatusEnum.values()) {
item = new TaskRespVO.Item();
item.setKey(String.valueOf(taskStatusEnum.getValue()));
item.setLabel(taskStatusEnum.name());
item.setValue(taskStatusCountMap.getOrDefault(taskStatusEnum.getValue(), 0L));
taskItems.add(item);
}
taskRespVO.setTaskItems(taskItems);
taskRespVO.setPlanItems(planItems);
return success(taskRespVO);

@ -26,6 +26,7 @@ import cn.iocoder.yudao.module.mes.dal.dataobject.bom.BomDetailDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger.DeviceLedgerDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.organization.OrganizationDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.plan.PlanDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.planrecord.PlanRecordDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.task.TaskDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.task.TaskDetailDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.zjproduct.ZjProductDO;
@ -34,6 +35,7 @@ import cn.iocoder.yudao.module.mes.dal.mysql.bom.BomDetailMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.bom.BomMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.deviceledger.DeviceLedgerMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.plan.PlanMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.planrecord.PlanRecordMapper;
import cn.iocoder.yudao.module.mes.service.bom.BomService;
import cn.iocoder.yudao.module.mes.service.deviceledger.DeviceLedgerService;
import cn.iocoder.yudao.module.mes.service.itemrequisition.ItemAnalysisService;
@ -106,6 +108,9 @@ public class PlanController {
@Resource
private BomDetailMapper bomDetailMapper;
@Resource
private PlanRecordMapper planRecordMapper;
@Resource
private TaskService taskService;
@ -204,6 +209,13 @@ public class PlanController {
return success(new PageResult<>(buildVOList(pageResult.getList()), pageResult.getTotal()));
}
@GetMapping("/page-by-task")
@Operation(summary = "根据任务单ID获得该任务下所有计划分页")
@PreAuthorize("@ss.hasPermission('mes:plan:query')")
public CommonResult<PageResult<PlanTaskPageRespVO>> getPlanPageByTaskId(@Valid PlanTaskPageReqVO pageReqVO) {
return success(planService.getPlanPageByTaskId(pageReqVO));
}
private List<PlanRespVO> buildVOList(List<PlanRespVO> list) {
if (CollUtil.isEmpty(list)) {
return Collections.emptyList();
@ -301,6 +313,11 @@ public class PlanController {
String code = statusUpdateVO.getCode();
PlanRecordDO planRecordDO = new PlanRecordDO();
planRecordDO.setTaskId(planDO.getTaskId());
planRecordDO.setPlanId(planDO.getId());
planRecordDO.setOperateTime(LocalDateTime.now());
// 1) 先处理计划状态
if ("pre".equals(code)) {
planDO.setStatus(PlanStatusEnum..getValue());
@ -308,17 +325,22 @@ public class PlanController {
planDO.setStatus(PlanStatusEnum..getValue());
} else if ("pause".equals(code)) {
planDO.setStatus(PlanStatusEnum..getValue());
planRecordDO.setOperateStatus(PlanStatusEnum..getValue());
} else if ("end".equals(code)) {
planDO.setStatus(PlanStatusEnum..getValue());
planRecordDO.setOperateStatus(PlanStatusEnum..getValue());
} else if ("store".equals(code)) {
if (statusUpdateVO.getWarehouseId() ==null ){
throw exception(WAREHOUSE_NOT_EXISTS);
}
planDO.setStatus(PlanStatusEnum..getValue());
planRecordDO.setOperateStatus(PlanStatusEnum..getValue());
} else if ("commence".equals(code)) {
planRecordDO.setOperateStatus(PlanStatusEnum..getValue());
planDO.setStatus(PlanStatusEnum..getValue());
}
planRecordMapper.insert(planRecordDO);
// 2) 先落库计划状态store 最后一条判断依赖这个)
planMapper.updateById(planDO);

@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.mes.controller.admin.plan.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import javax.validation.constraints.NotNull;
@Schema(description = "管理后台 - 按任务单查询生产计划分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class PlanTaskPageReqVO extends PageParam {
@Schema(description = "任务单ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "18331")
@NotNull(message = "任务单ID不能为空")
private Long taskId;
}

@ -0,0 +1,50 @@
package cn.iocoder.yudao.module.mes.controller.admin.plan.vo;
import cn.iocoder.yudao.module.mes.controller.admin.planrecord.vo.PlanRecordRespVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
@Schema(description = "管理后台 - 按任务单查询生产计划分页 Response VO")
@Data
public class PlanTaskPageRespVO {
@Schema(description = "计划单ID", example = "17689")
private Long id;
@Schema(description = "产品名称")
private String productName;
@Schema(description = "设备名称")
private String deviceName;
@Schema(description = "计划数量")
private Long planNumber;
@Schema(description = "完工数量")
private Long wangongNumber;
@Schema(description = "合格数量")
private Long passNumber;
@Schema(description = "不合格数量")
private Long noPassNumber;
@Schema(description = "合格率")
private BigDecimal passRate;
@Schema(description = "计划开始时间")
private LocalDateTime planStartTime;
@Schema(description = "计划结束时间")
private LocalDateTime planEndTime;
@Schema(description = "最晚开工时间")
private LocalDateTime latestStartTime;
@Schema(description = "计划记录集合,按 operateTime 升序")
private List<PlanRecordRespVO> planRecordList;
}

@ -0,0 +1,95 @@
package cn.iocoder.yudao.module.mes.controller.admin.planrecord;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import java.util.*;
import java.io.IOException;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
import cn.iocoder.yudao.module.mes.controller.admin.planrecord.vo.*;
import cn.iocoder.yudao.module.mes.dal.dataobject.planrecord.PlanRecordDO;
import cn.iocoder.yudao.module.mes.service.planrecord.PlanRecordService;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
@Tag(name = "管理后台 - 生产计划操作记录")
@RestController
@RequestMapping("/mes/plan-record")
@Validated
public class PlanRecordController {
@Resource
private PlanRecordService planRecordService;
@PostMapping("/create")
@Operation(summary = "创建生产计划操作记录")
@PreAuthorize("@ss.hasPermission('mes:plan-record:create')")
public CommonResult<Long> createPlanRecord(@Valid @RequestBody PlanRecordSaveReqVO createReqVO) {
return success(planRecordService.createPlanRecord(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新生产计划操作记录")
@PreAuthorize("@ss.hasPermission('mes:plan-record:update')")
public CommonResult<Boolean> updatePlanRecord(@Valid @RequestBody PlanRecordSaveReqVO updateReqVO) {
planRecordService.updatePlanRecord(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除生产计划操作记录")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('mes:plan-record:delete')")
public CommonResult<Boolean> deletePlanRecord(@RequestParam("id") Long id) {
planRecordService.deletePlanRecord(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得生产计划操作记录")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('mes:plan-record:query')")
public CommonResult<PlanRecordRespVO> getPlanRecord(@RequestParam("id") Long id) {
PlanRecordDO planRecord = planRecordService.getPlanRecord(id);
return success(BeanUtils.toBean(planRecord, PlanRecordRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得生产计划操作记录分页")
@PreAuthorize("@ss.hasPermission('mes:plan-record:query')")
public CommonResult<PageResult<PlanRecordRespVO>> getPlanRecordPage(@Valid PlanRecordPageReqVO pageReqVO) {
PageResult<PlanRecordDO> pageResult = planRecordService.getPlanRecordPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, PlanRecordRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出生产计划操作记录 Excel")
@PreAuthorize("@ss.hasPermission('mes:plan-record:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportPlanRecordExcel(@Valid PlanRecordPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<PlanRecordDO> list = planRecordService.getPlanRecordPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "生产计划操作记录.xls", "数据", PlanRecordRespVO.class,
BeanUtils.toBean(list, PlanRecordRespVO.class));
}
}

@ -0,0 +1,41 @@
package cn.iocoder.yudao.module.mes.controller.admin.planrecord.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 生产计划操作记录分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class PlanRecordPageReqVO extends PageParam {
@Schema(description = "任务单ID", example = "337")
private Long taskId;
@Schema(description = "计划ID", example = "20904")
private Long planId;
@Schema(description = "操作状态", example = "2")
private String operateStatus;
@Schema(description = "操作时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] operateTime;
@Schema(description = "备注", example = "你说的对")
private String remark;
@Schema(description = "是否启用")
private Boolean isEnable;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
}

@ -0,0 +1,47 @@
package cn.iocoder.yudao.module.mes.controller.admin.planrecord.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 生产计划操作记录 Response VO")
@Data
@ExcelIgnoreUnannotated
public class PlanRecordRespVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "23003")
@ExcelProperty("ID")
private Long id;
@Schema(description = "任务单ID", example = "337")
@ExcelProperty("任务单ID")
private Long taskId;
@Schema(description = "计划ID", example = "20904")
@ExcelProperty("计划ID")
private Long planId;
@Schema(description = "操作状态", example = "2")
@ExcelProperty("操作状态")
private String operateStatus;
@Schema(description = "操作时间")
@ExcelProperty("操作时间")
private LocalDateTime operateTime;
@Schema(description = "备注", example = "你说的对")
@ExcelProperty("备注")
private String remark;
@Schema(description = "是否启用")
@ExcelProperty("是否启用")
private Boolean isEnable;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
}

@ -0,0 +1,33 @@
package cn.iocoder.yudao.module.mes.controller.admin.planrecord.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 生产计划操作记录新增/修改 Request VO")
@Data
public class PlanRecordSaveReqVO {
@Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "23003")
private Long id;
@Schema(description = "任务单ID", example = "337")
private Long taskId;
@Schema(description = "计划ID", example = "20904")
private Long planId;
@Schema(description = "操作状态", example = "2")
private String operateStatus;
@Schema(description = "操作时间")
private LocalDateTime operateTime;
@Schema(description = "备注", example = "你说的对")
private String remark;
@Schema(description = "是否启用")
private Boolean isEnable;
}

@ -13,10 +13,12 @@ public enum TaskStatusEnum {
稿(0),
(1),
(2),
//旧状态-弃用
(3),
(4),
(5),
(6),
//新增状态
(7),
(8),
(9),

@ -1,7 +1,17 @@
package cn.iocoder.yudao.module.mes.controller.admin.zjtask;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.module.common.controller.admin.moldrepair.vo.MoldRepairRespVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductUnitDO;
import cn.iocoder.yudao.module.erp.service.product.ErpProductUnitService;
import cn.iocoder.yudao.module.mes.controller.admin.ticketmanagement.vo.TicketManagementBatchUpdateReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.zjtaskresults.vo.ZjTaskResultsRespVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.zjtaskresults.ZjTaskResultsDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.zjtype.ZjTypeDO;
import cn.iocoder.yudao.module.mes.service.zjtaskresults.ZjTaskResultsService;
import cn.iocoder.yudao.module.mes.service.zjtype.ZjTypeService;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
@ -16,12 +26,14 @@ import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;
import java.util.stream.Collectors;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
@ -40,6 +52,12 @@ public class ZjTaskController {
@Resource
private ZjTaskService zjTaskService;
@Resource
private ZjTaskResultsService zjTaskResultsService;
@Resource
private ZjTypeService zjTypeService;
@Resource
private ErpProductUnitService productUnitService;
@PostMapping("/create")
@Operation(summary = "创建质量管理-检验任务")
@ -82,6 +100,14 @@ public class ZjTaskController {
return success(BeanUtils.toBean(pageResult, ZjTaskRespVO.class));
}
@GetMapping("/page-by-ticket")
@Operation(summary = "根据任务单 id 获得质检任务分页,附带检验结果字段")
@PreAuthorize("@ss.hasPermission('mes:zj-task:query')")
public CommonResult<PageResult<ZjTaskWithResultsRespVO>> getZjTaskPageByTicket(@Valid ZjTaskQueryByTicketPageReqVO pageReqVO) {
PageResult<ZjTaskDO> pageResult = zjTaskService.getZjTaskPageByTicket(pageReqVO);
return success(new PageResult<>(buildTaskWithResultsVOList(pageResult.getList()), pageResult.getTotal()));
}
@GetMapping("/list")
@Operation(summary = "获得质量管理-检验任务列表")
@ -129,6 +155,44 @@ public class ZjTaskController {
return success(true);
}
private List<ZjTaskWithResultsRespVO> buildTaskWithResultsVOList(List<ZjTaskDO> list) {
if (CollUtil.isEmpty(list)) {
return Collections.emptyList();
}
List<ZjTaskResultsDO> taskResults = zjTaskResultsService.getTaskResultsByTaskIds(convertSet(list, ZjTaskDO::getId));
Map<Long, List<ZjTaskResultsRespVO>> taskResultsMap = buildTaskResultsMap(taskResults);
return BeanUtils.toBean(list, ZjTaskWithResultsRespVO.class, item -> {
item.setResults(taskResultsMap.getOrDefault(item.getId(), Collections.emptyList()));
});
}
private Map<Long, List<ZjTaskResultsRespVO>> buildTaskResultsMap(List<ZjTaskResultsDO> taskResults) {
if (CollUtil.isEmpty(taskResults)) {
return Collections.emptyMap();
}
Map<Long, ZjTypeDO> zjTypeMap = zjTypeService.getZjTypeVOMap(convertSet(taskResults, ZjTaskResultsDO::getZjType));
List<ErpProductUnitDO> unitDOList = productUnitService.getProductUnitListByStatus(CommonStatusEnum.ENABLE.getStatus());
Map<String, String> unitNameMap = unitDOList.stream()
.collect(Collectors.toMap(unit -> String.valueOf(unit.getId()), ErpProductUnitDO::getName, (first, second) -> first));
Map<Long, List<ZjTaskResultsRespVO>> result = new HashMap<>();
for (ZjTaskResultsDO taskResult : taskResults) {
if (taskResult.getTaskId() == null) {
continue;
}
ZjTaskResultsRespVO respVO = BeanUtils.toBean(taskResult, ZjTaskResultsRespVO.class);
MapUtils.findAndThen(zjTypeMap, taskResult.getZjType(), zjType -> respVO.setZjTypeName(zjType.getName()));
if (taskResult.getUnit() != null) {
respVO.setUnitName(unitNameMap.getOrDefault(taskResult.getUnit(), ""));
}
result.computeIfAbsent(taskResult.getTaskId(), key -> new ArrayList<>()).add(respVO);
}
return result;
}
}
}

@ -0,0 +1,60 @@
package cn.iocoder.yudao.module.mes.controller.admin.zjtask.vo;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 质检任务按任务单分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ZjTaskQueryByTicketPageReqVO extends PageParam {
@Schema(description = "任务单 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Long ticket;
@Schema(description = "任务名称")
private String name;
@Schema(description = "质检分类")
private String type;
@Schema(description = "检验方案 id")
private Long schemaId;
@Schema(description = "检验方案名称")
private String schemaName;
@Schema(description = "负责人 id")
private Long managerId;
@Schema(description = "负责人名称")
private String managerName;
@Schema(description = "执行人 id")
private Long executorId;
@Schema(description = "执行人名称")
private String executorName;
@Schema(description = "状态")
private Integer status;
@Schema(description = "结果")
private String result;
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
@Schema(description = "执行时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] executeTime;
}

@ -0,0 +1,17 @@
package cn.iocoder.yudao.module.mes.controller.admin.zjtask.vo;
import cn.iocoder.yudao.module.mes.controller.admin.zjtaskresults.vo.ZjTaskResultsRespVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.util.List;
@Schema(description = "管理后台 - 质检任务带结果列表 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
public class ZjTaskWithResultsRespVO extends ZjTaskRespVO {
@Schema(description = "检验项结果列表")
private List<ZjTaskResultsRespVO> results;
}

@ -0,0 +1,56 @@
package cn.iocoder.yudao.module.mes.dal.dataobject.planrecord;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
/**
* DO
*
* @author
*/
@TableName("mes_plan_record")
@KeySequence("mes_plan_record_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PlanRecordDO extends BaseDO {
/**
* ID
*/
@TableId
private Long id;
/**
* ID
*/
private Long taskId;
/**
* ID
*/
private Long planId;
/**
*
*/
private Integer operateStatus;
/**
*
*/
private LocalDateTime operateTime;
/**
*
*/
private String remark;
/**
*
*/
private Boolean isEnable;
}

@ -1,9 +1,11 @@
package cn.iocoder.yudao.module.mes.dal.mysql.bom;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.mes.dal.dataobject.bom.BomDetailDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
import java.util.List;
/**
@ -18,8 +20,13 @@ public interface BomDetailMapper extends BaseMapperX<BomDetailDO> {
return selectList(BomDetailDO::getBomId, bomId);
}
default List<BomDetailDO> selectListByBomIds(Collection<Long> bomIds) {
return selectList(new LambdaQueryWrapperX<BomDetailDO>()
.inIfPresent(BomDetailDO::getBomId, bomIds));
}
default int deleteByBomId(Long bomId) {
return delete(BomDetailDO::getBomId, bomId);
}
}
}

@ -7,6 +7,9 @@ import cn.iocoder.yudao.module.mes.controller.admin.bom.vo.BomPageReqVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.bom.BomDO;
import org.apache.ibatis.annotations.Mapper;
import java.util.Collection;
import java.util.List;
/**
* BOM Mapper
*
@ -42,4 +45,10 @@ public interface BomMapper extends BaseMapperX<BomDO> {
return selectOne(BomDO::getProductId, productId,
BomDO::getIsEnable, true);
}
}
default List<BomDO> selectListByProductIds(Collection<Long> productIds) {
return selectList(new LambdaQueryWrapperX<BomDO>()
.inIfPresent(BomDO::getProductId, productIds)
.eq(BomDO::getIsEnable, true));
}
}

@ -0,0 +1,32 @@
package cn.iocoder.yudao.module.mes.dal.mysql.planrecord;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.mes.dal.dataobject.planrecord.PlanRecordDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.mes.controller.admin.planrecord.vo.*;
/**
* Mapper
*
* @author
*/
@Mapper
public interface PlanRecordMapper extends BaseMapperX<PlanRecordDO> {
default PageResult<PlanRecordDO> selectPage(PlanRecordPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<PlanRecordDO>()
.eqIfPresent(PlanRecordDO::getTaskId, reqVO.getTaskId())
.eqIfPresent(PlanRecordDO::getPlanId, reqVO.getPlanId())
.eqIfPresent(PlanRecordDO::getOperateStatus, reqVO.getOperateStatus())
.betweenIfPresent(PlanRecordDO::getOperateTime, reqVO.getOperateTime())
.eqIfPresent(PlanRecordDO::getRemark, reqVO.getRemark())
.eqIfPresent(PlanRecordDO::getIsEnable, reqVO.getIsEnable())
.betweenIfPresent(PlanRecordDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(PlanRecordDO::getId));
}
}

@ -84,6 +84,24 @@ public interface ZjTaskMapper extends BaseMapperX<ZjTaskDO> {
return selectList(wrapper);
}
default PageResult<ZjTaskDO> selectPageByTicket(ZjTaskQueryByTicketPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<ZjTaskDO>()
.eqIfPresent(ZjTaskDO::getTicket, reqVO.getTicket())
.likeIfPresent(ZjTaskDO::getName, reqVO.getName())
.eqIfPresent(ZjTaskDO::getType, reqVO.getType())
.eqIfPresent(ZjTaskDO::getSchemaId, reqVO.getSchemaId())
.likeIfPresent(ZjTaskDO::getSchemaName, reqVO.getSchemaName())
.eqIfPresent(ZjTaskDO::getManagerId, reqVO.getManagerId())
.likeIfPresent(ZjTaskDO::getManagerName, reqVO.getManagerName())
.eqIfPresent(ZjTaskDO::getExecutorId, reqVO.getExecutorId())
.likeIfPresent(ZjTaskDO::getExecutorName, reqVO.getExecutorName())
.eqIfPresent(ZjTaskDO::getStatus, reqVO.getStatus())
.eqIfPresent(ZjTaskDO::getResult, reqVO.getResult())
.betweenIfPresent(ZjTaskDO::getCreateTime, reqVO.getCreateTime())
.betweenIfPresent(ZjTaskDO::getExecuteTime, reqVO.getExecuteTime())
.orderByDesc(ZjTaskDO::getId));
}
/**
*
*
@ -95,4 +113,4 @@ public interface ZjTaskMapper extends BaseMapperX<ZjTaskDO> {
@Param("status") Integer status,
@Param("cancelReason") String cancelReason);
}
}

@ -36,4 +36,10 @@ public interface ZjTaskResultsMapper extends BaseMapperX<ZjTaskResultsDO> {
.orderByDesc(ZjTaskResultsDO::getId));
}
}
default List<ZjTaskResultsDO> selectListByTaskIds(Collection<Long> taskIds) {
return selectList(new LambdaQueryWrapperX<ZjTaskResultsDO>()
.inIfPresent(ZjTaskResultsDO::getTaskId, taskIds)
.orderByDesc(ZjTaskResultsDO::getId));
}
}

@ -66,6 +66,8 @@ public interface BomService {
*/
List<BomDetailRespVO> getBomDetailListByBomId(Long bomId);
List<BomDetailRespVO> getBomDetailRespListByProductId(Long productId);
/**
*
*
@ -83,4 +85,4 @@ public interface BomService {
List<BomDetailDO> getBomDetailListByProductId(Long productId, Long number);
BomDO selectByProductId(Long productId);
}
}

@ -161,6 +161,19 @@ public class BomServiceImpl implements BomService {
return buildDetailVOList(list);
}
@Override
public List<BomDetailRespVO> getBomDetailRespListByProductId(Long productId) {
if (productId == null) {
return Collections.emptyList();
}
BomDO bomDO = bomMapper.selectByProductId(productId);
if (bomDO == null || bomDO.getId() == null) {
return Collections.emptyList();
}
List<BomDetailDO> list = bomDetailMapper.selectListByBomId(bomDO.getId());
return buildDetailVOList(list);
}
@Override
public List<BomDetailDO> getBomDetailListByProductId(Long productId) {
BomDO bomDO = bomMapper.selectByProductId(productId);
@ -227,4 +240,4 @@ public class BomServiceImpl implements BomService {
bomDetailMapper.deleteByBomId(bomId);
}
}
}

@ -61,6 +61,8 @@ public interface PlanService {
*/
PageResult<PlanRespVO> getPlanPage(PlanPageReqVO pageReqVO);
PageResult<PlanTaskPageRespVO> getPlanPageByTaskId(PlanTaskPageReqVO pageReqVO);
/**
* ()
**/
@ -110,4 +112,4 @@ public interface PlanService {
List<DevicePlanGanttRespVO> getDevicePlanGantt(DevicePlanGanttReqVO reqVO);
}
}

@ -19,17 +19,20 @@ import cn.iocoder.yudao.module.erp.service.stock.ErpStockService;
import cn.iocoder.yudao.module.mes.controller.admin.itemrequisition.vo.ItemRequisitionSaveReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.itemrequisition.vo.ItemRequisitionStatusEnum;
import cn.iocoder.yudao.module.mes.controller.admin.plan.vo.*;
import cn.iocoder.yudao.module.mes.controller.admin.planrecord.vo.PlanRecordRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.task.vo.TaskStatusEnum;
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger.DeviceLedgerDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.itemrequisition.ItemRequisitionDetailDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.organization.OrganizationDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.paigongrecord.PaigongRecordDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.plan.PlanDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.planrecord.PlanRecordDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.task.TaskDO;
import cn.iocoder.yudao.module.mes.dal.dataobject.task.TaskDetailDO;
import cn.iocoder.yudao.module.mes.dal.mysql.deviceledger.DeviceLedgerMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.paigongrecord.PaigongRecordMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.plan.PlanMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.planrecord.PlanRecordMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.stockindetail.StockInDetailMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.task.TaskMapper;
import cn.iocoder.yudao.module.mes.dal.redis.no.MesNoRedisDAO;
@ -43,6 +46,7 @@ import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.extern.slf4j.Slf4j;
@ -114,6 +118,10 @@ public class PlanServiceImpl implements PlanService {
@Lazy
private TaskMapper taskMapper;
@Resource
private PlanRecordMapper planRecordMapper;
@Override
@Transactional(rollbackFor = Exception.class)
@ -172,7 +180,13 @@ public class PlanServiceImpl implements PlanService {
plan.setStartTime(LocalDateTime.now());
plan.setRequisitionId(id);
planMapper.insert(plan);
//添加计划操作记录
PlanRecordDO planRecordDO = new PlanRecordDO();
planRecordDO.setTaskId(plan.getTaskId());
planRecordDO.setPlanId(plan.getId());
planRecordDO.setOperateTime(LocalDateTime.now());
planRecordDO.setOperateStatus(PlanStatusEnum..getValue());
planRecordMapper.insert(planRecordDO);
//判断计划是否全部完成
//查询任务明细总需求
@ -399,6 +413,54 @@ public class PlanServiceImpl implements PlanService {
return new PageResult<>(buildVOList(pageResult.getList()), pageResult.getTotal());
}
@Override
public PageResult<PlanTaskPageRespVO> getPlanPageByTaskId(PlanTaskPageReqVO pageReqVO) {
Page<PlanDO> mpPage = new Page<>(pageReqVO.getPageNo(), pageReqVO.getPageSize());
Page<PlanDO> page = planMapper.selectPage(mpPage, Wrappers.<PlanDO>lambdaQuery()
.eq(PlanDO::getTaskId, pageReqVO.getTaskId())
.orderByDesc(PlanDO::getId));
if (CollUtil.isEmpty(page.getRecords())) {
return new PageResult<>(Collections.emptyList(), page.getTotal());
}
Set<Long> productIds = page.getRecords().stream().map(PlanDO::getProductId).filter(Objects::nonNull).collect(Collectors.toSet());
Set<Long> deviceIds = page.getRecords().stream().map(PlanDO::getDeviceId).filter(Objects::nonNull).collect(Collectors.toSet());
Set<Long> planIds = page.getRecords().stream().map(PlanDO::getId).filter(Objects::nonNull).collect(Collectors.toSet());
Map<Long, ErpProductDO> productMap = erpProductService.getProductMap(productIds);
Map<Long, DeviceLedgerDO> deviceMap = CollUtil.isEmpty(deviceIds) ? Collections.emptyMap()
: deviceLedgerMapper.selectBatchIds(deviceIds).stream().collect(Collectors.toMap(DeviceLedgerDO::getId, item -> item, (a, b) -> a));
List<PlanRecordDO> planRecords = planRecordMapper.selectList(Wrappers.<PlanRecordDO>lambdaQuery()
.in(PlanRecordDO::getPlanId, planIds)
.orderByAsc(PlanRecordDO::getOperateTime)
.orderByAsc(PlanRecordDO::getId));
Map<Long, List<PlanRecordRespVO>> planRecordMap = planRecords.stream()
.collect(Collectors.groupingBy(PlanRecordDO::getPlanId, LinkedHashMap::new,
Collectors.mapping(record -> BeanUtils.toBean(record, PlanRecordRespVO.class), Collectors.toList())));
List<PlanTaskPageRespVO> list = page.getRecords().stream().map(plan -> {
PlanTaskPageRespVO respVO = new PlanTaskPageRespVO();
respVO.setId(plan.getId());
ErpProductDO product = productMap.get(plan.getProductId());
respVO.setProductName(product != null ? product.getName() : null);
DeviceLedgerDO device = deviceMap.get(plan.getDeviceId());
respVO.setDeviceName(device != null ? device.getDeviceName() : null);
respVO.setPlanNumber(plan.getPlanNumber());
respVO.setWangongNumber(plan.getWangongNumber());
respVO.setPassNumber(plan.getPassNumber());
respVO.setNoPassNumber(plan.getNoPassNumber());
respVO.setPassRate(plan.getPassRate());
respVO.setPlanStartTime(plan.getPlanStartTime());
respVO.setPlanEndTime(plan.getPlanEndTime());
respVO.setLatestStartTime(plan.getLatestStartTime());
respVO.setPlanRecordList(planRecordMap.getOrDefault(plan.getId(), Collections.emptyList()));
return respVO;
}).collect(Collectors.toList());
return new PageResult<>(list, page.getTotal());
}
@Resource
private ErpProductService productService;
@Resource
@ -653,4 +715,4 @@ public class PlanServiceImpl implements PlanService {
}
}

@ -0,0 +1,56 @@
package cn.iocoder.yudao.module.mes.service.planrecord;
import java.util.*;
import cn.iocoder.yudao.module.mes.controller.admin.planrecord.vo.*;
import cn.iocoder.yudao.module.mes.dal.dataobject.planrecord.PlanRecordDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import javax.validation.Valid;
/**
* Service
*
* @author
*/
public interface PlanRecordService {
/**
*
*
* @param createReqVO
* @return
*/
Long createPlanRecord(@Valid PlanRecordSaveReqVO createReqVO);
/**
*
*
* @param updateReqVO
*/
void updatePlanRecord(@Valid PlanRecordSaveReqVO updateReqVO);
/**
*
*
* @param id
*/
void deletePlanRecord(Long id);
/**
*
*
* @param id
* @return
*/
PlanRecordDO getPlanRecord(Long id);
/**
*
*
* @param pageReqVO
* @return
*/
PageResult<PlanRecordDO> getPlanRecordPage(PlanRecordPageReqVO pageReqVO);
}

@ -0,0 +1,75 @@
package cn.iocoder.yudao.module.mes.service.planrecord;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import cn.iocoder.yudao.module.mes.controller.admin.planrecord.vo.*;
import cn.iocoder.yudao.module.mes.dal.dataobject.planrecord.PlanRecordDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.mes.dal.mysql.planrecord.PlanRecordMapper;
import javax.annotation.Resource;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.*;
/**
* Service
*
* @author
*/
@Service
@Validated
public class PlanRecordServiceImpl implements PlanRecordService {
@Resource
private PlanRecordMapper planRecordMapper;
@Override
public Long createPlanRecord(PlanRecordSaveReqVO createReqVO) {
// 插入
PlanRecordDO planRecord = BeanUtils.toBean(createReqVO, PlanRecordDO.class);
planRecordMapper.insert(planRecord);
// 返回
return planRecord.getId();
}
@Override
public void updatePlanRecord(PlanRecordSaveReqVO updateReqVO) {
// 校验存在
validatePlanRecordExists(updateReqVO.getId());
// 更新
PlanRecordDO updateObj = BeanUtils.toBean(updateReqVO, PlanRecordDO.class);
planRecordMapper.updateById(updateObj);
}
@Override
public void deletePlanRecord(Long id) {
// 校验存在
validatePlanRecordExists(id);
// 删除
planRecordMapper.deleteById(id);
}
private void validatePlanRecordExists(Long id) {
if (planRecordMapper.selectById(id) == null) {
throw exception(PLAN_RECORD_NOT_EXISTS);
}
}
@Override
public PlanRecordDO getPlanRecord(Long id) {
return planRecordMapper.selectById(id);
}
@Override
public PageResult<PlanRecordDO> getPlanRecordPage(PlanRecordPageReqVO pageReqVO) {
return planRecordMapper.selectPage(pageReqVO);
}
}

@ -64,4 +64,6 @@ public interface ZjTaskService {
void batchUpdateJobStatus(@Valid ZjTaskBatchUpdateReqVO reqVO);
List<ZjTaskDO> getZjTaskList(@Valid ZjTaskPageReqVO pageReqVO);
}
PageResult<ZjTaskDO> getZjTaskPageByTicket(@Valid ZjTaskQueryByTicketPageReqVO pageReqVO);
}

@ -213,6 +213,15 @@ public class ZjTaskServiceImpl implements ZjTaskService {
});
}
@Override
public PageResult<ZjTaskDO> getZjTaskPageByTicket(ZjTaskQueryByTicketPageReqVO pageReqVO) {
PageResult<ZjTaskDO> pageResult = zjTaskMapper.selectPageByTicket(pageReqVO);
Map<Long, PlanDO> planMap = planService.getPlanMap(convertSet(pageResult.getList(), ZjTaskDO::getTicket));
return BeanUtils.toBean(pageResult, ZjTaskDO.class, zjTaskDO -> {
MapUtils.findAndThen(planMap, zjTaskDO.getTicket(), planDO -> zjTaskDO.setTicketCode(planDO.getCode()));
});
}
/**
* ID
@ -230,4 +239,4 @@ public class ZjTaskServiceImpl implements ZjTaskService {
.collect(Collectors.toList());
}
}
}

@ -52,9 +52,11 @@ public interface ZjTaskResultsService {
*/
PageResult<ZjTaskResultsDO> getZjTaskResultsPage(ZjTaskResultsPageReqVO pageReqVO);
List<ZjTaskResultsDO> getTaskResultsByTaskIds(Collection<Long> taskIds);
/**
* zjResultimages
*/
void batchUpdateZjTaskResults(List<ZjTaskResultsBatchUpdateReqVO.ResultItem> resultItems);
}
}

@ -71,6 +71,14 @@ public class ZjTaskResultsServiceImpl implements ZjTaskResultsService {
return zjTaskResultsMapper.selectPage(pageReqVO);
}
@Override
public List<ZjTaskResultsDO> getTaskResultsByTaskIds(Collection<Long> taskIds) {
if (taskIds == null || taskIds.isEmpty()) {
return Collections.emptyList();
}
return zjTaskResultsMapper.selectListByTaskIds(taskIds);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void batchUpdateZjTaskResults(List<ZjTaskResultsBatchUpdateReqVO.ResultItem> resultItems) {
@ -85,4 +93,4 @@ public class ZjTaskResultsServiceImpl implements ZjTaskResultsService {
}
}
}
}

@ -34,6 +34,9 @@
LEFT JOIN erp_product pr ON pr.id = p.product_id AND pr.deleted = b'0'
LEFT JOIN system_users u ON u.id = CAST(r.creator AS UNSIGNED)
WHERE r.deleted = b'0'
<if test="reqVO.taskId != null">
AND t.id = #{reqVO.taskId}
</if>
<if test="reqVO.beginBaogongTime != null">
AND r.baogong_time &gt;= #{reqVO.beginBaogongTime}
</if>

@ -0,0 +1,12 @@
<?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">
<mapper namespace="cn.iocoder.yudao.module.mes.dal.mysql.planrecord.PlanRecordMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>
Loading…
Cancel
Save