diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/PageUtil.java b/eladmin-common/src/main/java/me/zhengjie/utils/PageUtil.java index 44db68dd..90838f30 100644 --- a/eladmin-common/src/main/java/me/zhengjie/utils/PageUtil.java +++ b/eladmin-common/src/main/java/me/zhengjie/utils/PageUtil.java @@ -50,6 +50,7 @@ public class PageUtil extends cn.hutool.core.util.PageUtil { return map; } + /** * 自定义分页 */ diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/mapstruct/TbProductGroupMapper.xml b/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/mapstruct/TbProductGroupMapper.xml deleted file mode 100644 index 01454082..00000000 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/mapstruct/TbProductGroupMapper.xml +++ /dev/null @@ -1,199 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - insert into tb_product_group(name, merchant_id, shop_id, pic, is_show, detail, style, sort, product_ids, created_at, updated_at) - values (#{name}, #{merchantId}, #{shopId}, #{pic}, #{isShow}, #{detail}, #{style}, #{sort}, #{productIds}, #{createdAt}, #{updatedAt}) - - - - insert into tb_product_group(name, merchant_id, shop_id, pic, is_show, detail, style, sort, product_ids, created_at, updated_at) - values - - (#{entity.name}, #{entity.merchantId}, #{entity.shopId}, #{entity.pic}, #{entity.isShow}, #{entity.detail}, #{entity.style}, #{entity.sort}, #{entity.productIds}, #{entity.createdAt}, #{entity.updatedAt}) - - - - - insert into tb_product_group(name, merchant_id, shop_id, pic, is_show, detail, style, sort, product_ids, created_at, updated_at) - values - - (#{entity.name}, #{entity.merchantId}, #{entity.shopId}, #{entity.pic}, #{entity.isShow}, #{entity.detail}, #{entity.style}, #{entity.sort}, #{entity.productIds}, #{entity.createdAt}, #{entity.updatedAt}) - - on duplicate key update - name = values(name), - merchant_id = values(merchant_id), - shop_id = values(shop_id), - pic = values(pic), - is_show = values(is_show), - detail = values(detail), - style = values(style), - sort = values(sort), - product_ids = values(product_ids), - created_at = values(created_at), - updated_at = values(updated_at) - - - - - update tb_product_group - - - name = #{name}, - - - merchant_id = #{merchantId}, - - - shop_id = #{shopId}, - - - pic = #{pic}, - - - is_show = #{isShow}, - - - detail = #{detail}, - - - style = #{style}, - - - sort = #{sort}, - - - product_ids = #{productIds}, - - - created_at = #{createdAt}, - - - updated_at = #{updatedAt}, - - - where id = #{id} - - - - - delete from tb_product_group where id = #{id} - - - - diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/product/domain/TbProduct.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/domain/TbProduct.java similarity index 99% rename from eladmin-system/src/main/java/me/zhengjie/modules/product/domain/TbProduct.java rename to eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/domain/TbProduct.java index 051a62c7..6a581898 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/product/domain/TbProduct.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/domain/TbProduct.java @@ -13,12 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.zhengjie.modules.product.domain; +package me.zhengjie.modules.productInfo.product.domain; import lombok.Data; import cn.hutool.core.bean.BeanUtil; import io.swagger.annotations.ApiModelProperty; import cn.hutool.core.bean.copier.CopyOptions; + import javax.persistence.*; import javax.validation.constraints.*; import java.math.BigDecimal; @@ -292,7 +293,6 @@ public class TbProduct implements Serializable { @Column(name = "`tax_config_id`") @ApiModelProperty(value = "税率") private String taxConfigId; - public void copy(TbProduct source){ BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/domain/TbProductVo.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/domain/TbProductVo.java new file mode 100644 index 00000000..f33d1f61 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/domain/TbProductVo.java @@ -0,0 +1,210 @@ +package me.zhengjie.modules.productInfo.product.domain; + +import lombok.Data; +import me.zhengjie.modules.productInfo.productSku.domain.TbProductSku; + +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.List; + +/** + * @author lyf + */ +@Data +public class TbProductVo { + + + private Integer id; + + + private String sourcePath; + + + private String merchantId; + + + private String shopId; + + + private String name; + + private String type; + + + private BigDecimal packFee; + + + private BigDecimal lowPrice; + + + private String unitId; + + + private String coverImg; + + + private String categoryId; + + + private Integer specId; + + + private Integer brandId; + + + private String shortTitle; + + + private BigDecimal lowMemberPrice; + + + private String unitSnap; + + + private String shareImg; + + + private String images; + + + private String video; + + + private String videoCoverImg; + + + private Integer sort; + + + private Integer limitNumber; + + + private Integer productScore; + + + private Integer status; + + + private String failMsg; + + + private Integer isRecommend; + + + private Integer isHot; + + + private Integer isNew; + + + private Integer isOnSale; + + + private Integer isShow; + + + private String typeEnum; + + + private Integer isDistribute; + + + private Integer isDel; + + + private Integer isStock; + + + private Integer isPauseSale; + + + private Integer isFreeFreight; + + + private Long freightId; + + + private String strategyType; + + + private Integer strategyId; + + + private Integer isVip; + + + private Integer isDelete; + + + private String notice; + + + private Long createdAt; + + + private Long updatedAt; + + + private Double baseSalesNumber; + + + private Integer realSalesNumber; + + + private Integer salesNumber; + + private Integer thumbCount; + + + private Integer storeCount; + + + private Integer furnishMeal; + + + private Integer furnishExpress; + + + private Integer furnishDraw; + + + private Integer furnishVir; + + + private Integer isCombo; + + + private String groupSnap; + + + private Integer isShowCash; + + + private Integer isShowMall; + + + private Integer isNeedExamine; + + + private Integer showOnMallStatus; + + + private Long showOnMallTime; + + private String showOnMallErrorMsg; + + + private Integer enableLabel; + + + + private String taxConfigId; + + + + private String unitName; + + private List skuList; + + private HashMap specsInfo; +} diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/product/repository/TbProductRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/repository/TbProductRepository.java similarity index 87% rename from eladmin-system/src/main/java/me/zhengjie/modules/product/repository/TbProductRepository.java rename to eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/repository/TbProductRepository.java index 0108c22b..836e3795 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/product/repository/TbProductRepository.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/repository/TbProductRepository.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.zhengjie.modules.product.repository; +package me.zhengjie.modules.productInfo.product.repository; -import me.zhengjie.modules.product.domain.TbProduct; +import me.zhengjie.modules.productInfo.product.domain.TbProduct; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/product/rest/TbProductController.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/rest/TbProductController.java similarity index 91% rename from eladmin-system/src/main/java/me/zhengjie/modules/product/rest/TbProductController.java rename to eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/rest/TbProductController.java index 2e96dfcc..74dfd1c6 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/product/rest/TbProductController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/rest/TbProductController.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.zhengjie.modules.product.rest; +package me.zhengjie.modules.productInfo.product.rest; import me.zhengjie.annotation.Log; -import me.zhengjie.modules.product.domain.TbProduct; -import me.zhengjie.modules.product.service.TbProductService; -import me.zhengjie.modules.product.service.dto.TbProductQueryCriteria; +import me.zhengjie.modules.productInfo.product.domain.TbProduct; +import me.zhengjie.modules.productInfo.product.service.TbProductService; +import me.zhengjie.modules.productInfo.product.service.dto.TbProductQueryCriteria; import org.springframework.data.domain.Pageable; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/product/service/TbProductService.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/TbProductService.java similarity index 87% rename from eladmin-system/src/main/java/me/zhengjie/modules/product/service/TbProductService.java rename to eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/TbProductService.java index 73d4484b..c98905df 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/product/service/TbProductService.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/TbProductService.java @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.zhengjie.modules.product.service; +package me.zhengjie.modules.productInfo.product.service; -import me.zhengjie.modules.product.domain.TbProduct; -import me.zhengjie.modules.product.service.dto.TbProductDto; -import me.zhengjie.modules.product.service.dto.TbProductQueryCriteria; +import me.zhengjie.modules.productInfo.product.domain.TbProduct; +import me.zhengjie.modules.productInfo.product.service.dto.TbProductDto; +import me.zhengjie.modules.productInfo.product.service.dto.TbProductQueryCriteria; import org.springframework.data.domain.Pageable; import java.util.Map; import java.util.List; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/product/service/dto/TbProductDto.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/dto/TbProductDto.java similarity index 95% rename from eladmin-system/src/main/java/me/zhengjie/modules/product/service/dto/TbProductDto.java rename to eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/dto/TbProductDto.java index 20c07c77..5780a116 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/product/service/dto/TbProductDto.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/dto/TbProductDto.java @@ -13,11 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.zhengjie.modules.product.service.dto; +package me.zhengjie.modules.productInfo.product.service.dto; import lombok.Data; +import me.zhengjie.modules.productInfo.productSku.domain.TbProductSku; + import java.math.BigDecimal; import java.io.Serializable; +import java.util.List; /** * @website https://eladmin.vip @@ -210,4 +213,8 @@ public class TbProductDto implements Serializable { /** 税率 */ private String taxConfigId; + /** + * 商品sku信息 + */ + private List skuList; } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/product/service/dto/TbProductQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/dto/TbProductQueryCriteria.java similarity index 97% rename from eladmin-system/src/main/java/me/zhengjie/modules/product/service/dto/TbProductQueryCriteria.java rename to eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/dto/TbProductQueryCriteria.java index 5d166a7f..09af5739 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/product/service/dto/TbProductQueryCriteria.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/dto/TbProductQueryCriteria.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.zhengjie.modules.product.service.dto; +package me.zhengjie.modules.productInfo.product.service.dto; import lombok.Data; import java.math.BigDecimal; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/product/service/impl/TbProductServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/impl/TbProductServiceImpl.java similarity index 65% rename from eladmin-system/src/main/java/me/zhengjie/modules/product/service/impl/TbProductServiceImpl.java rename to eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/impl/TbProductServiceImpl.java index b84d7785..d73d8fc4 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/product/service/impl/TbProductServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/impl/TbProductServiceImpl.java @@ -13,29 +13,35 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.zhengjie.modules.product.service.impl; +package me.zhengjie.modules.productInfo.product.service.impl; -import me.zhengjie.modules.product.domain.TbProduct; +import me.zhengjie.modules.productInfo.product.domain.TbProduct; +import me.zhengjie.modules.productInfo.product.domain.TbProductVo; +import me.zhengjie.modules.productInfo.product.repository.TbProductRepository; +import me.zhengjie.modules.productInfo.product.service.TbProductService; +import me.zhengjie.modules.productInfo.product.service.dto.TbProductDto; +import me.zhengjie.modules.productInfo.product.service.dto.TbProductQueryCriteria; +import me.zhengjie.modules.productInfo.product.service.mapstruct.TbProductMapper; +import me.zhengjie.modules.productInfo.productSpec.domain.TbProductSpec; +import me.zhengjie.modules.productInfo.productSpec.repository.TbProductSpecRepository; +import me.zhengjie.modules.productInfo.productSku.domain.TbProductSku; +import me.zhengjie.modules.productInfo.productSku.repository.TbProductSkuRepository; +import me.zhengjie.modules.shopUnit.domain.TbShopUnit; +import me.zhengjie.modules.shopUnit.repository.TbShopUnitRepository; import me.zhengjie.utils.ValidationUtil; import me.zhengjie.utils.FileUtil; import lombok.RequiredArgsConstructor; -import me.zhengjie.modules.product.repository.TbProductRepository; -import me.zhengjie.modules.product.service.TbProductService; -import me.zhengjie.modules.product.service.dto.TbProductDto; -import me.zhengjie.modules.product.service.dto.TbProductQueryCriteria; -import me.zhengjie.modules.product.service.mapstruct.TbProductMapper; +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.util.List; -import java.util.Map; + +import java.util.*; import java.io.IOException; import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; -import java.util.LinkedHashMap; /** * @website https://eladmin.vip @@ -49,11 +55,80 @@ public class TbProductServiceImpl implements TbProductService { private final TbProductRepository tbProductRepository; private final TbProductMapper tbProductMapper; + private final TbProductSkuRepository tbProductSkuRepository; + private final TbShopUnitRepository tbShopUnitRepository; + private final TbProductSpecRepository tbProductSpecRepository; @Override public Map queryAll(TbProductQueryCriteria criteria, Pageable pageable){ + //查询商品数据 Page page = tbProductRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); - return PageUtil.toPage(page.map(tbProductMapper::toDto)); + List productId = new ArrayList<>(); + List unitId = new ArrayList<>(); + List specId = new ArrayList<>(); + for (TbProduct product : page.getContent()) { + //记录商品id + productId.add(product.getId().toString()); + //记录单位id + if (product.getUnitId() != null){ + unitId.add(Integer.valueOf(product.getUnitId())); + } + //记录规格id + specId.add(product.getSpecId()); + } + //sku + List tbProductSkus = tbProductSkuRepository.searchSku(productId); + //单位 + List tbShopUnits = new ArrayList<>(); + if (!unitId.isEmpty()){ + tbShopUnits = tbShopUnitRepository.searchUnit(unitId); + } + //商品规格 + List tbProductSpecs = new ArrayList<>(); + if (!specId.isEmpty()) { + tbProductSpecs = tbProductSpecRepository.searchSpec(specId); + } + //组装 + List tbProductVoList = new ArrayList<>(); + for (TbProduct product : page.getContent()) { + List skuList = new ArrayList<>(); + TbProductVo tbProductVo = new TbProductVo(); + //sku + for (TbProductSku sku : tbProductSkus) { + //sku + if (sku.getProductId().equals(product.getId().toString())){ + skuList.add(sku); + } + } + tbProductVo.setSkuList(skuList); + //单位 + if (tbShopUnits.isEmpty()){ + tbProductVo.setUnitName(""); + }else { + for (TbShopUnit tbShopUnit : tbShopUnits) { + if(tbShopUnit.getId().toString().equals(product.getUnitId())){ + tbProductVo.setUnitName(tbShopUnit.getName()); + } + } + } + //商品规格 + if (tbProductSpecs.isEmpty()){ + tbProductVo.setSpecsInfo(new HashMap<>()); + }else { + for (TbProductSpec spec :tbProductSpecs) { + if (spec.getId().equals(product.getSpecId())){ + HashMap specsMap = new HashMap<>(); + specsMap.put(spec.getName(),spec.getSpecList()); + tbProductVo.setSpecsInfo(specsMap); + } + } + } + + BeanUtils.copyProperties(product, tbProductVo); + tbProductVoList.add(tbProductVo); + } + System.out.println(tbProductVoList); + return PageUtil.toPage(tbProductVoList,tbProductVoList.size()); } @Override diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/product/service/mapstruct/TbProductMapper.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/mapstruct/TbProductMapper.java similarity index 81% rename from eladmin-system/src/main/java/me/zhengjie/modules/product/service/mapstruct/TbProductMapper.java rename to eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/mapstruct/TbProductMapper.java index 4082e439..87e7c109 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/product/service/mapstruct/TbProductMapper.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/product/service/mapstruct/TbProductMapper.java @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.zhengjie.modules.product.service.mapstruct; +package me.zhengjie.modules.productInfo.product.service.mapstruct; import me.zhengjie.base.BaseMapper; -import me.zhengjie.modules.product.domain.TbProduct; -import me.zhengjie.modules.product.service.dto.TbProductDto; +import me.zhengjie.modules.productInfo.product.domain.TbProduct; +import me.zhengjie.modules.productInfo.product.service.dto.TbProductDto; import org.mapstruct.Mapper; import org.mapstruct.ReportingPolicy; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/domain/TbProductGroup.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/domain/TbProductGroup.java similarity index 97% rename from eladmin-system/src/main/java/me/zhengjie/modules/productGroup/domain/TbProductGroup.java rename to eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/domain/TbProductGroup.java index 85d0868c..1320d547 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/domain/TbProductGroup.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/domain/TbProductGroup.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.zhengjie.modules.productGroup.domain; +package me.zhengjie.modules.productInfo.productGroup.domain; import lombok.Data; import cn.hutool.core.bean.BeanUtil; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/repository/TbProductGroupRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/repository/TbProductGroupRepository.java similarity index 86% rename from eladmin-system/src/main/java/me/zhengjie/modules/productGroup/repository/TbProductGroupRepository.java rename to eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/repository/TbProductGroupRepository.java index e7f63fb3..e8214dd6 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/repository/TbProductGroupRepository.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/repository/TbProductGroupRepository.java @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.zhengjie.modules.productGroup.repository; +package me.zhengjie.modules.productInfo.productGroup.repository; -import me.zhengjie.modules.productGroup.domain.TbProductGroup; +import me.zhengjie.modules.productInfo.productGroup.domain.TbProductGroup; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaSpecificationExecutor; -import org.springframework.data.jpa.repository.Query; /** * @website https://eladmin.vip diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/rest/TbProductGroupController.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/rest/TbProductGroupController.java similarity index 85% rename from eladmin-system/src/main/java/me/zhengjie/modules/productGroup/rest/TbProductGroupController.java rename to eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/rest/TbProductGroupController.java index 433d144e..4153b8bd 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/rest/TbProductGroupController.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/rest/TbProductGroupController.java @@ -13,16 +13,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.zhengjie.modules.productGroup.rest; +package me.zhengjie.modules.productInfo.productGroup.rest; import me.zhengjie.annotation.Log; -import me.zhengjie.modules.product.domain.TbProduct; -import me.zhengjie.modules.product.service.TbProductService; -import me.zhengjie.modules.product.service.dto.TbProductQueryCriteria; -import me.zhengjie.modules.productGroup.domain.TbProductGroup; -import me.zhengjie.modules.productGroup.service.TbProductGroupService; -import me.zhengjie.modules.productGroup.service.dto.TbProductGroupQueryCriteria; -import me.zhengjie.modules.productGroup.service.vo.AddProduct; +import me.zhengjie.modules.productInfo.product.service.TbProductService; +import me.zhengjie.modules.productInfo.product.service.dto.TbProductQueryCriteria; +import me.zhengjie.modules.productInfo.productGroup.domain.TbProductGroup; +import me.zhengjie.modules.productInfo.productGroup.service.TbProductGroupService; +import me.zhengjie.modules.productInfo.productGroup.service.dto.TbProductGroupQueryCriteria; +import me.zhengjie.modules.productInfo.productGroup.service.vo.AddProduct; import org.springframework.data.domain.Pageable; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -32,7 +31,6 @@ import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import io.swagger.annotations.*; import java.io.IOException; -import java.util.List; import javax.annotation.Resource; import javax.servlet.http.HttpServletResponse; @@ -103,6 +101,12 @@ public class TbProductGroupController { return new ResponseEntity<>(tbProductService.queryAll(criteria,pageable),HttpStatus.OK); } + /** + * 商品分类增加商品 + * @param addProduct + * @param userName + * @return + */ @PostMapping("/addProductInfo") public ResponseEntity addProductInfo(@RequestBody AddProduct addProduct,@RequestAttribute(value = "userName", required = false) String userName){ return new ResponseEntity<>(tbProductGroupService.updateProductIds(addProduct,userName),HttpStatus.OK); diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/TbProductGroupService.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/TbProductGroupService.java similarity index 83% rename from eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/TbProductGroupService.java rename to eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/TbProductGroupService.java index fc20eaf8..e86aa3ff 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/TbProductGroupService.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/TbProductGroupService.java @@ -13,12 +13,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.zhengjie.modules.productGroup.service; +package me.zhengjie.modules.productInfo.productGroup.service; -import me.zhengjie.modules.productGroup.domain.TbProductGroup; -import me.zhengjie.modules.productGroup.service.dto.TbProductGroupDto; -import me.zhengjie.modules.productGroup.service.dto.TbProductGroupQueryCriteria; -import me.zhengjie.modules.productGroup.service.vo.AddProduct; +import me.zhengjie.modules.productInfo.productGroup.domain.TbProductGroup; +import me.zhengjie.modules.productInfo.productGroup.service.dto.TbProductGroupDto; +import me.zhengjie.modules.productInfo.productGroup.service.dto.TbProductGroupQueryCriteria; +import me.zhengjie.modules.productInfo.productGroup.service.vo.AddProduct; import org.springframework.data.domain.Pageable; import org.springframework.http.ResponseEntity; @@ -84,5 +84,5 @@ public interface TbProductGroupService { */ void download(List all, HttpServletResponse response) throws IOException; - ResponseEntity updateProductIds(AddProduct addProduct,String userName); + ResponseEntity updateProductIds(AddProduct addProduct, String userName); } \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/dto/TbProductGroupDto.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/dto/TbProductGroupDto.java similarity index 95% rename from eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/dto/TbProductGroupDto.java rename to eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/dto/TbProductGroupDto.java index 3e1617fb..b185f7e4 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/dto/TbProductGroupDto.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/dto/TbProductGroupDto.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.zhengjie.modules.productGroup.service.dto; +package me.zhengjie.modules.productInfo.productGroup.service.dto; import lombok.Data; import java.io.Serializable; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/dto/TbProductGroupQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/dto/TbProductGroupQueryCriteria.java similarity index 92% rename from eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/dto/TbProductGroupQueryCriteria.java rename to eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/dto/TbProductGroupQueryCriteria.java index 4816085d..85d336db 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/dto/TbProductGroupQueryCriteria.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/dto/TbProductGroupQueryCriteria.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.zhengjie.modules.productGroup.service.dto; +package me.zhengjie.modules.productInfo.productGroup.service.dto; import lombok.Data; import java.util.List; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/impl/TbProductGroupServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/impl/TbProductGroupServiceImpl.java similarity index 86% rename from eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/impl/TbProductGroupServiceImpl.java rename to eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/impl/TbProductGroupServiceImpl.java index f8867a5d..a82329e6 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/impl/TbProductGroupServiceImpl.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/impl/TbProductGroupServiceImpl.java @@ -13,20 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.zhengjie.modules.productGroup.service.impl; +package me.zhengjie.modules.productInfo.productGroup.service.impl; -import me.zhengjie.modules.productGroup.domain.TbProductGroup; -import me.zhengjie.modules.productGroup.service.vo.AddProduct; +import me.zhengjie.modules.productInfo.productGroup.domain.TbProductGroup; +import me.zhengjie.modules.productInfo.productGroup.service.vo.AddProduct; +import me.zhengjie.modules.productInfo.productGroup.repository.TbProductGroupRepository; +import me.zhengjie.modules.productInfo.productGroup.service.dto.TbProductGroupDto; +import me.zhengjie.modules.productInfo.productGroup.service.dto.TbProductGroupQueryCriteria; import me.zhengjie.modules.security.service.OnlineUserService; import me.zhengjie.modules.security.service.dto.OnlineUserDto; import me.zhengjie.utils.ValidationUtil; import me.zhengjie.utils.FileUtil; import lombok.RequiredArgsConstructor; -import me.zhengjie.modules.productGroup.repository.TbProductGroupRepository; -import me.zhengjie.modules.productGroup.service.TbProductGroupService; -import me.zhengjie.modules.productGroup.service.dto.TbProductGroupDto; -import me.zhengjie.modules.productGroup.service.dto.TbProductGroupQueryCriteria; -import me.zhengjie.modules.productGroup.service.mapstruct.TbProductGroupMapper; +import me.zhengjie.modules.productInfo.productGroup.service.TbProductGroupService; +import me.zhengjie.modules.productInfo.productGroup.service.mapstruct.TbProductGroupMapper; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; @@ -122,15 +122,13 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { } @Override - public ResponseEntity updateProductIds(AddProduct addProduct,String userName) { + public ResponseEntity updateProductIds(AddProduct addProduct, String userName) { OnlineUserDto onlineUser = onlineUserService.getOne(addProduct.getKey()); - - if (addProduct.getIds().size()<1){ return new ResponseEntity<>("错误", HttpStatus.NOT_ACCEPTABLE); } - TbProductGroupDto productGroup = this.findById(addProduct.getProductId()); + TbProductGroupDto productGroup = this.findById(addProduct.getGroupId()); if (productGroup == null){ return new ResponseEntity<>("没有找到改分类", HttpStatus.NOT_ACCEPTABLE); @@ -138,14 +136,14 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { TbProductGroup tbProductGroup = new TbProductGroup(); StringBuilder sb = new StringBuilder(); // //如果没有 - if (productGroup.getProductIds() == null) { + if (productGroup.getProductIds() == null || "".equals(productGroup.getProductIds())) { for (String s : addProduct.getIds()) { sb.append(s); sb.append(","); } tbProductGroup.setProductIds(sb.toString()); - tbProductGroup.setId(addProduct.getProductId()); + tbProductGroup.setId(addProduct.getGroupId()); this.update(tbProductGroup); }else { //如果有 @@ -156,7 +154,7 @@ public class TbProductGroupServiceImpl implements TbProductGroupService { sb.append(productGroup.getProductIds()); tbProductGroup.setProductIds(sb.toString()); - tbProductGroup.setId(addProduct.getProductId()); + tbProductGroup.setId(addProduct.getGroupId()); this.update(tbProductGroup); } diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/mapstruct/TbProductGroupMapper.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/mapstruct/TbProductGroupMapper.java similarity index 80% rename from eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/mapstruct/TbProductGroupMapper.java rename to eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/mapstruct/TbProductGroupMapper.java index 49abb9a6..9b0c2377 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/mapstruct/TbProductGroupMapper.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/mapstruct/TbProductGroupMapper.java @@ -13,11 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package me.zhengjie.modules.productGroup.service.mapstruct; +package me.zhengjie.modules.productInfo.productGroup.service.mapstruct; import me.zhengjie.base.BaseMapper; -import me.zhengjie.modules.productGroup.domain.TbProductGroup; -import me.zhengjie.modules.productGroup.service.dto.TbProductGroupDto; +import me.zhengjie.modules.productInfo.productGroup.domain.TbProductGroup; +import me.zhengjie.modules.productInfo.productGroup.service.dto.TbProductGroupDto; import org.mapstruct.Mapper; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/vo/AddProduct.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/vo/AddProduct.java similarity index 65% rename from eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/vo/AddProduct.java rename to eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/vo/AddProduct.java index c05891eb..1012e0f4 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/productGroup/service/vo/AddProduct.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productGroup/service/vo/AddProduct.java @@ -1,4 +1,4 @@ -package me.zhengjie.modules.productGroup.service.vo; +package me.zhengjie.modules.productInfo.productGroup.service.vo; import lombok.Data; @@ -11,7 +11,7 @@ import java.util.List; public class AddProduct { List ids; - Integer productId; + Integer groupId; String key; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/domain/TbProductSku.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/domain/TbProductSku.java new file mode 100644 index 00000000..177ee296 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/domain/TbProductSku.java @@ -0,0 +1,132 @@ +/* +* 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.modules.productInfo.productSku.domain; + +import lombok.Data; +import cn.hutool.core.bean.BeanUtil; +import io.swagger.annotations.ApiModelProperty; +import cn.hutool.core.bean.copier.CopyOptions; +import javax.persistence.*; +import javax.validation.constraints.*; +import java.math.BigDecimal; +import java.io.Serializable; + +/** +* @website https://eladmin.vip +* @description / +* @author lyf +* @date 2024-01-03 +**/ +@Entity +@Data +@Table(name="tb_product_sku") +public class TbProductSku implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "`id`") + @ApiModelProperty(value = "自增id") + private Integer id; + + @Column(name = "`shop_id`") + @ApiModelProperty(value = "shopId") + private String shopId; + + @Column(name = "`bar_code`") + @ApiModelProperty(value = "条形码") + private String barCode; + + @Column(name = "`product_id`",nullable = false) + @NotBlank + @ApiModelProperty(value = "商品Id") + private String productId; + + @Column(name = "`origin_price`") + @ApiModelProperty(value = "原价") + private BigDecimal originPrice; + + @Column(name = "`cost_price`") + @ApiModelProperty(value = "成本价") + private BigDecimal costPrice; + + @Column(name = "`member_price`") + @ApiModelProperty(value = "会员价") + private BigDecimal memberPrice; + + @Column(name = "`meal_price`") + @ApiModelProperty(value = "mealPrice") + private BigDecimal mealPrice; + + @Column(name = "`sale_price`") + @ApiModelProperty(value = "售价") + private BigDecimal salePrice; + + @Column(name = "`guide_price`") + @ApiModelProperty(value = "进货参考价") + private BigDecimal guidePrice; + + @Column(name = "`strategy_price`") + @ApiModelProperty(value = "strategyPrice") + private BigDecimal strategyPrice; + + @Column(name = "`stock_number`") + @ApiModelProperty(value = "库存数量") + private Double stockNumber; + + @Column(name = "`spec_snap`") + @ApiModelProperty(value = "标签镜像") + private String specSnap; + + @Column(name = "`cover_img`") + @ApiModelProperty(value = "coverImg") + private String coverImg; + + @Column(name = "`warn_line`") + @ApiModelProperty(value = "库存警戒线") + private Integer warnLine; + + @Column(name = "`weight`") + @ApiModelProperty(value = "weight") + private Double weight; + + @Column(name = "`volume`") + @ApiModelProperty(value = "volume") + private Float volume; + + @Column(name = "`real_sales_number`") + @ApiModelProperty(value = "销量") + private Double realSalesNumber; + + @Column(name = "`first_shared`") + @ApiModelProperty(value = "一级分销金额") + private BigDecimal firstShared; + + @Column(name = "`second_shared`") + @ApiModelProperty(value = "二级分销金额") + private BigDecimal secondShared; + + @Column(name = "`created_at`") + @ApiModelProperty(value = "createdAt") + private Long createdAt; + + @Column(name = "`updated_at`") + @ApiModelProperty(value = "updatedAt") + private Long updatedAt; + + public void copy(TbProductSku source){ + BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); + } +} diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/domain/TbProductSkuVO.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/domain/TbProductSkuVO.java new file mode 100644 index 00000000..884e750b --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/domain/TbProductSkuVO.java @@ -0,0 +1,8 @@ +package me.zhengjie.modules.productInfo.productSku.domain; + +/** + * @author lyf + */ +public class TbProductSkuVO { + String realSalesNumber; +} diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/repository/TbProductSkuRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/repository/TbProductSkuRepository.java new file mode 100644 index 00000000..3accec3b --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/repository/TbProductSkuRepository.java @@ -0,0 +1,36 @@ +/* +* 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.modules.productInfo.productSku.repository; + +import me.zhengjie.modules.productInfo.productSku.domain.TbProductSku; +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.repository.query.Param; + +import java.util.List; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-03 +**/ +public interface TbProductSkuRepository extends JpaRepository, JpaSpecificationExecutor { + + @Query("SELECT sku FROM TbProductSku sku WHERE sku.productId IN :productId") + List searchSku(@Param("productId")List productId); + +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/rest/TbProductSkuController.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/rest/TbProductSkuController.java new file mode 100644 index 00000000..6a928c80 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/rest/TbProductSkuController.java @@ -0,0 +1,87 @@ +/* +* 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.modules.productInfo.productSku.rest; + +import me.zhengjie.annotation.Log; +import me.zhengjie.modules.productInfo.productSku.domain.TbProductSku; +import me.zhengjie.modules.productInfo.productSku.service.dto.TbProductSkuQueryCriteria; +import me.zhengjie.modules.productInfo.productSku.service.TbProductSkuService; +import org.springframework.data.domain.Pageable; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import io.swagger.annotations.*; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-03 +**/ +@RestController +@RequiredArgsConstructor +@Api(tags = "/product/sku管理") +@RequestMapping("/api/tbProductSku") +public class TbProductSkuController { + + private final TbProductSkuService tbProductSkuService; + + @Log("导出数据") + @ApiOperation("导出数据") + @GetMapping(value = "/download") + @PreAuthorize("@el.check('tbProductSku:list')") + public void exportTbProductSku(HttpServletResponse response, TbProductSkuQueryCriteria criteria) throws IOException { + tbProductSkuService.download(tbProductSkuService.queryAll(criteria), response); + } + + @GetMapping + @Log("查询/product/sku") + @ApiOperation("查询/product/sku") + @PreAuthorize("@el.check('tbProductSku:list')") + public ResponseEntity queryTbProductSku(TbProductSkuQueryCriteria criteria, Pageable pageable){ + return new ResponseEntity<>(tbProductSkuService.queryAll(criteria,pageable),HttpStatus.OK); + } + + @PostMapping + @Log("新增/product/sku") + @ApiOperation("新增/product/sku") + @PreAuthorize("@el.check('tbProductSku:add')") + public ResponseEntity createTbProductSku(@Validated @RequestBody TbProductSku resources){ + return new ResponseEntity<>(tbProductSkuService.create(resources),HttpStatus.CREATED); + } + + @PutMapping + @Log("修改/product/sku") + @ApiOperation("修改/product/sku") + @PreAuthorize("@el.check('tbProductSku:edit')") + public ResponseEntity updateTbProductSku(@Validated @RequestBody TbProductSku resources){ + tbProductSkuService.update(resources); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @DeleteMapping + @Log("删除/product/sku") + @ApiOperation("删除/product/sku") + @PreAuthorize("@el.check('tbProductSku:del')") + public ResponseEntity deleteTbProductSku(@RequestBody Integer[] ids) { + tbProductSkuService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/service/TbProductSkuService.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/service/TbProductSkuService.java new file mode 100644 index 00000000..0614d6ef --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/service/TbProductSkuService.java @@ -0,0 +1,83 @@ +/* +* 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.modules.productInfo.productSku.service; + +import me.zhengjie.modules.productInfo.productSku.domain.TbProductSku; +import me.zhengjie.modules.productInfo.productSku.service.dto.TbProductSkuQueryCriteria; +import me.zhengjie.modules.productInfo.productSku.service.dto.TbProductSkuDto; +import org.springframework.data.domain.Pageable; +import java.util.Map; +import java.util.List; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +/** +* @website https://eladmin.vip +* @description 服务接口 +* @author lyf +* @date 2024-01-03 +**/ +public interface TbProductSkuService { + + /** + * 查询数据分页 + * @param criteria 条件 + * @param pageable 分页参数 + * @return Map + */ + Map queryAll(TbProductSkuQueryCriteria criteria, Pageable pageable); + + /** + * 查询所有数据不分页 + * @param criteria 条件参数 + * @return List + */ + List queryAll(TbProductSkuQueryCriteria criteria); + + /** + * 根据ID查询 + * @param id ID + * @return TbProductSkuDto + */ + TbProductSkuDto findById(Integer id); + + /** + * 创建 + * @param resources / + * @return TbProductSkuDto + */ + TbProductSkuDto create(TbProductSku resources); + + /** + * 编辑 + * @param resources / + */ + void update(TbProductSku resources); + + /** + * 多选删除 + * @param ids / + */ + void deleteAll(Integer[] ids); + + /** + * 导出数据 + * @param all 待导出的数据 + * @param response / + * @throws IOException / + */ + void download(List all, HttpServletResponse response) throws IOException; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/service/dto/SkuDto.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/service/dto/SkuDto.java new file mode 100644 index 00000000..53e0162b --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/service/dto/SkuDto.java @@ -0,0 +1,37 @@ +package me.zhengjie.modules.productInfo.productSku.service.dto; + +import lombok.Data; + +import java.math.BigDecimal; + +/** + * @author lyf + */ +@Data +public class SkuDto { + /** + * 销量 + */ + private Double realSalesNumber; + /** + * 库存数量 + */ + private Double stockNumber; + + /** + * 原价 + */ + private Double originPrice; + /** + * 成本价 + */ + private Double costPrice; + /** + * 会员价 + */ + private Double memberPrice; + /** + * 商品id + */ + private String productId; +} diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/service/dto/TbProductSkuDto.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/service/dto/TbProductSkuDto.java new file mode 100644 index 00000000..288bd2a5 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/service/dto/TbProductSkuDto.java @@ -0,0 +1,88 @@ +/* +* 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.modules.productInfo.productSku.service.dto; + +import lombok.Data; +import java.math.BigDecimal; +import java.io.Serializable; + +/** +* @website https://eladmin.vip +* @description / +* @author lyf +* @date 2024-01-03 +**/ +@Data +public class TbProductSkuDto implements Serializable { + + /** 自增id */ + private Integer id; + + private String shopId; + + /** 条形码 */ + private String barCode; + + /** 商品Id */ + private String productId; + + /** 原价 */ + private BigDecimal originPrice; + + /** 成本价 */ + private BigDecimal costPrice; + + /** 会员价 */ + private BigDecimal memberPrice; + + private BigDecimal mealPrice; + + /** 售价 */ + private BigDecimal salePrice; + + /** 进货参考价 */ + private BigDecimal guidePrice; + + private BigDecimal strategyPrice; + + /** 库存数量 */ + private Double stockNumber; + + /** 标签镜像 */ + private String specSnap; + + private String coverImg; + + /** 库存警戒线 */ + private Integer warnLine; + + private Double weight; + + private Float volume; + + /** 销量 */ + private Double realSalesNumber; + + /** 一级分销金额 */ + private BigDecimal firstShared; + + /** 二级分销金额 */ + private BigDecimal secondShared; + + private Long createdAt; + + private Long updatedAt; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/service/dto/TbProductSkuQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/service/dto/TbProductSkuQueryCriteria.java new file mode 100644 index 00000000..2f1e326f --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/service/dto/TbProductSkuQueryCriteria.java @@ -0,0 +1,29 @@ +/* +* 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.modules.productInfo.productSku.service.dto; + +import lombok.Data; +import java.util.List; +import me.zhengjie.annotation.Query; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-03 +**/ +@Data +public class TbProductSkuQueryCriteria{ +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/service/impl/TbProductSkuServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/service/impl/TbProductSkuServiceImpl.java new file mode 100644 index 00000000..032683c2 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/service/impl/TbProductSkuServiceImpl.java @@ -0,0 +1,124 @@ +/* +* 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.modules.productInfo.productSku.service.impl; + +import me.zhengjie.modules.productInfo.productSku.domain.TbProductSku; +import me.zhengjie.modules.productInfo.productSku.service.dto.TbProductSkuQueryCriteria; +import me.zhengjie.modules.productInfo.productSku.service.mapstruct.TbProductSkuMapper; +import me.zhengjie.utils.ValidationUtil; +import me.zhengjie.utils.FileUtil; +import lombok.RequiredArgsConstructor; +import me.zhengjie.modules.productInfo.productSku.repository.TbProductSkuRepository; +import me.zhengjie.modules.productInfo.productSku.service.TbProductSkuService; +import me.zhengjie.modules.productInfo.productSku.service.dto.TbProductSkuDto; +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.util.List; +import java.util.Map; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.LinkedHashMap; + +/** +* @website https://eladmin.vip +* @description 服务实现 +* @author lyf +* @date 2024-01-03 +**/ +@Service +@RequiredArgsConstructor +public class TbProductSkuServiceImpl implements TbProductSkuService { + + private final TbProductSkuRepository tbProductSkuRepository; + private final TbProductSkuMapper tbProductSkuMapper; + + @Override + public Map queryAll(TbProductSkuQueryCriteria criteria, Pageable pageable){ + Page page = tbProductSkuRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + return PageUtil.toPage(page.map(tbProductSkuMapper::toDto)); + } + + @Override + public List queryAll(TbProductSkuQueryCriteria criteria){ + return tbProductSkuMapper.toDto(tbProductSkuRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); + } + + @Override + @Transactional + public TbProductSkuDto findById(Integer id) { + TbProductSku tbProductSku = tbProductSkuRepository.findById(id).orElseGet(TbProductSku::new); + ValidationUtil.isNull(tbProductSku.getId(),"TbProductSku","id",id); + return tbProductSkuMapper.toDto(tbProductSku); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public TbProductSkuDto create(TbProductSku resources) { + return tbProductSkuMapper.toDto(tbProductSkuRepository.save(resources)); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(TbProductSku resources) { + TbProductSku tbProductSku = tbProductSkuRepository.findById(resources.getId()).orElseGet(TbProductSku::new); + ValidationUtil.isNull( tbProductSku.getId(),"TbProductSku","id",resources.getId()); + tbProductSku.copy(resources); + tbProductSkuRepository.save(tbProductSku); + } + + @Override + public void deleteAll(Integer[] ids) { + for (Integer id : ids) { + tbProductSkuRepository.deleteById(id); + } + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (TbProductSkuDto tbProductSku : all) { + Map map = new LinkedHashMap<>(); + map.put(" shopId", tbProductSku.getShopId()); + map.put("条形码", tbProductSku.getBarCode()); + map.put("商品Id", tbProductSku.getProductId()); + map.put("原价", tbProductSku.getOriginPrice()); + map.put("成本价", tbProductSku.getCostPrice()); + map.put("会员价", tbProductSku.getMemberPrice()); + map.put(" mealPrice", tbProductSku.getMealPrice()); + map.put("售价", tbProductSku.getSalePrice()); + map.put("进货参考价", tbProductSku.getGuidePrice()); + map.put(" strategyPrice", tbProductSku.getStrategyPrice()); + map.put("库存数量", tbProductSku.getStockNumber()); + map.put("标签镜像", tbProductSku.getSpecSnap()); + map.put(" coverImg", tbProductSku.getCoverImg()); + map.put("库存警戒线", tbProductSku.getWarnLine()); + map.put(" weight", tbProductSku.getWeight()); + map.put(" volume", tbProductSku.getVolume()); + map.put("销量", tbProductSku.getRealSalesNumber()); + map.put("一级分销金额", tbProductSku.getFirstShared()); + map.put("二级分销金额", tbProductSku.getSecondShared()); + map.put(" createdAt", tbProductSku.getCreatedAt()); + map.put(" updatedAt", tbProductSku.getUpdatedAt()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/service/mapstruct/TbProductSkuMapper.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/service/mapstruct/TbProductSkuMapper.java new file mode 100644 index 00000000..f28a4f70 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSku/service/mapstruct/TbProductSkuMapper.java @@ -0,0 +1,32 @@ +/* +* 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.modules.productInfo.productSku.service.mapstruct; + +import me.zhengjie.base.BaseMapper; +import me.zhengjie.modules.productInfo.productSku.domain.TbProductSku; +import me.zhengjie.modules.productInfo.productSku.service.dto.TbProductSkuDto; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-03 +**/ +@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface TbProductSkuMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/domain/TbProductSpec.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/domain/TbProductSpec.java new file mode 100644 index 00000000..970052ed --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/domain/TbProductSpec.java @@ -0,0 +1,79 @@ +/* +* 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.modules.productInfo.productSpec.domain; + +import lombok.Data; +import cn.hutool.core.bean.BeanUtil; +import io.swagger.annotations.ApiModelProperty; +import cn.hutool.core.bean.copier.CopyOptions; +import javax.persistence.*; +import javax.validation.constraints.*; +import java.io.Serializable; + +/** +* @website https://eladmin.vip +* @description / +* @author lyf +* @date 2024-01-03 +**/ +@Entity +@Data +@Table(name="tb_product_spec") +public class TbProductSpec implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "`id`") + @ApiModelProperty(value = "id") + private Integer id; + + @Column(name = "`shop_id`") + @ApiModelProperty(value = "shopId") + private String shopId; + + @Column(name = "`name`",nullable = false) + @NotBlank + @ApiModelProperty(value = "商品属性名称") + private String name; + + @Column(name = "`spec_tag`") + @ApiModelProperty(value = "规格属性") + private String specTag; + + @Column(name = "`spec_tag_detail`") + @ApiModelProperty(value = "属性介绍") + private String specTagDetail; + + @Column(name = "`spec_list`") + @ApiModelProperty(value = "specList") + private String specList; + + @Column(name = "`sort`") + @ApiModelProperty(value = "排序") + private Integer sort; + + @Column(name = "`created_at`") + @ApiModelProperty(value = "createdAt") + private Long createdAt; + + @Column(name = "`updated_at`") + @ApiModelProperty(value = "updatedAt") + private Long updatedAt; + + public void copy(TbProductSpec source){ + BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); + } +} diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/repository/TbProductSpecRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/repository/TbProductSpecRepository.java new file mode 100644 index 00000000..504792d0 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/repository/TbProductSpecRepository.java @@ -0,0 +1,35 @@ +/* +* 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.modules.productInfo.productSpec.repository; + +import me.zhengjie.modules.productInfo.productSpec.domain.TbProductSpec; +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.repository.query.Param; + +import java.util.List; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-03 +**/ +public interface TbProductSpecRepository extends JpaRepository, JpaSpecificationExecutor { + + @Query("SELECT spec FROM TbProductSpec spec WHERE spec.id IN :ids") + List searchSpec(@Param("ids")List ids); +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/rest/TbProductSpecController.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/rest/TbProductSpecController.java new file mode 100644 index 00000000..6e703e0d --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/rest/TbProductSpecController.java @@ -0,0 +1,87 @@ +/* +* 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.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.TbProductSpecQueryCriteria; +import org.springframework.data.domain.Pageable; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import io.swagger.annotations.*; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-03 +**/ +@RestController +@RequiredArgsConstructor +@Api(tags = "product/spec管理") +@RequestMapping("/api/tbProductSpec") +public class TbProductSpecController { + + private final TbProductSpecService tbProductSpecService; + + @Log("导出数据") + @ApiOperation("导出数据") + @GetMapping(value = "/download") + @PreAuthorize("@el.check('tbProductSpec:list')") + public void exportTbProductSpec(HttpServletResponse response, TbProductSpecQueryCriteria criteria) throws IOException { + tbProductSpecService.download(tbProductSpecService.queryAll(criteria), response); + } + + @GetMapping + @Log("查询product/spec") + @ApiOperation("查询product/spec") + @PreAuthorize("@el.check('tbProductSpec:list')") + public ResponseEntity queryTbProductSpec(TbProductSpecQueryCriteria criteria, Pageable pageable){ + return new ResponseEntity<>(tbProductSpecService.queryAll(criteria,pageable),HttpStatus.OK); + } + + @PostMapping + @Log("新增product/spec") + @ApiOperation("新增product/spec") + @PreAuthorize("@el.check('tbProductSpec:add')") + public ResponseEntity createTbProductSpec(@Validated @RequestBody TbProductSpec resources){ + return new ResponseEntity<>(tbProductSpecService.create(resources),HttpStatus.CREATED); + } + + @PutMapping + @Log("修改product/spec") + @ApiOperation("修改product/spec") + @PreAuthorize("@el.check('tbProductSpec:edit')") + public ResponseEntity updateTbProductSpec(@Validated @RequestBody TbProductSpec resources){ + tbProductSpecService.update(resources); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @DeleteMapping + @Log("删除product/spec") + @ApiOperation("删除product/spec") + @PreAuthorize("@el.check('tbProductSpec:del')") + public ResponseEntity deleteTbProductSpec(@RequestBody Integer[] ids) { + tbProductSpecService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/service/TbProductSpecService.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/service/TbProductSpecService.java new file mode 100644 index 00000000..1bb16a97 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/service/TbProductSpecService.java @@ -0,0 +1,83 @@ +/* +* 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.modules.productInfo.productSpec.service; + +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; +import org.springframework.data.domain.Pageable; +import java.util.Map; +import java.util.List; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +/** +* @website https://eladmin.vip +* @description 服务接口 +* @author lyf +* @date 2024-01-03 +**/ +public interface TbProductSpecService { + + /** + * 查询数据分页 + * @param criteria 条件 + * @param pageable 分页参数 + * @return Map + */ + Map queryAll(TbProductSpecQueryCriteria criteria, Pageable pageable); + + /** + * 查询所有数据不分页 + * @param criteria 条件参数 + * @return List + */ + List queryAll(TbProductSpecQueryCriteria criteria); + + /** + * 根据ID查询 + * @param id ID + * @return TbProductSpecDto + */ + TbProductSpecDto findById(Integer id); + + /** + * 创建 + * @param resources / + * @return TbProductSpecDto + */ + TbProductSpecDto create(TbProductSpec resources); + + /** + * 编辑 + * @param resources / + */ + void update(TbProductSpec resources); + + /** + * 多选删除 + * @param ids / + */ + void deleteAll(Integer[] ids); + + /** + * 导出数据 + * @param all 待导出的数据 + * @param response / + * @throws IOException / + */ + void download(List all, HttpServletResponse response) throws IOException; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/service/dto/TbProductSpecDto.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/service/dto/TbProductSpecDto.java new file mode 100644 index 00000000..e5e52728 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/service/dto/TbProductSpecDto.java @@ -0,0 +1,52 @@ +/* +* 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.modules.productInfo.productSpec.service.dto; + +import lombok.Data; +import java.io.Serializable; + +/** +* @website https://eladmin.vip +* @description / +* @author lyf +* @date 2024-01-03 +**/ +@Data +public class TbProductSpecDto implements Serializable { + + /** id */ + private Integer id; + + private String shopId; + + /** 商品属性名称 */ + private String name; + + /** 规格属性 */ + private String specTag; + + /** 属性介绍 */ + private String specTagDetail; + + private String specList; + + /** 排序 */ + private Integer sort; + + private Long createdAt; + + private Long updatedAt; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/service/dto/TbProductSpecQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/service/dto/TbProductSpecQueryCriteria.java new file mode 100644 index 00000000..274da216 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/service/dto/TbProductSpecQueryCriteria.java @@ -0,0 +1,29 @@ +/* +* 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.modules.productInfo.productSpec.service.dto; + +import lombok.Data; +import java.util.List; +import me.zhengjie.annotation.Query; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-03 +**/ +@Data +public class TbProductSpecQueryCriteria{ +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/service/impl/TbProductSpecServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/service/impl/TbProductSpecServiceImpl.java new file mode 100644 index 00000000..01e8069d --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/service/impl/TbProductSpecServiceImpl.java @@ -0,0 +1,111 @@ +/* +* 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.modules.productInfo.productSpec.service.impl; + +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.dto.TbProductSpecDto; +import me.zhengjie.modules.productInfo.productSpec.service.dto.TbProductSpecQueryCriteria; +import me.zhengjie.utils.ValidationUtil; +import me.zhengjie.utils.FileUtil; +import lombok.RequiredArgsConstructor; +import me.zhengjie.modules.productInfo.productSpec.service.mapstruct.TbProductSpecMapper; +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.util.List; +import java.util.Map; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.LinkedHashMap; + +/** +* @website https://eladmin.vip +* @description 服务实现 +* @author lyf +* @date 2024-01-03 +**/ +@Service +@RequiredArgsConstructor +public class TbProductSpecServiceImpl implements TbProductSpecService { + + private final TbProductSpecRepository tbProductSpecRepository; + private final TbProductSpecMapper tbProductSpecMapper; + + @Override + public Map queryAll(TbProductSpecQueryCriteria criteria, Pageable pageable){ + Page page = tbProductSpecRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + return PageUtil.toPage(page.map(tbProductSpecMapper::toDto)); + } + + @Override + public List queryAll(TbProductSpecQueryCriteria criteria){ + return tbProductSpecMapper.toDto(tbProductSpecRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); + } + + @Override + @Transactional + public TbProductSpecDto findById(Integer id) { + TbProductSpec tbProductSpec = tbProductSpecRepository.findById(id).orElseGet(TbProductSpec::new); + ValidationUtil.isNull(tbProductSpec.getId(),"TbProductSpec","id",id); + return tbProductSpecMapper.toDto(tbProductSpec); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public TbProductSpecDto create(TbProductSpec resources) { + return tbProductSpecMapper.toDto(tbProductSpecRepository.save(resources)); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(TbProductSpec resources) { + TbProductSpec tbProductSpec = tbProductSpecRepository.findById(resources.getId()).orElseGet(TbProductSpec::new); + ValidationUtil.isNull( tbProductSpec.getId(),"TbProductSpec","id",resources.getId()); + tbProductSpec.copy(resources); + tbProductSpecRepository.save(tbProductSpec); + } + + @Override + public void deleteAll(Integer[] ids) { + for (Integer id : ids) { + tbProductSpecRepository.deleteById(id); + } + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (TbProductSpecDto tbProductSpec : all) { + Map map = new LinkedHashMap<>(); + map.put(" shopId", tbProductSpec.getShopId()); + map.put("商品属性名称", tbProductSpec.getName()); + map.put("规格属性", tbProductSpec.getSpecTag()); + map.put("属性介绍", tbProductSpec.getSpecTagDetail()); + map.put(" specList", tbProductSpec.getSpecList()); + map.put("排序", tbProductSpec.getSort()); + map.put(" createdAt", tbProductSpec.getCreatedAt()); + map.put(" updatedAt", tbProductSpec.getUpdatedAt()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/service/mapstruct/TbProductSpecMapper.java b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/service/mapstruct/TbProductSpecMapper.java new file mode 100644 index 00000000..37e2408d --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/productInfo/productSpec/service/mapstruct/TbProductSpecMapper.java @@ -0,0 +1,32 @@ +/* +* 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.modules.productInfo.productSpec.service.mapstruct; + +import me.zhengjie.base.BaseMapper; +import me.zhengjie.modules.productInfo.productSpec.domain.TbProductSpec; +import me.zhengjie.modules.productInfo.productSpec.service.dto.TbProductSpecDto; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-03 +**/ +@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface TbProductSpecMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/domain/TbShopUnit.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/domain/TbShopUnit.java new file mode 100644 index 00000000..051e88ed --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/domain/TbShopUnit.java @@ -0,0 +1,83 @@ +/* +* 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.modules.shopUnit.domain; + +import lombok.Data; +import cn.hutool.core.bean.BeanUtil; +import io.swagger.annotations.ApiModelProperty; +import cn.hutool.core.bean.copier.CopyOptions; +import javax.persistence.*; +import javax.validation.constraints.*; +import java.io.Serializable; + +/** +* @website https://eladmin.vip +* @description / +* @author lyf +* @date 2024-01-02 +**/ +@Entity +@Data +@Table(name="tb_shop_unit") +public class TbShopUnit implements Serializable { + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "`id`") + @ApiModelProperty(value = "id") + private Integer id; + + @Column(name = "`name`",nullable = false) + @NotBlank + @ApiModelProperty(value = "单位名称") + private String name; + + @Column(name = "`decimals_digits`") + @ApiModelProperty(value = "小数位(个数大于0,表示小数据精度位数)") + private Integer decimalsDigits; + + @Column(name = "`unit_type`") + @ApiModelProperty(value = "单位类型(weight代表重量,小数单位,为number代表个数)") + private String unitType; + + @Column(name = "`is_system`") + @ApiModelProperty(value = "0后台添加 -1系统默认 (公斤、瓶)") + private Integer isSystem; + + @Column(name = "`status`") + @ApiModelProperty(value = "预留字段1-正常") + private Integer status; + + @Column(name = "`merchant_id`") + @ApiModelProperty(value = "merchantId") + private String merchantId; + + @Column(name = "`shop_id`") + @ApiModelProperty(value = "店铺Id") + private String shopId; + + @Column(name = "`created_at`") + @ApiModelProperty(value = "createdAt") + private Long createdAt; + + @Column(name = "`updated_at`") + @ApiModelProperty(value = "updatedAt") + private Long updatedAt; + + public void copy(TbShopUnit source){ + BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true)); + } +} diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/repository/TbShopUnitRepository.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/repository/TbShopUnitRepository.java new file mode 100644 index 00000000..9a2b7490 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/repository/TbShopUnitRepository.java @@ -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.modules.shopUnit.repository; + +import me.zhengjie.modules.shopUnit.domain.TbShopUnit; +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.repository.query.Param; + +import java.util.List; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-02 +**/ +public interface TbShopUnitRepository extends JpaRepository, JpaSpecificationExecutor { + @Query("SELECT unit FROM TbShopUnit unit WHERE unit.id IN :ids") + List searchUnit(@Param("ids")List ids); +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/rest/TbShopUnitController.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/rest/TbShopUnitController.java new file mode 100644 index 00000000..38120fe1 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/rest/TbShopUnitController.java @@ -0,0 +1,87 @@ +/* +* 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.modules.shopUnit.rest; + +import me.zhengjie.annotation.Log; +import me.zhengjie.modules.shopUnit.domain.TbShopUnit; +import me.zhengjie.modules.shopUnit.service.TbShopUnitService; +import me.zhengjie.modules.shopUnit.service.dto.TbShopUnitQueryCriteria; +import org.springframework.data.domain.Pageable; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import io.swagger.annotations.*; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-02 +**/ +@RestController +@RequiredArgsConstructor +@Api(tags = "/shop/unit管理") +@RequestMapping("/api/tbShopUnit") +public class TbShopUnitController { + + private final TbShopUnitService tbShopUnitService; + + @Log("导出数据") + @ApiOperation("导出数据") + @GetMapping(value = "/download") + @PreAuthorize("@el.check('tbShopUnit:list')") + public void exportTbShopUnit(HttpServletResponse response, TbShopUnitQueryCriteria criteria) throws IOException { + tbShopUnitService.download(tbShopUnitService.queryAll(criteria), response); + } + + @GetMapping + @Log("查询/shop/unit") + @ApiOperation("查询/shop/unit") + @PreAuthorize("@el.check('tbShopUnit:list')") + public ResponseEntity queryTbShopUnit(TbShopUnitQueryCriteria criteria, Pageable pageable){ + return new ResponseEntity<>(tbShopUnitService.queryAll(criteria,pageable),HttpStatus.OK); + } + + @PostMapping + @Log("新增/shop/unit") + @ApiOperation("新增/shop/unit") + @PreAuthorize("@el.check('tbShopUnit:add')") + public ResponseEntity createTbShopUnit(@Validated @RequestBody TbShopUnit resources){ + return new ResponseEntity<>(tbShopUnitService.create(resources),HttpStatus.CREATED); + } + + @PutMapping + @Log("修改/shop/unit") + @ApiOperation("修改/shop/unit") + @PreAuthorize("@el.check('tbShopUnit:edit')") + public ResponseEntity updateTbShopUnit(@Validated @RequestBody TbShopUnit resources){ + tbShopUnitService.update(resources); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @DeleteMapping + @Log("删除/shop/unit") + @ApiOperation("删除/shop/unit") + @PreAuthorize("@el.check('tbShopUnit:del')") + public ResponseEntity deleteTbShopUnit(@RequestBody Integer[] ids) { + tbShopUnitService.deleteAll(ids); + return new ResponseEntity<>(HttpStatus.OK); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/service/TbShopUnitService.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/service/TbShopUnitService.java new file mode 100644 index 00000000..db60b6b6 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/service/TbShopUnitService.java @@ -0,0 +1,83 @@ +/* +* 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.modules.shopUnit.service; + +import me.zhengjie.modules.shopUnit.domain.TbShopUnit; +import me.zhengjie.modules.shopUnit.service.dto.TbShopUnitDto; +import me.zhengjie.modules.shopUnit.service.dto.TbShopUnitQueryCriteria; +import org.springframework.data.domain.Pageable; +import java.util.Map; +import java.util.List; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; + +/** +* @website https://eladmin.vip +* @description 服务接口 +* @author lyf +* @date 2024-01-02 +**/ +public interface TbShopUnitService { + + /** + * 查询数据分页 + * @param criteria 条件 + * @param pageable 分页参数 + * @return Map + */ + Map queryAll(TbShopUnitQueryCriteria criteria, Pageable pageable); + + /** + * 查询所有数据不分页 + * @param criteria 条件参数 + * @return List + */ + List queryAll(TbShopUnitQueryCriteria criteria); + + /** + * 根据ID查询 + * @param id ID + * @return TbShopUnitDto + */ + TbShopUnitDto findById(Integer id); + + /** + * 创建 + * @param resources / + * @return TbShopUnitDto + */ + TbShopUnitDto create(TbShopUnit resources); + + /** + * 编辑 + * @param resources / + */ + void update(TbShopUnit resources); + + /** + * 多选删除 + * @param ids / + */ + void deleteAll(Integer[] ids); + + /** + * 导出数据 + * @param all 待导出的数据 + * @param response / + * @throws IOException / + */ + void download(List all, HttpServletResponse response) throws IOException; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/service/dto/TbShopUnitDto.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/service/dto/TbShopUnitDto.java new file mode 100644 index 00000000..0600d9f8 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/service/dto/TbShopUnitDto.java @@ -0,0 +1,56 @@ +/* +* 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.modules.shopUnit.service.dto; + +import lombok.Data; +import java.io.Serializable; + +/** +* @website https://eladmin.vip +* @description / +* @author lyf +* @date 2024-01-02 +**/ +@Data +public class TbShopUnitDto implements Serializable { + + /** id */ + private Integer id; + + /** 单位名称 */ + private String name; + + /** 小数位(个数大于0,表示小数据精度位数) */ + private Integer decimalsDigits; + + /** 单位类型(weight代表重量,小数单位,为number代表个数) */ + private String unitType; + + /** 0后台添加 -1系统默认 (公斤、瓶) */ + private Integer isSystem; + + /** 预留字段1-正常 */ + private Integer status; + + private String merchantId; + + /** 店铺Id */ + private String shopId; + + private Long createdAt; + + private Long updatedAt; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/service/dto/TbShopUnitQueryCriteria.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/service/dto/TbShopUnitQueryCriteria.java new file mode 100644 index 00000000..fb851d47 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/service/dto/TbShopUnitQueryCriteria.java @@ -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.modules.shopUnit.service.dto; + +import lombok.Data; +import java.util.List; +import me.zhengjie.annotation.Query; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-02 +**/ +@Data +public class TbShopUnitQueryCriteria{ + @Query + private String name; + + @Query + private String shopId; +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/service/impl/TbShopUnitServiceImpl.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/service/impl/TbShopUnitServiceImpl.java new file mode 100644 index 00000000..13c78457 --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/service/impl/TbShopUnitServiceImpl.java @@ -0,0 +1,112 @@ +/* +* 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.modules.shopUnit.service.impl; + +import me.zhengjie.modules.shopUnit.domain.TbShopUnit; +import me.zhengjie.utils.ValidationUtil; +import me.zhengjie.utils.FileUtil; +import lombok.RequiredArgsConstructor; +import me.zhengjie.modules.shopUnit.repository.TbShopUnitRepository; +import me.zhengjie.modules.shopUnit.service.TbShopUnitService; +import me.zhengjie.modules.shopUnit.service.dto.TbShopUnitDto; +import me.zhengjie.modules.shopUnit.service.dto.TbShopUnitQueryCriteria; +import me.zhengjie.modules.shopUnit.service.mapstruct.TbShopUnitMapper; +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.util.List; +import java.util.Map; +import java.io.IOException; +import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.LinkedHashMap; + +/** +* @website https://eladmin.vip +* @description 服务实现 +* @author lyf +* @date 2024-01-02 +**/ +@Service +@RequiredArgsConstructor +public class TbShopUnitServiceImpl implements TbShopUnitService { + + private final TbShopUnitRepository tbShopUnitRepository; + private final TbShopUnitMapper tbShopUnitMapper; + + @Override + public Map queryAll(TbShopUnitQueryCriteria criteria, Pageable pageable){ + Page page = tbShopUnitRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable); + return PageUtil.toPage(page.map(tbShopUnitMapper::toDto)); + } + + @Override + public List queryAll(TbShopUnitQueryCriteria criteria){ + return tbShopUnitMapper.toDto(tbShopUnitRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder))); + } + + @Override + @Transactional + public TbShopUnitDto findById(Integer id) { + TbShopUnit tbShopUnit = tbShopUnitRepository.findById(id).orElseGet(TbShopUnit::new); + ValidationUtil.isNull(tbShopUnit.getId(),"TbShopUnit","id",id); + return tbShopUnitMapper.toDto(tbShopUnit); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public TbShopUnitDto create(TbShopUnit resources) { + return tbShopUnitMapper.toDto(tbShopUnitRepository.save(resources)); + } + + @Override + @Transactional(rollbackFor = Exception.class) + public void update(TbShopUnit resources) { + TbShopUnit tbShopUnit = tbShopUnitRepository.findById(resources.getId()).orElseGet(TbShopUnit::new); + ValidationUtil.isNull( tbShopUnit.getId(),"TbShopUnit","id",resources.getId()); + tbShopUnit.copy(resources); + tbShopUnitRepository.save(tbShopUnit); + } + + @Override + public void deleteAll(Integer[] ids) { + for (Integer id : ids) { + tbShopUnitRepository.deleteById(id); + } + } + + @Override + public void download(List all, HttpServletResponse response) throws IOException { + List> list = new ArrayList<>(); + for (TbShopUnitDto tbShopUnit : all) { + Map map = new LinkedHashMap<>(); + map.put("单位名称", tbShopUnit.getName()); + map.put("小数位(个数大于0,表示小数据精度位数)", tbShopUnit.getDecimalsDigits()); + map.put("单位类型(weight代表重量,小数单位,为number代表个数)", tbShopUnit.getUnitType()); + map.put("0后台添加 -1系统默认 (公斤、瓶)", tbShopUnit.getIsSystem()); + map.put("预留字段1-正常", tbShopUnit.getStatus()); + map.put(" merchantId", tbShopUnit.getMerchantId()); + map.put("店铺Id", tbShopUnit.getShopId()); + map.put(" createdAt", tbShopUnit.getCreatedAt()); + map.put(" updatedAt", tbShopUnit.getUpdatedAt()); + list.add(map); + } + FileUtil.downloadExcel(list, response); + } +} \ No newline at end of file diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/service/mapstruct/TbShopUnitMapper.java b/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/service/mapstruct/TbShopUnitMapper.java new file mode 100644 index 00000000..afa3d3dd --- /dev/null +++ b/eladmin-system/src/main/java/me/zhengjie/modules/shopUnit/service/mapstruct/TbShopUnitMapper.java @@ -0,0 +1,32 @@ +/* +* 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.modules.shopUnit.service.mapstruct; + +import me.zhengjie.base.BaseMapper; +import me.zhengjie.modules.shopUnit.domain.TbShopUnit; +import me.zhengjie.modules.shopUnit.service.dto.TbShopUnitDto; +import org.mapstruct.Mapper; +import org.mapstruct.ReportingPolicy; + +/** +* @website https://eladmin.vip +* @author lyf +* @date 2024-01-02 +**/ +@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE) +public interface TbShopUnitMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/product/spec/tbProductSpec.js b/product/spec/tbProductSpec.js new file mode 100644 index 00000000..89449755 --- /dev/null +++ b/product/spec/tbProductSpec.js @@ -0,0 +1,27 @@ +import request from '@/utils/request' + +export function add(data) { + return request({ + url: 'api/tbProductSpec', + method: 'post', + data + }) +} + +export function del(ids) { + return request({ + url: 'api/tbProductSpec/', + method: 'delete', + data: ids + }) +} + +export function edit(data) { + return request({ + url: 'api/tbProductSpec', + method: 'put', + data + }) +} + +export default { add, edit, del }