Merge branch 'main' of https://git.ngsk.tech/linweidong/besure_server
commit
0124acdf5c
@ -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,82 @@
|
|||||||
|
package cn.iocoder.yudao.module.erp.controller.admin.pallet;
|
||||||
|
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
|
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.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
@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(BeanUtils.toBean(pallet, ErpPalletRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/page")
|
||||||
|
@Operation(summary = "获得托盘分页")
|
||||||
|
@PreAuthorize("@ss.hasPermission('erp:pallet:query')")
|
||||||
|
public CommonResult<PageResult<ErpPalletRespVO>> getPalletPage(@Valid ErpPalletPageReqVO pageReqVO) {
|
||||||
|
PageResult<ErpPalletDO> pageResult = palletService.getPalletPage(pageReqVO);
|
||||||
|
return success(BeanUtils.toBean(pageResult, ErpPalletRespVO.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@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);
|
||||||
|
return success(convertList(list, item -> BeanUtils.toBean(item, ErpPalletRespVO.class)));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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,40 @@
|
|||||||
|
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.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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,24 @@
|
|||||||
|
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.util.List;
|
||||||
|
|
||||||
|
public interface ErpPalletService {
|
||||||
|
|
||||||
|
Long createPallet(@Valid ErpPalletSaveReqVO createReqVO);
|
||||||
|
|
||||||
|
void updatePallet(@Valid ErpPalletSaveReqVO updateReqVO);
|
||||||
|
|
||||||
|
void deletePallet(Long id);
|
||||||
|
|
||||||
|
ErpPalletDO getPallet(Long id);
|
||||||
|
|
||||||
|
PageResult<ErpPalletDO> getPalletPage(ErpPalletPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
List<ErpPalletDO> getPalletListByStatus(Integer status);
|
||||||
|
}
|
||||||
@ -0,0 +1,144 @@
|
|||||||
|
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.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.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@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);
|
||||||
|
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 PageResult<ErpPalletDO> getPalletPage(ErpPalletPageReqVO pageReqVO) {
|
||||||
|
return palletMapper.selectPage(pageReqVO);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ErpPalletDO> getPalletListByStatus(Integer status) {
|
||||||
|
return palletMapper.selectListByStatus(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue