Merge remote-tracking branch 'origin/main'
commit
add1d2e6fa
@ -0,0 +1,26 @@
|
||||
package cn.iocoder.yudao.module.erp.enums.stock;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
public enum ErpStockCheckSourceTypeEnum implements IntArrayValuable {
|
||||
|
||||
BY_LOCATION(1, "按库存"),
|
||||
BY_PRODUCT(2, "按产品");
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ErpStockCheckSourceTypeEnum::getType).toArray();
|
||||
|
||||
private final Integer type;
|
||||
private final String name;
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
package cn.iocoder.yudao.module.erp.enums.stock;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ErpStockOutModeEnum implements IntArrayValuable {
|
||||
|
||||
BY_PALLET(1, "按托出库"),
|
||||
SPLIT_PALLET(2, "拆托出库");
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ErpStockOutModeEnum::getMode).toArray();
|
||||
|
||||
private final Integer mode;
|
||||
private final String name;
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,141 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.pallet;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
import cn.iocoder.yudao.module.common.enums.QrcodeBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.common.service.qrcordrecord.QrcodeRecordService;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.pallet.vo.ErpPalletPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.pallet.vo.ErpPalletRespVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.pallet.vo.ErpPalletSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.pallet.ErpPalletDO;
|
||||
import cn.iocoder.yudao.module.erp.service.pallet.ErpPalletService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.EXPORT;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
|
||||
@Tag(name = "管理后台 - ERP 托盘")
|
||||
@RestController
|
||||
@RequestMapping("/erp/pallet")
|
||||
@Validated
|
||||
public class ErpPalletController {
|
||||
|
||||
@Resource
|
||||
private ErpPalletService palletService;
|
||||
@Resource
|
||||
private QrcodeRecordService qrcodeService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建托盘")
|
||||
@PreAuthorize("@ss.hasPermission('erp:pallet:create')")
|
||||
public CommonResult<Long> createPallet(@Valid @RequestBody ErpPalletSaveReqVO createReqVO) {
|
||||
return success(palletService.createPallet(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新托盘")
|
||||
@PreAuthorize("@ss.hasPermission('erp:pallet:update')")
|
||||
public CommonResult<Boolean> updatePallet(@Valid @RequestBody ErpPalletSaveReqVO updateReqVO) {
|
||||
palletService.updatePallet(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除托盘")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('erp:pallet:delete')")
|
||||
public CommonResult<Boolean> deletePallet(@RequestParam("id") Long id) {
|
||||
palletService.deletePallet(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得托盘")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1")
|
||||
@PreAuthorize("@ss.hasPermission('erp:pallet:query')")
|
||||
public CommonResult<ErpPalletRespVO> getPallet(@RequestParam("id") Long id) {
|
||||
ErpPalletDO pallet = palletService.getPallet(id);
|
||||
return success(buildPalletRespVO(pallet));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得托盘分页")
|
||||
@PreAuthorize("@ss.hasPermission('erp:pallet:query')")
|
||||
public CommonResult<PageResult<ErpPalletRespVO>> getPalletPage(@Valid ErpPalletPageReqVO pageReqVO) {
|
||||
PageResult<ErpPalletDO> pageResult = palletService.getPalletPage(pageReqVO);
|
||||
Map<Long, String> qrcodeMap = qrcodeService.selectQrcodeUrlMapByBizTypeAndIds(QrcodeBizTypeEnum.PALLET.getCode(),
|
||||
convertList(pageResult.getList(), ErpPalletDO::getId));
|
||||
List<ErpPalletRespVO> list = convertList(pageResult.getList(), pallet -> buildPalletRespVO(pallet, qrcodeMap));
|
||||
return success(new PageResult<>(list, pageResult.getTotal()));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出托盘 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('erp:pallet:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportPalletExcel(@Valid ErpPalletPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
PageResult<ErpPalletDO> pageResult = palletService.getPalletPage(pageReqVO);
|
||||
Map<Long, String> qrcodeMap = qrcodeService.selectQrcodeUrlMapByBizTypeAndIds(QrcodeBizTypeEnum.PALLET.getCode(),
|
||||
convertList(pageResult.getList(), ErpPalletDO::getId));
|
||||
List<ErpPalletRespVO> list = convertList(pageResult.getList(), pallet -> buildPalletRespVO(pallet, qrcodeMap));
|
||||
ExcelUtils.write(response, "托盘.xls", "数据", ErpPalletRespVO.class, list);
|
||||
}
|
||||
|
||||
@GetMapping("/simple-list")
|
||||
@Operation(summary = "获得托盘精简列表")
|
||||
@Parameter(name = "status", description = "托盘状态", example = "1")
|
||||
public CommonResult<List<ErpPalletRespVO>> getPalletSimpleList(@RequestParam(value = "status", required = false) Integer status) {
|
||||
List<ErpPalletDO> list = palletService.getPalletListByStatus(status);
|
||||
Map<Long, String> qrcodeMap = qrcodeService.selectQrcodeUrlMapByBizTypeAndIds(QrcodeBizTypeEnum.PALLET.getCode(),
|
||||
convertList(list, ErpPalletDO::getId));
|
||||
return success(convertList(list, item -> buildPalletRespVO(item, qrcodeMap)));
|
||||
}
|
||||
|
||||
@PostMapping("/regenerate-code")
|
||||
public CommonResult<Boolean> regenerateCode(@RequestParam("id") Long id,
|
||||
@RequestParam("code") String code) throws UnsupportedEncodingException {
|
||||
palletService.regenerateCode(id, code);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
private ErpPalletRespVO buildPalletRespVO(ErpPalletDO pallet) {
|
||||
if (pallet == null) {
|
||||
return null;
|
||||
}
|
||||
ErpPalletRespVO respVO = BeanUtils.toBean(pallet, ErpPalletRespVO.class);
|
||||
String qrcode = qrcodeService.selectQrcodeUrlByIdAndCode(QrcodeBizTypeEnum.PALLET.getCode(), pallet.getId(), pallet.getCode());
|
||||
if (qrcode != null) {
|
||||
respVO.setQrcode(qrcode);
|
||||
}
|
||||
return respVO;
|
||||
}
|
||||
|
||||
private ErpPalletRespVO buildPalletRespVO(ErpPalletDO pallet, Map<Long, String> qrcodeMap) {
|
||||
ErpPalletRespVO respVO = BeanUtils.toBean(pallet, ErpPalletRespVO.class);
|
||||
String qrcode = qrcodeMap.get(pallet.getId());
|
||||
if (qrcode != null) {
|
||||
respVO.setQrcode(qrcode);
|
||||
}
|
||||
return respVO;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.pallet.enums;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ErpPalletStatusEnum implements IntArrayValuable {
|
||||
|
||||
IDLE(1, "空闲"),
|
||||
OCCUPIED(2, "占用"),
|
||||
SCRAPPED(3, "报废");
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ErpPalletStatusEnum::getStatus).toArray();
|
||||
|
||||
private final Integer status;
|
||||
private final String name;
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,26 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.pallet.enums;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ErpPalletTypeEnum implements IntArrayValuable {
|
||||
|
||||
PLASTIC(1, "塑料"),
|
||||
STEEL(2, "钢质"),
|
||||
WOOD(3, "木托盘");
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ErpPalletTypeEnum::getType).toArray();
|
||||
|
||||
private final Integer type;
|
||||
private final String name;
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,59 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.pallet.vo;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.validation.InEnum;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.pallet.enums.ErpPalletStatusEnum;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.pallet.enums.ErpPalletTypeEnum;
|
||||
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.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY;
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - ERP 托盘分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ErpPalletPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "托盘编码", example = "TP202506100001")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "托盘类型", example = "1")
|
||||
@InEnum(ErpPalletTypeEnum.class)
|
||||
private Integer palletType;
|
||||
|
||||
@Schema(description = "托盘状态", example = "1")
|
||||
@InEnum(ErpPalletStatusEnum.class)
|
||||
private Integer status;
|
||||
|
||||
@Schema(description = "仓库编号", example = "1")
|
||||
private Long warehouseId;
|
||||
|
||||
@Schema(description = "库区编号", example = "11")
|
||||
private Long areaId;
|
||||
|
||||
@Schema(description = "生产任务单号", example = "PLAN20250610001")
|
||||
private String planCode;
|
||||
|
||||
@Schema(description = "产品编号", example = "1001")
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "采购日期")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY)
|
||||
private LocalDate[] purchaseDate;
|
||||
|
||||
@Schema(description = "投入使用日期")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY)
|
||||
private LocalDate[] useDate;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private LocalDateTime[] createTime;
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.stock.enums;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.core.IntArrayValuable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ErpWarehouseCategoryEnum implements IntArrayValuable {
|
||||
|
||||
PRODUCT(1, "产品"),
|
||||
MATERIAL(2, "物料"),
|
||||
SPARE_PART(3, "备件"),
|
||||
OTHER(4, "其他");
|
||||
|
||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ErpWarehouseCategoryEnum::getCategory).toArray();
|
||||
|
||||
private final Integer category;
|
||||
private final String name;
|
||||
|
||||
@Override
|
||||
public int[] array() {
|
||||
return ARRAYS;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
package cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@Schema(description = "管理后台 - ERP 仓库总览 Response VO")
|
||||
@Data
|
||||
public class ErpWarehouseSummaryRespVO {
|
||||
|
||||
@Schema(description = "仓库编号", example = "1")
|
||||
private Long warehouseId;
|
||||
|
||||
@Schema(description = "仓库名称", example = "A仓")
|
||||
private String warehouseName;
|
||||
|
||||
@Schema(description = "产品库存量", example = "1000")
|
||||
private BigDecimal productStockCount;
|
||||
|
||||
@Schema(description = "产品库存展示", example = "2托3包4个")
|
||||
private String productStockDisplay;
|
||||
|
||||
@Schema(description = "物料库存量", example = "1000")
|
||||
private BigDecimal materialStockCount;
|
||||
|
||||
@Schema(description = "物料库存展示", example = "10采购单位20库存单位")
|
||||
private String materialStockDisplay;
|
||||
|
||||
@Schema(description = "备件库存量", example = "1000")
|
||||
private BigDecimal sparePartStockCount;
|
||||
|
||||
@Schema(description = "备件库存展示", example = "10采购单位20库存单位")
|
||||
private String sparePartStockDisplay;
|
||||
|
||||
@Schema(description = "今日入库单数量", example = "5")
|
||||
private Long todayStockInOrderCount;
|
||||
|
||||
@Schema(description = "今日入库明细行数量", example = "18")
|
||||
private Long todayStockInItemCount;
|
||||
|
||||
@Schema(description = "今日入库产成品展示", example = "2托3包4个")
|
||||
private String todayProductStockInDisplay;
|
||||
|
||||
@Schema(description = "今日入库物料展示", example = "100个")
|
||||
private String todayMaterialStockInDisplay;
|
||||
|
||||
@Schema(description = "今日入库备件展示", example = "100个")
|
||||
private String todaySparePartStockInDisplay;
|
||||
|
||||
@Schema(description = "今日出库单数量", example = "3")
|
||||
private Long todayStockOutOrderCount;
|
||||
|
||||
@Schema(description = "今日出库明细行数量", example = "10")
|
||||
private Long todayStockOutItemCount;
|
||||
|
||||
@Schema(description = "今日出库产成品展示", example = "2托3包4个")
|
||||
private String todayProductStockOutDisplay;
|
||||
|
||||
@Schema(description = "今日出库物料展示", example = "100个")
|
||||
private String todayMaterialStockOutDisplay;
|
||||
|
||||
@Schema(description = "今日出库备件展示", example = "100个")
|
||||
private String todaySparePartStockOutDisplay;
|
||||
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.dataobject.pallet;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
|
||||
@TableName("erp_pallet")
|
||||
@KeySequence("erp_pallet_seq")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ErpPalletDO extends BaseDO {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
private String code;
|
||||
private Integer palletType;
|
||||
private String specification;
|
||||
private BigDecimal ratedLoadWeight;
|
||||
private String unit;
|
||||
private Integer status;
|
||||
private Long warehouseId;
|
||||
private Long areaId;
|
||||
private String planCode;
|
||||
private Long productId;
|
||||
private BigDecimal productCount;
|
||||
private String qrcode;
|
||||
private LocalDate purchaseDate;
|
||||
private LocalDate useDate;
|
||||
private String remark;
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.dataobject.stock;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@TableName("erp_stock_in_item_pallet")
|
||||
@KeySequence("erp_stock_in_item_pallet_seq")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ErpStockInItemPalletDO extends BaseDO {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
private Long inId;
|
||||
private Long inItemId;
|
||||
private Long palletId;
|
||||
private BigDecimal packageCount;
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.dataobject.stock;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
import com.baomidou.mybatisplus.annotation.KeySequence;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@TableName("erp_stock_out_item_pallet")
|
||||
@KeySequence("erp_stock_out_item_pallet_seq")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ErpStockOutItemPalletDO extends BaseDO {
|
||||
|
||||
@TableId
|
||||
private Long id;
|
||||
private Long outId;
|
||||
private Long outItemId;
|
||||
private Long palletId;
|
||||
private BigDecimal packageCount;
|
||||
}
|
||||
@ -0,0 +1,52 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.mysql.pallet;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.pallet.vo.ErpPalletPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.pallet.ErpPalletDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ErpPalletMapper extends BaseMapperX<ErpPalletDO> {
|
||||
|
||||
default PageResult<ErpPalletDO> selectPage(ErpPalletPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<ErpPalletDO>()
|
||||
.likeIfPresent(ErpPalletDO::getCode, reqVO.getCode())
|
||||
.eqIfPresent(ErpPalletDO::getPalletType, reqVO.getPalletType())
|
||||
.eqIfPresent(ErpPalletDO::getStatus, reqVO.getStatus())
|
||||
.eqIfPresent(ErpPalletDO::getWarehouseId, reqVO.getWarehouseId())
|
||||
.eqIfPresent(ErpPalletDO::getAreaId, reqVO.getAreaId())
|
||||
.likeIfPresent(ErpPalletDO::getPlanCode, reqVO.getPlanCode())
|
||||
.eqIfPresent(ErpPalletDO::getProductId, reqVO.getProductId())
|
||||
.betweenIfPresent(ErpPalletDO::getPurchaseDate, reqVO.getPurchaseDate())
|
||||
.betweenIfPresent(ErpPalletDO::getUseDate, reqVO.getUseDate())
|
||||
.betweenIfPresent(ErpPalletDO::getCreateTime, reqVO.getCreateTime())
|
||||
.orderByDesc(ErpPalletDO::getId));
|
||||
}
|
||||
|
||||
default ErpPalletDO selectByCode(String code) {
|
||||
return selectOne(ErpPalletDO::getCode, code);
|
||||
}
|
||||
|
||||
default List<ErpPalletDO> selectListByStatus(Integer status) {
|
||||
if (status == null) {
|
||||
return selectList();
|
||||
}
|
||||
return selectList(ErpPalletDO::getStatus, status);
|
||||
}
|
||||
|
||||
default List<ErpPalletDO> selectOccupiedList(Collection<Long> productIds, Collection<Long> warehouseIds,
|
||||
Collection<Long> areaIds) {
|
||||
boolean containsNullArea = areaIds != null && areaIds.stream().anyMatch(java.util.Objects::isNull);
|
||||
return selectList(new LambdaQueryWrapperX<ErpPalletDO>()
|
||||
.inIfPresent(ErpPalletDO::getProductId, productIds)
|
||||
.inIfPresent(ErpPalletDO::getWarehouseId, warehouseIds)
|
||||
.inIfPresent(ErpPalletDO::getAreaId, containsNullArea ? null : areaIds)
|
||||
.gt(ErpPalletDO::getProductCount, BigDecimal.ZERO));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.mysql.stock;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemPalletDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ErpStockInItemPalletMapper extends BaseMapperX<ErpStockInItemPalletDO> {
|
||||
|
||||
default List<ErpStockInItemPalletDO> selectListByInId(Long inId) {
|
||||
return selectList(ErpStockInItemPalletDO::getInId, inId);
|
||||
}
|
||||
|
||||
default List<ErpStockInItemPalletDO> selectListByInIds(Collection<Long> inIds) {
|
||||
return selectList(ErpStockInItemPalletDO::getInId, inIds);
|
||||
}
|
||||
|
||||
default int deleteByInId(Long inId) {
|
||||
return delete(ErpStockInItemPalletDO::getInId, inId);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package cn.iocoder.yudao.module.erp.dal.mysql.stock;
|
||||
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemPalletDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ErpStockOutItemPalletMapper extends BaseMapperX<ErpStockOutItemPalletDO> {
|
||||
|
||||
default List<ErpStockOutItemPalletDO> selectListByOutId(Long outId) {
|
||||
return selectList(ErpStockOutItemPalletDO::getOutId, outId);
|
||||
}
|
||||
|
||||
default List<ErpStockOutItemPalletDO> selectListByOutIds(Collection<Long> outIds) {
|
||||
return selectList(ErpStockOutItemPalletDO::getOutId, outIds);
|
||||
}
|
||||
|
||||
default int deleteByOutId(Long outId) {
|
||||
return delete(ErpStockOutItemPalletDO::getOutId, outId);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
package cn.iocoder.yudao.module.erp.handler;
|
||||
|
||||
import cn.iocoder.yudao.module.common.enums.QrcodeBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.common.handler.QrcodeBizHandler;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.pallet.ErpPalletMapper;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Component
|
||||
public class PalletQrcodeBizHandler implements QrcodeBizHandler {
|
||||
|
||||
@Resource
|
||||
private ErpPalletMapper palletMapper;
|
||||
|
||||
@Override
|
||||
public String getBizType() {
|
||||
return QrcodeBizTypeEnum.PALLET.getCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exists(Long id) {
|
||||
return palletMapper.selectById(id) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildDeepLink(Long id) {
|
||||
return "https://www.baidu.com";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String buildH5Path(Long id) {
|
||||
return "https://baike.baidu.com/item/%E6%98%9F%E5%BA%A7/8072715?fr=aladdin";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
package cn.iocoder.yudao.module.erp.service.pallet;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.pallet.vo.ErpPalletPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.pallet.vo.ErpPalletSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.pallet.ErpPalletDO;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface ErpPalletService {
|
||||
|
||||
Long createPallet(@Valid ErpPalletSaveReqVO createReqVO);
|
||||
|
||||
void updatePallet(@Valid ErpPalletSaveReqVO updateReqVO);
|
||||
|
||||
void deletePallet(Long id);
|
||||
|
||||
ErpPalletDO getPallet(Long id);
|
||||
|
||||
List<ErpPalletDO> getPalletList(Collection<Long> ids);
|
||||
|
||||
Map<Long, ErpPalletDO> getPalletMap(Collection<Long> ids);
|
||||
|
||||
PageResult<ErpPalletDO> getPalletPage(ErpPalletPageReqVO pageReqVO);
|
||||
|
||||
List<ErpPalletDO> getPalletListByStatus(Integer status);
|
||||
|
||||
List<ErpPalletDO> getOccupiedPalletList(Collection<Long> productIds, Collection<Long> warehouseIds, Collection<Long> areaIds);
|
||||
|
||||
void regenerateCode(Long id, String code) throws UnsupportedEncodingException;
|
||||
}
|
||||
@ -0,0 +1,205 @@
|
||||
package cn.iocoder.yudao.module.erp.service.pallet;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.common.enums.CodeTypeEnum;
|
||||
import cn.iocoder.yudao.module.common.enums.QrcodeBizTypeEnum;
|
||||
import cn.iocoder.yudao.module.common.service.qrcordrecord.QrcodeRecordService;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.autocode.util.AutoCodeUtil;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.pallet.vo.ErpPalletPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.pallet.vo.ErpPalletSaveReqVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.pallet.ErpPalletDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.warehousearea.WarehouseAreaDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.pallet.ErpPalletMapper;
|
||||
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
|
||||
import cn.iocoder.yudao.module.erp.service.stock.ErpWarehouseService;
|
||||
import cn.iocoder.yudao.module.erp.service.warehousearea.WarehouseAreaService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap;
|
||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.PALLET_CODE_EMPTY;
|
||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.PALLET_CODE_EXISTS;
|
||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.PALLET_NOT_EXISTS;
|
||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.PRODUCT_NOT_EXISTS;
|
||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.WAREHOUSE_AREA_NOT_EXISTS;
|
||||
import static cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.WAREHOUSE_LOCATION_WAREHOUSE_AREA_NOT_MATCH;
|
||||
|
||||
@Service
|
||||
@Validated
|
||||
public class ErpPalletServiceImpl implements ErpPalletService {
|
||||
|
||||
@Resource
|
||||
private ErpPalletMapper palletMapper;
|
||||
@Resource
|
||||
private AutoCodeUtil autoCodeUtil;
|
||||
@Resource
|
||||
private ErpWarehouseService warehouseService;
|
||||
@Resource
|
||||
private WarehouseAreaService warehouseAreaService;
|
||||
@Resource
|
||||
private ErpProductService productService;
|
||||
@Resource
|
||||
private QrcodeRecordService qrcodeService;
|
||||
|
||||
@Override
|
||||
public Long createPallet(ErpPalletSaveReqVO createReqVO) {
|
||||
validateWarehouseAreaMatch(createReqVO.getWarehouseId(), createReqVO.getAreaId());
|
||||
validateProductExists(createReqVO.getProductId());
|
||||
ErpPalletDO pallet = BeanUtils.toBean(createReqVO, ErpPalletDO.class);
|
||||
if (StringUtils.isBlank(pallet.getCode())) {
|
||||
pallet.setCode(autoCodeUtil.genSerialCode("PALLET_CODE_GENERATE", null));
|
||||
} else {
|
||||
validateCodeUnique(null, pallet.getCode());
|
||||
}
|
||||
if (StringUtils.isBlank(pallet.getQrcode())) {
|
||||
pallet.setQrcode(pallet.getCode());
|
||||
}
|
||||
palletMapper.insert(pallet);
|
||||
generatePalletQrcode(pallet.getId(), pallet.getCode());
|
||||
return pallet.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updatePallet(ErpPalletSaveReqVO updateReqVO) {
|
||||
ErpPalletDO pallet = validatePalletExists(updateReqVO.getId());
|
||||
validateWarehouseAreaMatch(updateReqVO.getWarehouseId(), updateReqVO.getAreaId());
|
||||
validateProductExists(updateReqVO.getProductId());
|
||||
ErpPalletDO updateObj = BeanUtils.toBean(updateReqVO, ErpPalletDO.class);
|
||||
if (StringUtils.isBlank(updateObj.getCode())) {
|
||||
updateObj.setCode(pallet.getCode());
|
||||
} else {
|
||||
validateCodeUnique(updateObj.getId(), updateObj.getCode());
|
||||
}
|
||||
if (StringUtils.isBlank(updateObj.getQrcode())) {
|
||||
updateObj.setQrcode(updateObj.getCode());
|
||||
}
|
||||
palletMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deletePallet(Long id) {
|
||||
validatePalletExists(id);
|
||||
palletMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ErpPalletDO getPallet(Long id) {
|
||||
return palletMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ErpPalletDO> getPalletList(Collection<Long> ids) {
|
||||
return ids == null || ids.isEmpty() ? Collections.emptyList() : palletMapper.selectBatchIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Long, ErpPalletDO> getPalletMap(Collection<Long> ids) {
|
||||
return convertMap(getPalletList(ids), ErpPalletDO::getId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ErpPalletDO> getPalletPage(ErpPalletPageReqVO pageReqVO) {
|
||||
return palletMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ErpPalletDO> getPalletListByStatus(Integer status) {
|
||||
return palletMapper.selectListByStatus(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ErpPalletDO> getOccupiedPalletList(Collection<Long> productIds, Collection<Long> warehouseIds,
|
||||
Collection<Long> areaIds) {
|
||||
return palletMapper.selectOccupiedList(productIds, warehouseIds, areaIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void regenerateCode(Long id, String code) throws UnsupportedEncodingException {
|
||||
validatePalletExists(id);
|
||||
if (StringUtils.isBlank(code)) {
|
||||
throw exception(PALLET_CODE_EMPTY);
|
||||
}
|
||||
CodeTypeEnum codeType = autoCodeUtil.queryCodeType("PALLET_CODE_GENERATE");
|
||||
qrcodeService.regenerateByCodeType(
|
||||
QrcodeBizTypeEnum.PALLET,
|
||||
id,
|
||||
code,
|
||||
"DETAIL",
|
||||
codeType.getCode()
|
||||
);
|
||||
}
|
||||
|
||||
private ErpPalletDO validatePalletExists(Long id) {
|
||||
ErpPalletDO pallet = palletMapper.selectById(id);
|
||||
if (pallet == null) {
|
||||
throw exception(PALLET_NOT_EXISTS);
|
||||
}
|
||||
return pallet;
|
||||
}
|
||||
|
||||
private void validateCodeUnique(Long id, String code) {
|
||||
ErpPalletDO pallet = palletMapper.selectByCode(code);
|
||||
if (pallet == null) {
|
||||
return;
|
||||
}
|
||||
if (id == null || !pallet.getId().equals(id)) {
|
||||
throw exception(PALLET_CODE_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateWarehouseAreaMatch(Long warehouseId, Long areaId) {
|
||||
if (warehouseId == null && areaId == null) {
|
||||
return;
|
||||
}
|
||||
if (warehouseId != null && warehouseService.validWarehouseList(Collections.singleton(warehouseId)).isEmpty()) {
|
||||
throw exception(cn.iocoder.yudao.module.erp.enums.ErrorCodeConstants.WAREHOUSE_NOT_EXISTS);
|
||||
}
|
||||
if (areaId == null) {
|
||||
return;
|
||||
}
|
||||
WarehouseAreaDO area = warehouseAreaService.getWarehouseArea(areaId);
|
||||
if (area == null) {
|
||||
throw exception(WAREHOUSE_AREA_NOT_EXISTS);
|
||||
}
|
||||
if (warehouseId == null || !warehouseId.equals(area.getWarehouseId())) {
|
||||
throw exception(WAREHOUSE_LOCATION_WAREHOUSE_AREA_NOT_MATCH);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateProductExists(Long productId) {
|
||||
if (productId == null) {
|
||||
return;
|
||||
}
|
||||
if (productService.validProductList(Collections.singleton(productId)).isEmpty()) {
|
||||
throw exception(PRODUCT_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void generatePalletQrcode(Long id, String code) {
|
||||
CodeTypeEnum codeType = autoCodeUtil.queryCodeType("PALLET_CODE_GENERATE");
|
||||
if (codeType == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
qrcodeService.generateOrRefresh(
|
||||
QrcodeBizTypeEnum.PALLET,
|
||||
id,
|
||||
code,
|
||||
"DETAIL",
|
||||
codeType
|
||||
);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
package cn.iocoder.yudao.module.erp.service.stock;
|
||||
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWarehouseSummaryRespVO;
|
||||
|
||||
public interface ErpWarehouseSummaryService {
|
||||
|
||||
ErpWarehouseSummaryRespVO getWarehouseSummary(Long warehouseId);
|
||||
|
||||
}
|
||||
@ -0,0 +1,261 @@
|
||||
package cn.iocoder.yudao.module.erp.service.stock;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ErpProductRespVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.warehouse.ErpWarehouseSummaryRespVO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.product.ErpProductDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockInItemDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpStockOutItemDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.dataobject.stock.ErpWarehouseDO;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInItemMapper;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockInMapper;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockMapper;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockOutItemMapper;
|
||||
import cn.iocoder.yudao.module.erp.dal.mysql.stock.ErpStockOutMapper;
|
||||
import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Validated
|
||||
public class ErpWarehouseSummaryServiceImpl implements ErpWarehouseSummaryService {
|
||||
|
||||
@Resource
|
||||
private ErpWarehouseService warehouseService;
|
||||
@Resource
|
||||
private ErpStockMapper stockMapper;
|
||||
@Resource
|
||||
private ErpStockInMapper stockInMapper;
|
||||
@Resource
|
||||
private ErpStockInItemMapper stockInItemMapper;
|
||||
@Resource
|
||||
private ErpStockOutMapper stockOutMapper;
|
||||
@Resource
|
||||
private ErpStockOutItemMapper stockOutItemMapper;
|
||||
@Resource
|
||||
private ErpProductService productService;
|
||||
|
||||
@Override
|
||||
public ErpWarehouseSummaryRespVO getWarehouseSummary(Long warehouseId) {
|
||||
ErpWarehouseDO warehouse = warehouseService.getWarehouse(warehouseId);
|
||||
ErpWarehouseSummaryRespVO respVO = new ErpWarehouseSummaryRespVO();
|
||||
respVO.setWarehouseId(warehouseId);
|
||||
respVO.setWarehouseName(warehouse != null ? warehouse.getName() : null);
|
||||
|
||||
List<ErpStockDO> stockList = stockMapper.selectListByWarehouseIdsAndAreaIds(Collections.singletonList(warehouseId), null);
|
||||
fillStockSummary(respVO, stockList);
|
||||
|
||||
LocalDateTime beginTime = LocalDate.now().atStartOfDay();
|
||||
LocalDateTime endTime = beginTime.plusDays(1);
|
||||
fillTodayInSummary(respVO, warehouseId, beginTime, endTime);
|
||||
fillTodayOutSummary(respVO, warehouseId, beginTime, endTime);
|
||||
return respVO;
|
||||
}
|
||||
|
||||
private void fillStockSummary(ErpWarehouseSummaryRespVO respVO, List<ErpStockDO> stockList) {
|
||||
if (CollUtil.isEmpty(stockList)) {
|
||||
respVO.setProductStockCount(BigDecimal.ZERO);
|
||||
respVO.setMaterialStockCount(BigDecimal.ZERO);
|
||||
respVO.setSparePartStockCount(BigDecimal.ZERO);
|
||||
respVO.setProductStockDisplay(formatProductDisplay(BigDecimal.ZERO, null, null, null));
|
||||
respVO.setMaterialStockDisplay(formatUnitDisplay(BigDecimal.ZERO, null, null, null));
|
||||
respVO.setSparePartStockDisplay(formatUnitDisplay(BigDecimal.ZERO, null, null, null));
|
||||
return;
|
||||
}
|
||||
|
||||
Map<Integer, List<ErpStockDO>> categoryMap = stockList.stream().collect(Collectors.groupingBy(this::resolveCategoryType));
|
||||
BigDecimal productCount = sumCount(categoryMap.get(1));
|
||||
BigDecimal materialCount = sumCount(categoryMap.get(2));
|
||||
BigDecimal sparePartCount = sumCount(categoryMap.get(3));
|
||||
|
||||
respVO.setProductStockCount(productCount);
|
||||
respVO.setMaterialStockCount(materialCount);
|
||||
respVO.setSparePartStockCount(sparePartCount);
|
||||
|
||||
ErpStockDO productStock = firstStock(categoryMap.get(1));
|
||||
ErpStockDO materialStock = firstStock(categoryMap.get(2));
|
||||
ErpStockDO sparePartStock = firstStock(categoryMap.get(3));
|
||||
respVO.setProductStockDisplay(formatProductDisplay(productCount,
|
||||
productStock != null ? productStock.getPalletTotalQuantity() : null,
|
||||
productStock != null ? productStock.getPalletPackageQuantity() : null,
|
||||
productStock != null ? productStock.getPackageQuantity() : null));
|
||||
respVO.setMaterialStockDisplay(formatUnitDisplay(materialCount,
|
||||
materialStock != null ? materialStock.getPurchaseUnitConvertQuantity() : null,
|
||||
materialStock != null ? materialStock.getPurchaseUnitName() : null,
|
||||
materialStock != null ? materialStock.getUnitName() : null));
|
||||
respVO.setSparePartStockDisplay(formatUnitDisplay(sparePartCount,
|
||||
sparePartStock != null ? sparePartStock.getPurchaseUnitConvertQuantity() : null,
|
||||
sparePartStock != null ? sparePartStock.getPurchaseUnitName() : null,
|
||||
sparePartStock != null ? sparePartStock.getUnitName() : null));
|
||||
}
|
||||
|
||||
private void fillTodayInSummary(ErpWarehouseSummaryRespVO respVO, Long warehouseId, LocalDateTime beginTime, LocalDateTime endTime) {
|
||||
List<ErpStockInDO> stockInList = stockInMapper.selectList(new LambdaQueryWrapper<ErpStockInDO>()
|
||||
.eq(ErpStockInDO::getStatus, 20)
|
||||
.between(ErpStockInDO::getInTime, beginTime, endTime));
|
||||
List<Long> inIds = stockInList.stream()
|
||||
.filter(stockIn -> hasWarehouseIn(stockIn.getId(), warehouseId))
|
||||
.map(ErpStockInDO::getId)
|
||||
.collect(Collectors.toList());
|
||||
respVO.setTodayStockInOrderCount((long) inIds.size());
|
||||
|
||||
List<ErpStockInItemDO> itemList = stockInItemMapper.selectListByInIds(inIds);
|
||||
respVO.setTodayStockInItemCount((long) itemList.size());
|
||||
fillInOutDisplay(respVO, true, itemList);
|
||||
}
|
||||
|
||||
private void fillTodayOutSummary(ErpWarehouseSummaryRespVO respVO, Long warehouseId, LocalDateTime beginTime, LocalDateTime endTime) {
|
||||
List<ErpStockOutDO> stockOutList = stockOutMapper.selectList(new LambdaQueryWrapper<ErpStockOutDO>()
|
||||
.eq(ErpStockOutDO::getStatus, 20)
|
||||
.between(ErpStockOutDO::getOutTime, beginTime, endTime));
|
||||
List<Long> outIds = stockOutList.stream()
|
||||
.filter(stockOut -> hasWarehouseOut(stockOut.getId(), warehouseId))
|
||||
.map(ErpStockOutDO::getId)
|
||||
.collect(Collectors.toList());
|
||||
respVO.setTodayStockOutOrderCount((long) outIds.size());
|
||||
|
||||
List<ErpStockOutItemDO> itemList = stockOutItemMapper.selectListByOutIds(outIds);
|
||||
respVO.setTodayStockOutItemCount((long) itemList.size());
|
||||
fillInOutDisplay(respVO, false, itemList);
|
||||
}
|
||||
|
||||
private void fillInOutDisplay(ErpWarehouseSummaryRespVO respVO, boolean inbound, List<?> itemList) {
|
||||
if (CollUtil.isEmpty(itemList)) {
|
||||
if (inbound) {
|
||||
respVO.setTodayProductStockInDisplay(formatProductDisplay(BigDecimal.ZERO, null, null, null));
|
||||
respVO.setTodayMaterialStockInDisplay(formatUnitDisplay(BigDecimal.ZERO, null, null, null));
|
||||
respVO.setTodaySparePartStockInDisplay(formatUnitDisplay(BigDecimal.ZERO, null, null, null));
|
||||
} else {
|
||||
respVO.setTodayProductStockOutDisplay(formatProductDisplay(BigDecimal.ZERO, null, null, null));
|
||||
respVO.setTodayMaterialStockOutDisplay(formatUnitDisplay(BigDecimal.ZERO, null, null, null));
|
||||
respVO.setTodaySparePartStockOutDisplay(formatUnitDisplay(BigDecimal.ZERO, null, null, null));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
Set<Long> productIds = itemList.stream()
|
||||
.map(item -> item instanceof ErpStockInItemDO ? ((ErpStockInItemDO) item).getProductId() : ((ErpStockOutItemDO) item).getProductId())
|
||||
.collect(Collectors.toSet());
|
||||
Map<Long, ErpProductRespVO> productMap = productService.getProductVOMap(productIds);
|
||||
|
||||
BigDecimal productCount = BigDecimal.ZERO;
|
||||
BigDecimal materialCount = BigDecimal.ZERO;
|
||||
BigDecimal sparePartCount = BigDecimal.ZERO;
|
||||
|
||||
for (Object item : itemList) {
|
||||
Long productId = item instanceof ErpStockInItemDO ? ((ErpStockInItemDO) item).getProductId() : ((ErpStockOutItemDO) item).getProductId();
|
||||
BigDecimal count = item instanceof ErpStockInItemDO ? ((ErpStockInItemDO) item).getCount() : ((ErpStockOutItemDO) item).getCount();
|
||||
ErpProductRespVO product = productMap.get(productId);
|
||||
Integer categoryType = product != null ? product.getCategoryType() : null;
|
||||
if (Integer.valueOf(1).equals(categoryType)) {
|
||||
productCount = productCount.add(safeCount(count));
|
||||
} else if (Integer.valueOf(2).equals(categoryType)) {
|
||||
materialCount = materialCount.add(safeCount(count));
|
||||
} else if (Integer.valueOf(3).equals(categoryType)) {
|
||||
sparePartCount = sparePartCount.add(safeCount(count));
|
||||
}
|
||||
}
|
||||
|
||||
if (inbound) {
|
||||
respVO.setTodayProductStockInDisplay(formatProductDisplay(productCount, null, null, null));
|
||||
respVO.setTodayMaterialStockInDisplay(formatUnitDisplay(materialCount, null, null, null));
|
||||
respVO.setTodaySparePartStockInDisplay(formatUnitDisplay(sparePartCount, null, null, null));
|
||||
} else {
|
||||
respVO.setTodayProductStockOutDisplay(formatProductDisplay(productCount, null, null, null));
|
||||
respVO.setTodayMaterialStockOutDisplay(formatUnitDisplay(materialCount, null, null, null));
|
||||
respVO.setTodaySparePartStockOutDisplay(formatUnitDisplay(sparePartCount, null, null, null));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean hasWarehouseIn(Long inId, Long warehouseId) {
|
||||
return stockInItemMapper.selectListByInId(inId).stream().anyMatch(item -> warehouseId.equals(item.getWarehouseId()));
|
||||
}
|
||||
|
||||
private boolean hasWarehouseOut(Long outId, Long warehouseId) {
|
||||
return stockOutItemMapper.selectListByOutId(outId).stream().anyMatch(item -> warehouseId.equals(item.getWarehouseId()));
|
||||
}
|
||||
|
||||
private Integer resolveCategoryType(ErpStockDO stock) {
|
||||
if (stock.getCategoryType() != null) {
|
||||
return stock.getCategoryType();
|
||||
}
|
||||
ErpProductRespVO product = productService.getProductVOMap(Collections.singleton(stock.getProductId())).get(stock.getProductId());
|
||||
return product != null ? product.getCategoryType() : null;
|
||||
}
|
||||
|
||||
private ErpStockDO firstStock(List<ErpStockDO> list) {
|
||||
return CollUtil.isEmpty(list) ? null : list.get(0);
|
||||
}
|
||||
|
||||
private BigDecimal sumCount(List<ErpStockDO> list) {
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
for (ErpStockDO stock : list) {
|
||||
total = total.add(safeCount(stock.getCount()));
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
private BigDecimal safeCount(BigDecimal count) {
|
||||
return count == null ? BigDecimal.ZERO : count;
|
||||
}
|
||||
|
||||
private String formatProductDisplay(BigDecimal count, BigDecimal palletTotalQuantity, BigDecimal palletPackageQuantity,
|
||||
BigDecimal packageQuantity) {
|
||||
BigDecimal safeCount = safeCount(count);
|
||||
if (palletTotalQuantity == null || palletTotalQuantity.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
return formatNumber(safeCount) + "个";
|
||||
}
|
||||
BigDecimal palletCount = safeCount.divideToIntegralValue(palletTotalQuantity);
|
||||
BigDecimal remainAfterPallet = safeCount.remainder(palletTotalQuantity);
|
||||
if (palletPackageQuantity == null || palletPackageQuantity.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
return formatNumber(palletCount) + "托" + formatNumber(remainAfterPallet) + "个";
|
||||
}
|
||||
BigDecimal packageCount = remainAfterPallet.divideToIntegralValue(palletPackageQuantity);
|
||||
BigDecimal remainAfterPackage = remainAfterPallet.remainder(palletPackageQuantity);
|
||||
if (packageQuantity == null || packageQuantity.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
return formatNumber(palletCount) + "托" + formatNumber(packageCount) + "包" + formatNumber(remainAfterPackage) + "个";
|
||||
}
|
||||
BigDecimal unitCount = remainAfterPackage.divideToIntegralValue(packageQuantity);
|
||||
return formatNumber(palletCount) + "托" + formatNumber(packageCount) + "包" + formatNumber(unitCount) + "个";
|
||||
}
|
||||
|
||||
private String formatUnitDisplay(BigDecimal count, BigDecimal purchaseUnitConvertQuantity, String purchaseUnitName, String unitName) {
|
||||
BigDecimal safeCount = safeCount(count);
|
||||
if (purchaseUnitConvertQuantity == null || purchaseUnitConvertQuantity.compareTo(BigDecimal.ZERO) <= 0
|
||||
|| purchaseUnitName == null || unitName == null) {
|
||||
return formatNumber(safeCount) + (unitName != null ? unitName : "个");
|
||||
}
|
||||
BigDecimal purchaseCount = safeCount.divideToIntegralValue(purchaseUnitConvertQuantity);
|
||||
BigDecimal unitCount = safeCount.remainder(purchaseUnitConvertQuantity);
|
||||
StringBuilder display = new StringBuilder();
|
||||
if (purchaseCount.compareTo(BigDecimal.ZERO) > 0) {
|
||||
display.append(formatNumber(purchaseCount)).append(purchaseUnitName);
|
||||
}
|
||||
if (unitCount.compareTo(BigDecimal.ZERO) > 0 || display.length() == 0) {
|
||||
display.append(formatNumber(unitCount)).append(unitName);
|
||||
}
|
||||
return display.toString();
|
||||
}
|
||||
|
||||
private String formatNumber(BigDecimal value) {
|
||||
return value == null ? "0" : value.stripTrailingZeros().toPlainString();
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,21 @@
|
||||
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 TaskPackagingSchemeRespVO {
|
||||
|
||||
@Schema(description = "任务单 ID", example = "1")
|
||||
private Long taskId;
|
||||
|
||||
@Schema(description = "任务单名称", example = "RW20240618001")
|
||||
private String taskName;
|
||||
|
||||
@Schema(description = "产品默认包装方案列表")
|
||||
private List<TaskProductPackagingSchemeRespVO> products;
|
||||
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
package cn.iocoder.yudao.module.mes.controller.admin.task.vo;
|
||||
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.product.vo.product.ProductPackagingSchemeRespVO;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Schema(description = "管理后台 - 生产任务单产品默认包装方案 Response VO")
|
||||
@Data
|
||||
public class TaskProductPackagingSchemeRespVO {
|
||||
|
||||
@Schema(description = "产品 ID", example = "1")
|
||||
private Long productId;
|
||||
|
||||
@Schema(description = "产品编码", example = "CP001")
|
||||
private String productCode;
|
||||
|
||||
@Schema(description = "产品名称", example = "产品A")
|
||||
private String productName;
|
||||
|
||||
@Schema(description = "任务明细 ID 列表")
|
||||
private List<Long> taskDetailIds;
|
||||
|
||||
@Schema(description = "默认包装方案列表")
|
||||
private List<ProductPackagingSchemeRespVO> packagingSchemes;
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue