| | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.github.yulichang.wrapper.MPJLambdaWrapper; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.apache.shiro.SecurityUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Lazy; |
| | |
| | | |
| | | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) |
| | | @Override |
| | | public void updateStatusByIds(List<Integer> idList, Integer status) { |
| | | if (CollectionUtils.isEmpty(idList)){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"商品状态不能为空"); |
| | | public void updateStatusByIds(BaseGoods param) { |
| | | if (CollectionUtils.isEmpty(param.getIdList()) |
| | | || param.getStatus() == null |
| | | || !(Constants.equalsInteger(param.getStatus(), Constants.ONE)||Constants.equalsInteger(param.getStatus() ,Constants.ZERO))){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST); |
| | | } |
| | | idList.forEach(s->updateStatusById(s,status)); |
| | | |
| | | param.getIdList().forEach(s->updateStatusById(s,param.getStatus())); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = {Exception.class,BusinessException.class}) |
| | | @Override |
| | | public void updateStatusById(Integer id, Integer status) { |
| | | |
| | | LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); |
| | | if (Objects.isNull(status)){ |
| | | throw new BusinessException(ResponseStatus.BAD_REQUEST.getCode(),"商品状态不能为空"); |
| | | } |
| | | if (Constants.equalsInteger(status,Constants.ZERO)){ |
| | | //如果启用 |
| | | BaseGoods baseGoods = new BaseGoods(); |
| | | baseGoods.setId(id); |
| | | baseGoods.setEditDate(new Date()); |
| | | baseGoods.setEditor(user.getId()); |
| | | baseGoods.setStatus(status); |
| | | baseGoodsMapper.updateById(baseGoods); |
| | | }else if (Constants.equalsInteger(status,Constants.ONE)){ |
| | | //如果禁用 |
| | | BaseGoods baseGoods = new BaseGoods(); |
| | | baseGoods.setId(id); |
| | | baseGoods.setEditDate(new Date()); |
| | | baseGoods.setEditor(user.getId()); |
| | | baseGoods.setStatus(status); |
| | | baseGoodsMapper.updateById(baseGoods); |
| | | |
| | |
| | | goodsUpdate.lambda() |
| | | .eq(Goods::getType,Constants.ONE) |
| | | .eq(Goods::getGoodsId,id) |
| | | .set(Goods::getStatus,Constants.ONE); |
| | | .set(Goods::getStatus,Constants.ONE) |
| | | .set(Goods::getEditor,user.getId()) |
| | | .set(Goods::getEditDate,new Date()); |
| | | goodsMapper.update(null,goodsUpdate); |
| | | } |
| | | } |
| | |
| | | |
| | | @Override |
| | | public PageData<BaseGoods> findPage(PageWrap<BaseGoods> pageWrap) { |
| | | pageWrap.getModel().setIsdeleted(Constants.ZERO); |
| | | IPage<BaseGoods> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); |
| | | MPJLambdaWrapper<BaseGoods> queryWrapper = new MPJLambdaWrapper<>(); |
| | | Utils.MP.blankToNull(pageWrap.getModel()); |
| | | |
| | | if (pageWrap.getModel().getId() != null) { |
| | | queryWrapper.like(BaseGoods::getId, pageWrap.getModel().getId()); |
| | | } |
| | | if (pageWrap.getModel().getName() != null) { |
| | | queryWrapper.eq(BaseGoods::getName, pageWrap.getModel().getName()); |
| | | } |
| | | if (pageWrap.getModel().getStatus() != null) { |
| | | queryWrapper.eq(BaseGoods::getStatus, pageWrap.getModel().getStatus()); |
| | | } |
| | | if (pageWrap.getModel().getCategoryId() != null) { |
| | | queryWrapper.eq(BaseGoods::getCategoryId, pageWrap.getModel().getCategoryId()); |
| | | } |
| | | if (pageWrap.getModel().getBrandId() != null) { |
| | | queryWrapper.eq(BaseGoods::getBrandId, pageWrap.getModel().getBrandId()); |
| | | } |
| | | queryWrapper.leftJoin(Brand.class,Brand::getId,BaseGoods::getBrandId) |
| | | .leftJoin(BaseCategory.class,BaseCategory::getId,BaseGoods::getBaseDataId) |
| | | .leftJoin(BaseCategory.class,BaseCategory::getId,BaseGoods::getCategoryId) |
| | | .selectAll(BaseGoods.class) |
| | | .selectAs(Brand::getName,BaseGoods::getBrandName) |
| | | .selectAs(BaseCategory::getSortnum,BaseGoods::getCategoryName); |
| | | .selectAs(BaseCategory::getName,BaseGoods::getCategoryName) |
| | | .eq(BaseGoods::getIsdeleted, Constants.ZERO) |
| | | .like(StringUtils.isNotBlank(pageWrap.getModel().getName()), BaseGoods::getName,pageWrap.getModel().getName()) |
| | | .eq(pageWrap.getModel().getId()!=null,BaseGoods::getId, pageWrap.getModel().getId()) |
| | | .eq(pageWrap.getModel().getCategoryId()!=null,BaseGoods::getCategoryId, pageWrap.getModel().getCategoryId()) |
| | | .eq(pageWrap.getModel().getBrandId()!=null,BaseGoods::getBrandId, pageWrap.getModel().getBrandId()) |
| | | .eq(pageWrap.getModel().getStatus()!=null,BaseGoods::getStatus, pageWrap.getModel().getStatus()); |
| | | |
| | | queryWrapper.orderByDesc(Goods::getId); |
| | | return PageData.from(baseGoodsJoinMapper.selectJoinPage(page,BaseGoods.class,queryWrapper)); |
| | | PageData<BaseGoods> pageData =PageData.from(baseGoodsJoinMapper.selectJoinPage(page,BaseGoods.class,queryWrapper)); |
| | | String prefixUrl = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() |
| | | + systemDictDataBiz.queryByCode(Constants.OSS, Constants.GOODS_IMG).getCode(); |
| | | pageData.getRecords().forEach(i->{ |
| | | i.setFullImgUrl(prefixUrl + i.getImgurl()); |
| | | }); |
| | | return pageData; |
| | | } |
| | | |
| | | @Override |