Compare commits

...

9 Commits

@ -91,7 +91,7 @@ public class ErpStockInServiceImpl implements ErpStockInService {
// 2.2 插入入库单项
stockInItems.forEach(o -> {
o.setInId(stockIn.getId());
// o.setCount(o.getCount());
o.setCount(o.getCount());
});
stockInItemMapper.insertBatch(stockInItems);
// for (ErpStockInItemDO item : stockInItems) {

@ -110,6 +110,13 @@ public class DeviceController {
return success(pageResult);
}
@GetMapping("/available-list")
@Operation(summary = "获取设备下拉列表(全量+是否已选+已删除标识)")
@PreAuthorize("@ss.hasPermission('iot:device:query')")
public CommonResult<List<DeviceSelectRespVO>> getAvailableDeviceList() {
return success(deviceService.getDeviceSelectList());
}
@GetMapping("/export-excel")
@Operation(summary = "导出物联设备 Excel")
@PreAuthorize("@ss.hasPermission('iot:device:export')")
@ -249,6 +256,12 @@ public class DeviceController {
return success(deviceOperationalStatus);
}
@GetMapping("/getDeviceOverview")
@Operation(summary = "获取设备概况")
public CommonResult<DeviceOverviewRespVO> getDeviceOverview() {
return success(deviceService.getDeviceOverview());
}
// ==================== 子表(设备属性) ====================
@ -351,4 +364,4 @@ public class DeviceController {
return success(true);
}
}
}

@ -0,0 +1,33 @@
package cn.iocoder.yudao.module.iot.controller.admin.device.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - 设备概况 Resp VO")
@Data
public class DeviceOverviewRespVO {
@Schema(description = "设备总数")
private Integer totalDevices;
@Schema(description = "运行")
private Integer runningCount;
@Schema(description = "待机")
private Integer standbyCount;
@Schema(description = "故障")
private Integer faultCount;
@Schema(description = "离线")
private Integer offlineCount;
@Schema(description = "利用率=运行/设备总数")
private String utilizationRate;
@Schema(description = "开机率=(运行+待机+故障)/设备总数")
private String bootRate;
@Schema(description = "故障率=故障/设备总数")
private String faultRate;
}

@ -0,0 +1,24 @@
package cn.iocoder.yudao.module.iot.controller.admin.device.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class DeviceSelectRespVO {
@Schema(description = "设备ID")
private Long id;
@Schema(description = "设备编码")
private String deviceCode;
@Schema(description = "设备名称(原始)")
private String deviceName;
@Schema(description = "设备名称(展示用,删除状态会拼接“(已删除)”)")
private String displayName;
@Schema(description = "是否已被mes_organization.dv_id选择")
private Boolean selected;
}

@ -14,6 +14,7 @@ import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -127,4 +128,13 @@ public interface DeviceMapper extends BaseMapperX<DeviceDO> {
Integer getTotalDeviceCount();
List<Long> getAllDeviceIds();
}
List<DeviceSelectRespVO> selectDeviceSelectList();
DeviceDO selectByIdWithDeleted(@Param("id") Long id);
List<DeviceDO> selectListIncludeDeletedByIds(@Param("ids") Collection<Long> ids);
}

@ -136,13 +136,22 @@ public interface DeviceService {
DeviceOperationStatusRespVO getDeviceOperationalStatus();
DeviceOverviewRespVO getDeviceOverview();
List<Map<String, Object>> getMultiDeviceAttributes(Long goviewId);
List<DeviceContactModelDO> getDeviceAttributeList(Long deviceId);
List<Long> deviceLedgerList();
List<DeviceSelectRespVO> getDeviceSelectList();
void updateDeviceEnabled(@Valid DeviceUpdateEnabledReqVO updateEnabledReqVO) throws MqttException;
DeviceDO getDeviceByMqttTopic(String topic);
}
Map<Long, DeviceDO> getMapIncludeDeleted(Collection<Long> ids);
}

