更改商品bug

This commit is contained in:
liuyingfang
2024-03-05 16:38:12 +08:00
parent 5463204fb5
commit c6744bc012
17 changed files with 72 additions and 56 deletions

View File

@@ -73,6 +73,17 @@ public class ListUtil {
return stringList; return stringList;
} }
public static List<Integer> stringChangeIntegerList(String listString){
// 使用Fastjson将JSON字符串转换为JSONArray对象
listString = listString.replaceAll("\"", "").replaceAll("\\[", "").replaceAll("\\]", "");
List<Integer> integerList = Stream.of(listString.split(","))
.map(Integer::valueOf)
.collect(Collectors.toList());
return integerList;
}
public static List<Integer> stringChangeIntegerList(List<String> listString){ public static List<Integer> stringChangeIntegerList(List<String> listString){
// method1 创建一个Integer类型的集合循环遍历String类型的数组并把数据添加进集合 // method1 创建一个Integer类型的集合循环遍历String类型的数组并把数据添加进集合

View File

@@ -44,19 +44,11 @@ public class TbProductController {
private final TbProductService tbProductService; private final TbProductService tbProductService;
@Log("导出数据")
@ApiOperation("导出数据")
@GetMapping(value = "/download")
@PreAuthorize("@el.check('tbProduct:list')")
public void exportTbProduct(HttpServletResponse response, TbProductQueryCriteria criteria) throws IOException {
tbProductService.download(tbProductService.queryAll(criteria), response);
}
@GetMapping @GetMapping
@Log("查询/product") @Log("查询/product")
@ApiOperation("查询/product") @ApiOperation("查询/product")
public ResponseEntity<Object> queryTbProduct(TbProductQueryCriteria criteria, Pageable pageable){ public ResponseEntity<Object> queryTbProduct(TbProductQueryCriteria criteria){
return new ResponseEntity<>(tbProductService.queryAll(criteria,pageable),HttpStatus.OK); return new ResponseEntity<>(tbProductService.queryAll(criteria),HttpStatus.OK);
} }
@GetMapping("/{product}") @GetMapping("/{product}")

View File

@@ -102,7 +102,7 @@ public class TbProductGroupController {
*/ */
@GetMapping("/addProduct") @GetMapping("/addProduct")
public ResponseEntity<Object> ProductList(TbProductQueryCriteria criteria, Pageable pageable){ public ResponseEntity<Object> ProductList(TbProductQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(tbProductService.queryAll(criteria,pageable),HttpStatus.OK); return new ResponseEntity<>(tbProductService.queryAll(criteria),HttpStatus.OK);
} }
/** /**

View File

@@ -44,20 +44,20 @@ public class TbShopInfoController {
private final TbShopInfoService tbShopInfoService; private final TbShopInfoService tbShopInfoService;
@Log("导出数据") // @Log("导出数据")
@ApiOperation("导出数据") // @ApiOperation("导出数据")
@GetMapping(value = "/download") // @GetMapping(value = "/download")
@PreAuthorize("@el.check('tbShopInfo:list')") // @PreAuthorize("@el.check('tbShopInfo:list')")
public void exportTbShopInfo(HttpServletResponse response, TbShopInfoQueryCriteria criteria) throws IOException { // public void exportTbShopInfo(HttpServletResponse response, TbShopInfoQueryCriteria criteria) throws IOException {
tbShopInfoService.download(tbShopInfoService.queryAll(criteria), response); // tbShopInfoService.download(tbShopInfoService.queryAll(criteria), response);
} // }
@GetMapping @GetMapping
@Log("查询/shop/list") @Log("查询/shop/list")
@ApiOperation("查询/shop/list") @ApiOperation("查询/shop/list")
@PreAuthorize("@el.check('tbShopInfo:list')") @PreAuthorize("@el.check('tbShopInfo:list')")
public ResponseEntity<Object> queryTbShopInfo(TbShopInfoQueryCriteria criteria, Pageable pageable){ public ResponseEntity<Object> queryTbShopInfo(TbShopInfoQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(tbShopInfoService.queryAll(criteria,pageable),HttpStatus.OK); return new ResponseEntity<>(tbShopInfoService.queryAll(criteria),HttpStatus.OK);
} }
@GetMapping("/{shopId}") @GetMapping("/{shopId}")

View File

@@ -55,7 +55,7 @@ public class TbProductGroupDto implements Serializable {
private Integer sort; private Integer sort;
/** 商品列表 */ /** 商品列表 */
private List<String> productIds; private List<Integer> productIds;
private Long createdAt; private Long createdAt;

View File

@@ -121,4 +121,10 @@ public class TbProductQueryCriteria{
@Query @Query
private String typeEnum; private String typeEnum;
private Integer page;
private Integer size;
private String sort;
} }

View File

@@ -65,4 +65,10 @@ public class TbShopInfoQueryCriteria{
/** 精确 */ /** 精确 */
@Query @Query
private Integer status; private Integer status;
private Integer page;
private Integer size;
private String sort;
} }

View File

@@ -19,6 +19,7 @@ import cn.ysk.cashier.base.BaseMapper;
import cn.ysk.cashier.pojo.product.TbProductGroup; import cn.ysk.cashier.pojo.product.TbProductGroup;
import cn.ysk.cashier.dto.product.TbProductGroupDto; import cn.ysk.cashier.dto.product.TbProductGroupDto;
import cn.ysk.cashier.utils.ListUtil;
import org.mapstruct.Mapper; import org.mapstruct.Mapper;
import org.mapstruct.Mapping; import org.mapstruct.Mapping;
@@ -38,13 +39,7 @@ import java.util.stream.Collectors;
public interface TbProductGroupMapper extends BaseMapper<TbProductGroupDto, TbProductGroup> { public interface TbProductGroupMapper extends BaseMapper<TbProductGroupDto, TbProductGroup> {
// 自定义的字符串到整数列表的转换方法 // 自定义的字符串到整数列表的转换方法
default List<Integer> map(String value) { default List<Integer> map(String value) {
if (value == null || value.isEmpty()) { return ListUtil.stringChangeIntegerList(value);
return Collections.emptyList();
}
// 分割字符串然后将每个数字字符串转换为Integer收集到List中
return Arrays.stream(value.split(","))
.map(Integer::valueOf)
.collect(Collectors.toList());
} }
// 如果需要从DTO转回实体也可能需要实现反向的映射方法 // 如果需要从DTO转回实体也可能需要实现反向的映射方法

View File

@@ -80,7 +80,7 @@ public class TbProductGroupServiceImpl implements TbProductGroupService {
TbProductGroup tbProductGroup = tbProductGroupRepository.findById(productGroup).orElseGet(TbProductGroup::new); TbProductGroup tbProductGroup = tbProductGroupRepository.findById(productGroup).orElseGet(TbProductGroup::new);
TbProductGroupDto dto = tbProductGroupMapper.toDto(tbProductGroup); TbProductGroupDto dto = tbProductGroupMapper.toDto(tbProductGroup);
if (!CollectionUtils.isEmpty(dto.getProductIds())){ if (!CollectionUtils.isEmpty(dto.getProductIds())){
return tbProductRepository.findByIds(ListUtil.stringChangeIntegerList(dto.getProductIds())); return tbProductRepository.findByIds(dto.getProductIds());
} }
return new ArrayList<>(); return new ArrayList<>();
} }

View File

@@ -37,10 +37,13 @@ import cn.ysk.cashier.pojo.shop.TbShopUnit;
import cn.ysk.cashier.repository.shop.TbShopUnitRepository; import cn.ysk.cashier.repository.shop.TbShopUnitRepository;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.util.StringUtils;
import java.time.Instant; import java.time.Instant;
import java.util.*; import java.util.*;
@@ -68,7 +71,9 @@ public class TbProductServiceImpl implements TbProductService {
@Override @Override
public Map<String,Object> queryAll(TbProductQueryCriteria criteria, Pageable pageable){ public Map<String,Object> queryAll(TbProductQueryCriteria criteria){
Sort sort = Sort.by(Sort.Direction.DESC, "id");
Pageable pageable = PageRequest.of(criteria.getPage(), criteria.getSize(), sort);
//查询商品数据 //查询商品数据
Page<TbProduct> page = tbProductRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); Page<TbProduct> page = tbProductRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
List<String> productId = new ArrayList<>(); List<String> productId = new ArrayList<>();
@@ -147,7 +152,7 @@ public class TbProductServiceImpl implements TbProductService {
//单位 //单位
CompletableFuture<TbShopUnit> tbShopUnits = CompletableFuture.supplyAsync(() -> CompletableFuture<TbShopUnit> tbShopUnits = CompletableFuture.supplyAsync(() ->
tbShopUnitRepository.searchUnit(Integer.valueOf(tbProduct.getUnitId()))); tbShopUnitRepository.searchUnit(Integer.valueOf(StringUtils.isEmpty(tbProduct.getUnitId())? null:tbProduct.getUnitId() )));
//sku //sku
CompletableFuture<List<TbProductSku>> tbProductSkus = CompletableFuture.supplyAsync(() -> CompletableFuture<List<TbProductSku>> tbProductSkus = CompletableFuture.supplyAsync(() ->
tbProductSkuRepository.searchSku(tbProduct.getId().toString())); tbProductSkuRepository.searchSku(tbProduct.getId().toString()));
@@ -163,8 +168,6 @@ public class TbProductServiceImpl implements TbProductService {
if (tbProduct.getUnitId() == null){ if (tbProduct.getUnitId() == null){
tbProductVo.setUnitId(null); tbProductVo.setUnitId(null);
tbProductVo.setUnitName(null); tbProductVo.setUnitName(null);
}else {
tbProductVo.setUnitName(tbShopUnits.get().getName());
} }
//套餐 //套餐
if (tbProduct.getGroupSnap() == null){ if (tbProduct.getGroupSnap() == null){
@@ -203,7 +206,7 @@ public class TbProductServiceImpl implements TbProductService {
} }
@Override @Override
public List<TbProductDto> queryAll(TbProductQueryCriteria criteria){ public List<TbProductDto> queryAlls(TbProductQueryCriteria criteria){
return tbProductMapper.toDto(tbProductRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); return tbProductMapper.toDto(tbProductRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
} }
@@ -225,6 +228,7 @@ public class TbProductServiceImpl implements TbProductService {
if (resources.getCategoryId() == null){ if (resources.getCategoryId() == null){
throw new BadRequestException("必填内容未填写"); throw new BadRequestException("必填内容未填写");
} }
product.setImages(resources.getImages().toString());
product.setCategoryId(String.valueOf(resources.getCategoryId())); product.setCategoryId(String.valueOf(resources.getCategoryId()));
product.setIsDel(0); product.setIsDel(0);
product.setIsDelete(0); product.setIsDelete(0);

View File

@@ -60,7 +60,7 @@ public class TbShopCategoryServiceImpl implements TbShopCategoryService {
public Map<String,Object> queryAll(TbShopCategoryQueryCriteria criteria, Pageable pageable){ public Map<String,Object> queryAll(TbShopCategoryQueryCriteria criteria, Pageable pageable){
// Page<TbShopCategory> page = tbShopCategoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); // Page<TbShopCategory> page = tbShopCategoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
PageRequest.of(0, 10, Sort.by("sort")); PageRequest.of(pageable.getPageNumber(), pageable.getPageSize(), Sort.by("sort"));
Page<TbShopCategory> page = tbShopCategoryRepository.findAllBy(criteria.getShopId(), pageable); Page<TbShopCategory> page = tbShopCategoryRepository.findAllBy(criteria.getShopId(), pageable);
tbShopCategoryRepository.findAllBy(criteria.getShopId(),pageable); tbShopCategoryRepository.findAllBy(criteria.getShopId(),pageable);
@@ -112,14 +112,16 @@ public class TbShopCategoryServiceImpl implements TbShopCategoryService {
resources.setUpdatedAt(Instant.now().toEpochMilli()); resources.setUpdatedAt(Instant.now().toEpochMilli());
TbShopCategoryDto dto = tbShopCategoryMapper.toDto(tbShopCategoryRepository.save(resources)); TbShopCategoryDto dto = tbShopCategoryMapper.toDto(tbShopCategoryRepository.save(resources));
if (resources.getName() != null){
throw new BadRequestException("分类名称重复");
}
if (resources.getPid() == null || "".equals(resources.getPid())){ if (resources.getPid() == null || "".equals(resources.getPid())){
resources.setTree(resources.getId()); resources.setTree(resources.getId());
}else { }else {
resources.setTree(Integer.valueOf(resources.getPid().trim())); resources.setTree(Integer.valueOf(resources.getPid().trim()));
} }
ValidationUtil.isNull( dto.getId(),"TbShopCategory","id",resources.getId()); ValidationUtil.isNull(dto.getId(),"TbShopCategory","id",resources.getId());
tbShopCategoryRepository.save(resources); tbShopCategoryRepository.save(resources);
return tbShopCategoryRepository.save(resources); return tbShopCategoryRepository.save(resources);
} }
@@ -132,9 +134,7 @@ public class TbShopCategoryServiceImpl implements TbShopCategoryService {
throw new BadRequestException("必要参数为空"); throw new BadRequestException("必要参数为空");
} }
TbShopCategory byName = tbShopCategoryRepository.findByName(resources.getName(), resources.getShopId()); TbShopCategory byName = tbShopCategoryRepository.findByName(resources.getName(), resources.getShopId());
if (byName != null){
throw new BadRequestException("分类名称重复");
}
resources.setUpdatedAt(Instant.now().toEpochMilli()); resources.setUpdatedAt(Instant.now().toEpochMilli());
ValidationUtil.isNull( tbShopCategory.getId(),"TbShopCategory","id",resources.getId()); ValidationUtil.isNull( tbShopCategory.getId(),"TbShopCategory","id",resources.getId());
tbShopCategory.copy(resources); tbShopCategory.copy(resources);

View File

@@ -16,6 +16,7 @@
package cn.ysk.cashier.service.impl.shopimpl; package cn.ysk.cashier.service.impl.shopimpl;
import cn.ysk.cashier.exception.BadRequestException; import cn.ysk.cashier.exception.BadRequestException;
import cn.ysk.cashier.pojo.product.TbShopCategory;
import cn.ysk.cashier.pojo.shop.TbMerchantAccount; import cn.ysk.cashier.pojo.shop.TbMerchantAccount;
import cn.ysk.cashier.pojo.shop.TbPlussShopStaff; import cn.ysk.cashier.pojo.shop.TbPlussShopStaff;
import cn.ysk.cashier.repository.shop.TbMerchantAccountRepository; import cn.ysk.cashier.repository.shop.TbMerchantAccountRepository;
@@ -36,6 +37,8 @@ import cn.ysk.cashier.dto.shop.TbShopInfoDto;
import cn.ysk.cashier.dto.shop.TbShopInfoQueryCriteria; import cn.ysk.cashier.dto.shop.TbShopInfoQueryCriteria;
import cn.ysk.cashier.mapper.shop.TbShopInfoMapper; import cn.ysk.cashier.mapper.shop.TbShopInfoMapper;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -73,11 +76,10 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
private final TbPlussShopStaffRepository shopStaffRepository; private final TbPlussShopStaffRepository shopStaffRepository;
@Override @Override
public Map<String,Object> queryAll(TbShopInfoQueryCriteria criteria, Pageable pageable){ public Map<String,Object> queryAll(TbShopInfoQueryCriteria criteria){
// if (!"admin".equals(criteria.getAccount())){ Sort sort = Sort.by(Sort.Direction.DESC, "id");
// throw new BadRequestException("登录账号有误"); Pageable pageables = PageRequest.of(criteria.getPage(), criteria.getSize(), sort);
// } Page<TbShopInfo> page = tbShopInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageables);
Page<TbShopInfo> page = tbShopInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
List<TbShopInfo> content = page.getContent(); List<TbShopInfo> content = page.getContent();
for (TbShopInfo data: content){ for (TbShopInfo data: content){
if (data.getProfiles() == null){ if (data.getProfiles() == null){
@@ -87,10 +89,10 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
return PageUtil.toPage(page); return PageUtil.toPage(page);
} }
@Override // @Override
public List<TbShopInfoDto> queryAll(TbShopInfoQueryCriteria criteria){ // public List<TbShopInfoDto> queryAll(TbShopInfoQueryCriteria criteria){
return tbShopInfoMapper.toDto(tbShopInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); // return tbShopInfoMapper.toDto(tbShopInfoRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
} // }
@Override @Override
@Transactional @Transactional
@@ -178,6 +180,7 @@ public class TbShopInfoServiceImpl implements TbShopInfoService {
tbPlussShopStaff.setStatus(1); tbPlussShopStaff.setStatus(1);
tbPlussShopStaff.setCreatedAt(Instant.now().toEpochMilli()); tbPlussShopStaff.setCreatedAt(Instant.now().toEpochMilli());
tbPlussShopStaff.setUpdatedAt(Instant.now().toEpochMilli()); tbPlussShopStaff.setUpdatedAt(Instant.now().toEpochMilli());
tbPlussShopStaff.setCode(save.getPhone());
shopStaffRepository.save(tbPlussShopStaff); shopStaffRepository.save(tbPlussShopStaff);
if (resources.getRegisterCode() != null){ if (resources.getRegisterCode() != null){

View File

@@ -106,6 +106,7 @@ public class TbShopTableServiceImpl implements TbShopTableService {
resources.setCreatedAt(Instant.now().toEpochMilli()); resources.setCreatedAt(Instant.now().toEpochMilli());
resources.setUpdatedAt(Instant.now().toEpochMilli()); resources.setUpdatedAt(Instant.now().toEpochMilli());
resources.setQrcode(""); resources.setQrcode("");
resources.setStatus("closed");
return tbShopTableRepository.save(resources); return tbShopTableRepository.save(resources);
} }

View File

@@ -36,17 +36,16 @@ public interface TbProductService {
/** /**
* 查询数据分页 * 查询数据分页
* @param criteria 条件 * @param criteria 条件
* @param pageable 分页参数
* @return Map<String,Object> * @return Map<String,Object>
*/ */
Map<String,Object> queryAll(TbProductQueryCriteria criteria, Pageable pageable); Map<String,Object> queryAll(TbProductQueryCriteria criteria);
/** /**
* 查询所有数据不分页 * 查询所有数据不分页
* @param criteria 条件参数 * @param criteria 条件参数
* @return List<TbProductDto> * @return List<TbProductDto>
*/ */
List<TbProductDto> queryAll(TbProductQueryCriteria criteria); List<TbProductDto> queryAlls(TbProductQueryCriteria criteria);
/** /**
* 根据ID查询 * 根据ID查询

View File

@@ -35,17 +35,16 @@ public interface TbShopInfoService {
/** /**
* 查询数据分页 * 查询数据分页
* @param criteria 条件 * @param criteria 条件
* @param pageable 分页参数
* @return Map<String,Object> * @return Map<String,Object>
*/ */
Map<String,Object> queryAll(TbShopInfoQueryCriteria criteria, Pageable pageable); Map<String,Object> queryAll(TbShopInfoQueryCriteria criteria);
/** /**
* 查询所有数据不分页 * 查询所有数据不分页
* @param criteria 条件参数 * @param criteria 条件参数
* @return List<TbShopInfoDto> * @return List<TbShopInfoDto>
*/ */
List<TbShopInfoDto> queryAll(TbShopInfoQueryCriteria criteria); // List<TbShopInfoDto> queryAll(TbShopInfoQueryCriteria criteria);
/** /**
* 根据ID查询 * 根据ID查询

View File

@@ -66,7 +66,7 @@ public class TbProductVo {
private String shareImg; private String shareImg;
private String images; private List<String> images;
private String video; private String video;

View File

@@ -5,7 +5,7 @@ spring:
freemarker: freemarker:
check-template-location: false check-template-location: false
profiles: profiles:
active: @env@ active: dev
jackson: jackson:
time-zone: GMT+8 time-zone: GMT+8