package com.doumee.service.business.impl;
|
|
import com.doumee.biz.system.SystemDictDataBiz;
|
import com.doumee.core.constants.ResponseStatus;
|
import com.doumee.core.exception.BusinessException;
|
import com.doumee.core.model.LoginUserInfo;
|
import com.doumee.core.model.PageData;
|
import com.doumee.core.model.PageWrap;
|
import com.doumee.core.utils.Constants;
|
import com.doumee.core.utils.Utils;
|
import com.doumee.dao.business.BrandMapper;
|
import com.doumee.dao.business.model.Brand;
|
import com.doumee.dao.business.model.Category;
|
import com.doumee.service.business.BrandService;
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import org.apache.shiro.SecurityUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.util.CollectionUtils;
|
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Objects;
|
|
/**
|
* 品牌信息表Service实现
|
* @author 江蹄蹄
|
* @date 2023/05/12 13:58
|
*/
|
@Service
|
public class BrandServiceImpl implements BrandService {
|
|
@Autowired
|
private BrandMapper brandMapper;
|
|
@Autowired
|
private SystemDictDataBiz systemDictDataBiz;
|
@Override
|
public Integer create(Brand brand) {
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
if(brandMapper.selectCount(new QueryWrapper<Brand>().eq("ISDELETED",Constants.ZERO).eq("name",brand.getName()))>0){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"【"+brand.getName()+"】已存在");
|
};
|
brand.setStatus(Constants.ZERO);
|
brand.setCreateDate(new Date());
|
brand.setCreator(user.getId());
|
brand.setIsdeleted(Constants.ZERO);
|
brandMapper.insert(brand);
|
return brand.getId();
|
}
|
|
@Override
|
public void deleteById(Integer id) {
|
Brand brand = brandMapper.selectById(id);
|
if(Objects.isNull(brand)){
|
throw new BusinessException(ResponseStatus.DATA_EMPTY.getCode(),"未查询到对象信息");
|
}
|
brand.setIsdeleted(Constants.ONE);
|
brandMapper.updateById(brand);
|
}
|
|
@Override
|
public void delete(Brand brand) {
|
UpdateWrapper<Brand> deleteWrapper = new UpdateWrapper<>(brand);
|
brandMapper.delete(deleteWrapper);
|
}
|
|
@Override
|
public void deleteByIdInBatch(List<Integer> ids) {
|
if (CollectionUtils.isEmpty(ids)) {
|
return;
|
}
|
brandMapper.deleteBatchIds(ids);
|
}
|
|
@Override
|
public void updateById(Brand brand) {
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
if(brandMapper.selectCount(new QueryWrapper<Brand>().eq("ISDELETED",Constants.ZERO).ne("id",brand.getId()).eq("name",brand.getName()))>0){
|
throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"【"+brand.getName()+"】已存在");
|
};
|
brand.setStatus(Constants.ZERO);
|
brand.setEditDate(new Date());
|
brand.setEditor(user.getId());
|
brand.setIsdeleted(Constants.ZERO);
|
brandMapper.updateById(brand);
|
}
|
|
@Override
|
public void updateByIdInBatch(List<Brand> brands) {
|
if (CollectionUtils.isEmpty(brands)) {
|
return;
|
}
|
for (Brand brand: brands) {
|
this.updateById(brand);
|
}
|
}
|
|
@Override
|
public Brand findById(Integer id) {
|
String prefixUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FILE_DIR).getCode()
|
+ systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode();
|
Brand brand = brandMapper.selectById(id);
|
brand.setImgfullurl(prefixUrl+brand.getImgurl());
|
return brand;
|
}
|
|
@Override
|
public Brand findOne(Brand brand) {
|
QueryWrapper<Brand> wrapper = new QueryWrapper<>(brand);
|
return brandMapper.selectOne(wrapper);
|
}
|
|
@Override
|
public List<Brand> findList(Brand brand) {
|
QueryWrapper<Brand> wrapper = new QueryWrapper<>(brand);
|
wrapper.lambda().eq(Brand::getIsdeleted,Constants.ZERO);
|
wrapper.lambda().eq(Brand::getStatus,Constants.ZERO);
|
wrapper.lambda().orderByAsc(Brand::getSortnum);
|
List<Brand> list = brandMapper.selectList(wrapper);
|
String prefixUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FILE_DIR).getCode()
|
+ systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode();
|
for (Brand b:list) {
|
b.setImgfullurl(prefixUrl+b.getImgurl());
|
}
|
return list;
|
}
|
|
@Override
|
public PageData<Brand> findPage(PageWrap<Brand> pageWrap) {
|
IPage<Brand> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
|
QueryWrapper<Brand> queryWrapper = new QueryWrapper<>();
|
Utils.MP.blankToNull(pageWrap.getModel());
|
queryWrapper.lambda().eq(Brand::getIsdeleted, Constants.ZERO);
|
if (pageWrap.getModel().getName() != null) {
|
queryWrapper.lambda().like(Brand::getName, pageWrap.getModel().getName());
|
}
|
if (pageWrap.getModel().getStatus() != null) {
|
queryWrapper.lambda().eq(Brand::getStatus, pageWrap.getModel().getStatus());
|
}
|
queryWrapper.lambda().orderByAsc(Brand::getSortnum);
|
IPage<Brand> brandIPage = brandMapper.selectPage(page, queryWrapper);
|
String prefixUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FILE_DIR).getCode()
|
+ systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.PROJECTS).getCode();
|
brandIPage.getRecords().forEach(i->{
|
i.setImgfullurl(prefixUrl+i.getImgurl());
|
});
|
return PageData.from(brandIPage);
|
}
|
|
@Override
|
public long count(Brand brand) {
|
QueryWrapper<Brand> wrapper = new QueryWrapper<>(brand);
|
return brandMapper.selectCount(wrapper);
|
}
|
}
|