【大型电商项目开发】仓库管理之采购功能完成-30

【大型电商项目开发】仓库管理之采购功能完成-30,第1张

一:整合ware服务 1.将仓库服务添加到注册中心中
#数据源
spring:
  datasource:
    username: root
    password: 123456
    url: jdbc:mysql://127.0.0.1:3306/gulimail_wms?serverTimezone=GMT%2B8&characterEncoding=utf-8&useUnicode=true
    driver-class-name: com.mysql.jdbc.Driver
  cloud:
    #nacos地址
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848
    #服务的名称,用于让nacos知道那个服务正在被调用
  application:
    name: gulimail-ware
2.开启服务的注册发现功能

在主启动类添加@EnableDiscoveryClient注解

/**
 * @EnableDiscoveryClient 开启服务注册发现功能
 */
@EnableDiscoveryClient
3.打开包扫描,识别dao文件

在主启动类添加@MapperScan注解

@MapperScan("com.sysg.gulimail.ware.dao")
4.开启事务

在主启动类添加@EnableTransactionManagement注解

@EnableTransactionManagement


此时服务就跑起来了!!!

5.配置网关
spring:
  cloud:
    gateway:
      routes:
        - id: product_route
          uri: lb://gulimail-product
          predicates:
            - Path=/api/product/**
          filters:
            - RewritePath=/api/(?>.*),/$\{segment}

        - id: third_party_route
          uri: lb://gulimail-third-party
          predicates:
            - Path=/api/thirdparty/**
          filters:
            - RewritePath=/api/thirdparty/(?>.*),/$\{segment}

        - id: member_route
          uri: lb://gulimail-member
          predicates:
            - Path=/api/member/**
          filters:
            - RewritePath=/api/(?>.*),/$\{segment}

        - id: ware_route
          uri: lb://gulimail-ware
          predicates:
            - Path=/api/ware/**
          filters:
            - RewritePath=/api/(?>.*),/$\{segment}
二:获取仓库列表 1.编辑WareInfoServiceImpl的queryPage方法
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<WareInfoEntity> wrapper = new QueryWrapper<>();
        String key = (String) params.get("key");
        if(!StringUtils.isEmpty(key)){
            wrapper.eq("id",key).or().like("name",key).or().like("address",key).or().like("areacode",key);
        }
        IPage<WareInfoEntity> page = this.page(new Query<WareInfoEntity>().getPage(params), wrapper);
        return new PageUtils(page);
    }
2.添加可以查看sql语句的配置
logging:
  level: 
    com.sysg: debug
3.查看SQL语句
SELECT id,address,name,areacode FROM wms_ware_info WHERE (id = ? OR name LIKE ? OR address LIKE ? OR areacode LIKE ?)
Parameters: 1(String), %1%(String), %1%(String), %1%(String)
三:查询商品库存 1.编辑WareSkuController的list方法
   /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("ware:waresku:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = wareSkuService.queryPage(params);
        return R.ok().put("page", page);
    }
2.编辑WareSkuServiceImpl的queryPage方法
/**
     *
     * @param params
     * @return
     */
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<WareSkuEntity> wrapper = new QueryWrapper<>();
        String skuId = (String) params.get("skuId");
        if (StringUtils.isNotEmpty(skuId)){
            wrapper.eq("sku_id",skuId);
        }
        String wareId = (String) params.get("wareId");
        if (StringUtils.isNotEmpty(wareId)){
            wrapper.eq("ware_id",wareId);
        }
        IPage<WareSkuEntity> page = this.page(new Query<WareSkuEntity>().getPage(params), wrapper);
        return new PageUtils(page);
    }
3.打印执行的sql
SELECT id,sku_name,ware_id,stock_locked,stock,sku_id FROM wms_ware_sku WHERE (ware_id = 1)
四:查询采购需求

请求url:/ware/purchasedetail/list

1.编辑PurchaseDetailServiceImpl的queryPage方法
@Override
    public PageUtils queryPage(Map<String, Object> params) {
        /**
         * status: 0,//状态
         * wareId: 1,//仓库id
         */
        QueryWrapper<PurchaseDetailEntity> queryWrapper = new QueryWrapper<PurchaseDetailEntity>();
        String key = (String) params.get("key");
        if(!StringUtils.isEmpty(key)){
            //purchase_id  sku_id
            queryWrapper.and(w->{
                w.eq("purchase_id",key).or().eq("sku_id",key);
            });
        }
        String status = (String) params.get("status");
        if(!StringUtils.isEmpty(status)){
            //purchase_id  sku_id
            queryWrapper.eq("status",status);
        }
        String wareId = (String) params.get("wareId");
        if(!StringUtils.isEmpty(wareId)){
            //purchase_id  sku_id
            queryWrapper.eq("ware_id",wareId);
        }
        IPage<PurchaseDetailEntity> page = this.page(
                new Query<PurchaseDetailEntity>().getPage(params),
                queryWrapper
        );
        return new PageUtils(page);
    }
