|
|
@@ -0,0 +1,191 @@
|
|
|
+package org.jeecg.modules.rooms.service;
|
|
|
+
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.bean.copier.CopyOptions;
|
|
|
+import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
+import com.baomidou.mybatisplus.extension.service.IService;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import org.apache.commons.collections.map.HashedMap;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
+import org.jeecg.common.util.CommonUtils;
|
|
|
+import org.jeecg.modules.business.entity.BusHotel;
|
|
|
+import org.jeecg.modules.business.service.impl.BusHotelServiceImpl;
|
|
|
+import org.jeecg.modules.rooms.DTO.CesGoodsDelDto;
|
|
|
+import org.jeecg.modules.rooms.DTO.CesGoodsDto;
|
|
|
+import org.jeecg.modules.rooms.DTO.CesGoodsSearchDto;
|
|
|
+import org.jeecg.modules.rooms.Vo.CesGoodsVo;
|
|
|
+import org.jeecg.modules.rooms.Vo.CesRoomLayoutVo;
|
|
|
+import org.jeecg.modules.rooms.entity.CesGoods;
|
|
|
+import org.jeecg.modules.rooms.entity.CesGoodsUnit;
|
|
|
+import org.jeecg.modules.rooms.entity.CesStockType;
|
|
|
+import org.jeecg.modules.rooms.mapper.CesGoodsMapper;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+/**
|
|
|
+ * <p>
|
|
|
+ * 商品表 服务实现类
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @author fendo
|
|
|
+ * @since 2023-03-13
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class CesGoodsServiceImpl extends ServiceImpl<CesGoodsMapper, CesGoods> implements IService<CesGoods> {
|
|
|
+ @Resource
|
|
|
+ private CesGoodsMapper goodsMapper;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private BusHotelServiceImpl busHotelService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CesStockTypeServiceImpl stockTypeService;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CesGoodsUnitServiceImpl goodsUnitService;
|
|
|
+
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private CesGoodsSpecsServiceImpl specsService;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询商品库存
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Result fetchList(CesGoodsSearchDto dto){
|
|
|
+ QueryWrapper<CesGoods> queryWrapper = new QueryWrapper<>();
|
|
|
+ if(!StringUtils.isBlank(dto.getSearch())){
|
|
|
+ String search = CommonUtils.escapeChar(dto.getSearch());
|
|
|
+ queryWrapper.like(CesGoods.BAR_CODE, search);
|
|
|
+ queryWrapper.like(CesGoods.NAME,search);
|
|
|
+ }
|
|
|
+ queryWrapper.eq(CesGoods.HOTEL_ID,dto.getHotelId());
|
|
|
+ queryWrapper.eq(CesGoods.INVALID,false);
|
|
|
+ queryWrapper.orderByDesc(CesGoods.CREATAT);
|
|
|
+
|
|
|
+ IPage<CesGoods> dataPage = goodsMapper.selectPage(new Page<>(dto.getPageNo().intValue(),dto .getPageSize().intValue()),queryWrapper);
|
|
|
+ List<CesGoods> result = dataPage.getRecords();
|
|
|
+ List<String> hotelIds = result.stream().map(v -> v.getHotelId()).collect(Collectors.toList());
|
|
|
+ List<BusHotel> hotels = busHotelService.findHotelsByIds(hotelIds);
|
|
|
+ List<String> typeIds = result.stream().map(v -> v.getGoodType()).collect(Collectors.toList());
|
|
|
+ List<CesStockType> typeList = stockTypeService.fetchByIds(typeIds);
|
|
|
+ List<String> unitIds = result.stream().map(v -> v.getGoodUnit()).collect(Collectors.toList());
|
|
|
+ List<CesGoodsUnit> unitList = goodsUnitService.fetchByIds(unitIds);
|
|
|
+ List<CesGoodsVo> voList = new ArrayList<>();
|
|
|
+ result.forEach( v -> {
|
|
|
+ CesGoodsVo vo = new CesGoodsVo();
|
|
|
+ BeanUtil.copyProperties(v,vo);
|
|
|
+ Optional<BusHotel> busHotelOptional = hotels.stream().filter(c -> c.getId().equals(v.getHotelId())).findFirst();
|
|
|
+ if(busHotelOptional.isPresent()){
|
|
|
+ vo.setHotelName(busHotelOptional.get().getName());
|
|
|
+ }
|
|
|
+ Optional<CesStockType> typeOptional = typeList.stream().filter(c -> c.getId().equals(v.getGoodType())).findFirst();
|
|
|
+ if(typeOptional.isPresent()){
|
|
|
+ vo.setTypeName(typeOptional.get().getName());
|
|
|
+ }
|
|
|
+ Optional<CesGoodsUnit> unitOptional = unitList.stream().filter(c -> c.getId().equals(v.getGoodUnit())).findFirst();
|
|
|
+ if(unitOptional.isPresent()){
|
|
|
+ vo.setUnitName(unitOptional.get().getName());
|
|
|
+ }
|
|
|
+ voList.add(vo);
|
|
|
+ });
|
|
|
+ Map<String,Object> map = new HashedMap();
|
|
|
+ map.put("records",voList);
|
|
|
+ map.put("total",dataPage.getTotal());
|
|
|
+ return Result.OK(map);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建商品
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Result create(CesGoodsDto dto){
|
|
|
+ //不能有相同条码的数据
|
|
|
+ QueryWrapper<CesGoods> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq(CesGoods.BAR_CODE,dto.getBarCode());
|
|
|
+ queryWrapper.eq(CesGoods.INVALID,false);
|
|
|
+ queryWrapper.eq(CesGoods.HOTEL_ID,dto.getHotelId());
|
|
|
+ //查询
|
|
|
+ CesGoods exitGoods = goodsMapper.selectOne(queryWrapper);
|
|
|
+ if(!ObjectUtils.isEmpty(exitGoods)) return Result.error("该条码已有!");
|
|
|
+
|
|
|
+ CesGoods goods = new CesGoods();
|
|
|
+ BeanUtil.copyProperties(dto,goods);
|
|
|
+ goods.setCreatAt(LocalDateTime.now());
|
|
|
+ goods.setUpdateAt(LocalDateTime.now());
|
|
|
+ goodsMapper.insert(goods);
|
|
|
+ return Result.OK("保存成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改
|
|
|
+ * @param dto
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public Result modify(CesGoodsDto dto){
|
|
|
+ CesGoods goods = goodsMapper.selectOne(Wrappers.<CesGoods>lambdaQuery().eq(CesGoods::getId,dto.getId()).eq(CesGoods::getInvalid,false));
|
|
|
+ if(ObjectUtils.isEmpty(goods)) return Result.error("商品数据未找到!");
|
|
|
+ //不能有相同条码的数据
|
|
|
+ QueryWrapper<CesGoods> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq(CesGoods.BAR_CODE,dto.getBarCode());
|
|
|
+ queryWrapper.eq(CesGoods.INVALID,false);
|
|
|
+ queryWrapper.eq(CesGoods.HOTEL_ID,dto.getHotelId());
|
|
|
+ queryWrapper.ne(CesGoods.ID,dto.getId());
|
|
|
+ //查询
|
|
|
+ CesGoods exitGoods = goodsMapper.selectOne(queryWrapper);
|
|
|
+ if(!ObjectUtils.isEmpty(exitGoods)) return Result.error("该条码已有!");
|
|
|
+
|
|
|
+ BeanUtil.copyProperties(dto,goods,CopyOptions.create().setIgnoreNullValue(true).setIgnoreError(true));
|
|
|
+ goods.setUpdateAt(LocalDateTime.now());
|
|
|
+ goodsMapper.updateById(goods);
|
|
|
+ return Result.ok("修改成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Result delete(String id,String hotelId){
|
|
|
+ CesGoods goods = goodsMapper.selectOne(Wrappers.<CesGoods>lambdaQuery().eq(CesGoods::getId,id).eq(CesGoods::getHotelId,hotelId).eq(CesGoods::getInvalid,false));
|
|
|
+ if(ObjectUtils.isEmpty(goods)) return Result.error("商品数据未找到!");
|
|
|
+ goods.setUpdateAt(LocalDateTime.now());
|
|
|
+ goods.setInvalid(true);
|
|
|
+ goodsMapper.updateById(goods);
|
|
|
+ return Result.ok("删除成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+ public Result delBatch(List<String> ids){
|
|
|
+ if(CollectionUtil.isEmpty(ids)) return Result.ok("删除成功!");
|
|
|
+ List<CesGoods> goods = goodsMapper.selectBatchIds(ids);
|
|
|
+ goods.forEach(good -> {
|
|
|
+ good.setUpdateAt(LocalDateTime.now());
|
|
|
+ good.setInvalid(true);
|
|
|
+ });
|
|
|
+ updateBatchById(goods);
|
|
|
+ return Result.ok("删除成功!");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|