收银后台跟进1.10

This commit is contained in:
liuyingfang 2024-01-10 14:42:55 +08:00
parent acffdcac01
commit 1c6573ac75
23 changed files with 260 additions and 27 deletions

View File

@ -0,0 +1,28 @@
package me.zhengjie.utils;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.util.ArrayList;
import java.util.List;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
/**
* @author lyf
*/
public class ListUtil {
public static JSONArray stringChangeList(String listString){
// 使用Fastjson将JSON字符串转换为JSONArray对象
return JSON.parseArray(listString);
}
}

View File

@ -16,8 +16,11 @@
package me.zhengjie.utils;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.config.ElAdminProperties;
import net.dreamlu.mica.ip2region.core.Ip2regionSearcher;
@ -28,10 +31,12 @@ import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.UnknownHostException;
import java.util.Calendar;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.*;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import java.util.List;
/**
* @author Zheng Jie
@ -263,6 +268,11 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
}
}
/**
* String转hashmap
* @param mapString
* @return
*/
public static HashMap<String,Object> stringChangeMap(String mapString){
JSONObject jsonObject = new JSONObject(mapString);

View File

@ -51,7 +51,7 @@ public class TbShopCategory implements Serializable {
@Column(name = "`tree`")
@ApiModelProperty(value = "分类层级")
private String tree;
private Integer tree;
@Column(name = "`pid`")
@ApiModelProperty(value = "上级分类id-为0则表示是顶级")

View File

@ -16,8 +16,14 @@
package me.zhengjie.modules.productInfo.productCategory.repository;
import me.zhengjie.modules.productInfo.productCategory.domain.TbShopCategory;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Page;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.domain.Pageable;
import java.util.List;
/**
* @website https://eladmin.vip
@ -25,4 +31,13 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
* @date 2024-01-08
**/
public interface TbShopCategoryRepository extends JpaRepository<TbShopCategory, Integer>, JpaSpecificationExecutor<TbShopCategory> {
@Query("SELECT category FROM TbShopCategory category where category.name = :name and category.shopId = :shopId")
TbShopCategory findByName(@Param("name") String name,@Param("shopId") String shopId);
@Query("SELECT category FROM TbShopCategory category where category.tree IN :ids and category.id != category.tree")
List<TbShopCategory> findChildren(@Param("ids")List<Integer> ids);
@Query(" SELECT category FROM TbShopCategory category where category.shopId = :shopId and category.id = category.tree")
Page<TbShopCategory> findAllBy(@Param("shopId") String shopId,Pageable pageable);
}

View File

@ -81,6 +81,7 @@ public class TbShopCategoryController {
@ApiOperation("删除product/category")
@PreAuthorize("@el.check('tbShopCategory:del')")
public ResponseEntity<Object> deleteTbShopCategory(@RequestBody Integer[] ids) {
tbShopCategoryService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}

View File

@ -59,7 +59,7 @@ public interface TbShopCategoryService {
* @param resources /
* @return TbShopCategoryDto
*/
TbShopCategoryDto create(TbShopCategory resources);
TbShopCategory create(TbShopCategory resources);
/**
* 编辑

View File

@ -15,8 +15,14 @@
*/
package me.zhengjie.modules.productInfo.productCategory.service.dto;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import lombok.Data;
import me.zhengjie.modules.productInfo.productCategory.domain.TbShopCategory;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
/**
* @website https://eladmin.vip
@ -37,7 +43,7 @@ public class TbShopCategoryDto implements Serializable {
private String shortName;
/** 分类层级 */
private String tree;
private Integer tree;
/** 上级分类id-为0则表示是顶级 */
private String pid;
@ -69,4 +75,12 @@ public class TbShopCategoryDto implements Serializable {
private Long createdAt;
private Long updatedAt;
/**
* 子分类
*/
private List<TbShopCategory> childrenList = new ArrayList<>();
public void copy(TbShopCategory source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}

View File

@ -38,4 +38,8 @@ public class TbShopCategoryQueryCriteria{
/** 精确 */
@Query
private String shopId;
private String tree;
}

View File

@ -15,6 +15,8 @@
*/
package me.zhengjie.modules.productInfo.productCategory.service.impl;
import cn.hutool.core.bean.BeanUtil;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.productInfo.productCategory.domain.TbShopCategory;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.utils.FileUtil;
@ -24,18 +26,24 @@ import me.zhengjie.modules.productInfo.productCategory.service.TbShopCategorySer
import me.zhengjie.modules.productInfo.productCategory.service.dto.TbShopCategoryDto;
import me.zhengjie.modules.productInfo.productCategory.service.dto.TbShopCategoryQueryCriteria;
import me.zhengjie.modules.productInfo.productCategory.service.mapstruct.TbShopCategoryMapper;
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.transaction.annotation.Transactional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.prefs.BackingStoreException;
/**
* @website https://eladmin.vip
@ -52,8 +60,38 @@ public class TbShopCategoryServiceImpl implements TbShopCategoryService {
@Override
public Map<String,Object> queryAll(TbShopCategoryQueryCriteria criteria, Pageable pageable){
Page<TbShopCategory> page = tbShopCategoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(tbShopCategoryMapper::toDto));
// Page<TbShopCategory> page = tbShopCategoryRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
PageRequest.of(0, 10, Sort.by("sort"));
Page<TbShopCategory> page = tbShopCategoryRepository.findAllBy(criteria.getShopId(), pageable);
tbShopCategoryRepository.findAllBy(criteria.getShopId(),pageable);
List<Integer> treeId = new ArrayList<>();
for (TbShopCategory category : page.getContent()) {
Integer ids = category.getId();
treeId.add(ids);
}
//找到子分类
List<TbShopCategory> children = tbShopCategoryRepository.findChildren(treeId);
if (children.isEmpty()){
return PageUtil.toPage(page.map(tbShopCategoryMapper::toDto));
}
List<TbShopCategoryDto> dto = new ArrayList<>();
for (TbShopCategory category : page.getContent()) {
List<TbShopCategory> tbShopCategoryChildren = new ArrayList<>();
for (TbShopCategory tbShopCategory :children) {
if (tbShopCategory.getTree().equals(category.getId())){
tbShopCategoryChildren.add(tbShopCategory);
}
}
TbShopCategoryDto tbShopCategoryDto = new TbShopCategoryDto();
tbShopCategoryDto.setChildrenList(tbShopCategoryChildren);
BeanUtils.copyProperties(category, tbShopCategoryDto);
dto.add(tbShopCategoryDto);
}
return PageUtil.toPage(dto, dto.size());
}
@Override
@ -71,14 +109,35 @@ public class TbShopCategoryServiceImpl implements TbShopCategoryService {
@Override
@Transactional(rollbackFor = Exception.class)
public TbShopCategoryDto create(TbShopCategory resources) {
return tbShopCategoryMapper.toDto(tbShopCategoryRepository.save(resources));
public TbShopCategory create(TbShopCategory resources) {
resources.setCreatedAt(Instant.now().toEpochMilli());
resources.setUpdatedAt(Instant.now().toEpochMilli());
TbShopCategoryDto dto = tbShopCategoryMapper.toDto(tbShopCategoryRepository.save(resources));
if (resources.getPid() == null || "".equals(resources.getPid())){
resources.setTree(resources.getId());
}else {
resources.setTree(Integer.valueOf(resources.getPid().trim()));
}
ValidationUtil.isNull( dto.getId(),"TbShopCategory","id",resources.getId());
tbShopCategoryRepository.save(resources);
return tbShopCategoryRepository.save(resources);
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(TbShopCategory resources) {
TbShopCategory tbShopCategory = tbShopCategoryRepository.findById(resources.getId()).orElseGet(TbShopCategory::new);
if (resources.getName() == null || resources.getShopId() == null){
throw new BadRequestException("必要参数为空");
}
TbShopCategory byName = tbShopCategoryRepository.findByName(resources.getName(), resources.getShopId());
if (byName != null){
throw new BadRequestException("分类名称重复");
}
resources.setUpdatedAt(Instant.now().toEpochMilli());
ValidationUtil.isNull( tbShopCategory.getId(),"TbShopCategory","id",resources.getId());
tbShopCategory.copy(resources);
tbShopCategoryRepository.save(tbShopCategory);

View File

@ -51,7 +51,7 @@ public class TbProductGroup implements Serializable {
@Column(name = "`shop_id`")
@ApiModelProperty(value = "店铺Id")
private String shopId;
private Integer shopId;
@Column(name = "`pic`")
@ApiModelProperty(value = "图标")

View File

@ -37,7 +37,7 @@ public class TbProductGroupDto implements Serializable {
private String merchantId;
/** 店铺Id */
private String shopId;
private Integer shopId;
/** 图标 */
private String pic;

View File

@ -26,4 +26,9 @@ import me.zhengjie.annotation.Query;
**/
@Data
public class TbProductGroupQueryCriteria{
@Query
private Integer shopId;
@Query
private String name;
}

View File

@ -63,6 +63,8 @@ public class TbProductGroupServiceImpl implements TbProductGroupService {
public Map<String,Object> queryAll(TbProductGroupQueryCriteria criteria, Pageable pageable){
Page<TbProductGroup> page = tbProductGroupRepository.findAll((root, criteriaQuery, criteriaBuilder) ->
QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(tbProductGroupMapper::toDto));
}

View File

@ -35,4 +35,7 @@ public interface TbProductSpecRepository extends JpaRepository<TbProductSpec, In
@Query("SELECT spec FROM TbProductSpec spec WHERE spec.id = :ids")
TbProductSpec searchSpec(@Param("ids")Integer ids);
@Query("SELECT spec FROM TbProductSpec spec WHERE spec.shopId = :shopId and spec.name = :name")
TbProductSpec findAllByName(@Param("shopId")String shopId, @Param("name")String name);
}

View File

@ -18,6 +18,7 @@ package me.zhengjie.modules.productInfo.productSpec.rest;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.productInfo.productSpec.domain.TbProductSpec;
import me.zhengjie.modules.productInfo.productSpec.service.TbProductSpecService;
import me.zhengjie.modules.productInfo.productSpec.service.dto.SpecDto;
import me.zhengjie.modules.productInfo.productSpec.service.dto.TbProductSpecQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
@ -63,7 +64,7 @@ public class TbProductSpecController {
@Log("新增product/spec")
@ApiOperation("新增product/spec")
@PreAuthorize("@el.check('tbProductSpec:add')")
public ResponseEntity<Object> createTbProductSpec(@Validated @RequestBody TbProductSpec resources){
public ResponseEntity<Object> createTbProductSpec(@Validated @RequestBody SpecDto resources){
return new ResponseEntity<>(tbProductSpecService.create(resources),HttpStatus.CREATED);
}

View File

@ -15,6 +15,7 @@
*/
package me.zhengjie.modules.productInfo.productSpec.service;
import me.zhengjie.modules.productInfo.productSpec.service.dto.SpecDto;
import me.zhengjie.modules.productInfo.productSpec.service.dto.TbProductSpecDto;
import me.zhengjie.modules.productInfo.productSpec.service.dto.TbProductSpecQueryCriteria;
import me.zhengjie.modules.productInfo.productSpec.domain.TbProductSpec;
@ -59,7 +60,7 @@ public interface TbProductSpecService {
* @param resources /
* @return TbProductSpecDto
*/
TbProductSpecDto create(TbProductSpec resources);
TbProductSpecDto create(SpecDto resources);
/**
* 编辑

View File

@ -0,0 +1,37 @@
package me.zhengjie.modules.productInfo.productSpec.service.VO;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.Data;
import java.util.HashMap;
import java.util.List;
/**
* @author lyf
*/
@Data
public class TbProductSpecVo {
/** id */
private Integer id;
private String shopId;
/** 商品属性名称 */
private String name;
/** 规格属性 */
private String specTag;
/** 属性介绍 */
private String specTagDetail;
private JSONArray specList;
/** 排序 */
private Integer sort;
private Long createdAt;
private Long updatedAt;
}

View File

@ -0,0 +1,22 @@
package me.zhengjie.modules.productInfo.productSpec.service.dto;
import lombok.Data;
import java.util.List;
/**
* @author lyf
*/
@Data
public class SpecDto {
/**
* 规格名称
*/
private String name;
/**
* shopId
*/
private String shopId;
private List<String> specList;
}

View File

@ -26,4 +26,9 @@ import me.zhengjie.annotation.Query;
**/
@Data
public class TbProductSpecQueryCriteria{
/**
* shopId
*/
@Query
private String shopId;
}

View File

@ -15,21 +15,24 @@
*/
package me.zhengjie.modules.productInfo.productSpec.service.impl;
import me.zhengjie.exception.BadRequestException;
import me.zhengjie.modules.productInfo.productSpec.domain.TbProductSpec;
import me.zhengjie.modules.productInfo.productSpec.repository.TbProductSpecRepository;
import me.zhengjie.modules.productInfo.productSpec.service.TbProductSpecService;
import me.zhengjie.modules.productInfo.productSpec.service.VO.TbProductSpecVo;
import me.zhengjie.modules.productInfo.productSpec.service.dto.SpecDto;
import me.zhengjie.modules.productInfo.productSpec.service.dto.TbProductSpecDto;
import me.zhengjie.modules.productInfo.productSpec.service.dto.TbProductSpecQueryCriteria;
import me.zhengjie.utils.ValidationUtil;
import me.zhengjie.utils.FileUtil;
import me.zhengjie.utils.*;
import lombok.RequiredArgsConstructor;
import me.zhengjie.modules.productInfo.productSpec.service.mapstruct.TbProductSpecMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import me.zhengjie.utils.PageUtil;
import me.zhengjie.utils.QueryHelp;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.io.IOException;
@ -52,8 +55,17 @@ public class TbProductSpecServiceImpl implements TbProductSpecService {
@Override
public Map<String,Object> queryAll(TbProductSpecQueryCriteria criteria, Pageable pageable){
Page<TbProductSpec> page = tbProductSpecRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(tbProductSpecMapper::toDto));
List<TbProductSpecVo> specList = new ArrayList<>();
for (TbProductSpec spec :page.getContent()) {
TbProductSpecVo specVo = new TbProductSpecVo();
specVo.setSpecList(ListUtil.stringChangeList(spec.getSpecList()));
BeanUtils.copyProperties(spec, specVo);
specList.add(specVo);
}
return PageUtil.toPage(specList, specList.size());
}
@Override
@ -71,14 +83,28 @@ public class TbProductSpecServiceImpl implements TbProductSpecService {
@Override
@Transactional(rollbackFor = Exception.class)
public TbProductSpecDto create(TbProductSpec resources) {
return tbProductSpecMapper.toDto(tbProductSpecRepository.save(resources));
public TbProductSpecDto create(SpecDto specDto) {
TbProductSpec allByName = tbProductSpecRepository.findAllByName(specDto.getShopId(), specDto.getName());
if (allByName != null){
throw new BadRequestException("规格名称重复");
}
TbProductSpec tbProductSpec = new TbProductSpec();
tbProductSpec.setName(specDto.getName());
tbProductSpec.setSpecList(specDto.getSpecList().toString().trim());
tbProductSpec.setShopId(specDto.getShopId());
tbProductSpec.setCreatedAt(Instant.now().toEpochMilli());
tbProductSpec.setUpdatedAt(Instant.now().toEpochMilli());
return tbProductSpecMapper.toDto(tbProductSpecRepository.save(tbProductSpec));
}
@Override
@Transactional(rollbackFor = Exception.class)
public void update(TbProductSpec resources) {
TbProductSpec tbProductSpec = tbProductSpecRepository.findById(resources.getId()).orElseGet(TbProductSpec::new);
TbProductSpec allByName = tbProductSpecRepository.findAllByName(resources.getShopId(), resources.getName());
if (allByName != null){
throw new BadRequestException("规格名称重复");
}
ValidationUtil.isNull( tbProductSpec.getId(),"TbProductSpec","id",resources.getId());
tbProductSpec.copy(resources);
tbProductSpecRepository.save(tbProductSpec);

View File

@ -71,7 +71,7 @@ public class TbShopUnitController {
@Log("修改/shop/unit")
@ApiOperation("修改/shop/unit")
@PreAuthorize("@el.check('tbShopUnit:edit')")
public ResponseEntity<Object> updateTbShopUnit(@Validated @RequestBody TbShopUnit resources)throws Exception{
public ResponseEntity<Object> updateTbShopUnit(@Validated @RequestBody TbShopUnit resources){
tbShopUnitService.update(resources);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}

View File

@ -59,13 +59,13 @@ public interface TbShopUnitService {
* @param resources /
* @return TbShopUnitDto
*/
TbShopUnitDto create(TbShopUnit resources)throws Exception;
TbShopUnitDto create(TbShopUnit resources);
/**
* 编辑
* @param resources /
*/
void update(TbShopUnit resources)throws Exception;
void update(TbShopUnit resources);
/**
* 多选删除

View File

@ -76,7 +76,7 @@ public class TbShopUnitServiceImpl implements TbShopUnitService {
@Override
@Transactional(rollbackFor = Exception.class)
public TbShopUnitDto create(TbShopUnit resources)throws Exception{
public TbShopUnitDto create(TbShopUnit resources){
TbShopUnit name = tbShopUnitRepository.findName(resources.getName(), resources.getShopId());
if (name != null){
@ -93,7 +93,7 @@ public class TbShopUnitServiceImpl implements TbShopUnitService {
@Override
@Transactional(rollbackFor = Exception.class)
public void update(TbShopUnit resources) throws Exception{
public void update(TbShopUnit resources) {
TbShopUnit tbShopUnit = tbShopUnitRepository.findById(resources.getId()).orElseGet(TbShopUnit::new);
TbShopUnit name = tbShopUnitRepository.findName(resources.getName(), resources.getShopId());
if (name != null){