fix:修改设备台账问题及产品相关问题

main
HuangHuiKang 6 days ago
parent f577a93129
commit c5c7702628

@ -36,4 +36,13 @@ public class ErpProductPageReqVO extends PageParam {
@Schema(description = "产品规格", example = "红色")
private String standard;
@Schema(description = "是否只查询库存不为 0 的产品", example = "true")
private Boolean stockNotZero;
@Schema(description = "仓库编号", example = "1")
private Long warehouseId;
@Schema(description = "库区编号", example = "1")
private Long areaId;
}

@ -105,6 +105,9 @@ public class ErpProductRespVO extends ErpProductDO {
@ExcelProperty("预警库存")
private BigDecimal safetyNumber;
@Schema(description = "库存数量", example = "100")
private BigDecimal stockCount;
@Schema(description = "默认仓库 ID", example = "1")
private Long defaultWarehouseId;

@ -63,6 +63,17 @@ public interface ErpProductMapper extends BaseMapperX<ErpProductDO> {
.betweenIfPresent(ErpProductDO::getCreateTime, reqVO.getCreateTime())
.orderByDesc(ErpProductDO::getId);
if (Boolean.TRUE.equals(reqVO.getStockNotZero())) {
StringBuilder stockExistsSql = new StringBuilder("SELECT 1 FROM erp_stock s WHERE s.deleted = b'0' AND s.product_id = erp_product.id AND s.count != 0");
if (reqVO.getWarehouseId() != null) {
stockExistsSql.append(" AND s.warehouse_id = ").append(reqVO.getWarehouseId());
}
if (reqVO.getAreaId() != null) {
stockExistsSql.append(" AND s.area_id = ").append(reqVO.getAreaId());
}
queryWrapper.exists(stockExistsSql.toString());
}
return selectPage(reqVO,queryWrapper);
}

@ -17,6 +17,7 @@ import org.apache.ibatis.annotations.Param;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.Collections;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@ -185,6 +186,34 @@ public interface ErpStockMapper extends BaseMapperX<ErpStockDO> {
return BigDecimal.valueOf(MapUtil.getDouble(result.get(0), "sumCount", 0D));
}
default Map<Long, BigDecimal> selectSumCountMapByProductIds(Collection<Long> productIds) {
return selectSumCountMapByProductIds(productIds, null, null);
}
default Map<Long, BigDecimal> selectSumCountMapByProductIds(Collection<Long> productIds, Long warehouseId, Long areaId) {
if (CollUtil.isEmpty(productIds)) {
return Collections.emptyMap();
}
QueryWrapper<ErpStockDO> queryWrapper = new QueryWrapper<ErpStockDO>()
.select("product_id AS productId", "SUM(count) AS stockCount")
.in("product_id", productIds)
.groupBy("product_id");
if (warehouseId != null) {
queryWrapper.eq("warehouse_id", warehouseId);
}
if (areaId != null) {
queryWrapper.eq("area_id", areaId);
}
List<Map<String, Object>> result = selectMaps(queryWrapper);
if (CollUtil.isEmpty(result)) {
return Collections.emptyMap();
}
return result.stream().collect(Collectors.toMap(
item -> ((Number) item.get("productId")).longValue(),
item -> item.get("stockCount") == null ? BigDecimal.ZERO : new BigDecimal(item.get("stockCount").toString()),
(count1, count2) -> count1));
}
void updateStockCount(@Param("productId") Long productId,
@Param("warehouseId") Long warehouseId,
@Param("num") BigDecimal num);

@ -634,17 +634,22 @@ public class ErpProductServiceImpl implements ErpProductService {
@Override
public PageResult<ErpProductRespVO> getProductVOPage(ErpProductPageReqVO pageReqVO) {
PageResult<ErpProductDO> pageResult = productMapper.selectPage(pageReqVO);
return new PageResult<>(buildProductVOList(pageResult.getList()), pageResult.getTotal());
return new PageResult<>(buildProductVOList(pageResult.getList(), pageReqVO.getWarehouseId(), pageReqVO.getAreaId()), pageResult.getTotal());
}
@Override
public List<ErpProductRespVO> buildProductVOList(List<ErpProductDO> list) {
return buildProductVOList(list, null, null);
}
private List<ErpProductRespVO> buildProductVOList(List<ErpProductDO> list, Long warehouseId, Long areaId) {
if (CollUtil.isEmpty(list)) {
return Collections.emptyList();
}
Set<Long> productIds = convertSet(list, ErpProductDO::getId);
List<ProductSupplierRelDO> supplierRels = productSupplierRelMapper.selectListByProductIds(
convertSet(list, ErpProductDO::getId));
productIds);
Map<Long, List<ProductPackagingSchemeRespVO>> packagingSchemeMap =
productPackagingSchemeRelMapper.selectListByProductIds(convertSet(list, ErpProductDO::getId))
productPackagingSchemeRelMapper.selectListByProductIds(productIds)
.stream()
.collect(Collectors.groupingBy(ProductPackagingSchemeRelDO::getProductId,
Collectors.mapping(rel -> BeanUtils.toBean(rel, ProductPackagingSchemeRespVO.class),
@ -665,6 +670,7 @@ public class ErpProductServiceImpl implements ErpProductService {
convertSet(list, ErpProductDO::getUnitId));
Map<Long, ErpProductUnitDO> purchaseUnitMap = productUnitService.getProductUnitMap(
convertSet(list, ErpProductDO::getPurchaseUnitId));
Map<Long, BigDecimal> stockCountMap = erpStockMapper.selectSumCountMapByProductIds(productIds, warehouseId, areaId);
return BeanUtils.toBean(list, ErpProductRespVO.class, product -> {
MapUtils.findAndThen(categoryMap, product.getCategoryId(), category -> {
product.setCategoryName(category.getName());
@ -687,6 +693,7 @@ public class ErpProductServiceImpl implements ErpProductService {
product.setPackagingSchemes(packagingSchemeMap.getOrDefault(product.getId(), Collections.emptyList()));
product.setSuppliers(supplierMap.getOrDefault(product.getId(), Collections.emptyList()));
product.setDefaultSupplierId(defaultSupplierMap.get(product.getId()));
product.setStockCount(stockCountMap.getOrDefault(product.getId(), BigDecimal.ZERO));
if (Boolean.TRUE.equals(product.getDeleted())) {
product.setName(product.getName() + "(已被删除)");
}

@ -48,6 +48,7 @@ public interface ErrorCodeConstants {
ErrorCode DEVICE_MODEL_ATTRIBUTE_NOT_EXISTS = new ErrorCode(1_003_000_005, "采集设备模型点位不存在");
ErrorCode DEVICE_MODEL_POINT_CODE_EXISTS = new ErrorCode(1_003_000_005, "采集设备采集点位编码已存在");
ErrorCode DEVICE_MODEL_ATTRIBUTE_POTIN_CODE_EXISTS = new ErrorCode(1_003_000_005, "采集设备模型点位编码已存在");
ErrorCode DEVICE_MODEL_MUST_LETTER = new ErrorCode(1_003_000_005, "必须以字母开头");
ErrorCode DEVICE_ATTRIBUTE_NOT_EXISTS = new ErrorCode(1_003_000_006, "设备属性不存在");
ErrorCode DEVICE_ATTRIBUTE_TYPE_NOT_EXISTS = new ErrorCode(1_003_000_007, "采集点分类不存在");

@ -1371,8 +1371,8 @@ public class TDengineService {
// 2. 必须以字母开头
if (!Character.isLetter(tableName.charAt(0))) {
throw exception(DEVICE_MODEL_POINT_CODE_EXISTS,
"表名必须以字母开头: " + tableName);
throw exception(DEVICE_MODEL_MUST_LETTER,
tableName);
}
// 3. 只能包含字母、数字、下划线

@ -8,6 +8,15 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode;
* report 使 1-003-000-000
*/
public interface ErrorCodeConstants {
ErrorCode CUSTOMER_NOT_EXISTS = new ErrorCode(5_0900, "客户不存在");
ErrorCode CUSTOMER_IN_POOL = new ErrorCode(5_0901, "客户【{}】放入公海失败,原因:已经是公海客户");
ErrorCode CUSTOMER_LOCKED_PUT_POOL_FAIL = new ErrorCode(5_0902, "客户【{}】放入公海失败,原因:客户已锁定");
ErrorCode CUSTOMER_LOCK_FAIL_IS_LOCK = new ErrorCode(5_0903, "锁定客户失败,它已经处于锁定状态");
ErrorCode CUSTOMER_UNLOCK_FAIL_IS_UNLOCK = new ErrorCode(5_0904, "解锁客户失败,它已经处于未锁定状态");
ErrorCode CUSTOMER_IMPORT_LIST_IS_EMPTY = new ErrorCode(5_0905, "导入客户数据不能为空");
ErrorCode CUSTOMER_CREATE_NAME_NOT_NULL = new ErrorCode(5_0906, "客户名称不能为空");
ErrorCode CUSTOMER_NAME_EXISTS = new ErrorCode(5_0907, "已存在名为【{}】的客户");
ErrorCode CUSTOMER_UPDATE_DEAL_STATUS_FAIL = new ErrorCode(5_0908, "更新客户的成交状态失败,原因:已经是该状态,无需更新");
ErrorCode MOLD_REPAIR_ID_NULL = new ErrorCode(5_0090, "维修单ID不能为空");

@ -173,8 +173,8 @@ public class DeviceLedgerController {
@GetMapping("/list")
@Operation(summary = "获得设备台账列表")
@PreAuthorize("@ss.hasPermission('mes:device-ledger:query')")
public CommonResult<List<DeviceLedgerDO>> getDeviceLedgerList() {
List<DeviceLedgerDO> deviceLedgerDOList = deviceLedgerService.getDeviceLedgerList();
public CommonResult<List<DeviceLedgerDO>> getDeviceLedgerList(@Valid DeviceLedgerPageReqVO pageReqVO) {
List<DeviceLedgerDO> deviceLedgerDOList = deviceLedgerService.getDeviceLedgerList(pageReqVO);
return success(deviceLedgerDOList);
}

@ -21,7 +21,14 @@ import org.apache.ibatis.annotations.Param;
public interface DeviceLedgerMapper extends BaseMapperX<DeviceLedgerDO> {
default PageResult<DeviceLedgerDO> selectPage(DeviceLedgerPageReqVO reqVO) {
return selectPage(reqVO, buildQueryWrapper(reqVO));
}
default List<DeviceLedgerDO> selectList(DeviceLedgerPageReqVO reqVO) {
return selectList(buildQueryWrapper(reqVO));
}
default LambdaQueryWrapperX<DeviceLedgerDO> buildQueryWrapper(DeviceLedgerPageReqVO reqVO) {
LambdaQueryWrapperX<DeviceLedgerDO> deviceLedgerDOLambdaQueryWrapperX = new LambdaQueryWrapperX<>();
if(StringUtils.isNotBlank(reqVO.getDeviceCode())&&StringUtils.isNotBlank(reqVO.getDeviceName())&&reqVO.getDeviceCode().equals(reqVO.getDeviceName())){
if(reqVO.getDeviceCode().contains("EQUIPMENT-")){
@ -74,7 +81,7 @@ public interface DeviceLedgerMapper extends BaseMapperX<DeviceLedgerDO> {
deviceLedgerDOLambdaQueryWrapperX.in(DeviceLedgerDO::getId, idList);
}
return selectPage(reqVO, deviceLedgerDOLambdaQueryWrapperX);
return deviceLedgerDOLambdaQueryWrapperX;
}
List<DeviceLedgerDO> selectListByIds(@Param("ids") Collection<Long> ids);

@ -62,6 +62,8 @@ public interface DeviceLedgerService {
List<DeviceCapacityReportRespVO> getDeviceCapacityReportList(DeviceCapacityReportPageReqVO pageReqVO);
List<DeviceLedgerDO> getDeviceLedgerList();
List<DeviceLedgerDO> getDeviceLedgerList(DeviceLedgerPageReqVO pageReqVO);
/**
* VO
*

@ -485,11 +485,38 @@ public class DeviceLedgerServiceImpl implements DeviceLedgerService {
@Override
public PageResult<DeviceLedgerDO> getDeviceLedgerPage(DeviceLedgerPageReqVO pageReqVO) {
if (!prepareDeviceLedgerQuery(pageReqVO)) {
return new PageResult<>(Collections.emptyList(), 0L);
}
List<DeviceLineDO> deviceLineList = deviceLineService.getDeviceLineList(new DeviceLineListReqVO());
Map<Long, List<DeviceLineDO>> collect = deviceLineList.stream().collect(Collectors.groupingBy(DeviceLineDO::getId));
Map<Long, DeviceLineDO> deviceLineMap = deviceLineList.stream()
.collect(Collectors.toMap(DeviceLineDO::getId, Function.identity(), (a, b) -> a));
PageResult<DeviceLedgerDO> deviceLedgerDOPageResult = deviceLedgerMapper.selectPage(pageReqVO);
for (DeviceLedgerDO deviceLedgerDO : deviceLedgerDOPageResult.getList()) {
if (deviceLedgerDO.getDeviceType()!=null){
DeviceTypeDO deviceTypeDO = deviceTypeMapper.selectById(deviceLedgerDO.getDeviceType());
deviceLedgerDO.setTypeName(deviceTypeDO.getName());
}
if(deviceLedgerDO.getDeviceLine()!=null&&CollUtil.isNotEmpty(collect.get(deviceLedgerDO.getDeviceLine().longValue()))){
deviceLedgerDO.setWorkshopName(collect.get(deviceLedgerDO.getDeviceLine().longValue()).get(0).getName());
}
fillTopCategoryInfo(deviceLedgerDO, deviceLineMap);
}
fillIotDeviceInfo(deviceLedgerDOPageResult.getList());
return deviceLedgerDOPageResult;
}
private boolean prepareDeviceLedgerQuery(DeviceLedgerPageReqVO pageReqVO) {
if (pageReqVO == null) {
return true;
}
if (pageReqVO.getDeviceLine() != null) {
Set<Integer> deviceLineIds = new LinkedHashSet<>();
collectDeviceLineIds(Long.valueOf(pageReqVO.getDeviceLine()), deviceLineIds);
if (deviceLineIds.isEmpty()) {
return new PageResult<>(Collections.emptyList(), 0L);
return false;
}
pageReqVO.setDeviceLineIds(new ArrayList<>(deviceLineIds));
}
@ -507,25 +534,13 @@ public class DeviceLedgerServiceImpl implements DeviceLedgerService {
.map(String::valueOf)
.collect(Collectors.joining(","));
pageReqVO.setIds(ids);
}
List<DeviceLineDO> deviceLineList = deviceLineService.getDeviceLineList(new DeviceLineListReqVO());
Map<Long, List<DeviceLineDO>> collect = deviceLineList.stream().collect(Collectors.groupingBy(DeviceLineDO::getId));
Map<Long, DeviceLineDO> deviceLineMap = deviceLineList.stream()
.collect(Collectors.toMap(DeviceLineDO::getId, Function.identity(), (a, b) -> a));
PageResult<DeviceLedgerDO> deviceLedgerDOPageResult = deviceLedgerMapper.selectPage(pageReqVO);
for (DeviceLedgerDO deviceLedgerDO : deviceLedgerDOPageResult.getList()) {
if (deviceLedgerDO.getDeviceType()!=null){
DeviceTypeDO deviceTypeDO = deviceTypeMapper.selectById(deviceLedgerDO.getDeviceType());
deviceLedgerDO.setTypeName(deviceTypeDO.getName());
}
if(deviceLedgerDO.getDeviceLine()!=null&&CollUtil.isNotEmpty(collect.get(deviceLedgerDO.getDeviceLine().longValue()))){
deviceLedgerDO.setWorkshopName(collect.get(deviceLedgerDO.getDeviceLine().longValue()).get(0).getName());
if (StringUtils.isBlank(ids)) {
return false;
}
fillTopCategoryInfo(deviceLedgerDO, deviceLineMap);
pageReqVO.setIds(ids);
}
fillIotDeviceInfo(deviceLedgerDOPageResult.getList());
return deviceLedgerDOPageResult;
return true;
}
private void collectDeviceLineIds(Long deviceLineId, Set<Integer> results) {
@ -715,6 +730,21 @@ public class DeviceLedgerServiceImpl implements DeviceLedgerService {
public List<DeviceLedgerDO> getDeviceLedgerList() {
List<DeviceLedgerDO> list = deviceLedgerMapper.selectList();
fillTopCategoryInfo(list);
fillIotDeviceInfo(list);
return list;
}
@Override
public List<DeviceLedgerDO> getDeviceLedgerList(DeviceLedgerPageReqVO pageReqVO) {
if (pageReqVO == null) {
return getDeviceLedgerList();
}
if (!prepareDeviceLedgerQuery(pageReqVO)) {
return Collections.emptyList();
}
List<DeviceLedgerDO> list = deviceLedgerMapper.selectList(pageReqVO);
fillTopCategoryInfo(list);
fillIotDeviceInfo(list);
return list;
}

Loading…
Cancel
Save