package com.ruoyi.basic.service.impl;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.ruoyi.basic.dto.SealConfigExport;
|
import com.ruoyi.basic.mapper.SealConfigMapper;
|
import com.ruoyi.basic.pojo.SealConfig;
|
import com.ruoyi.basic.service.SealConfigService;
|
import com.ruoyi.common.exception.base.BaseException;
|
import com.ruoyi.common.utils.QueryWrappers;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.time.format.DateTimeFormatter;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* 印章管理(报告用印) 服务实现
|
*/
|
@Service
|
public class SealConfigServiceImpl extends ServiceImpl<SealConfigMapper, SealConfig> implements SealConfigService {
|
|
@Resource
|
private SealConfigMapper sealConfigMapper;
|
|
private static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
@Override
|
public IPage<SealConfig> pageSeal(Page page, SealConfig query) {
|
QueryWrapper<SealConfig> wrapper = QueryWrappers.queryWrappers(query);
|
if (wrapper == null) {
|
wrapper = Wrappers.query();
|
}
|
wrapper.orderByDesc("create_time").orderByAsc("code");
|
return this.page(page, wrapper);
|
}
|
|
@Override
|
public int addSeal(SealConfig seal) {
|
validate(seal);
|
seal.setCode(generateCode());
|
return sealConfigMapper.insert(seal);
|
}
|
|
@Override
|
public int updateSeal(SealConfig seal) {
|
if (seal.getId() == null) {
|
throw new BaseException("印章id不能为空");
|
}
|
validate(seal);
|
// 编号不允许前端修改,保持自动生成值不变
|
SealConfig db = sealConfigMapper.selectById(seal.getId());
|
if (db != null) {
|
seal.setCode(db.getCode());
|
}
|
return sealConfigMapper.updateById(seal);
|
}
|
|
@Override
|
public int delSeal(Integer id) {
|
return sealConfigMapper.deleteById(id);
|
}
|
|
@Override
|
public List<SealConfig> selectEnabled() {
|
return this.list(Wrappers.<SealConfig>lambdaQuery()
|
.eq(SealConfig::getStatus, 1)
|
.orderByAsc(SealConfig::getCode));
|
}
|
|
@Override
|
public List<SealConfigExport> listForExport(SealConfig query) {
|
QueryWrapper<SealConfig> wrapper = QueryWrappers.queryWrappers(query);
|
if (wrapper == null) {
|
wrapper = Wrappers.query();
|
}
|
wrapper.orderByAsc("code");
|
List<SealConfig> list = this.list(wrapper);
|
List<SealConfigExport> exports = new ArrayList<>();
|
for (SealConfig seal : list) {
|
SealConfigExport export = new SealConfigExport();
|
export.setCode(seal.getCode());
|
export.setName(seal.getName());
|
export.setUseScope(seal.getUseScope());
|
export.setStatusName(seal.getStatus() != null && seal.getStatus() == 1 ? "启用" : "停用");
|
export.setRemark(seal.getRemark());
|
export.setCreateTime(seal.getCreateTime() == null ? "" : seal.getCreateTime().format(DATE_FORMAT));
|
exports.add(export);
|
}
|
return exports;
|
}
|
|
private void validate(SealConfig seal) {
|
if (StringUtils.isBlank(seal.getName())) {
|
throw new BaseException("印章名称不能为空");
|
}
|
if (StringUtils.isBlank(seal.getAddress())) {
|
throw new BaseException("印章图片不能为空");
|
}
|
}
|
|
/**
|
* 自动生成印章编号:YZ-001、YZ-002 ...
|
*/
|
private String generateCode() {
|
Integer max = sealConfigMapper.selectMaxCodeSuffix();
|
int next = (max == null ? 0 : max) + 1;
|
return String.format("YZ-%03d", next);
|
}
|
}
|