package com.yuanchu.mom.service.impl;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.deepoove.poi.XWPFTemplate;
|
import com.deepoove.poi.config.Configure;
|
import com.deepoove.poi.config.ConfigureBuilder;
|
import com.deepoove.poi.data.Pictures;
|
import com.yuanchu.mom.dto.PersonSupervisionRecordDto;
|
import com.yuanchu.mom.exception.ErrorException;
|
import com.yuanchu.mom.mapper.UserMapper;
|
import com.yuanchu.mom.pojo.PersonSupervisionControlSheet;
|
import com.yuanchu.mom.pojo.PersonSupervisionProcessingSheet;
|
import com.yuanchu.mom.pojo.PersonSupervisionRecord;
|
import com.yuanchu.mom.mapper.PersonSupervisionRecordMapper;
|
import com.yuanchu.mom.service.PersonSupervisionControlSheetService;
|
import com.yuanchu.mom.service.PersonSupervisionProcessingSheetService;
|
import com.yuanchu.mom.service.PersonSupervisionRecordService;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.yuanchu.mom.utils.DateImageUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.servlet.http.HttpServletResponse;
|
import java.io.InputStream;
|
import java.io.OutputStream;
|
import java.net.URLEncoder;
|
import java.util.HashMap;
|
import java.util.List;
|
|
/**
|
* <p>
|
* 监督记录 服务实现类
|
* </p>
|
*
|
* @author
|
* @since 2024-10-10 04:16:49
|
*/
|
@Service
|
@Transactional(rollbackFor = Exception.class)
|
public class PersonSupervisionRecordServiceImpl extends ServiceImpl<PersonSupervisionRecordMapper, PersonSupervisionRecord> implements PersonSupervisionRecordService {
|
|
@Autowired
|
private PersonSupervisionControlSheetService personSupervisionControlSheetService;
|
|
@Autowired
|
private PersonSupervisionProcessingSheetService personSupervisionProcessingSheetService;
|
|
@Autowired
|
private UserMapper userMapper;
|
|
@Value("${file.path}")
|
private String imgUrl;
|
|
@Override
|
public void deletePersonSupervisionRecord(List<Integer> ids) {
|
if (CollectionUtils.isNotEmpty(ids)) {
|
ids.forEach(id -> {
|
personSupervisionControlSheetService.remove(Wrappers.<PersonSupervisionControlSheet>lambdaQuery()
|
.eq(PersonSupervisionControlSheet::getSupervisionRecordId, id));
|
personSupervisionProcessingSheetService.remove(Wrappers.<PersonSupervisionProcessingSheet>lambdaQuery()
|
.eq(PersonSupervisionProcessingSheet::getSupervisionRecordId, id));
|
baseMapper.deleteById(id);
|
});
|
}
|
}
|
|
@Override
|
public IPage<PersonSupervisionRecordDto> personSupervisionRecordPage(Page page, Integer userId, String userName, Integer departLimsId) {
|
return baseMapper.personSupervisionRecordPage(page, userId, departLimsId, userName);
|
}
|
|
/**
|
* 导出人员监督记录
|
* @param id
|
* @param response
|
*/
|
@Override
|
public void exportPersonSupervisionRecord(Integer id, HttpServletResponse response) {
|
PersonSupervisionRecordDto recordDto = baseMapper.selectPersonSupervisionRecord(id);
|
|
//获取技术负责人的签名地址
|
String ratifyUrl = null;
|
if (recordDto.getTechnicalDirector() != null) {
|
ratifyUrl = userMapper.selectById(recordDto.getTechnicalDirector()).getSignatureUrl();
|
if (StringUtils.isBlank(ratifyUrl)) {
|
throw new ErrorException("找不到技术负责人的签名");
|
}
|
}
|
|
// 获取路径
|
InputStream inputStream = this.getClass().getResourceAsStream("/static/supervision-record.docx");
|
ConfigureBuilder builder = Configure.builder();
|
builder.useSpringEL(true);
|
String finalRatifyUrl = ratifyUrl;
|
XWPFTemplate template = XWPFTemplate.compile(inputStream, builder.build()).render(
|
new HashMap<String, Object>() {{
|
put("supervision", recordDto);
|
put("technicalDirectorUrl", StringUtils.isNotBlank(finalRatifyUrl) ? Pictures.ofLocal(imgUrl + "/" + finalRatifyUrl).create() : null);
|
put("technicalDirectorDateUrl", recordDto.getTechnicalDirectorDate() != null ?
|
Pictures.ofStream(DateImageUtil.createDateImage(recordDto.getTechnicalDirectorDate())).create() : null);
|
}});
|
|
try {
|
response.setContentType("application/msword");
|
String fileName = URLEncoder.encode(
|
"人员监督记录", "UTF-8");
|
response.setHeader("Content-disposition",
|
"attachment;filename=" + fileName + ".docx");
|
OutputStream os = response.getOutputStream();
|
template.write(os);
|
os.flush();
|
os.close();
|
} catch (Exception e) {
|
e.printStackTrace();
|
throw new RuntimeException("导出失败");
|
}
|
|
|
}
|
}
|