|
@@ -1,18 +1,151 @@
|
|
|
package cn.cslg.permission.service.qiaobi;
|
|
|
|
|
|
+import cn.cslg.permission.common.model.Records;
|
|
|
+import cn.cslg.permission.common.model.qiaobi.goods.GoodsAddDTO;
|
|
|
+import cn.cslg.permission.common.model.qiaobi.goods.GoodsQueryDTO;
|
|
|
+import cn.cslg.permission.common.model.qiaobi.goods.GoodsQueryVO;
|
|
|
+import cn.cslg.permission.common.model.qiaobi.version.QiaoBiVersionVO;
|
|
|
+import cn.cslg.permission.common.utils.StringUtils;
|
|
|
+import cn.cslg.permission.domain.Personnel;
|
|
|
+import cn.cslg.permission.domain.Version;
|
|
|
import cn.cslg.permission.domain.qiaobi.Goods;
|
|
|
+import cn.cslg.permission.exception.ExceptionEnum;
|
|
|
+import cn.cslg.permission.exception.XiaoShiException;
|
|
|
+import cn.cslg.permission.service.PersonnelService;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import cn.cslg.permission.mapper.qiaobi.GoodsMapper;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
-* @author admin
|
|
|
-* @description 针对表【GOODS(商品表)】的数据库操作Service实现
|
|
|
-* @createDate 2025-06-20 17:06:25
|
|
|
-*/
|
|
|
+ * @author admin
|
|
|
+ * @description 针对表【GOODS(商品表)】的数据库操作Service实现
|
|
|
+ * @createDate 2025-06-20 17:06:25
|
|
|
+ */
|
|
|
@Service
|
|
|
-public class GoodsService extends ServiceImpl<GoodsMapper, Goods>{
|
|
|
+public class GoodsService extends ServiceImpl<GoodsMapper, Goods> {
|
|
|
+ @Autowired
|
|
|
+ private PersonnelService personnelService;
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Integer addGoods(GoodsAddDTO goodsAddDTO) {
|
|
|
+ Integer id = goodsAddDTO.getId();
|
|
|
+ Double price = goodsAddDTO.getPrice();
|
|
|
+ Integer goodCount = goodsAddDTO.getGoodCount();
|
|
|
+ List<Integer> goodLimits = goodsAddDTO.getGoodLimits();
|
|
|
+ Integer goodUnit = goodsAddDTO.getGoodUnit();
|
|
|
+ String goodLimit = null;
|
|
|
+ if (goodLimits != null && goodLimits.size() > 0) {
|
|
|
+ goodLimit = StringUtils.join(goodLimits, ",");
|
|
|
+ }
|
|
|
+ if (id != null) {
|
|
|
+ UpdateWrapper<Goods> updateWrapper = new UpdateWrapper<>();
|
|
|
+ updateWrapper.set("PRICE", price);
|
|
|
+ updateWrapper.set("GOOD_COUNT", goodCount);
|
|
|
+ updateWrapper.set("GOOD_LIMIT", goodLimit);
|
|
|
+ updateWrapper.set("GOOD_UNIT", goodUnit);
|
|
|
+ this.update(updateWrapper);
|
|
|
+ } else {
|
|
|
+ Goods goods = new Goods();
|
|
|
+ BeanUtils.copyProperties(goodsAddDTO, goods);
|
|
|
+ goods.setBuyLimit(goodLimit);
|
|
|
+ id = goods.getId();
|
|
|
+ }
|
|
|
+ return id;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Records queryGoods(GoodsQueryDTO goodsQueryDTO) {
|
|
|
+ Records records = new Records();
|
|
|
+ Long current = goodsQueryDTO.getCurrent();
|
|
|
+ Long size = goodsQueryDTO.getSize();
|
|
|
+ String goodName = goodsQueryDTO.getGoodName();
|
|
|
+ Integer goodType = goodsQueryDTO.getGoodType();
|
|
|
+ Integer status = goodsQueryDTO.getStatus();
|
|
|
+ LambdaQueryWrapper<Goods> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ if (goodName != null) {
|
|
|
+ queryWrapper.like(Goods::getGoodName, goodName);
|
|
|
+ }
|
|
|
+ if (goodType != null) {
|
|
|
+ queryWrapper.eq(Goods::getGoodType, goodType);
|
|
|
+ }
|
|
|
+ if (status != null) {
|
|
|
+ queryWrapper.eq(Goods::getStatus, status);
|
|
|
+ }
|
|
|
+ List<Goods> goods = new ArrayList<>();
|
|
|
+ if (current != null && size != null) {
|
|
|
+ IPage<Goods> goodsIPage = this.page(new Page<>(current, size), queryWrapper);
|
|
|
+ goods = goodsIPage.getRecords();
|
|
|
+ records.setCurrent(current);
|
|
|
+ records.setSize(size);
|
|
|
+ records.setTotal(goodsIPage.getTotal());
|
|
|
+ } else {
|
|
|
+ goods = this.list(queryWrapper);
|
|
|
+ }
|
|
|
+ List<GoodsQueryVO> goodsQueryVOS = this.loadGoodsQueryVO(goods);
|
|
|
+ records.setRecords(goodsQueryVOS);
|
|
|
+ return records;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<GoodsQueryVO> loadGoodsQueryVO(List<Goods> goodsList) {
|
|
|
+ List<GoodsQueryVO> goodsQueryVOS = new ArrayList<>();
|
|
|
+ if (goodsQueryVOS == null || goodsQueryVOS.size() == 0) {
|
|
|
+ return goodsQueryVOS;
|
|
|
+ }
|
|
|
+ List<Integer> createIds = goodsList.stream().map(Goods::getCreateId).collect(Collectors.toList());
|
|
|
+ List<Personnel> personnelList = new ArrayList<>();
|
|
|
+ if (createIds != null && createIds.size() > 0) {
|
|
|
+ personnelList = personnelService.getPersonByIds(createIds);
|
|
|
+ }
|
|
|
+ for (Goods goods : goodsList) {
|
|
|
+ GoodsQueryVO goodsQueryVO = new GoodsQueryVO();
|
|
|
+ String limits = goods.getBuyLimit();
|
|
|
+ Integer createId = goods.getId();
|
|
|
+ Personnel personnel = personnelList.stream().filter(item -> item.getId().equals(createId)).findFirst().orElse(null);
|
|
|
+ BeanUtils.copyProperties(goods, goodsQueryVO);
|
|
|
+ if (personnel != null) {
|
|
|
+ goodsQueryVO.setCreateName(personnel.getPersonnelName());
|
|
|
+ }
|
|
|
+ List<Integer> goodLimits = new ArrayList<>();
|
|
|
+ if (limits != null) {
|
|
|
+ String[] temStrs = StringUtils.split(limits, ",");
|
|
|
+ for (int i = 0; i < temStrs.length; i++) {
|
|
|
+ goodLimits.add(Integer.parseInt(temStrs[i]));
|
|
|
+ }
|
|
|
+ goodsQueryVO.setGoodLimits(goodLimits);
|
|
|
+ }
|
|
|
+ goodsQueryVOS.add(goodsQueryVO);
|
|
|
+ }
|
|
|
+ return goodsQueryVOS;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void delete(List<Integer> ids) {
|
|
|
+ if (ids == null || ids.size() == 0) {
|
|
|
+ throw new XiaoShiException(ExceptionEnum.BUSINESS_CHECK, "请选择商品");
|
|
|
+ }
|
|
|
+ //删除版本
|
|
|
+ this.removeByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Goods> queryByIds(List<Integer> ids) {
|
|
|
+ if (ids == null || ids.size() == 0) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<Goods> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.in(Goods::getId, ids);
|
|
|
+ return this.list(queryWrapper);
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|