|
@@ -0,0 +1,113 @@
|
|
|
+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.DiBu;
|
|
|
+import org.dromara.commodityManagement.domain.bo.DiBuBo;
|
|
|
+import org.dromara.commodityManagement.domain.vo.DiBuVo;
|
|
|
+import org.dromara.commodityManagement.mapper.DiBuMapper;
|
|
|
+import org.dromara.commodityManagement.service.DiBuService;
|
|
|
+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;
|
|
|
+
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 底布管理服务实现
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
+public class DiBuServiceImpl implements DiBuService {
|
|
|
+
|
|
|
+ private final DiBuMapper diBuMapper;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据底布对象查询底布数据
|
|
|
+ * @param diBuBo 底布BO对象
|
|
|
+ * @param pageQuery 分页参数
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public TableDataInfo<DiBuVo> selectPageDiBuList(DiBuBo diBuBo, PageQuery pageQuery) {
|
|
|
+ QueryWrapper<DiBu> qw = new QueryWrapper<>();
|
|
|
+ qw.eq(StringUtils.isNotBlank(diBuBo.getName()), "name", diBuBo.getName());
|
|
|
+ Page<DiBuVo> page = diBuMapper.selectVoPage(pageQuery.build(), qw);
|
|
|
+ return TableDataInfo.build(page);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增底布
|
|
|
+ * @param diBuBo 底布BO对象
|
|
|
+ * @return 影响行数
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int insertDiBu(DiBuBo diBuBo) {
|
|
|
+ DiBu diBu = MapstructUtils.convert(diBuBo, DiBu.class);
|
|
|
+ validEntityBeforeSave(diBu);
|
|
|
+ return diBuMapper.insert(diBu);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改底布
|
|
|
+ * @param diBuBo 底布BO对象
|
|
|
+ * @return 影响行数
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int updateDiBu(DiBuBo diBuBo) {
|
|
|
+ DiBu diBu = MapstructUtils.convert(diBuBo, DiBu.class);
|
|
|
+ validEntityBeforeSave(diBu);
|
|
|
+ QueryWrapper<DiBu> qw = new QueryWrapper<>();
|
|
|
+ qw.eq("id", diBu.getId());
|
|
|
+ return diBuMapper.update(diBu,qw);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据底布ID删除底布
|
|
|
+ * @param diBuId 底布ID
|
|
|
+ * @return 影响行数
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int deleteDiBuById(Long[] diBuId) {
|
|
|
+ return diBuMapper.deleteByIds(Arrays.asList(diBuId));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询底布列表
|
|
|
+ * @return 底布列表
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<DiBu> selectDiBuListByIds(Long[] diBuIds) {
|
|
|
+ return MapstructUtils.convert(diBuMapper.selectVoByIds(Arrays.asList(diBuIds)), DiBu.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<DiBu> selectDiBuList() {
|
|
|
+ return diBuMapper.selectList();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 保存前校验数据
|
|
|
+ * @param entity 底布对象
|
|
|
+ */
|
|
|
+ private void validEntityBeforeSave(DiBu entity) {
|
|
|
+ if (!StringUtils.isNotEmpty(entity.getName())) {
|
|
|
+ throw new ServiceException("名称不能为空!");
|
|
|
+ } else if (!StringUtils.isNoneBlank(entity.getColor())) {
|
|
|
+ throw new ServiceException("颜色不能为空!");
|
|
|
+ } else if (!StringUtils.isNoneBlank(entity.getMenfu())) {
|
|
|
+ throw new ServiceException("门幅不能为空!");
|
|
|
+ } else if (!StringUtils.isNoneBlank(entity.getWeight())) {
|
|
|
+ throw new ServiceException("克重不能为空!");
|
|
|
+ } else if (!StringUtils.isNoneBlank(entity.getPrice())) {
|
|
|
+ throw new ServiceException("价格不能为空!");
|
|
|
+ } else if (!StringUtils.isNoneBlank(entity.getUnit())) {
|
|
|
+ throw new ServiceException("单位不能为空!");
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|