@ -1244,6 +1244,61 @@ public class DeviceServiceImpl implements DeviceService {
return result;
}
@Override
public DeviceOverviewRespVO getDeviceOverview() {
DeviceOverviewRespVO result = new DeviceOverviewRespVO();
Integer totalDevices = deviceMapper.getTotalDeviceCount();
int total = totalDevices == null ? 0 : totalDevices;
result.setTotalDevices(total);
List<Long> deviceIds = deviceMapper.getAllDeviceIds();
if (CollectionUtils.isEmpty(deviceIds)) {
result.setRunningCount(0);
result.setStandbyCount(0);
result.setFaultCount(0);
result.setOfflineCount(0);
result.setUtilizationRate("0.00%");
result.setBootRate("0.00%");
result.setFaultRate("0.00%");
return result;
}
Map<Long, String> deviceStatusMap = tdengineService.getLatestDeviceStatusAlternative(deviceIds);
int runningCount = 0;
int standbyCount = 0;
int faultCount = 0;
int offlineCount = 0;
for (Long deviceId : deviceIds) {
String status = deviceStatusMap.get(deviceId);
if ("1".equals(status)) {
runningCount++;
} else if ("2".equals(status)) {
standbyCount++;
} else if ("3".equals(status)) {
faultCount++;
} else if ("0".equals(status)){
offlineCount++;
}
}
result.setRunningCount(runningCount);
result.setStandbyCount(standbyCount);
result.setFaultCount(faultCount);
result.setOfflineCount(offlineCount);
double utilizationRate = total > 0 ? (double) runningCount / total * 100 : 0;
double bootRate = total > 0 ? (double) (runningCount + standbyCount + faultCount) / total * 100 : 0;
double faultRate = total > 0 ? (double) faultCount / total * 100 : 0;
result.setUtilizationRate(String.format("%.2f%%", utilizationRate));
result.setBootRate(String.format("%.2f%%", bootRate));
result.setFaultRate(String.format("%.2f%%", faultRate));
return result;
}
/**
*
@ -1652,4 +1707,24 @@ public class DeviceServiceImpl implements DeviceService {
return deviceMapper.deviceLedgerList();
}
}
@Override
public List<DeviceSelectRespVO> getDeviceSelectList() {
return deviceMapper.selectDeviceSelectList();
}
@Override
public Map<Long, DeviceDO> getMapIncludeDeleted(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {
return Collections.emptyMap();
}
List<DeviceDO> list = deviceMapper.selectListIncludeDeletedByIds(ids);
return list.stream().collect(Collectors.toMap(
DeviceDO::getId,
Function.identity(),
(a, b) -> a
));
}
}

@ -204,4 +204,47 @@
WHERE deleted = 0
ORDER BY id
</select>
</mapper>
<select id="selectDeviceSelectList"
resultType="cn.iocoder.yudao.module.iot.controller.admin.device.vo.DeviceSelectRespVO">
SELECT
d.id,
d.device_code AS deviceCode,
d.device_name AS deviceName,
d.device_name AS displayName,
CASE
WHEN EXISTS (
SELECT 1
FROM mes_organization mo
WHERE mo.deleted = 0
AND mo.dv_id = d.id
) THEN TRUE
ELSE FALSE
END AS selected
FROM iot_device d
WHERE d.deleted = 0
ORDER BY d.id DESC
</select>
<select id="selectByIdWithDeleted"
resultType="cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO">
SELECT *
FROM iot_device
WHERE id = #{id}
LIMIT 1
</select>
<select id="selectListIncludeDeletedByIds"
resultType="cn.iocoder.yudao.module.iot.dal.dataobject.device.DeviceDO">
SELECT
id,
device_name,
deleted
FROM iot_device
WHERE id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
</mapper>

@ -192,6 +192,7 @@ public interface ErrorCodeConstants {
ErrorCode SCHEDULE_TIME_FORMAT_INVALID = new ErrorCode(100_301_0012, "排产时间格式错误start={}, end={}格式需为HH:mm");
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不能为空");

@ -1,5 +1,7 @@
package cn.iocoder.yudao.module.mes.controller.admin.baogongrecord.vo;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.mes.enums.BaogongTrendTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
@ -12,6 +14,10 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_
@Data
public class BaogongRecordTrendReqVO {
@Schema(description = "趋势类型1-近一年2-本月3-本周4-今日5-自定义", example = "4")
@InEnum(BaogongTrendTypeEnum.class)
private Integer trendType;
@Schema(description = "开始时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime beginBaogongTime;
@ -21,4 +27,3 @@ public class BaogongRecordTrendReqVO {
private LocalDateTime endBaogongTime;
}

@ -56,13 +56,13 @@ public class OrganizationController {
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得产线工位")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('mes:organization:query')")
public CommonResult<OrganizationRespVO> getOrganization(@RequestParam("id") Long id) {
OrganizationDO organization = organizationService.getOrganization(id);
return success(BeanUtils.toBean(organization, OrganizationRespVO.class));
return success(organizationService.getOrganizationVO(id));
}
@GetMapping("/list")

@ -41,7 +41,7 @@ import java.time.LocalDateTime;
private Long machineId;
@Schema(description = "对应机台id", example = "17654")
@ExcelProperty("对应机台")
@ExcelProperty("对应机台(设备台账名称)")
private String machineName;
@Schema(description = "联系电话")
@ -83,7 +83,6 @@ import java.time.LocalDateTime;
private Long dvId;
@Schema(description = "关联采集设备")
@ExcelProperty("关联采集设备")
private Long dvName;
@ExcelProperty("关联采集设备名称")
private String dvName;
}

@ -55,6 +55,6 @@ public class OrganizationSaveReqVO {
private Long dvId;
@Schema(description = "关联采集设备")
private Long dvName;
private String dvName;
}

@ -67,9 +67,11 @@ import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.error;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import static cn.iocoder.yudao.module.mes.enums.ErrorCodeConstants.WAREHOUSE_NOT_EXISTS;
import static org.apache.ibatis.ognl.OgnlOps.getIntValue;
@Tag(name = "管理后台 - 生产计划")
@ -309,6 +311,9 @@ public class PlanController {
} else if ("end".equals(code)) {
planDO.setStatus(PlanStatusEnum..getValue());
} else if ("store".equals(code)) {
if (statusUpdateVO.getWarehouseId() ==null ){
throw exception(WAREHOUSE_NOT_EXISTS);
}
planDO.setStatus(PlanStatusEnum..getValue());
} else if ("commence".equals(code)) {
planDO.setStatus(PlanStatusEnum..getValue());

@ -45,6 +45,8 @@ public class DevicePlanGanttRespVO {
private Long planNumber;
@Schema(description = "计划编码")
private String planCode;
@Schema(description = "计划状态")
private Integer planStatus;
@Schema(description = "任务单编码")
private String taskCode;
@Schema(description = "产品名称")

@ -20,5 +20,9 @@ public class PlanStatusUpdateVO {
@Schema(description = "更新状态", example = "21176")
private int status;
@Schema(description = "仓库Id", example = "21176")
private Long warehouseId;
}

@ -200,7 +200,12 @@ public class TaskController {
}
@GetMapping("/trend")
@Operation(summary = "任务单趋势统计")
@PreAuthorize("@ss.hasPermission('mes:task:query')")
public CommonResult<TaskTrendRespVO> getTaskTrend(@Valid TaskTrendReqVO reqVO) {
return success(taskService.getTaskTrend(reqVO));
}
// ==================== 子表(生产任务单明细) ====================

@ -70,7 +70,8 @@ public class TaskOneClickScheduleRespVO {
@Schema(description = "产品名称", example = "汽车内饰件A")
private String productName;
@Schema(description = "计划状态", example = "")
private Integer planStatus;
@Schema(description = "计划开始时间(yyyy-MM-dd HH:mm:ss)")
private String planStartTimeStr;

@ -0,0 +1,15 @@
package cn.iocoder.yudao.module.mes.controller.admin.task.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Schema(description = "管理后台 - 任务单趋势明细 Response VO")
@Data
public class TaskTrendItemRespVO {
@Schema(description = "横轴标签")
private String day;
@Schema(description = "数量")
private Long count;
}

@ -0,0 +1,28 @@
package cn.iocoder.yudao.module.mes.controller.admin.task.vo;
import cn.iocoder.yudao.framework.common.validation.InEnum;
import cn.iocoder.yudao.module.mes.enums.BaogongTrendTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
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
public class TaskTrendReqVO {
@Schema(description = "趋势类型1-近一年2-本月3-本周4-今日5-自定义", example = "4")
@InEnum(BaogongTrendTypeEnum.class)
private Integer trendType;
@Schema(description = "开始时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime beginTime;
@Schema(description = "结束时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime endTime;
}

@ -0,0 +1,32 @@
package cn.iocoder.yudao.module.mes.controller.admin.task.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.util.List;
@Schema(description = "管理后台 - 任务单趋势汇总 Response VO")
@Data
public class TaskTrendRespVO {
@Schema(description = "任务单总数")
private Long totalNum;
@Schema(description = "下达数")
private Long issuedNum;
@Schema(description = "部分排产数")
private Long partialScheduledNum;
@Schema(description = "待生产数")
private Long waitingProductionNum;
@Schema(description = "生产中数")
private Long producingNum;
@Schema(description = "已完成数")
private Long completedNum;
@Schema(description = "趋势集合")
private List<TaskTrendItemRespVO> dayTrend;
}

@ -37,4 +37,10 @@ public interface BaogongRecordMapper extends BaseMapperX<BaogongRecordDO> {
List<BaogongRecordTrendDayRespVO> selectTrendByDay(@Param("reqVO") BaogongRecordTrendReqVO reqVO);
}
List<BaogongRecordTrendDayRespVO> selectTrendByMonth(@Param("reqVO") BaogongRecordTrendReqVO reqVO);
List<BaogongRecordTrendDayRespVO> selectTrendByWeekday(@Param("reqVO") BaogongRecordTrendReqVO reqVO);
List<BaogongRecordTrendDayRespVO> selectTrendByHour(@Param("reqVO") BaogongRecordTrendReqVO reqVO);
}

@ -57,4 +57,6 @@ public interface DeviceLedgerMapper extends BaseMapperX<DeviceLedgerDO> {
List<DeviceLedgerDO> selectListByIds(@Param("ids") Collection<Long> ids);
DeviceLedgerDO selectByIdWithDeleted(@Param("id") Long id);
}

@ -5,8 +5,12 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.mes.controller.admin.task.vo.TaskPageReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.task.vo.TaskStatusEnum;
import cn.iocoder.yudao.module.mes.controller.admin.task.vo.TaskTrendItemRespVO;
import cn.iocoder.yudao.module.mes.controller.admin.task.vo.TaskTrendReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.task.vo.TaskTrendRespVO;
import cn.iocoder.yudao.module.mes.dal.dataobject.task.TaskDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -55,4 +59,14 @@ public interface TaskMapper extends BaseMapperX<TaskDO> {
default List<TaskDO> selectList(List<Integer> status) {
return selectList(TaskDO::getStatus, status);
}
}
TaskTrendRespVO selectTrendSummary(@Param("reqVO") TaskTrendReqVO reqVO);
List<TaskTrendItemRespVO> selectTrendByDay(@Param("reqVO") TaskTrendReqVO reqVO);
List<TaskTrendItemRespVO> selectTrendByMonth(@Param("reqVO") TaskTrendReqVO reqVO);
List<TaskTrendItemRespVO> selectTrendByWeekday(@Param("reqVO") TaskTrendReqVO reqVO);
List<TaskTrendItemRespVO> selectTrendByHour(@Param("reqVO") TaskTrendReqVO reqVO);
}

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.mes.enums;
import cn.hutool.core.util.ArrayUtil;
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import java.util.Arrays;
@Getter
@AllArgsConstructor
public enum BaogongTrendTypeEnum implements IntArrayValuable {
YEAR(1, "近一年"),
MONTH(2, "本月"),
WEEK(3, "本周"),
TODAY(4, "今日"),
CUSTOM(5, "自定义");
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BaogongTrendTypeEnum::getType).toArray();
private final Integer type;
private final String name;
@Override
public int[] array() {
return ARRAYS;
}
public static BaogongTrendTypeEnum valueOf(Integer type) {
return ArrayUtil.firstMatch(item -> item.getType().equals(type), values());
}
}

@ -8,12 +8,17 @@ import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;
import cn.iocoder.yudao.module.mes.controller.admin.baogongrecord.vo.*;
import cn.iocoder.yudao.module.mes.dal.dataobject.baogongrecord.BaogongRecordDO;
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.enums.BaogongTrendTypeEnum;
import cn.iocoder.yudao.module.mes.dal.mysql.baogongrecord.BaogongRecordMapper;
@ -36,6 +41,7 @@ public class BaogongRecordServiceImpl implements BaogongRecordService {
public Long createBaogongRecord(BaogongRecordSaveReqVO createReqVO) {
// 插入
BaogongRecordDO baogongRecord = BeanUtils.toBean(createReqVO, BaogongRecordDO.class);
baogongRecord.setBaogongTime(LocalDateTime.now());
baogongRecordMapper.insert(baogongRecord);
// 返回
return baogongRecord.getId();
@ -85,6 +91,7 @@ public class BaogongRecordServiceImpl implements BaogongRecordService {
@Override
public BaogongRecordTrendRespVO getBaogongRecordTrend(BaogongRecordTrendReqVO reqVO) {
fillTrendTimeRange(reqVO);
BaogongRecordTrendRespVO respVO = baogongRecordMapper.selectTrendSummary(reqVO);
if (respVO == null) {
respVO = new BaogongRecordTrendRespVO();
@ -93,10 +100,59 @@ public class BaogongRecordServiceImpl implements BaogongRecordService {
respVO.setNoPassNum(0L);
respVO.setPassRate(BigDecimal.ZERO);
}
List<BaogongRecordTrendDayRespVO> dayTrend = baogongRecordMapper.selectTrendByDay(reqVO);
List<BaogongRecordTrendDayRespVO> dayTrend = buildTrend(reqVO);
respVO.setDayTrend(dayTrend);
return respVO;
}
private List<BaogongRecordTrendDayRespVO> buildTrend(BaogongRecordTrendReqVO reqVO) {
BaogongTrendTypeEnum trendType = BaogongTrendTypeEnum.valueOf(reqVO.getTrendType());
if (trendType == BaogongTrendTypeEnum.CUSTOM) {
return Collections.emptyList();
}
if (trendType == BaogongTrendTypeEnum.YEAR) {
return baogongRecordMapper.selectTrendByMonth(reqVO);
}
if (trendType == BaogongTrendTypeEnum.WEEK) {
return baogongRecordMapper.selectTrendByWeekday(reqVO);
}
if (trendType == BaogongTrendTypeEnum.TODAY) {
return baogongRecordMapper.selectTrendByHour(reqVO);
}
return baogongRecordMapper.selectTrendByDay(reqVO);
}
private void fillTrendTimeRange(BaogongRecordTrendReqVO reqVO) {
BaogongTrendTypeEnum trendType = BaogongTrendTypeEnum.valueOf(reqVO.getTrendType());
if (trendType == null) {
return;
}
LocalDateTime now = LocalDateTime.now();
if (trendType == BaogongTrendTypeEnum.YEAR) {
reqVO.setBeginBaogongTime(now.minusMonths(11).withDayOfMonth(1).toLocalDate().atStartOfDay());
reqVO.setEndBaogongTime(now.withDayOfMonth(now.toLocalDate().lengthOfMonth()).toLocalDate().atTime(LocalTime.MAX));
return;
}
if (trendType == BaogongTrendTypeEnum.MONTH) {
LocalDate currentDate = now.toLocalDate();
reqVO.setBeginBaogongTime(currentDate.withDayOfMonth(1).atStartOfDay());
reqVO.setEndBaogongTime(currentDate.withDayOfMonth(currentDate.lengthOfMonth()).atTime(LocalTime.MAX));
return;
}
if (trendType == BaogongTrendTypeEnum.WEEK) {
LocalDate currentDate = now.toLocalDate();
LocalDate weekStart = currentDate.with(DayOfWeek.MONDAY);
LocalDate weekEnd = currentDate.with(DayOfWeek.SUNDAY);
reqVO.setBeginBaogongTime(weekStart.atStartOfDay());
reqVO.setEndBaogongTime(weekEnd.atTime(LocalTime.MAX));
return;
}
if (trendType == BaogongTrendTypeEnum.TODAY) {
LocalDate currentDate = now.toLocalDate();
reqVO.setBeginBaogongTime(currentDate.atStartOfDay());
reqVO.setEndBaogongTime(currentDate.atTime(LocalTime.MAX));
}
}
}
}

@ -79,5 +79,8 @@ public interface OrganizationService {
List<LineAnalysisTreeDTO.LineNode> deviceParameterAnalysis(String keyword,Integer showDevices);
OrganizationRespVO getOrganizationVO(Long id);
// List<DeviceParametersDTO> getDeviceParametersByOrganizationId(Long id);
}

@ -16,6 +16,7 @@ import cn.iocoder.yudao.module.mes.controller.admin.orgworker.vo.OrgWorkerPageRe
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.orgworker.OrgWorkerDO;
import cn.iocoder.yudao.module.mes.dal.mysql.deviceledger.DeviceLedgerMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.organization.OrganizationMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.orgworker.OrgWorkerMapper;
import cn.iocoder.yudao.module.mes.dal.redis.no.MesNoRedisDAO;
@ -28,6 +29,7 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
@ -66,6 +68,9 @@ public class OrganizationServiceImpl implements OrganizationService {
@Resource
private DeviceLedgerService deviceLedgerService;
@Resource
@Lazy
private DeviceLedgerMapper deviceLedgerMapper;
@Autowired
private AutoCodeUtil autoCodeUtil;
@ -120,9 +125,11 @@ public class OrganizationServiceImpl implements OrganizationService {
// 设备台账关联产线
if (updateObj.getMachineId() != null) {
DeviceLedgerDO deviceLedgerDO = deviceLedgerService.getDeviceLedger(updateObj.getMachineId());
deviceLedgerDO.setWorkshop(String.valueOf(updateObj.getParentId()));
deviceLedgerService.updateDeviceLedger(BeanUtils.toBean(deviceLedgerDO, DeviceLedgerSaveReqVO.class));
}
if (deviceLedgerDO != null){
deviceLedgerDO.setWorkshop(String.valueOf(updateObj.getParentId()));
deviceLedgerService.updateDeviceLedger(BeanUtils.toBean(deviceLedgerDO, DeviceLedgerSaveReqVO.class));
}
}
}
@Override
@ -223,39 +230,23 @@ public class OrganizationServiceImpl implements OrganizationService {
return Collections.emptyList();
}
//关联机台
// Map<Long, MachineComponentDO> map = machineComponentService.getMap(
// convertSet(list, OrganizationDO::getMachineId));
//
// return BeanUtils.toBean(list, OrganizationRespVO.class, item -> {
// MapUtils.findAndThen(map, item.getMachineId(),
// machine -> item.setMachineName(machine.getName()));
//
// });
//关联设备
Map<Long, DeviceDO> map = deviceService.getMap(
convertSet(list, OrganizationDO::getDvId));
// List<DeviceLedgerDO> deviceLedgerDOList = deviceLedgerService.getDeviceLedgerList();
// Map<Long, DeviceLedgerDO> resultMap = deviceLedgerDOList.stream()
// .filter(Objects::nonNull)
// .collect(Collectors.toMap(
// DeviceLedgerDO::getId,
// Function.identity(),
// (existing, replacement) -> existing // 处理重复key
// ));
// return BeanUtils.toBean(list, OrganizationRespVO.class, item -> {
// MapUtils.findAndThen(resultMap, item.getDvId(),
// device -> item.setMachineName(device.getDeviceName()));
// });
Set<Long> dvIds = convertSet(list, OrganizationDO::getDvId);
return BeanUtils.toBean(list, OrganizationRespVO.class, item -> {
MapUtils.findAndThen(map, item.getDvId(),
device -> item.setMachineName(device.getDeviceName()));
Map<Long, DeviceDO> deviceMap = deviceService.getMapIncludeDeleted(dvIds);
return BeanUtils.toBean(list, OrganizationRespVO.class, item -> {
MapUtils.findAndThen(deviceMap, item.getDvId(), device -> {
String deviceName = device.getDeviceName();
// 按你项目删除标记字段调整,比如 getDeleted()/getIsDeleted()/getStatus()
if (Boolean.TRUE.equals(device.getDeleted())) {
deviceName = deviceName + "(已被删除)";
}
item.setMachineName(deviceName);
});
});
}
@Override
public List<OrganizationRespVO> buildWorkerVOList(List<OrganizationDO> list) {
if (CollUtil.isEmpty(list)) {
@ -731,4 +722,46 @@ public class OrganizationServiceImpl implements OrganizationService {
.build();
}
// OrganizationServiceImpl.java
@Override
public OrganizationRespVO getOrganizationVO(Long id) {
OrganizationDO organization = organizationMapper.selectById(id);
if (organization == null) {
return null;
}
OrganizationRespVO respVO = BeanUtils.toBean(organization, OrganizationRespVO.class);
if (organization.getMachineId() != null) {
DeviceLedgerDO ledger = deviceLedgerMapper.selectByIdWithDeleted(organization.getMachineId());
if (ledger != null) {
String machineName = (ledger.getDeviceCode() == null ? "" : ledger.getDeviceCode())
+ "-"
+ (ledger.getDeviceName() == null ? "" : ledger.getDeviceName());
if (Boolean.TRUE.equals(ledger.getDeleted())) {
machineName += "(已被删除)";
}
respVO.setMachineName(machineName);
}
}
if (organization.getDvId() != null) {
DeviceDO device = deviceMapper.selectByIdWithDeleted(organization.getDvId());
if (device != null) {
String deviceName = (device.getDeviceCode() == null ? "" : device.getDeviceCode())
+ "-"
+ (device.getDeviceName() == null ? "" : device.getDeviceName());
if (Boolean.TRUE.equals(device.getDeleted())) {
deviceName += "(已被删除)";
}
respVO.setDvName(deviceName);
}
}
return respVO;
}
}

@ -262,7 +262,7 @@ public class PlanServiceImpl implements PlanService {
stockIn.setInType("产品入库");
ErpStockInSaveReqVO.Item item = new ErpStockInSaveReqVO.Item();
// todo 修改仓库
item.setWarehouseId(12L);
item.setWarehouseId(statusUpdateVO.getWarehouseId());
item.setProductId(planDO.getProductId());
if (planDO.getPassNumber() == null) {
planDO.setPassNumber(0L);
@ -641,6 +641,7 @@ public class PlanServiceImpl implements PlanService {
item.setPlanStartTimeStr(plan.getPlanStartTime().format(DateTimeFormatter.ofPattern(DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)));
item.setPlanEndTimeStr(plan.getPlanEndTime().format(DateTimeFormatter.ofPattern(DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)));
item.setLatestStartTimeStr(plan.getLatestStartTime().format(DateTimeFormatter.ofPattern(DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)));
item.setPlanStatus(plan.getStatus()!=null ? plan.getStatus() : null);
plans.add(item);
}

@ -172,6 +172,8 @@ public interface TaskService {
List<TaskDetailDO> getTaskDetailListByTaskIds(Collection<Long> taskIds);
TaskTrendRespVO getTaskTrend(TaskTrendReqVO reqVO);
}
}

@ -32,6 +32,7 @@ import cn.iocoder.yudao.module.mes.dal.mysql.task.TaskDetailMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.task.TaskMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.task.ViewTaskProductSummaryMapper;
import cn.iocoder.yudao.module.mes.dal.redis.no.MesNoRedisDAO;
import cn.iocoder.yudao.module.mes.enums.BaogongTrendTypeEnum;
import cn.iocoder.yudao.module.mes.service.deviceledger.DeviceLedgerService;
import cn.iocoder.yudao.module.mes.strategy.task.ScheduleSortStrategyFactory;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
@ -46,6 +47,7 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
@ -673,7 +675,7 @@ public class TaskServiceImpl implements TaskService {
deliveryDate = taskDO.getDeliveryDate().toLocalDate();
}
h.setDeliveryDateStr(deliveryDate == null ? null : deliveryDate.format(DATE_FMT));
h.setPlanStatus(history.getStatus());
historyItems.add(h);
}
@ -914,4 +916,82 @@ public class TaskServiceImpl implements TaskService {
);
}
}
@Override
public TaskTrendRespVO getTaskTrend(TaskTrendReqVO reqVO) {
fillTrendTimeRange(reqVO);
TaskTrendRespVO respVO = taskMapper.selectTrendSummary(reqVO);
if (respVO == null) {
respVO = new TaskTrendRespVO();
}
if (respVO.getTotalNum() == null) {
respVO.setTotalNum(0L);
}
if (respVO.getIssuedNum() == null) {
respVO.setIssuedNum(0L);
}
if (respVO.getPartialScheduledNum() == null) {
respVO.setPartialScheduledNum(0L);
}
if (respVO.getWaitingProductionNum() == null) {
respVO.setWaitingProductionNum(0L);
}
if (respVO.getProducingNum() == null) {
respVO.setProducingNum(0L);
}
if (respVO.getCompletedNum() == null) {
respVO.setCompletedNum(0L);
}
respVO.setDayTrend(buildTrend(reqVO));
return respVO;
}
private List<TaskTrendItemRespVO> buildTrend(TaskTrendReqVO reqVO) {
BaogongTrendTypeEnum trendType = BaogongTrendTypeEnum.valueOf(reqVO.getTrendType());
if (trendType == BaogongTrendTypeEnum.CUSTOM) {
return Collections.emptyList();
}
if (trendType == BaogongTrendTypeEnum.YEAR) {
return taskMapper.selectTrendByMonth(reqVO);
}
if (trendType == BaogongTrendTypeEnum.WEEK) {
return taskMapper.selectTrendByWeekday(reqVO);
}
if (trendType == BaogongTrendTypeEnum.TODAY) {
return taskMapper.selectTrendByHour(reqVO);
}
return taskMapper.selectTrendByDay(reqVO);
}
private void fillTrendTimeRange(TaskTrendReqVO reqVO) {
BaogongTrendTypeEnum trendType = BaogongTrendTypeEnum.valueOf(reqVO.getTrendType());
if (trendType == null) {
return;
}
LocalDateTime now = LocalDateTime.now();
if (trendType == BaogongTrendTypeEnum.YEAR) {
reqVO.setBeginTime(now.minusMonths(11).withDayOfMonth(1).toLocalDate().atStartOfDay());
reqVO.setEndTime(now.withDayOfMonth(now.toLocalDate().lengthOfMonth()).toLocalDate().atTime(LocalTime.MAX));
return;
}
if (trendType == BaogongTrendTypeEnum.MONTH) {
LocalDate currentDate = now.toLocalDate();
reqVO.setBeginTime(currentDate.withDayOfMonth(1).atStartOfDay());
reqVO.setEndTime(currentDate.withDayOfMonth(currentDate.lengthOfMonth()).atTime(LocalTime.MAX));
return;
}
if (trendType == BaogongTrendTypeEnum.WEEK) {
LocalDate currentDate = now.toLocalDate();
LocalDate weekStart = currentDate.with(DayOfWeek.MONDAY);
LocalDate weekEnd = currentDate.with(DayOfWeek.SUNDAY);
reqVO.setBeginTime(weekStart.atStartOfDay());
reqVO.setEndTime(weekEnd.atTime(LocalTime.MAX));
return;
}
if (trendType == BaogongTrendTypeEnum.TODAY) {
LocalDate currentDate = now.toLocalDate();
reqVO.setBeginTime(currentDate.atStartOfDay());
reqVO.setEndTime(currentDate.atTime(LocalTime.MAX));
}
}
}

@ -75,7 +75,7 @@
<select id="selectTrendByDay"
resultType="cn.iocoder.yudao.module.mes.controller.admin.baogongrecord.vo.BaogongRecordTrendDayRespVO">
SELECT
DATE_FORMAT(r.baogong_time, '%Y-%m-%d') AS day,
d.day AS day,
IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) AS baogongNum,
CASE
WHEN IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) = 0 THEN 0
@ -84,17 +84,112 @@
IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) * 100, 2
)
END AS passRate
FROM mes_baogong_record r
WHERE r.deleted = b'0'
<if test="reqVO.beginBaogongTime != null">
AND r.baogong_time &gt;= #{reqVO.beginBaogongTime}
</if>
<if test="reqVO.endBaogongTime != null">
AND r.baogong_time &lt;= #{reqVO.endBaogongTime}
</if>
GROUP BY DATE_FORMAT(r.baogong_time, '%Y-%m-%d')
ORDER BY day ASC
FROM (
SELECT DATE_FORMAT(DATE_ADD(#{reqVO.beginBaogongTime}, INTERVAL seq.num DAY), '%Y-%m-%d') AS day
FROM (
SELECT 0 AS num UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL
SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL
SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12 UNION ALL SELECT 13 UNION ALL SELECT 14 UNION ALL
SELECT 15 UNION ALL SELECT 16 UNION ALL SELECT 17 UNION ALL SELECT 18 UNION ALL SELECT 19 UNION ALL
SELECT 20 UNION ALL SELECT 21 UNION ALL SELECT 22 UNION ALL SELECT 23 UNION ALL SELECT 24 UNION ALL
SELECT 25 UNION ALL SELECT 26 UNION ALL SELECT 27 UNION ALL SELECT 28 UNION ALL SELECT 29 UNION ALL
SELECT 30
) seq
WHERE DATE_ADD(#{reqVO.beginBaogongTime}, INTERVAL seq.num DAY) &lt;= #{reqVO.endBaogongTime}
) d
LEFT JOIN mes_baogong_record r
ON r.deleted = b'0'
AND DATE_FORMAT(r.baogong_time, '%Y-%m-%d') = d.day
GROUP BY d.day
ORDER BY d.day ASC
</select>
<select id="selectTrendByMonth"
resultType="cn.iocoder.yudao.module.mes.controller.admin.baogongrecord.vo.BaogongRecordTrendDayRespVO">
SELECT
m.day AS day,
IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) AS baogongNum,
CASE
WHEN IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) = 0 THEN 0
ELSE ROUND(
IFNULL(SUM(IFNULL(r.num, 0)), 0) /
IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) * 100, 2
)
END AS passRate
FROM (
SELECT DATE_FORMAT(DATE_ADD(#{reqVO.beginBaogongTime}, INTERVAL seq.num MONTH), '%Y-%m') AS day
FROM (
SELECT 0 AS num UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL
SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL
SELECT 10 UNION ALL SELECT 11
) seq
) m
LEFT JOIN mes_baogong_record r
ON r.deleted = b'0'
AND DATE_FORMAT(r.baogong_time, '%Y-%m') = m.day
AND r.baogong_time &gt;= #{reqVO.beginBaogongTime}
AND r.baogong_time &lt;= #{reqVO.endBaogongTime}
GROUP BY m.day
ORDER BY m.day ASC
</select>
<select id="selectTrendByWeekday"
resultType="cn.iocoder.yudao.module.mes.controller.admin.baogongrecord.vo.BaogongRecordTrendDayRespVO">
SELECT
w.day_name AS day,
IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) AS baogongNum,
CASE
WHEN IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) = 0 THEN 0
ELSE ROUND(
IFNULL(SUM(IFNULL(r.num, 0)), 0) /
IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) * 100, 2
)
END AS passRate
FROM (
SELECT 1 AS idx, DATE_FORMAT(#{reqVO.beginBaogongTime}, '%Y-%m-%d') AS day_key, '星期一' AS day_name UNION ALL
SELECT 2, DATE_FORMAT(DATE_ADD(#{reqVO.beginBaogongTime}, INTERVAL 1 DAY), '%Y-%m-%d'), '星期二' UNION ALL
SELECT 3, DATE_FORMAT(DATE_ADD(#{reqVO.beginBaogongTime}, INTERVAL 2 DAY), '%Y-%m-%d'), '星期三' UNION ALL
SELECT 4, DATE_FORMAT(DATE_ADD(#{reqVO.beginBaogongTime}, INTERVAL 3 DAY), '%Y-%m-%d'), '星期四' UNION ALL
SELECT 5, DATE_FORMAT(DATE_ADD(#{reqVO.beginBaogongTime}, INTERVAL 4 DAY), '%Y-%m-%d'), '星期五' UNION ALL
SELECT 6, DATE_FORMAT(DATE_ADD(#{reqVO.beginBaogongTime}, INTERVAL 5 DAY), '%Y-%m-%d'), '星期六' UNION ALL
SELECT 7, DATE_FORMAT(DATE_ADD(#{reqVO.beginBaogongTime}, INTERVAL 6 DAY), '%Y-%m-%d'), '星期日'
) w
LEFT JOIN mes_baogong_record r
ON r.deleted = b'0'
AND DATE_FORMAT(r.baogong_time, '%Y-%m-%d') = w.day_key
AND r.baogong_time &gt;= #{reqVO.beginBaogongTime}
AND r.baogong_time &lt;= #{reqVO.endBaogongTime}
GROUP BY w.idx, w.day_name
ORDER BY w.idx ASC
</select>
<select id="selectTrendByHour"
resultType="cn.iocoder.yudao.module.mes.controller.admin.baogongrecord.vo.BaogongRecordTrendDayRespVO">
SELECT
h.day AS day,
IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) AS baogongNum,
CASE
WHEN IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) = 0 THEN 0
ELSE ROUND(
IFNULL(SUM(IFNULL(r.num, 0)), 0) /
IFNULL(SUM(IFNULL(r.num, 0) + IFNULL(r.no_pass_num, 0)), 0) * 100, 2
)
END AS passRate
FROM (
SELECT '00:00' AS day UNION ALL SELECT '01:00' UNION ALL SELECT '02:00' UNION ALL SELECT '03:00' UNION ALL
SELECT '04:00' UNION ALL SELECT '05:00' UNION ALL SELECT '06:00' UNION ALL SELECT '07:00' UNION ALL
SELECT '08:00' UNION ALL SELECT '09:00' UNION ALL SELECT '10:00' UNION ALL SELECT '11:00' UNION ALL
SELECT '12:00' UNION ALL SELECT '13:00' UNION ALL SELECT '14:00' UNION ALL SELECT '15:00' UNION ALL
SELECT '16:00' UNION ALL SELECT '17:00' UNION ALL SELECT '18:00' UNION ALL SELECT '19:00' UNION ALL
SELECT '20:00' UNION ALL SELECT '21:00' UNION ALL SELECT '22:00' UNION ALL SELECT '23:00'
) h
LEFT JOIN mes_baogong_record r
ON r.deleted = b'0'
AND DATE_FORMAT(r.baogong_time, '%H:00') = h.day
AND r.baogong_time &gt;= #{reqVO.beginBaogongTime}
AND r.baogong_time &lt;= #{reqVO.endBaogongTime}
GROUP BY h.day
ORDER BY h.day ASC
</select>
</mapper>
</mapper>

@ -19,5 +19,13 @@
AND deleted = 0
</select>
<!-- DeviceLedgerMapper.xml -->
<select id="selectByIdWithDeleted"
resultType="cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger.DeviceLedgerDO">
SELECT *
FROM mes_device_ledger
WHERE id = #{id}
LIMIT 1
</select>
</mapper>

@ -9,4 +9,114 @@
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>
<select id="selectTrendSummary"
resultType="cn.iocoder.yudao.module.mes.controller.admin.task.vo.TaskTrendRespVO">
SELECT
COUNT(1) AS totalNum,
SUM(CASE WHEN t.status = 2 THEN 1 ELSE 0 END) AS issuedNum,
SUM(CASE WHEN t.status = 7 THEN 1 ELSE 0 END) AS partialScheduledNum,
SUM(CASE WHEN t.status = 8 THEN 1 ELSE 0 END) AS waitingProductionNum,
SUM(CASE WHEN t.status = 9 THEN 1 ELSE 0 END) AS producingNum,
SUM(CASE WHEN t.status = 10 THEN 1 ELSE 0 END) AS completedNum
FROM mes_task t
WHERE t.deleted = b'0'
<if test="reqVO.beginTime != null">
AND t.create_time &gt;= #{reqVO.beginTime}
</if>
<if test="reqVO.endTime != null">
AND t.create_time &lt;= #{reqVO.endTime}
</if>
</select>
<select id="selectTrendByDay"
resultType="cn.iocoder.yudao.module.mes.controller.admin.task.vo.TaskTrendItemRespVO">
SELECT
d.day AS day,
COUNT(t.id) AS count
FROM (
SELECT DATE_FORMAT(DATE_ADD(#{reqVO.beginTime}, INTERVAL seq.num DAY), '%Y-%m-%d') AS day
FROM (
SELECT 0 AS num UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL
SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL
SELECT 10 UNION ALL SELECT 11 UNION ALL SELECT 12 UNION ALL SELECT 13 UNION ALL SELECT 14 UNION ALL
SELECT 15 UNION ALL SELECT 16 UNION ALL SELECT 17 UNION ALL SELECT 18 UNION ALL SELECT 19 UNION ALL
SELECT 20 UNION ALL SELECT 21 UNION ALL SELECT 22 UNION ALL SELECT 23 UNION ALL SELECT 24 UNION ALL
SELECT 25 UNION ALL SELECT 26 UNION ALL SELECT 27 UNION ALL SELECT 28 UNION ALL SELECT 29 UNION ALL
SELECT 30
) seq
WHERE DATE_ADD(#{reqVO.beginTime}, INTERVAL seq.num DAY) &lt;= #{reqVO.endTime}
) d
LEFT JOIN mes_task t
ON t.deleted = b'0'
AND DATE_FORMAT(t.create_time, '%Y-%m-%d') = d.day
GROUP BY d.day
ORDER BY d.day ASC
</select>
<select id="selectTrendByMonth"
resultType="cn.iocoder.yudao.module.mes.controller.admin.task.vo.TaskTrendItemRespVO">
SELECT
m.day AS day,
COUNT(t.id) AS count
FROM (
SELECT DATE_FORMAT(DATE_ADD(#{reqVO.beginTime}, INTERVAL seq.num MONTH), '%Y-%m') AS day
FROM (
SELECT 0 AS num UNION ALL SELECT 1 UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL SELECT 4 UNION ALL
SELECT 5 UNION ALL SELECT 6 UNION ALL SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL
SELECT 10 UNION ALL SELECT 11
) seq
) m
LEFT JOIN mes_task t
ON t.deleted = b'0'
AND DATE_FORMAT(t.create_time, '%Y-%m') = m.day
AND t.create_time &gt;= #{reqVO.beginTime}
AND t.create_time &lt;= #{reqVO.endTime}
GROUP BY m.day
ORDER BY m.day ASC
</select>
<select id="selectTrendByWeekday"
resultType="cn.iocoder.yudao.module.mes.controller.admin.task.vo.TaskTrendItemRespVO">
SELECT
w.day_name AS day,
COUNT(t.id) AS count
FROM (
SELECT 1 AS idx, DATE_FORMAT(#{reqVO.beginTime}, '%Y-%m-%d') AS day_key, '星期一' AS day_name UNION ALL
SELECT 2, DATE_FORMAT(DATE_ADD(#{reqVO.beginTime}, INTERVAL 1 DAY), '%Y-%m-%d'), '星期二' UNION ALL
SELECT 3, DATE_FORMAT(DATE_ADD(#{reqVO.beginTime}, INTERVAL 2 DAY), '%Y-%m-%d'), '星期三' UNION ALL
SELECT 4, DATE_FORMAT(DATE_ADD(#{reqVO.beginTime}, INTERVAL 3 DAY), '%Y-%m-%d'), '星期四' UNION ALL
SELECT 5, DATE_FORMAT(DATE_ADD(#{reqVO.beginTime}, INTERVAL 4 DAY), '%Y-%m-%d'), '星期五' UNION ALL
SELECT 6, DATE_FORMAT(DATE_ADD(#{reqVO.beginTime}, INTERVAL 5 DAY), '%Y-%m-%d'), '星期六' UNION ALL
SELECT 7, DATE_FORMAT(DATE_ADD(#{reqVO.beginTime}, INTERVAL 6 DAY), '%Y-%m-%d'), '星期日'
) w
LEFT JOIN mes_task t
ON t.deleted = b'0'
AND DATE_FORMAT(t.create_time, '%Y-%m-%d') = w.day_key
AND t.create_time &gt;= #{reqVO.beginTime}
AND t.create_time &lt;= #{reqVO.endTime}
GROUP BY w.idx, w.day_name
ORDER BY w.idx ASC
</select>
<select id="selectTrendByHour"
resultType="cn.iocoder.yudao.module.mes.controller.admin.task.vo.TaskTrendItemRespVO">
SELECT
h.day AS day,
COUNT(t.id) AS count
FROM (
SELECT '00:00' AS day UNION ALL SELECT '01:00' UNION ALL SELECT '02:00' UNION ALL SELECT '03:00' UNION ALL
SELECT '04:00' UNION ALL SELECT '05:00' UNION ALL SELECT '06:00' UNION ALL SELECT '07:00' UNION ALL
SELECT '08:00' UNION ALL SELECT '09:00' UNION ALL SELECT '10:00' UNION ALL SELECT '11:00' UNION ALL
SELECT '12:00' UNION ALL SELECT '13:00' UNION ALL SELECT '14:00' UNION ALL SELECT '15:00' UNION ALL
SELECT '16:00' UNION ALL SELECT '17:00' UNION ALL SELECT '18:00' UNION ALL SELECT '19:00' UNION ALL
SELECT '20:00' UNION ALL SELECT '21:00' UNION ALL SELECT '22:00' UNION ALL SELECT '23:00'
) h
LEFT JOIN mes_task t
ON t.deleted = b'0'
AND DATE_FORMAT(t.create_time, '%H:00') = h.day
AND t.create_time &gt;= #{reqVO.beginTime}
AND t.create_time &lt;= #{reqVO.endTime}
GROUP BY h.day
ORDER BY h.day ASC
</select>
</mapper>

Loading…
Cancel
Save