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.ApplicationInfoMapper; import com.doumee.dao.business.ServerProviderMapper; import com.doumee.dao.business.model.ApplicationInfo; import com.doumee.dao.business.model.Labels; import com.doumee.dao.business.model.ServerProvider; import com.doumee.service.business.ApplicationInfoService; 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.github.yulichang.wrapper.MPJLambdaWrapper; import io.swagger.models.Model; import org.apache.commons.lang3.StringUtils; 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 2025/09/08 10:24 */ @Service public class ApplicationInfoServiceImpl implements ApplicationInfoService { @Autowired private ApplicationInfoMapper applicationInfoMapper; @Autowired private ServerProviderMapper serverProviderMapper; @Autowired private SystemDictDataBiz systemDictDataBiz; @Override public Integer create(ApplicationInfo applicationInfo) { if(Objects.isNull(applicationInfo) || Objects.isNull(applicationInfo.getServerId()) || StringUtils.isBlank(applicationInfo.getName()) || StringUtils.isBlank(applicationInfo.getLogo()) ){ throw new BusinessException(ResponseStatus.BAD_REQUEST); } if(serverProviderMapper.selectCount(new QueryWrapper().lambda().eq(ServerProvider::getIsdeleted, Constants.ZERO) .eq(ServerProvider::getId,applicationInfo.getServerId()))<=Constants.ZERO){ throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"服务商信息已删除!"); } LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); applicationInfo.setCreateDate(new Date()); applicationInfo.setCreator(loginUserInfo.getId()); applicationInfo.setEditor(applicationInfo.getCreator()); applicationInfo.setEditDate(applicationInfo.getCreateDate()); applicationInfo.setStatus(Constants.ZERO); applicationInfo.setIsdeleted(Constants.ZERO); applicationInfoMapper.insert(applicationInfo); return applicationInfo.getId(); } @Override public void deleteById(Integer id) { applicationInfoMapper.update(null,new UpdateWrapper().lambda() .set(ApplicationInfo::getIsdeleted,Constants.ONE).eq(ApplicationInfo::getId,id)); } @Override public void delete(ApplicationInfo applicationInfo) { UpdateWrapper deleteWrapper = new UpdateWrapper<>(applicationInfo); applicationInfoMapper.delete(deleteWrapper); } @Override public void deleteByIdInBatch(List ids) { if (CollectionUtils.isEmpty(ids)) { return; } applicationInfoMapper.deleteBatchIds(ids); } @Override public void updateById(ApplicationInfo applicationInfo) { if(Objects.isNull(applicationInfo) || Objects.isNull(applicationInfo.getId()) || Objects.isNull(applicationInfo.getServerId()) || StringUtils.isBlank(applicationInfo.getName()) || StringUtils.isBlank(applicationInfo.getLogo()) ){ throw new BusinessException(ResponseStatus.BAD_REQUEST); } LoginUserInfo loginUserInfo = (LoginUserInfo) SecurityUtils.getSubject().getPrincipal(); applicationInfo.setEditor(loginUserInfo.getId()); applicationInfo.setEditDate(new Date()); applicationInfoMapper.updateById(applicationInfo); } @Override public void updateByIdInBatch(List applicationInfos) { if (CollectionUtils.isEmpty(applicationInfos)) { return; } for (ApplicationInfo applicationInfo: applicationInfos) { this.updateById(applicationInfo); } } @Override public void updateStatus(ApplicationInfo applicationInfo) { if(Objects.isNull(applicationInfo) || Objects.isNull(applicationInfo.getId()) || Objects.isNull(applicationInfo.getStatus()) ){ throw new BusinessException(ResponseStatus.BAD_REQUEST); } applicationInfoMapper.update(null,new UpdateWrapper().lambda().set(ApplicationInfo::getStatus,applicationInfo.getStatus()) .eq(ApplicationInfo::getId,applicationInfo.getId())); } @Override public ApplicationInfo findById(Integer id) { MPJLambdaWrapper queryWrapper = new MPJLambdaWrapper(); queryWrapper.selectAll(ApplicationInfo.class) .selectAs(ServerProvider::getName,ApplicationInfo::getServerName) .leftJoin(ServerProvider.class,ServerProvider::getId,ApplicationInfo::getServerId) .eq(ApplicationInfo::getId,id) .orderByDesc(ApplicationInfo::getId) ; String prefix = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() + systemDictDataBiz.queryByCode(Constants.OSS, Constants.LOGO_FILE).getCode(); ApplicationInfo applicationInfo = applicationInfoMapper.selectJoinOne(ApplicationInfo.class,queryWrapper); if(Objects.isNull(applicationInfo)){ throw new BusinessException(ResponseStatus.DATA_EMPTY); } applicationInfo.setFullLog(prefix + applicationInfo.getLogo()); if(StringUtils.isNotBlank(applicationInfo.getMutifileUrl())){ applicationInfo.setFullMutifileUrl(prefix + applicationInfo.getMutifileUrl()); } return applicationInfo; } @Override public ApplicationInfo findOne(ApplicationInfo applicationInfo) { QueryWrapper wrapper = new QueryWrapper<>(applicationInfo); return applicationInfoMapper.selectOne(wrapper); } @Override public List findList(ApplicationInfo applicationInfo) { QueryWrapper wrapper = new QueryWrapper<>(applicationInfo); return applicationInfoMapper.selectList(wrapper); } @Override public PageData findPage(PageWrap pageWrap) { IPage page = new Page<>(pageWrap.getPage(), pageWrap.getCapacity()); MPJLambdaWrapper queryWrapper = new MPJLambdaWrapper(); Utils.MP.blankToNull(pageWrap.getModel()); ApplicationInfo model = pageWrap.getModel(); queryWrapper.selectAll(ApplicationInfo.class) .selectAs(ServerProvider::getName,ApplicationInfo::getServerName) .leftJoin(ServerProvider.class,ServerProvider::getId,ApplicationInfo::getServerId) .eq(ApplicationInfo::getIsdeleted,Constants.ZERO) .eq(Objects.nonNull(model.getStatus()),ApplicationInfo::getStatus,model.getStatus()) .like(StringUtils.isNotBlank(model.getName()),ApplicationInfo::getName,model.getName()) .like(StringUtils.isNotBlank(model.getServerName()),ServerProvider::getName,model.getServerName()) .and(StringUtils.isNotBlank(model.getApplicationInfo()),i->i.like(ApplicationInfo::getName,model.getApplicationInfo()).or().like(ServerProvider::getName,model.getApplicationInfo())) .orderByDesc(ServerProvider::getId) ; IPage iPage = applicationInfoMapper.selectJoinPage(page, ApplicationInfo.class ,queryWrapper); String prefix = systemDictDataBiz.queryByCode(Constants.OSS, Constants.RESOURCE_PATH).getCode() + systemDictDataBiz.queryByCode(Constants.OSS, Constants.LOGO_FILE).getCode(); iPage.getRecords().forEach(i->{ i.setFullLog(prefix + i.getLogo()); if(StringUtils.isNotBlank(i.getMutifileUrl())){ i.setFullMutifileUrl(prefix + i.getMutifileUrl()); } }); return PageData.from(iPage); } @Override public long count(ApplicationInfo applicationInfo) { QueryWrapper wrapper = new QueryWrapper<>(applicationInfo); return applicationInfoMapper.selectCount(wrapper); } }