存酒业务逻辑+mybatisPlus
This commit is contained in:
parent
8f7acca8e6
commit
963e311b60
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package me.zhengjie.utils;
|
package me.zhengjie.utils;
|
||||||
|
|
||||||
|
import org.apache.poi.ss.formula.functions.T;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
|
|
@ -49,8 +50,12 @@ public class PageUtil extends cn.hutool.core.util.PageUtil {
|
||||||
map.put("totalElements",page.getTotalElements());
|
map.put("totalElements",page.getTotalElements());
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
public static Map<String,Object> toPlusPage(List<T> list, Integer total) {
|
||||||
|
Map<String,Object> map = new LinkedHashMap<>(2);
|
||||||
|
map.put("content",list);
|
||||||
|
map.put("totalElements",total);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 自定义分页
|
* 自定义分页
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -93,10 +93,20 @@
|
||||||
<version>2.1.4</version>
|
<version>2.1.4</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- <dependency>-->
|
||||||
|
<!-- <groupId>com.baomidou</groupId>-->
|
||||||
|
<!-- <artifactId>mybatis-plus-extension</artifactId>-->
|
||||||
|
<!-- <version>3.3.2</version>-->
|
||||||
|
<!-- </dependency>-->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.baomidou</groupId>
|
<groupId>com.baomidou</groupId>
|
||||||
<artifactId>mybatis-plus-extension</artifactId>
|
<artifactId>mybatis-plus-generator</artifactId>
|
||||||
<version>3.3.2</version>
|
<version>3.5.3.1</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.baomidou</groupId>
|
||||||
|
<artifactId>mybatis-plus-boot-starter</artifactId>
|
||||||
|
<version>3.5.3.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<profiles>
|
<profiles>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,36 @@
|
||||||
|
package me.zhengjie.config;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.DbType;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.*;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||||
|
import org.mybatis.spring.annotation.MapperScan;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
@MapperScan("me.zhengjie.mybatis.mapper")
|
||||||
|
@EnableTransactionManagement
|
||||||
|
public class MybatisPlusConfig {
|
||||||
|
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public PaginationInnerInterceptor paginationInnerInterceptor() {
|
||||||
|
PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor();
|
||||||
|
// 设置最大单页限制数量,默认 500 条,-1 不受限制
|
||||||
|
paginationInterceptor.setMaxLimit(-1L);
|
||||||
|
paginationInterceptor.setDbType(DbType.MYSQL);
|
||||||
|
// 开启 count 的 join 优化,只针对部分 left join
|
||||||
|
paginationInterceptor.setOptimizeJoin(true);
|
||||||
|
return paginationInterceptor;
|
||||||
|
}
|
||||||
|
@Bean
|
||||||
|
public MybatisPlusInterceptor mybatisPlusInterceptor(){
|
||||||
|
MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
|
||||||
|
mybatisPlusInterceptor.setInterceptors(Collections.singletonList(paginationInnerInterceptor()));
|
||||||
|
return mybatisPlusInterceptor;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -15,6 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package me.zhengjie.modules.productInfo.product.domain;
|
package me.zhengjie.modules.productInfo.product.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
@ -36,12 +39,14 @@ import java.io.Serializable;
|
||||||
@Entity
|
@Entity
|
||||||
@Data
|
@Data
|
||||||
@Table(name="tb_product")
|
@Table(name="tb_product")
|
||||||
|
@TableName("tb_product")
|
||||||
public class TbProduct implements Serializable {
|
public class TbProduct implements Serializable {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@Column(name = "`id`")
|
@Column(name = "`id`")
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@ApiModelProperty(value = "id")
|
@ApiModelProperty(value = "id")
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
@Column(name = "`source_path`")
|
@Column(name = "`source_path`")
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,10 @@
|
||||||
package me.zhengjie.modules.productInfo.productSku.domain;
|
package me.zhengjie.modules.productInfo.productSku.domain;
|
||||||
|
|
||||||
import cn.hutool.json.JSON;
|
import cn.hutool.json.JSON;
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
@ -35,12 +38,14 @@ import java.io.Serializable;
|
||||||
@Entity
|
@Entity
|
||||||
@Data
|
@Data
|
||||||
@Table(name="tb_product_sku")
|
@Table(name="tb_product_sku")
|
||||||
|
@TableName("tb_product_sku")
|
||||||
public class TbProductSku implements Serializable {
|
public class TbProductSku implements Serializable {
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@Column(name = "`id`")
|
@Column(name = "`id`")
|
||||||
@ApiModelProperty(value = "自增id")
|
@ApiModelProperty(value = "自增id")
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
@Column(name = "`shop_id`")
|
@Column(name = "`shop_id`")
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,9 @@
|
||||||
*/
|
*/
|
||||||
package me.zhengjie.modules.shopInfo.merchantAccount.domain;
|
package me.zhengjie.modules.shopInfo.merchantAccount.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import cn.hutool.core.bean.BeanUtil;
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
@ -31,6 +34,7 @@ import java.io.Serializable;
|
||||||
**/
|
**/
|
||||||
@Entity
|
@Entity
|
||||||
@Data
|
@Data
|
||||||
|
@TableName("tb_merchant_account")
|
||||||
@Table(name="tb_merchant_account")
|
@Table(name="tb_merchant_account")
|
||||||
public class TbMerchantAccount implements Serializable {
|
public class TbMerchantAccount implements Serializable {
|
||||||
|
|
||||||
|
|
@ -38,6 +42,7 @@ public class TbMerchantAccount implements Serializable {
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
@Column(name = "`id`")
|
@Column(name = "`id`")
|
||||||
@ApiModelProperty(value = "自增id")
|
@ApiModelProperty(value = "自增id")
|
||||||
|
@TableId(type = IdType.AUTO)
|
||||||
private Integer id;
|
private Integer id;
|
||||||
|
|
||||||
@Column(name = "`account`",nullable = false)
|
@Column(name = "`account`",nullable = false)
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@
|
||||||
*/
|
*/
|
||||||
package me.zhengjie.modules.shopInfo.shopRegister.service.impl;
|
package me.zhengjie.modules.shopInfo.shopRegister.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.api.R;
|
|
||||||
import me.zhengjie.exception.BadRequestException;
|
import me.zhengjie.exception.BadRequestException;
|
||||||
import me.zhengjie.modules.shopInfo.shopRegister.domain.TbMerchantRegister;
|
import me.zhengjie.modules.shopInfo.shopRegister.domain.TbMerchantRegister;
|
||||||
import me.zhengjie.utils.ValidationUtil;
|
import me.zhengjie.utils.ValidationUtil;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
package me.zhengjie.mybatis.entity;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class StorageVo {
|
||||||
|
private Integer id;
|
||||||
|
private String productName;
|
||||||
|
private String img;
|
||||||
|
private String account;
|
||||||
|
private String unit;
|
||||||
|
private Integer num;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,33 @@
|
||||||
|
package me.zhengjie.mybatis.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName("tb_user_storage")
|
||||||
|
public class TbUserStorage extends Model<TbUserStorage> {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
@TableId(type = IdType.ASSIGN_UUID)
|
||||||
|
private String id; // 记录ID
|
||||||
|
private Integer userId; // 用户ID
|
||||||
|
private String shopId; // 用户ID
|
||||||
|
private Integer productId;
|
||||||
|
private Integer num;
|
||||||
|
private Integer outNum;
|
||||||
|
private Integer inNum;
|
||||||
|
private Date createTime;
|
||||||
|
private String account;
|
||||||
|
private String unit;
|
||||||
|
private String productName;
|
||||||
|
private Integer skuId;
|
||||||
|
private String skuName;
|
||||||
|
private String imgUrl;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package me.zhengjie.mybatis.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import me.zhengjie.modules.shopInfo.merchantAccount.domain.TbMerchantAccount;
|
||||||
|
import me.zhengjie.mybatis.entity.TbUserStorage;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @website https://eladmin.vip
|
||||||
|
* @author lyf
|
||||||
|
* @date 2024-02-08
|
||||||
|
**/
|
||||||
|
public interface TbMerchantAccountMapper extends BaseMapper<TbMerchantAccount> {
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package me.zhengjie.mybatis.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import me.zhengjie.modules.productInfo.product.domain.TbProduct;
|
||||||
|
import me.zhengjie.modules.productInfo.productSku.domain.TbProductSku;
|
||||||
|
|
||||||
|
public interface TbProducSkutMapper extends BaseMapper<TbProductSku> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
package me.zhengjie.mybatis.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import me.zhengjie.modules.productInfo.product.domain.TbProduct;
|
||||||
|
import me.zhengjie.mybatis.entity.TbUserStorage;
|
||||||
|
|
||||||
|
public interface TbProductMapper extends BaseMapper<TbProduct> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
package me.zhengjie.mybatis.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import me.zhengjie.mybatis.entity.TbUserStorage;
|
||||||
|
|
||||||
|
public interface TbUserStorageMapper extends BaseMapper<TbUserStorage> {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,40 @@
|
||||||
|
package me.zhengjie.mybatis.rest;
|
||||||
|
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import me.zhengjie.annotation.Log;
|
||||||
|
import me.zhengjie.mybatis.entity.StorageVo;
|
||||||
|
import me.zhengjie.mybatis.service.ShopService;
|
||||||
|
import me.zhengjie.utils.SecurityUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Api(tags = "/shop/storage")
|
||||||
|
@RequestMapping("/api/storage")
|
||||||
|
public class StorageController {
|
||||||
|
@Autowired
|
||||||
|
private ShopService shopService;
|
||||||
|
@PostMapping("/findStorage")
|
||||||
|
public ResponseEntity<Object> findStorage(@RequestParam Integer shopId,String account,Pageable pageable){
|
||||||
|
return new ResponseEntity<>(shopService.findStorage(shopId,account,pageable), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
@PostMapping("/outStorage")
|
||||||
|
@Log("商品出库")
|
||||||
|
public ResponseEntity<Object> outStorage(@RequestParam Integer id,@RequestParam Integer num){
|
||||||
|
String userName = SecurityUtils.getCurrentUsername();
|
||||||
|
shopService.outStorage(id,userName,num);
|
||||||
|
return new ResponseEntity<>( HttpStatus.OK);
|
||||||
|
}
|
||||||
|
@PostMapping("/inStorage")
|
||||||
|
@Log("商品入库")
|
||||||
|
public ResponseEntity<Object> inStorage(@RequestBody StorageVo storageVo){
|
||||||
|
String userName = SecurityUtils.getCurrentUsername();
|
||||||
|
shopService.inStorage(storageVo,userName);
|
||||||
|
return new ResponseEntity<>(HttpStatus.OK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,34 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package me.zhengjie.mybatis.service;
|
||||||
|
|
||||||
|
import me.zhengjie.mybatis.entity.StorageVo;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @website https://eladmin.vip
|
||||||
|
* @description 服务接口
|
||||||
|
* @author admin
|
||||||
|
* @date 2023-10-30
|
||||||
|
**/
|
||||||
|
public interface ShopService {
|
||||||
|
Object findStorage(Integer shopId, String account, Pageable pageable);
|
||||||
|
|
||||||
|
void outStorage(Integer id, String userName, Integer num);
|
||||||
|
|
||||||
|
|
||||||
|
void inStorage(StorageVo storageVo, String userName);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,123 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2019-2020 Zheng Jie
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package me.zhengjie.mybatis.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import me.zhengjie.exception.NewBadRequestException;
|
||||||
|
import me.zhengjie.modules.productInfo.productSku.domain.TbProductSku;
|
||||||
|
import me.zhengjie.modules.shopInfo.merchantAccount.domain.TbMerchantAccount;
|
||||||
|
import me.zhengjie.mybatis.entity.StorageVo;
|
||||||
|
import me.zhengjie.mybatis.entity.TbUserStorage;
|
||||||
|
import me.zhengjie.mybatis.mapper.TbMerchantAccountMapper;
|
||||||
|
import me.zhengjie.mybatis.mapper.TbProducSkutMapper;
|
||||||
|
import me.zhengjie.mybatis.mapper.TbProductMapper;
|
||||||
|
import me.zhengjie.mybatis.mapper.TbUserStorageMapper;
|
||||||
|
import me.zhengjie.mybatis.service.ShopService;
|
||||||
|
import me.zhengjie.utils.*;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author admin
|
||||||
|
* @website https://eladmin.vip
|
||||||
|
* @description 服务实现
|
||||||
|
* @date 2023-10-30
|
||||||
|
**/
|
||||||
|
@Service
|
||||||
|
public class ShopServiceImpl implements ShopService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private TbUserStorageMapper userStorageMapper;
|
||||||
|
@Autowired
|
||||||
|
private TbMerchantAccountMapper tbMerchantAccountMapper;
|
||||||
|
@Autowired
|
||||||
|
private TbProducSkutMapper producSkutMapper;
|
||||||
|
@Autowired
|
||||||
|
private TbProductMapper productMapper;
|
||||||
|
@Override
|
||||||
|
public Object findStorage(Integer shopId, String account, Pageable pageable) {
|
||||||
|
QueryWrapper<TbUserStorage> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("shop_id", shopId);
|
||||||
|
if (StringUtils.isNotEmpty(account)) {
|
||||||
|
queryWrapper.eq("account", account);
|
||||||
|
}
|
||||||
|
IPage<TbUserStorage> iPage = userStorageMapper.selectPage(new Page<>(pageable.getPageNumber(), pageable.getPageSize()), queryWrapper);
|
||||||
|
return PageUtil.toPage(iPage.getRecords(), iPage.getTotal());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void outStorage(Integer id, String userName, Integer num) {
|
||||||
|
if (Objects.isNull(num) || num < 0) {
|
||||||
|
throw new NewBadRequestException("请输入出库数量");
|
||||||
|
}
|
||||||
|
QueryWrapper<TbMerchantAccount> wrapper = new QueryWrapper<>();
|
||||||
|
wrapper.eq("account", userName);
|
||||||
|
TbMerchantAccount merchantAccount = tbMerchantAccountMapper.selectOne(wrapper);
|
||||||
|
|
||||||
|
QueryWrapper<TbUserStorage> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("id", id);
|
||||||
|
queryWrapper.eq("shop_id", merchantAccount.getShopId());
|
||||||
|
TbUserStorage userStorage = userStorageMapper.selectOne(queryWrapper);
|
||||||
|
if (Objects.isNull(userStorage)) {
|
||||||
|
throw new NewBadRequestException("存储商品在该店铺不存在");
|
||||||
|
}
|
||||||
|
if (userStorage.getNum() < num) {
|
||||||
|
throw new NewBadRequestException("库存不足");
|
||||||
|
}
|
||||||
|
userStorage.setNum(userStorage.getNum() - num);
|
||||||
|
userStorage.setOutNum(userStorage.getOutNum() + num);
|
||||||
|
userStorageMapper.updateById(userStorage);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void inStorage(StorageVo storageVo, String userName) {
|
||||||
|
if (Objects.isNull(storageVo.getNum()) || storageVo.getNum() < 0) {
|
||||||
|
throw new NewBadRequestException("请输入出库数量");
|
||||||
|
}
|
||||||
|
QueryWrapper<TbMerchantAccount> wrapper = new QueryWrapper<>();
|
||||||
|
wrapper.eq("account", userName);
|
||||||
|
TbMerchantAccount merchantAccount = tbMerchantAccountMapper.selectOne(wrapper);
|
||||||
|
|
||||||
|
QueryWrapper<TbUserStorage> queryWrapper = new QueryWrapper<>();
|
||||||
|
queryWrapper.eq("product_name", storageVo.getProductName());
|
||||||
|
queryWrapper.eq("account", storageVo.getAccount());
|
||||||
|
queryWrapper.eq("shop_id", merchantAccount.getShopId());
|
||||||
|
TbUserStorage userStorage = userStorageMapper.selectOne(queryWrapper);
|
||||||
|
if (Objects.nonNull(userStorage)) {
|
||||||
|
userStorage.setNum(userStorage.getNum() + storageVo.getNum());
|
||||||
|
userStorage.setInNum(userStorage.getInNum() + storageVo.getNum());
|
||||||
|
userStorageMapper.updateById(userStorage);
|
||||||
|
}else {
|
||||||
|
userStorage = new TbUserStorage();
|
||||||
|
userStorage.setAccount(storageVo.getAccount());
|
||||||
|
userStorage.setCreateTime(new Date());
|
||||||
|
userStorage.setShopId(merchantAccount.getShopId());
|
||||||
|
userStorage.setNum(storageVo.getNum());
|
||||||
|
userStorage.setOutNum(0);
|
||||||
|
userStorage.setInNum(storageVo.getNum());
|
||||||
|
userStorage.setImgUrl(storageVo.getImg());
|
||||||
|
userStorage.setProductName(storageVo.getImg());
|
||||||
|
userStorage.setUnit(storageVo.getUnit());
|
||||||
|
userStorageMapper.insert(userStorage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue