|
@@ -0,0 +1,72 @@
|
|
|
+package org.dromara.commodityManagement.service.impl;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
+import org.dromara.commodityManagement.domain.Brand;
|
|
|
+import org.dromara.commodityManagement.domain.bo.BrandBo;
|
|
|
+import org.dromara.commodityManagement.domain.vo.BrandVo;
|
|
|
+import org.dromara.commodityManagement.mapper.BrandMapper;
|
|
|
+import org.dromara.commodityManagement.service.BrandService;
|
|
|
+import org.dromara.common.core.exception.ServiceException;
|
|
|
+import org.dromara.common.core.utils.MapstructUtils;
|
|
|
+import org.dromara.common.core.utils.StringUtils;
|
|
|
+import org.dromara.common.mybatis.core.page.PageQuery;
|
|
|
+import org.dromara.common.mybatis.core.page.TableDataInfo;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+@RequiredArgsConstructor
|
|
|
+@Service
|
|
|
+public class BrandServiceImpl implements BrandService {
|
|
|
+
|
|
|
+ private final BrandMapper brandMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询品牌列表
|
|
|
+ * @param brand 品牌Bo对象
|
|
|
+ * @param pageQuery 查询条件
|
|
|
+ * @return 分页结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<BrandVo> selectPageBrandList(BrandBo brand,PageQuery pageQuery) {
|
|
|
+ QueryWrapper<Brand> qw = new QueryWrapper<>();
|
|
|
+ qw.eq(StringUtils.isNotBlank(brand.getName()), "name", brand.getName());
|
|
|
+ qw.eq("type", "2");
|
|
|
+ Page<BrandVo> page = brandMapper.selectVoPage(pageQuery.build(), qw);
|
|
|
+ return TableDataInfo.build(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int insertBrand(BrandBo brandBo) {
|
|
|
+ Brand brand = MapstructUtils.convert(brandBo, Brand.class);
|
|
|
+ validEntityBeforeSave(brand);
|
|
|
+ return brandMapper.insert(brand);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int updateBrand(BrandBo brandBo) {
|
|
|
+ Brand brand = MapstructUtils.convert(brandBo, Brand.class);
|
|
|
+ validEntityBeforeSave(brand);
|
|
|
+ QueryWrapper<Brand> qw = new QueryWrapper<>();
|
|
|
+ qw.eq("id", brand.getId());
|
|
|
+ return brandMapper.update(brand,qw);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int deleteBrandById(int brandId) {
|
|
|
+ return brandMapper.deleteById(brandId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前校验
|
|
|
+ * @param entity 实体对象
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(Brand entity) {
|
|
|
+ if (!StringUtils.isNotEmpty(entity.getName())) {
|
|
|
+ throw new ServiceException("名称不能为空!");
|
|
|
+ } else if (!StringUtils.isNoneBlank(entity.getType())) {
|
|
|
+ throw new ServiceException("类型不能为空!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|