当前位置:网站首页>商品管统——采购需求合并到采购单

商品管统——采购需求合并到采购单

2020-11-10 07:37:16 osc_y8ifc29r

一 采购简要流程

二 查询未领取的采购单

1 请求

GET /ware/purchase/unreceive/list

2 响应数据

{
    "msg": "success",
    "code": 0,
    "page": {
        "totalCount": 0,
        "pageSize": 10,
        "totalPage": 0,
        "currPage": 1,
        "list": [{
            "id": 1,
            "assigneeId": 1,
            "assigneeName": "aa",
            "phone": "123",
            "priority": 1,
            "status": 1,
            "wareId": 1,
            "amount": 22.0000,
            "createTime": "2019-12-12",
            "updateTime": "2019-12-12"
        }]
    }
}

三 合并采购需求

1 请求

POST /ware/purchase/merge

2 请求参数

{
    purchaseId: 1, //整单id
    items: [1, 2, 3, 4] //合并项集合
}

3 响应数据

{
    "msg": "success",
    "code": 0
}

四 控制器

    /**
     * 功能描述:合并采购需求
     *
     * @param mergeVo 待合并的采购单
     * @return R 返回给前端的数据
     * @author cakin
     * @date 2020/11/9
     */
    @PostMapping("/merge")
    public R merge(@RequestBody MergeVo mergeVo) {
        purchaseService.mergePurchase(mergeVo);
        return R.ok();
    }

    /**
     * 功能描述:查询未领取的采购单
     *
     * @param params 过滤条件
     * @return R 返回给前端的数据
     * @author cakin
     * @date 2020/11/9
     */
    @RequestMapping("/unreceive/list")
    public R unreceivelist(@RequestParam Map<String, Object> params) {
        PageUtils page = purchaseService.queryPageUnreceivePurchase(params);
        return R.ok().put("page", page);
    }

五 服务层

    /**
     * 功能描述:查询未领取的采购单
     *
     * @param params 过滤条件
     * @return PageUtils 分页结果
     * @author cakin
     * @date 2020/11/9
     */
    @Override
    public PageUtils queryPageUnreceivePurchase(Map<String, Object> params) {
        IPage<PurchaseEntity> page = this.page(
                new Query<PurchaseEntity>().getPage(params),
                // 0-刚新建 1-刚分配
                new QueryWrapper<PurchaseEntity>().eq("status", 0).or().eq("status", 1)
        );
        return new PageUtils(page);
    }

    /**
     * 功能描述:合并采购需求
     *
     * @param mergeVo 待合并的采购单
     * @author cakin
     * @date 2020/11/9
     */
    @Transactional
    @Override
    public void mergePurchase(MergeVo mergeVo) {
        Long purchaseId = mergeVo.getPurchaseId();
        if (purchaseId == null) {
            // 新建一个采购单
            PurchaseEntity purchaseEntity = new PurchaseEntity();
            // 采购单初始化
            purchaseEntity.setStatus(WareConstant.PurchaseStatusEnum.CREATED.getCode());
            purchaseEntity.setCreateTime(new Date());
            purchaseEntity.setUpdateTime(new Date());
            this.save(purchaseEntity);
            purchaseId = purchaseEntity.getId();
        }
        // TODO 确认采购单状态是0,1才可以合并
        List<Long> items = mergeVo.getItems();
        Long finalPurchaseId = purchaseId;
        List<PurchaseDetailEntity> collect = items.stream().map(i -> {
            PurchaseDetailEntity detailEntity = new PurchaseDetailEntity();
            detailEntity.setId(i);
            detailEntity.setPurchaseId(finalPurchaseId);
            detailEntity.setStatus(WareConstant.PurchaseDetailStatusEnum.ASSIGNED.getCode());
            return detailEntity;
        }).collect(Collectors.toList());
        // 更新采购需求
        detailService.updateBatchById(collect);
        // 更新采购单的时间字段
        PurchaseEntity purchaseEntity = new PurchaseEntity();
        purchaseEntity.setId(purchaseId);
        purchaseEntity.setUpdateTime(new Date());
        this.updateById(purchaseEntity);
    }

六 VO

/**
 * @className: MergeVo
 * @description: 采购单
 * @date: 2020/11/9
 * @author: cakin
 */
@Data
public class MergeVo {
    /**
     * 整单id
     */
    private Long purchaseId;
    /**
     * 合并项集合
     */
    private List<Long> items;
}

七 枚举类

/**
 * @className: WareConstant
 * @description: 仓库枚举类
 * @date: 2020/11/9
 * @author: cakin
 */
public class WareConstant {
    /**
     * @className: PurchaseStatusEnum
     * @description: 采购单状态枚举
     * @date: 2020/11/9
     * @author: cakin
     */
    public enum PurchaseStatusEnum {
        CREATED(0, "新建"), ASSIGNED(1, "已分配"),
        RECEIVE(2, "已领取"), FINISH(3, "已完成"),
        HASERROR(4, "有异常");
        private int code;
        private String msg;
        PurchaseStatusEnum(int code, String msg) {
            this.code = code;
            this.msg = msg;
        }
        public int getCode() {
            return code;
        }
        public String getMsg() {
            return msg;
        }
    }

    /**
     * @className: PurchaseDetailStatusEnum
     * @description: 采购需求枚举
     * @date: 2020/11/9
     * @author: cakin
     */
    public enum PurchaseDetailStatusEnum {
        CREATED(0, "新建"), ASSIGNED(1, "已分配"),
        BUYING(2, "正在采购"), FINISH(3, "已完成"),
        HASERROR(4, "采购失败");
        private int code;
        private String msg;
        PurchaseDetailStatusEnum(int code, String msg) {
            this.code = code;
            this.msg = msg;
        }
        public int getCode() {
            return code;
        }
        public String getMsg() {
            return msg;
        }
    }
}

八 测试

 

版权声明
本文为[osc_y8ifc29r]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4313107/blog/4710449