package com.doumee.service.business.impl;
|
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.doumee.biz.system.SystemDictDataBiz;
|
import com.doumee.core.constants.Constants;
|
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.Utils;
|
import com.doumee.dao.business.CarouselMapper;
|
import com.doumee.dao.business.model.Carousel;
|
import com.doumee.dao.dto.FootDataDTO;
|
import com.doumee.dao.system.model.SystemDictData;
|
import com.doumee.dao.vo.FootDataVO;
|
import com.doumee.service.business.CarouselService;
|
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 com.doumee.service.system.SystemDictDataService;
|
import org.apache.shiro.SecurityUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.StringUtils;
|
|
import java.util.Date;
|
import java.util.List;
|
import java.util.Objects;
|
|
/**
|
* 轮播图Service实现
|
* @author 江蹄蹄
|
* @since 2025/06/18 09:30
|
*/
|
@Service
|
public class CarouselServiceImpl implements CarouselService {
|
|
@Autowired
|
private CarouselMapper carouselMapper;
|
|
@Autowired
|
private SystemDictDataBiz systemDictDataBiz;
|
|
@Autowired
|
private SystemDictDataService systemDictDataService;
|
|
@Override
|
public Integer create(Carousel carousel) {
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
if(Objects.isNull(carousel)
|
// || Objects.isNull(carousel.getImgurl())
|
|| Objects.isNull(carousel.getJumpType())
|
// || Objects.isNull(carousel.getSortnum())
|
|| StringUtils.isEmpty(carousel.getTitle())
|
){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST);
|
}
|
carousel.setType(Constants.ZERO);
|
carousel.setIsdeleted(Constants.ZERO);
|
carousel.setStatus(Constants.ZERO);
|
carousel.setCreateDate(new Date());
|
carousel.setCreator(user.getId());
|
carouselMapper.insert(carousel);
|
return carousel.getId();
|
}
|
|
|
@Override
|
public void deleteById(Integer id) {
|
carouselMapper.update(new UpdateWrapper<Carousel>().lambda().set(Carousel::getIsdeleted,Constants.ONE).eq(Carousel::getId,id));
|
}
|
|
@Override
|
public void delete(Carousel carousel) {
|
UpdateWrapper<Carousel> deleteWrapper = new UpdateWrapper<>(carousel);
|
carouselMapper.delete(deleteWrapper);
|
}
|
|
@Override
|
public void deleteByIdInBatch(List<Integer> ids) {
|
if (CollectionUtils.isEmpty(ids)) {
|
return;
|
}
|
carouselMapper.deleteBatchIds(ids);
|
}
|
|
@Override
|
public void updateById(Carousel carousel) {
|
LoginUserInfo user = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal();
|
if(Objects.isNull(carousel)
|
|| Objects.isNull(carousel.getId())
|
|| Objects.isNull(carousel.getImgurl())
|
|| Objects.isNull(carousel.getJumpType())
|
|| Objects.isNull(carousel.getSortnum())
|
){
|
throw new BusinessException(ResponseStatus.BAD_REQUEST);
|
}
|
carousel.setIsdeleted(Constants.ZERO);
|
carousel.setStatus(Constants.ZERO);
|
carousel.setEditDate(new Date());
|
carousel.setEditor(user.getId());
|
carousel.setType(null);
|
carouselMapper.updateById(carousel);
|
}
|
|
@Override
|
public void updateByIdInBatch(List<Carousel> carousels) {
|
if (CollectionUtils.isEmpty(carousels)) {
|
return;
|
}
|
for (Carousel carousel: carousels) {
|
this.updateById(carousel);
|
}
|
}
|
|
|
@Override
|
public void updateStatus(Carousel carousel){
|
if(Objects.isNull(carousel)
|
|| Objects.isNull(carousel.getStatus())
|
|| Objects.isNull(carousel.getId())
|
|| !(Constants.equalsInteger(carousel.getStatus(),Constants.ZERO)
|
|| Constants.equalsInteger(carousel.getStatus(),Constants.ONE))
|
){
|
throw new BusinessException(ResponseStatus.DATA_EMPTY);
|
}
|
carouselMapper.update(new UpdateWrapper<Carousel>().lambda().set(Carousel::getStatus,carousel.getStatus()).eq(Carousel::getId,carousel.getId()));
|
}
|
|
@Override
|
public void updateSortnum(Carousel carousel){
|
if(Objects.isNull(carousel)
|
|| Objects.isNull(carousel.getSortnum())
|
|| Objects.isNull(carousel.getId())
|
){
|
throw new BusinessException(ResponseStatus.DATA_EMPTY);
|
}
|
carouselMapper.update(new UpdateWrapper<Carousel>().lambda().set(Carousel::getSortnum,carousel.getSortnum()).eq(Carousel::getId,carousel.getId()));
|
}
|
|
|
@Override
|
public Carousel findById(Integer id) {
|
Carousel carousel = new Carousel();
|
if(Objects.isNull(carousel)){
|
throw new BusinessException(ResponseStatus.DATA_EMPTY);
|
}
|
String fileDir = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FILE_DIR).getCode();
|
this.imgFullPath(fileDir,carousel);
|
return carousel;
|
}
|
|
public void imgFullPath(String fileDir,Carousel carousel){
|
if(org.apache.commons.lang3.StringUtils.isNotBlank(carousel.getImgurl())){
|
carousel.setFullImgurl(fileDir + carousel.getImgurl());
|
}
|
if(org.apache.commons.lang3.StringUtils.isNotBlank(carousel.getThumbnailImgurl())){
|
carousel.setFullThumbnailImgurl(fileDir + carousel.getThumbnailImgurl());
|
}
|
}
|
|
@Override
|
public Carousel findOne(Carousel carousel) {
|
QueryWrapper<Carousel> wrapper = new QueryWrapper<>(carousel);
|
return carouselMapper.selectOne(wrapper);
|
}
|
|
@Override
|
public List<Carousel> findList() {
|
QueryWrapper<Carousel> wrapper = new QueryWrapper<>();
|
wrapper.lambda().eq(Carousel::getIsdeleted,Constants.ZERO)
|
.eq(Carousel::getStatus,Constants.ZERO)
|
.orderByDesc(Carousel::getSortnum);
|
List<Carousel> carouselList =
|
carouselMapper.selectList(wrapper);
|
if(com.github.xiaoymin.knife4j.core.util.CollectionUtils.isNotEmpty(carouselList)){
|
String fileDir = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FILE_DIR).getCode();
|
for (Carousel carousel:carouselList) {
|
this.imgFullPath(fileDir,carousel);
|
}
|
}
|
return carouselList;
|
}
|
|
@Override
|
public PageData<Carousel> findPage(PageWrap<Carousel> pageWrap) {
|
IPage<Carousel> page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity());
|
QueryWrapper<Carousel> queryWrapper = new QueryWrapper<>();
|
Utils.MP.blankToNull(pageWrap.getModel());
|
queryWrapper.lambda().eq(Carousel::getIsdeleted,Constants.ZERO)
|
.eq(pageWrap.getModel().getId() != null, Carousel::getId, pageWrap.getModel().getId())
|
.eq(pageWrap.getModel().getRemark() != null, Carousel::getRemark, pageWrap.getModel().getRemark())
|
.like(pageWrap.getModel().getTitle() != null, Carousel::getTitle, pageWrap.getModel().getTitle())
|
.eq(pageWrap.getModel().getType() != null, Carousel::getType, pageWrap.getModel().getType())
|
.like(pageWrap.getModel().getDetail() != null, Carousel::getDetail, pageWrap.getModel().getDetail())
|
.eq(pageWrap.getModel().getJumpType() != null, Carousel::getJumpType, pageWrap.getModel().getJumpType())
|
.like(pageWrap.getModel().getContent() != null, Carousel::getContent, pageWrap.getModel().getContent())
|
.eq(pageWrap.getModel().getSortnum() != null, Carousel::getSortnum, pageWrap.getModel().getSortnum())
|
.eq(pageWrap.getModel().getStatus() != null, Carousel::getStatus, pageWrap.getModel().getStatus())
|
.orderByDesc(Carousel::getSortnum)
|
|
;
|
for(PageWrap.SortData sortData: pageWrap.getSorts()) {
|
if (sortData.getDirection().equalsIgnoreCase(PageWrap.DESC)) {
|
queryWrapper.orderByDesc(sortData.getProperty());
|
} else {
|
queryWrapper.orderByAsc(sortData.getProperty());
|
}
|
}
|
IPage<Carousel> iPage = carouselMapper.selectPage(page, queryWrapper);
|
String fileDir = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FILE_DIR).getCode();
|
for (Carousel carousel:iPage.getRecords()) {
|
this.imgFullPath(fileDir,carousel);
|
}
|
return PageData.from(iPage);
|
}
|
|
@Override
|
public long count(Carousel carousel) {
|
QueryWrapper<Carousel> wrapper = new QueryWrapper<>(carousel);
|
return carouselMapper.selectCount(wrapper);
|
}
|
|
|
|
@Override
|
public FootDataVO getFoodDataVO(){
|
FootDataVO footDataVO = new FootDataVO();
|
String path =systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FILE_DIR).getCode();
|
footDataVO.setFootWords(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FOOT_WORDS).getCode());
|
footDataVO.setFootImgUrl(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FOOT_IMGURL).getCode());
|
footDataVO.setFootFullImgUrl(path+
|
footDataVO.getFootImgUrl());
|
footDataVO.setFootImgUrl2(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.FOOT_IMGURL2).getCode());
|
footDataVO.setFootFullImgUrl2(path +
|
footDataVO.getFootImgUrl2());
|
footDataVO.setAddress(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.ADDRESS).getCode());
|
footDataVO.setLinkPhone(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.LINK_PHONE).getCode());
|
footDataVO.setLinkMobile(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.LINK_MOBILE).getCode());
|
SystemDictData solveScheme = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SOLVE_SCHEME);
|
if(Objects.nonNull(solveScheme) & org.apache.commons.lang3.StringUtils.isNotBlank(solveScheme.getCode())){
|
footDataVO.setSolveScheme(JSONArray.parseArray(solveScheme.getCode()));
|
}
|
SystemDictData wisdomSystem = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.WISDOM_SYSTEM);
|
if(Objects.nonNull(wisdomSystem) & org.apache.commons.lang3.StringUtils.isNotBlank(wisdomSystem.getCode())){
|
footDataVO.setWisdomSystem(JSONArray.parseArray(wisdomSystem.getCode()));
|
}
|
SystemDictData honors = systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.HONORS);
|
if(Objects.nonNull(wisdomSystem) & org.apache.commons.lang3.StringUtils.isNotBlank(honors.getCode())){
|
footDataVO.setHonors(JSONArray.parseArray(honors.getCode()));
|
}
|
footDataVO.setServerTime(systemDictDataBiz.queryByCode(Constants.SYSTEM,Constants.SERVER_TIME).getCode());
|
return footDataVO;
|
}
|
|
|
|
|
@Override
|
@Transactional(rollbackFor = {Exception.class})
|
public void updFoodDataVO(FootDataDTO footDataDTO) {
|
SystemDictData footWords = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FOOT_WORDS);
|
if (Objects.nonNull(footWords)) {
|
footWords.setCode(footDataDTO.getFootWords());
|
systemDictDataBiz.updateById(footWords);
|
}
|
|
SystemDictData footImgUrl = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.FOOT_IMGURL);
|
if (Objects.nonNull(footImgUrl)) {
|
footImgUrl.setCode(footDataDTO.getFootImgUrl());
|
systemDictDataBiz.updateById(footImgUrl);
|
}
|
|
SystemDictData linkPhone = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.LINK_PHONE);
|
if (Objects.nonNull(linkPhone)) {
|
linkPhone.setCode(footDataDTO.getLinkPhone());
|
systemDictDataBiz.updateById(linkPhone);
|
}
|
|
SystemDictData linkMobile = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.LINK_MOBILE);
|
if (Objects.nonNull(linkMobile)) {
|
linkMobile.setCode(footDataDTO.getLinkMobile());
|
systemDictDataBiz.updateById(linkMobile);
|
}
|
|
SystemDictData serverTime = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.SERVER_TIME);
|
if (Objects.nonNull(serverTime)) {
|
serverTime.setCode(footDataDTO.getServerTime());
|
systemDictDataBiz.updateById(serverTime);
|
}
|
|
SystemDictData address = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.ADDRESS);
|
if (Objects.nonNull(address)) {
|
address.setCode(footDataDTO.getAddress());
|
systemDictDataBiz.updateById(address);
|
}
|
|
SystemDictData solveScheme = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.SOLVE_SCHEME);
|
if (Objects.nonNull(solveScheme)&&Objects.nonNull(footDataDTO.getSolveScheme())) {
|
solveScheme.setCode(footDataDTO.getSolveScheme().toString());
|
systemDictDataBiz.updateById(solveScheme);
|
}
|
|
SystemDictData wisdomSystem = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.WISDOM_SYSTEM);
|
if (Objects.nonNull(wisdomSystem)&&Objects.nonNull(footDataDTO.getWisdomSystem())) {
|
wisdomSystem.setCode(footDataDTO.getWisdomSystem().toString());
|
systemDictDataBiz.updateById(wisdomSystem);
|
}
|
SystemDictData honors = systemDictDataBiz.queryByCode(Constants.SYSTEM, Constants.HONORS);
|
if (Objects.nonNull(wisdomSystem)&&Objects.nonNull(footDataDTO.getHonors())) {
|
wisdomSystem.setCode(footDataDTO.getHonors().toString());
|
systemDictDataBiz.updateById(wisdomSystem);
|
}
|
}
|
|
|
|
}
|