图库修改功能提交
This commit is contained in:
parent
0cde19efd7
commit
6cdcb244e7
@ -1,8 +1,6 @@
|
|||||||
package com.suisung.mall.common.modules.library;
|
package com.suisung.mall.common.modules.library;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.IdType;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
@ -27,12 +25,14 @@ public class LibraryProduct implements Serializable {
|
|||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@ApiModelProperty(value = "商品名", example = "小米12 Pro")
|
@ApiModelProperty(value = "商品名", example = "小米12 Pro")
|
||||||
|
@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@ApiModelProperty(value = "商品标题", example = "小米12 Pro")
|
@ApiModelProperty(value = "商品标题", example = "小米12 Pro")
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
@ApiModelProperty(value = "条形码/Barcode", example = "6923450657713")
|
@ApiModelProperty(value = "条形码/Barcode", example = "6923450657713")
|
||||||
|
@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||||
private String barcode;
|
private String barcode;
|
||||||
|
|
||||||
@ApiModelProperty(value = "第一级分类", example = "生鲜")
|
@ApiModelProperty(value = "第一级分类", example = "生鲜")
|
||||||
@ -73,6 +73,7 @@ public class LibraryProduct implements Serializable {
|
|||||||
private String keywords;
|
private String keywords;
|
||||||
|
|
||||||
@ApiModelProperty(value = "封面图主图", example = "/media/images/product/1001.jpg")
|
@ApiModelProperty(value = "封面图主图", example = "/media/images/product/1001.jpg")
|
||||||
|
@TableField(updateStrategy = FieldStrategy.NOT_EMPTY)
|
||||||
private String thumb;
|
private String thumb;
|
||||||
|
|
||||||
@ApiModelProperty(value = "排序值,越小越前面", example = "50")
|
@ApiModelProperty(value = "排序值,越小越前面", example = "50")
|
||||||
@ -85,8 +86,10 @@ public class LibraryProduct implements Serializable {
|
|||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
@ApiModelProperty(value = "创建时间", example = "2023-01-01 12:00:00")
|
@ApiModelProperty(value = "创建时间", example = "2023-01-01 12:00:00")
|
||||||
|
@TableField(value = "created_at")
|
||||||
private Date createdAt;
|
private Date createdAt;
|
||||||
|
|
||||||
@ApiModelProperty(value = "更新时间", example = "2023-01-02 15:30:00")
|
@ApiModelProperty(value = "更新时间", example = "2023-01-02 15:30:00")
|
||||||
|
@TableField(value = "updated_at")
|
||||||
private Date updatedAt;
|
private Date updatedAt;
|
||||||
}
|
}
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
package com.suisung.mall.shop.library.controller;
|
||||||
|
|
||||||
|
import cn.hutool.json.JSONArray;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import com.suisung.mall.common.api.CommonResult;
|
||||||
|
import com.suisung.mall.common.modules.library.LibraryProduct;
|
||||||
|
import com.suisung.mall.common.pojo.dto.LibraryProductDTO;
|
||||||
|
import com.suisung.mall.shop.library.service.LibraryProductService;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Api(tags = "图库管理")
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/admin/shop/libraryProduct")
|
||||||
|
public class LibraryProductController {
|
||||||
|
@Autowired
|
||||||
|
private LibraryProductService libraryProductService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页列表查询
|
||||||
|
* @param
|
||||||
|
* @param pageNum
|
||||||
|
* @param pageSize
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ApiOperation(value = "列表查询-图库数据", notes = "列表查询")
|
||||||
|
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||||
|
public Page<LibraryProduct> list(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum,
|
||||||
|
@RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
|
||||||
|
return libraryProductService.findLibraryProductPage(pageNum, pageSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量保存
|
||||||
|
* @param
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@ApiOperation(value = "批量修改", notes = "批量修改")
|
||||||
|
@RequestMapping(value = "/saveBatch", method = RequestMethod.PUT)
|
||||||
|
public CommonResult saveBatch(@RequestBody JSONArray jsonLibraryProduct) {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
String json = gson.toJson(jsonLibraryProduct);
|
||||||
|
List<LibraryProductDTO> libraryProducts= gson.fromJson(json,new TypeToken<List<LibraryProductDTO>>(){}.getType());
|
||||||
|
return libraryProductService.updateBatchLibraryProductDTO(libraryProducts);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -8,11 +8,15 @@
|
|||||||
|
|
||||||
package com.suisung.mall.shop.library.service;
|
package com.suisung.mall.shop.library.service;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.suisung.mall.common.api.CommonResult;
|
||||||
|
import com.suisung.mall.common.modules.library.LibraryProduct;
|
||||||
import com.suisung.mall.common.pojo.dto.LibraryProductDTO;
|
import com.suisung.mall.common.pojo.dto.LibraryProductDTO;
|
||||||
|
import com.suisung.mall.core.web.service.IBaseService;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface LibraryProductService {
|
public interface LibraryProductService extends IBaseService<LibraryProduct> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 匹配商品
|
* 匹配商品
|
||||||
@ -25,4 +29,13 @@ public interface LibraryProductService {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
List<LibraryProductDTO> matchLibraryProducts(String barcode, String productName, List<String> keywords);
|
List<LibraryProductDTO> matchLibraryProducts(String barcode, String productName, List<String> keywords);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Page<LibraryProduct> findLibraryProductPage(Integer pageNum, Integer pageSize);
|
||||||
|
|
||||||
|
CommonResult updateBatchLibraryProductDTO(List<LibraryProductDTO> products);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,8 +12,16 @@ import cn.hutool.core.collection.CollUtil;
|
|||||||
import cn.hutool.core.collection.CollectionUtil;
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.suisung.mall.common.feignService.AccountService;
|
import com.suisung.mall.common.feignService.AccountService;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.suisung.mall.common.api.CommonResult;
|
||||||
|
import com.suisung.mall.common.domain.UserDto;
|
||||||
|
import com.suisung.mall.common.exception.ApiException;
|
||||||
import com.suisung.mall.common.modules.library.LibraryProduct;
|
import com.suisung.mall.common.modules.library.LibraryProduct;
|
||||||
import com.suisung.mall.common.pojo.dto.LibraryProductDTO;
|
import com.suisung.mall.common.pojo.dto.LibraryProductDTO;
|
||||||
|
import com.suisung.mall.common.utils.ContextUtil;
|
||||||
|
import com.suisung.mall.core.consts.ConstantRedis;
|
||||||
|
import com.suisung.mall.core.web.service.RedisService;
|
||||||
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
|
import com.suisung.mall.core.web.service.impl.BaseServiceImpl;
|
||||||
import com.suisung.mall.shop.library.mapper.LibraryProductMapper;
|
import com.suisung.mall.shop.library.mapper.LibraryProductMapper;
|
||||||
import com.suisung.mall.shop.library.service.LibraryProductService;
|
import com.suisung.mall.shop.library.service.LibraryProductService;
|
||||||
@ -21,8 +29,10 @@ import org.apache.commons.lang3.StringUtils;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -37,6 +47,8 @@ public class LibraryProductImpl extends BaseServiceImpl<LibraryProductMapper, Li
|
|||||||
@Autowired
|
@Autowired
|
||||||
private AccountService accountService;
|
private AccountService accountService;
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RedisService redisService;
|
||||||
/**
|
/**
|
||||||
* 匹配商品
|
* 匹配商品
|
||||||
* 如果 barcode 匹配到数据,其他条件不会被匹配
|
* 如果 barcode 匹配到数据,其他条件不会被匹配
|
||||||
@ -71,4 +83,72 @@ public class LibraryProductImpl extends BaseServiceImpl<LibraryProductMapper, Li
|
|||||||
return list;
|
return list;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<LibraryProduct> findLibraryProductPage(Integer pageNum, Integer pageSize) {
|
||||||
|
String barcode= getParameter("barcode");
|
||||||
|
String name= getParameter("name");
|
||||||
|
QueryWrapper<LibraryProduct> queryWrapper = new QueryWrapper<>();
|
||||||
|
if(StringUtils.isNotEmpty(barcode)){
|
||||||
|
queryWrapper.like("barcode", barcode);
|
||||||
|
}
|
||||||
|
if(StringUtils.isNotEmpty(name)){
|
||||||
|
queryWrapper.like("name", name);
|
||||||
|
}
|
||||||
|
String barcodeEmty= getParameter("barcodeEmty");
|
||||||
|
if(StringUtils.isNotEmpty(barcodeEmty)){
|
||||||
|
if(barcodeEmty.equals("yes")){
|
||||||
|
queryWrapper.eq("barcode","");
|
||||||
|
}
|
||||||
|
if(barcodeEmty.equals("no")){
|
||||||
|
queryWrapper.ne("barcode","");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
queryWrapper.orderByDesc("updated_at");
|
||||||
|
Page<LibraryProduct> page= this.lists(queryWrapper,pageNum, pageSize);
|
||||||
|
|
||||||
|
List<LibraryProduct> libraryProductList= page.getRecords();
|
||||||
|
libraryProductList.forEach(libraryProduct->{
|
||||||
|
libraryProduct.setThumb(staticDomain+libraryProduct.getThumb());
|
||||||
|
});
|
||||||
|
page.setRecords(libraryProductList);
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改名称或者条形码
|
||||||
|
* @param products
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = ApiException.class)
|
||||||
|
public CommonResult updateBatchLibraryProductDTO(List<LibraryProductDTO> products) {
|
||||||
|
List<LibraryProduct> updateProductList = new ArrayList<>();
|
||||||
|
UserDto userDto=ContextUtil.getCurrentUser();
|
||||||
|
assert userDto != null;
|
||||||
|
if(userDto.getRole_id()!=9){
|
||||||
|
throw new ApiException("权限不足");
|
||||||
|
}
|
||||||
|
List<String> updateTableIds=new ArrayList<>();
|
||||||
|
products.forEach(product->{
|
||||||
|
if (null==product.getId()){
|
||||||
|
throw new ApiException("id is null");
|
||||||
|
}
|
||||||
|
LibraryProduct libraryProduct=new LibraryProduct();
|
||||||
|
libraryProduct.setId(product.getId());
|
||||||
|
libraryProduct.setName(product.getName());
|
||||||
|
libraryProduct.setBarcode(product.getBarcode());
|
||||||
|
updateProductList.add(libraryProduct);
|
||||||
|
updateTableIds.add(ConstantRedis.Cache_NameSpace+"library_product:"+product.getId());
|
||||||
|
});
|
||||||
|
boolean result=this.updateBatchById(updateProductList,updateProductList.size());
|
||||||
|
if(result){
|
||||||
|
redisService.del(updateTableIds);
|
||||||
|
return CommonResult.success("保存成功");
|
||||||
|
}
|
||||||
|
return CommonResult.failed("保存失败");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
3
sql/shop/dev/20250903_dml.sql
Normal file
3
sql/shop/dev/20250903_dml.sql
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
INSERT INTO `admin_base_protocol` (`ctl`, `met`, `db`, `rights_id`, `log`, `path`,`comment`) VALUES ('/admin/shop/libraryProduct/list', 'index', 'master', '', '0', '/admin/shop/libraryProduct/list','图库查询');
|
||||||
|
|
||||||
|
INSERT INTO `admin_base_protocol` (`ctl`, `met`, `db`, `rights_id`, `log`, `path`,`comment`) VALUES ('/admin/shop/libraryProduct/saveBatch', 'index', 'master', '', '0', '/admin/shop/libraryProduct/saveBatch','图库修改');
|
||||||
Loading…
Reference in New Issue
Block a user