产线关联设备台账 台账关联采集设备

plp
kkk-ops 5 days ago
parent 3337c09132
commit 43c6726455

@ -1,8 +1,14 @@
package cn.iocoder.yudao.module.mes.controller.admin.deviceledger;
import cn.iocoder.yudao.framework.common.util.collection.MapUtils;
import cn.iocoder.yudao.module.common.dal.dataobject.mold.MoldDO;
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
import cn.iocoder.yudao.module.mes.controller.admin.deviceledger.utils.ResumeNameUtils;
import cn.iocoder.yudao.module.mes.controller.admin.plan.vo.PlanRespVO;
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.mysql.deviceledger.DeviceLedgerMapper;
import cn.iocoder.yudao.module.mes.service.organization.OrganizationService;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import com.alibaba.excel.util.StringUtils;
@ -22,6 +28,7 @@ import java.time.format.DateTimeFormatter;
import java.util.*;
import java.io.IOException;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
@ -33,6 +40,7 @@ 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 static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import cn.iocoder.yudao.module.mes.controller.admin.deviceledger.vo.*;
import cn.iocoder.yudao.module.mes.dal.dataobject.deviceledger.DeviceLedgerDO;
@ -47,6 +55,9 @@ public class DeviceLedgerController {
@Resource
private DeviceLedgerService deviceLedgerService;
@Resource
private OrganizationService organizationService;
@Resource
private AdminUserApi adminUserApi;
@ -87,9 +98,8 @@ public class DeviceLedgerController {
@PreAuthorize("@ss.hasPermission('mes:device-ledger:query')")
public CommonResult<DeviceLedgerRespVO> getDeviceLedger(@RequestParam("id") Long id) {
DeviceLedgerDO deviceLedger = deviceLedgerService.getDeviceLedger(id);
DeviceLedgerRespVO respVO = BeanUtils.toBean(deviceLedger, DeviceLedgerRespVO.class);
respVO.setCreatorName(adminUserApi.getUser(Long.valueOf(deviceLedger.getCreator())).getNickname());
if (StringUtils.isNotBlank(respVO.getDeviceManager())) {
String[] userIds = respVO.getDeviceManager().split(",");
StringBuilder names = new StringBuilder();
@ -112,6 +122,33 @@ public class DeviceLedgerController {
@PreAuthorize("@ss.hasPermission('mes:device-ledger:query')")
public CommonResult<PageResult<?>> getDeviceLedgerPage(@Valid DeviceLedgerPageReqVO pageReqVO) {
PageResult<DeviceLedgerDO> pageResult = deviceLedgerService.getDeviceLedgerPage(pageReqVO);
Set<Long> workshopIds = pageResult.getList().stream()
.map(DeviceLedgerDO::getWorkshop)
.filter(StringUtils::isNotBlank) // 使用StringUtils或手动判断
.flatMap(workshop -> {
try {
return Stream.of(Long.valueOf(workshop.trim()));
} catch (NumberFormatException e) {
return Stream.empty(); // 转换失败时返回空流,相当于跳过
}
})
.collect(Collectors.toSet());
Map<Long, OrganizationDO> organizationMap = organizationService.getMap(workshopIds);
// 4. 设置 workshopName
for (DeviceLedgerDO item : pageResult.getList()) {
if (item.getWorkshop() != null) {
try {
Long workshopId = Long.parseLong(item.getWorkshop().trim());
OrganizationDO org = organizationMap.get(workshopId);
if (org != null) {
item.setWorkshopName(org.getName());
}
} catch (NumberFormatException e) {
}
}
}
return success(ResumeNameUtils.buildPageCreatorName(BeanUtils.toBean(pageResult, DeviceLedgerRespVO.class)));
}
@ -123,6 +160,17 @@ public class DeviceLedgerController {
return success(deviceLedgerDOList);
}
@GetMapping("/noUsedlist")
@Operation(summary = "获得未关联设备台账列表")
@PreAuthorize("@ss.hasPermission('mes:device-ledger:query')")
public CommonResult<List<DeviceLedgerDO>> getDeviceLedgerListByNoUsed() {
List<DeviceLedgerDO> deviceLedgerDOList = deviceLedgerService.getDeviceLedgerList();
deviceLedgerDOList.removeIf(device ->
device.getWorkshop() != null
);
return success(deviceLedgerDOList);
}
@GetMapping("/export-excel")
@Operation(summary = "导出设备台账 Excel")

@ -80,4 +80,7 @@ public class DeviceLedgerPageReqVO extends PageParam {
@Schema(description = "关键件id")
private String componentId;
@Schema(description = "关联采集设备id")
private Long dvId;
}

@ -100,8 +100,11 @@ public class DeviceLedgerRespVO extends BaseDO {
// @ExcelProperty("供应商")
private String supplier;
@Schema(description = "所属车间")
// @ExcelProperty("所属车间")
@Schema(description = "所属产线")
@ExcelProperty("所属产线")
private String workshopName;
@Schema(description = "所属产线ID")
private String workshop;
@Schema(description = "所属系统组织")
@ -145,4 +148,7 @@ public class DeviceLedgerRespVO extends BaseDO {
@Schema(description = "模具id")
private String moldId;
@Schema(description = "关联采集设备id")
private Long dvId;
}

@ -75,4 +75,7 @@ public class DeviceLedgerSaveReqVO {
@Schema(description = "模具ids集合")
private String moldId;
@Schema(description = "关联采集设备id")
private Long dvId;
}

@ -66,9 +66,15 @@ public class DeviceLedgerDO extends BaseDO {
*/
private String supplier;
/**
*
* 线
*/
private String workshop;
/**
* 线
*/
@TableField(exist = false)
private String workshopName;
/**
*
*/
@ -164,4 +170,9 @@ public class DeviceLedgerDO extends BaseDO {
@TableField(exist = false)
private List<MoldDO> moldList;
/**
*
*/
private Long dvId;
}

@ -92,8 +92,9 @@ public class DeviceLedgerServiceImpl implements DeviceLedgerService {
// 插入
DeviceLedgerDO deviceLedger = BeanUtils.toBean(createReqVO, DeviceLedgerDO.class);
// 创建台账
deviceLedgerMapper.insert(deviceLedger);
// 返回
return deviceLedger.getId();
}

@ -10,13 +10,17 @@ import cn.iocoder.yudao.module.iot.dal.dataobject.devicecontactmodel.DeviceConta
import cn.iocoder.yudao.module.iot.dal.mysql.device.DeviceMapper;
import cn.iocoder.yudao.module.iot.dal.mysql.devicecontactmodel.DeviceContactModelMapper;
import cn.iocoder.yudao.module.iot.service.device.DeviceService;
import cn.iocoder.yudao.module.mes.controller.admin.deviceledger.vo.DeviceLedgerSaveReqVO;
import cn.iocoder.yudao.module.mes.controller.admin.organization.vo.*;
import cn.iocoder.yudao.module.mes.controller.admin.orgworker.vo.OrgWorkerPageReqVO;
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.organization.OrganizationMapper;
import cn.iocoder.yudao.module.mes.dal.mysql.orgworker.OrgWorkerMapper;
import cn.iocoder.yudao.module.mes.dal.redis.no.MesNoRedisDAO;
import cn.iocoder.yudao.module.mes.service.deviceledger.DeviceLedgerService;
import cn.iocoder.yudao.module.mes.service.deviceledger.DeviceLedgerServiceImpl;
import cn.iocoder.yudao.module.mes.service.machine.MachineComponentService;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
@ -58,6 +62,9 @@ public class OrganizationServiceImpl implements OrganizationService {
@Resource
private DeviceMapper deviceMapper;
@Resource
private DeviceLedgerService deviceLedgerService;
@Autowired
private AutoCodeUtil autoCodeUtil;
@Override
@ -86,6 +93,12 @@ public class OrganizationServiceImpl implements OrganizationService {
}
}
organizationMapper.insert(organization);
// 设备台账关联产线
if (organization.getMachineId() != null) {
DeviceLedgerDO deviceLedgerDO = deviceLedgerService.getDeviceLedger(organization.getMachineId());
deviceLedgerDO.setWorkshop(String.valueOf(organization.getParentId()));
deviceLedgerService.updateDeviceLedger(BeanUtils.toBean(deviceLedgerDO, DeviceLedgerSaveReqVO.class));
}
// 返回
return organization.getId();
}
@ -102,6 +115,12 @@ public class OrganizationServiceImpl implements OrganizationService {
// 更新
OrganizationDO updateObj = BeanUtils.toBean(updateReqVO, OrganizationDO.class);
organizationMapper.updateById(updateObj);
// 设备台账关联产线
if (updateObj.getMachineId() != null) {
DeviceLedgerDO deviceLedgerDO = deviceLedgerService.getDeviceLedger(updateObj.getMachineId());
deviceLedgerDO.setWorkshop(String.valueOf(updateObj.getParentId()));
deviceLedgerService.updateDeviceLedger(BeanUtils.toBean(deviceLedgerDO, DeviceLedgerSaveReqVO.class));
}
}
@Override
@ -112,8 +131,15 @@ public class OrganizationServiceImpl implements OrganizationService {
if (organizationMapper.selectCountByParentId(id) > 0) {
throw exception(ORGANIZATION_EXITS_CHILDREN);
}
DeviceLedgerDO deviceLedgerDO = deviceLedgerService.getDeviceLedger(organizationMapper.selectById(id).getMachineId());
if (deviceLedgerDO != null) {
deviceLedgerDO.setWorkshop(null);
deviceLedgerService.updateDeviceLedger(BeanUtils.toBean(deviceLedgerDO, DeviceLedgerSaveReqVO.class));
}
// 删除
organizationMapper.deleteById(id);
// 设备台账关联产线
}
private void validateOrganizationExists(Long id) {
@ -204,13 +230,21 @@ public class OrganizationServiceImpl implements OrganizationService {
//
// });
//关联设备
Map<Long, DeviceDO> map = deviceService.getMap(
convertSet(list, OrganizationDO::getMachineId));
// Map<Long, DeviceDO> map = deviceService.getMap(
// convertSet(list, OrganizationDO::getMachineId));
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(map, item.getMachineId(),
MapUtils.findAndThen(resultMap, item.getMachineId(),
device -> item.setMachineName(device.getDeviceName()));
});
}
@Override

Loading…
Cancel
Save