New file |
| | |
| | | package com.panzhihua.service_community.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.panzhihua.common.model.vos.common.ComBatteryCommodityVo; |
| | | import com.panzhihua.common.model.vos.common.ComBatteryStoreClassVo; |
| | | import com.panzhihua.service_community.dao.ComBatteryCommodityMapper; |
| | | import com.panzhihua.service_community.entity.ComBatteryCommodity; |
| | | import com.panzhihua.service_community.entity.ComBatteryStoreClass; |
| | | import com.panzhihua.service_community.dao.ComBatteryStoreClassMapper; |
| | | import com.panzhihua.service_community.service.ComBatteryStoreClassService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import org.springframework.beans.BeanUtils; |
| | | import com.panzhihua.common.model.dtos.common.*; |
| | | import com.panzhihua.common.model.vos.R; |
| | | import org.springframework.stereotype.Service; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * title: 电动车商城-商家分类表表服务实现类 |
| | | * <p> |
| | | * projectName 成都呐喊信息技术有限公司-智慧社区项目 |
| | | * <p> |
| | | * description: 电动车商城-商家分类表表服务实现类 |
| | | * |
| | | * @author lyq |
| | | * @date 2022-03-29 11:01:56 |
| | | */ |
| | | @Service("comBatteryStoreClassService") |
| | | public class ComBatteryStoreClassServiceImpl extends ServiceImpl<ComBatteryStoreClassMapper, ComBatteryStoreClass> implements ComBatteryStoreClassService { |
| | | |
| | | @Resource |
| | | private ComBatteryCommodityMapper commodityMapper; |
| | | |
| | | /** |
| | | * description queryByPage 分页查询 |
| | | * |
| | | * @param comBatteryStoreClass 请求参数 |
| | | * @return 分页查询列表数据 |
| | | * @author lyq |
| | | * @date 2022-03-29 11:01:56 |
| | | */ |
| | | @Override |
| | | public R queryByPage(PageComBatteryStoreClassDto comBatteryStoreClass) { |
| | | return R.ok(this.baseMapper.queryAllByLimit(comBatteryStoreClass, new Page(comBatteryStoreClass.getPageNum(), comBatteryStoreClass.getPageSize()))); |
| | | } |
| | | |
| | | /** |
| | | * description insert 新增数据 |
| | | * |
| | | * @param comBatteryStoreClass 请求参数 |
| | | * @return 新增结果 |
| | | * @author lyq |
| | | * @date 2022-03-29 11:01:56 |
| | | */ |
| | | @Override |
| | | public R insert(AddComBatteryStoreClassDto comBatteryStoreClass) { |
| | | ComBatteryStoreClass entity = new ComBatteryStoreClass(); |
| | | BeanUtils.copyProperties(comBatteryStoreClass, entity); |
| | | if (this.baseMapper.insert(entity) > 0) { |
| | | return R.ok(); |
| | | } |
| | | return R.fail("添加失败"); |
| | | } |
| | | |
| | | /** |
| | | * description update 修改数据 |
| | | * |
| | | * @param editDto 请求参数 |
| | | * @return 修改结果 |
| | | * @author lyq |
| | | * @date 2022-03-29 11:01:56 |
| | | */ |
| | | @Override |
| | | public R update(EditComBatteryStoreClassDto editDto) { |
| | | ComBatteryStoreClass entity = this.baseMapper.selectById(editDto.getId()); |
| | | if (entity == null) { |
| | | return R.fail("未查询到该记录"); |
| | | } |
| | | BeanUtils.copyProperties(editDto, entity); |
| | | if (this.baseMapper.updateById(entity) > 0) { |
| | | return R.ok(); |
| | | } |
| | | return R.fail("修改失败"); |
| | | } |
| | | |
| | | /** |
| | | * description deleteById 通过主键删除数据 |
| | | * |
| | | * @param id 主键id |
| | | * @return 删除结果 |
| | | * @author lyq |
| | | * @date 2022-03-29 11:01:56 |
| | | */ |
| | | @Override |
| | | public R deleteById(Long id) { |
| | | Integer count = commodityMapper.selectCount(new QueryWrapper<ComBatteryCommodity>().lambda() |
| | | .eq(ComBatteryCommodity::getClassId,id).eq(ComBatteryCommodity::getIsDel,ComBatteryCommodity.IsDel.NO)); |
| | | if(count > 0){ |
| | | return R.fail("该分类下已绑定商品,不可删除"); |
| | | } |
| | | if (this.baseMapper.deleteById(id) > 0) { |
| | | return R.ok(); |
| | | } |
| | | return R.fail("删除失败"); |
| | | } |
| | | |
| | | /** |
| | | * description detailById 查询详情 |
| | | * |
| | | * @param id 主键id |
| | | * @return 详情数据 |
| | | * @author lyq |
| | | * @date 2022-03-29 11:01:56 |
| | | */ |
| | | @Override |
| | | public R detailById(Long id) { |
| | | return R.ok(this.baseMapper.queryById(id)); |
| | | } |
| | | |
| | | /** |
| | | * description queryByPage 查询列表 |
| | | * |
| | | * @param comBatteryStoreClass 请求参数 |
| | | * @return 列表数据 |
| | | * @author lyq |
| | | * @date 2022-03-29 11:01:56 |
| | | */ |
| | | @Override |
| | | public R queryByList(PageComBatteryStoreClassDto comBatteryStoreClass) { |
| | | return R.ok(this.baseMapper.queryAllByList(comBatteryStoreClass)); |
| | | } |
| | | |
| | | /** |
| | | * 修改分类状态 |
| | | * @param id 分类id |
| | | * @param status 状态 |
| | | * @return 修改结果 |
| | | */ |
| | | @Override |
| | | public R updateStatus(Long id, Integer status) { |
| | | ComBatteryStoreClass entity = new ComBatteryStoreClass(); |
| | | entity.setId(id); |
| | | entity.setStatus(status); |
| | | if (this.baseMapper.updateById(entity) > 0) { |
| | | return R.ok(); |
| | | } |
| | | return R.fail("修改失败"); |
| | | } |
| | | |
| | | /** |
| | | * 小程序查询商家分类列表以及分类下商品列表 |
| | | * @param comBatteryStoreClass 请求参数 |
| | | * @return 商家分类列表以及分类下商品列表 |
| | | */ |
| | | @Override |
| | | public R queryByAppletsList(PageComBatteryStoreClassDto comBatteryStoreClass) { |
| | | List<ComBatteryStoreClassVo> storeClassList = this.baseMapper.queryAllByList(comBatteryStoreClass); |
| | | storeClassList.forEach(storeClass -> { |
| | | List<ComBatteryCommodityVo> commodityList = commodityMapper.queryAllByClassIdList(storeClass.getId()); |
| | | storeClass.setCommodityList(commodityList); |
| | | }); |
| | | return R.ok(storeClassList); |
| | | } |
| | | } |