2.打印sql
SELECT id,ware_id,purchase_id,sku_price,sku_num,sku_id,status FROM wms_purchase_detail WHERE (( (purchase_id = 1 OR sku_id = 1) ) AND status = 0 AND ware_id = 1)
五.合并采购需求

1.查询未领取的采购单

GET /ware/purchase/unreceive/list

/**
     * 查询未领取的采购单
     * @param params
     * @return
             */
    @Override
    public PageUtils queryPageUnreceivePurchase(Map<String, Object> params) {
        IPage<PurchaseEntity> page = this.page(
                new Query<PurchaseEntity>().getPage(params),
                new QueryWrapper<PurchaseEntity>().eq("status",0).or().eq("status",1)
        );
        return new PageUtils(page);
    }
2.合并采购需求

POST /ware/purchase/merge
请求参数:

{
purchased:1,//整单id
items:[1,2,3,4]  //合并项集合
}
@Transactional
    @Override
    public void mergePurchase(MergeVo mergeVo) {
        Long purchaseId = mergeVo.getPurchaseId();
        if(purchaseId == null){
            //1、新建一个
            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);
    }

注:此时的需求合并是更新 *** 作,当我们点击合并之后,会将最新的数据更新到数据库中,当没有采购单id的时候,则会新建新的采购单。

3.将日期时间格式化
spring:
    #日期格式化
  jackson:
    date-format: yyyy-MM-dd HH:mm:ss
六:领取采购单 1.请求地址

POST /ware/purchase/received
请求参数:[1,2,3,4] //采购单id

2.代码实现
   /**
     * 领取采购单
     * @return
     */
    @PostMapping("/received")
    public R received(@RequestBody List<Long> ids){
        purchaseService.received(ids);
        return R.ok();
    }

注:当领取采购单的时候,我们需要判断当前采购单是否已经被领取,其次需要改变采购单的状态为已分配,采购项的状态为已分配。

/**
     *
     * @param ids 采购单id
     */
    @Override
    public void received(List<Long> ids) {
        //1、确认当前采购单是新建或者已分配状态
        List<PurchaseEntity> collect = ids.stream().map(id -> {
            //通过采购单id查询出采购单的详细信息
            PurchaseEntity byId = this.getById(id);
            return byId;
        }).filter(item -> {
            if (item.getStatus() == WareConstant.PurchaseStatusEnum.CREATED.getCode() ||
                    item.getStatus() == WareConstant.PurchaseStatusEnum.ASSIGNED.getCode()) {
                return true;
            }
            return false;
        }).map(item->{
            //2、改变采购单的状态
            item.setStatus(WareConstant.PurchaseStatusEnum.RECEIVE.getCode());
            item.setUpdateTime(new Date());
            return item;
        }).collect(Collectors.toList());
        this.updateBatchById(collect);
        //3、改变采购项的状态
        collect.forEach((item)->{
            List<PurchaseDetailEntity> entities = detailService.listDetailByPurchaseId(item.getId());
            List<PurchaseDetailEntity> detailEntities = entities.stream().map(entity -> {
                PurchaseDetailEntity entity1 = new PurchaseDetailEntity();
                entity1.setId(entity.getId());
                entity1.setStatus(WareConstant.PurchaseDetailStatusEnum.BUYING.getCode());
                return entity1;
            }).collect(Collectors.toList());
            detailService.updateBatchById(detailEntities);
        });
    }
七:完成采购 1.请求地址

POST /ware/purchase/done

2.请求参数
{
id:123//采购单id
items:[{itemId:1,status:4,reason:""}]   //采购项
}

提交的时候,需要上传采购项的状态,如果没有完成,需要说明原因。

3.远程调用

1)新建feign包,新建ProductFeignService方法

2)添加@FeignClient(“gulimail-product”)注解,指定需要远程调用那个包
3)在ware的主启动类添加@EnableFeignClients注解,用于发现@FeignClient注解
4)编辑ProductFeignService方法

@FeignClient("gulimail-product")
public interface ProductFeignService {
    /**
     * 1)让所有请求过网关
     * 1.@FeignClient("gulimail-gateway"):给网关发请求
     * 2./api/product/skuinfo/info/{skuId}
     * @param skuId
     * @return
     */
    @RequestMapping("/product/skuinfo/info/{skuId}")
    //@RequiresPermissions("product:skuinfo:info")
    public R info(@PathVariable("skuId") Long skuId);
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/874502.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-13
下一篇 2022-05-13

发表评论

登录后才能评论

评论列表(0条)

保存