package com.oying.modules.pc.store.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.oying.exception.BadRequestException;
|
import com.oying.modules.pc.common.core.constrant.AuditStatusEnum;
|
import com.oying.modules.pc.store.domain.StoreAudit;
|
import com.oying.modules.pc.store.domain.dto.StoreAuditQueryCriteria;
|
import com.oying.modules.pc.store.events.StoreAuditVerdictEvent;
|
import com.oying.modules.pc.store.mapper.StoreAuditMapper;
|
import com.oying.modules.pc.store.service.StoreAuditService;
|
import com.oying.utils.FileUtil;
|
import com.oying.utils.PageResult;
|
import com.oying.utils.PageUtil;
|
import lombok.RequiredArgsConstructor;
|
import org.springframework.context.ApplicationEventPublisher;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.IOException;
|
import java.util.ArrayList;
|
import java.util.LinkedHashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* @author lzp
|
* @description 服务实现
|
* @date 2025-07-01
|
**/
|
@Service
|
@RequiredArgsConstructor
|
public class StoreAuditServiceImpl extends ServiceImpl<StoreAuditMapper, StoreAudit> implements StoreAuditService {
|
|
private final ApplicationEventPublisher eventPublisher;
|
|
private final StoreAuditMapper storeAuditMapper;
|
|
@Override
|
public PageResult<StoreAudit> queryAll(StoreAuditQueryCriteria criteria, Page<Object> page) {
|
return PageUtil.toPage(storeAuditMapper.findAll(criteria, page));
|
}
|
|
@Override
|
public List<StoreAudit> queryAll(StoreAuditQueryCriteria criteria) {
|
return storeAuditMapper.findAll(criteria);
|
}
|
|
@Override
|
public StoreAudit getByStoreId(Long storeId) {
|
LambdaQueryWrapper<StoreAudit> wrapper = new LambdaQueryWrapper<StoreAudit>()
|
.eq(StoreAudit::getStoreId, storeId);
|
return storeAuditMapper.selectOne(wrapper);
|
}
|
|
@Override
|
public boolean hasPendingByStoreId(Long storeId) {
|
LambdaQueryWrapper<StoreAudit> wrapper = new LambdaQueryWrapper<StoreAudit>()
|
.eq(StoreAudit::getStoreId, storeId)
|
.eq(StoreAudit::getStatus, AuditStatusEnum.PENDING.getValue());
|
return storeAuditMapper.selectCount(wrapper) > 0;
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void create(StoreAudit resources) {
|
storeAuditMapper.insert(resources);
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void update(StoreAudit resources, boolean isDirectUpdate) {
|
if (isDirectUpdate) {
|
storeAuditMapper.updateById(resources);
|
} else {
|
StoreAudit existingRevision = this.getById(resources.getAuditor());
|
existingRevision.copy(resources);
|
storeAuditMapper.updateById(existingRevision);
|
}
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void processVerdict(StoreAudit resources) {
|
AuditStatusEnum newAuditStatus = AuditStatusEnum.get(resources.getStatus());
|
StoreAudit existingAudit = this.getById(resources.getAuditId());
|
AuditStatusEnum existingAuditStatus = AuditStatusEnum.getOrDefault(existingAudit.getStatus(), AuditStatusEnum.DRAFT);
|
if (!existingAuditStatus.nextContains(newAuditStatus)) {
|
throw new BadRequestException("审核状态错误");
|
}
|
existingAudit.copy(resources);
|
storeAuditMapper.updateById(existingAudit);
|
eventPublisher.publishEvent(new StoreAuditVerdictEvent(existingAudit.getAuditId()));
|
}
|
|
@Override
|
@Transactional(rollbackFor = Exception.class)
|
public void deleteAll(List<Long> ids) {
|
storeAuditMapper.deleteBatchIds(ids);
|
}
|
|
@Override
|
public void download(List<StoreAudit> all, HttpServletResponse response) throws IOException {
|
List<Map<String, Object>> list = new ArrayList<>();
|
for (StoreAudit storeRevision : all) {
|
Map<String, Object> map = new LinkedHashMap<>();
|
map.put("审核ID", storeRevision.getAuditId());
|
map.put("店铺ID", storeRevision.getStoreId());
|
map.put("审批ID", storeRevision.getAuditId());
|
map.put("类型", storeRevision.getType());
|
map.put("新数据", storeRevision.getData());
|
map.put("创建人", storeRevision.getCreateBy());
|
map.put("创建时间", storeRevision.getCreateTime());
|
map.put("修改人", storeRevision.getUpdateBy());
|
map.put("修改时间", storeRevision.getUpdateTime());
|
list.add(map);
|
}
|
FileUtil.downloadExcel(list, response);
|
}
|
}
|