Commit 50355ab1 authored by limei's avatar limei

新增报告页面功能

parent bd82b4ca
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
<!-- <artifactId>amos-boot-module-common-api</artifactId>--> <!-- <artifactId>amos-boot-module-common-api</artifactId>-->
<!-- <version>${amos-biz-boot.version}</version>--> <!-- <version>${amos-biz-boot.version}</version>-->
<!-- </dependency>--> <!-- </dependency>-->
<dependency> <dependency>
<groupId>com.yeejoin</groupId> <groupId>com.yeejoin</groupId>
<artifactId>amos-component-rule</artifactId> <artifactId>amos-component-rule</artifactId>
<exclusions> <exclusions>
...@@ -29,7 +29,23 @@ ...@@ -29,7 +29,23 @@
<artifactId>tyboot-core-auth</artifactId> <artifactId>tyboot-core-auth</artifactId>
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>com.aspose</groupId>-->
<!-- <artifactId>aspose-words</artifactId>-->
<!-- <version>15.8.0</version>-->
<!-- </dependency>-->
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>15.8.0</version>
<classifier>jdk16</classifier>
</dependency>
</dependencies> </dependencies>
</project> </project>
...@@ -19,4 +19,27 @@ public class CheckResultDto { ...@@ -19,4 +19,27 @@ public class CheckResultDto {
@ApiModelProperty(value="模型名称") @ApiModelProperty(value="模型名称")
private String name; private String name;
private String allTotal;
private String failTotal;
private String checkItemLabel;
private String checkItemValue;
private String batchNo;
private String checkExplain;
private String amosOrgCode;
private String amosOrgName;
private String modelName;
private String isRight;
private Integer modelId;
} }
\ No newline at end of file
package com.yeejoin.amos.boot.module.tdc.api.entity;
import lombok.NonNull;
import org.springframework.web.multipart.MultipartFile;
import java.io.*;
public class PowerReportFile implements MultipartFile {
private String name;
private String originalFilename;
private String contentType;
public PowerReportFile(String name, String originalFilename, String contentType, @NonNull byte[] bytes) {
super();
this.name = name;
this.originalFilename = originalFilename;
this.contentType = contentType;
this.bytes = bytes;
}
public PowerReportFile() {
super();
// TODO Auto-generated constructor stub
}
public String getName() {
return name;
}
public String getOriginalFilename() {
return originalFilename;
}
public String getContentType() {
return contentType;
}
public byte[] getBytes() {
return bytes;
}
@NonNull
byte[] bytes;
@Override
public boolean isEmpty() {
return bytes.length == 0;
}
@Override
public long getSize() {
return bytes.length;
}
@Override
public InputStream getInputStream() {
return new ByteArrayInputStream(bytes);
}
@Override
public void transferTo(File destination) throws IOException {
OutputStream outputStream = null;
try {
outputStream = new FileOutputStream(destination);
outputStream.write(bytes);
} finally {
if (outputStream != null) {
outputStream.close();
}
}
}
}
package com.yeejoin.amos.boot.module.tdc.api.enums;
public enum WordPowerTypeEum {
/**
* 模板分类
*/
select("报告","powerReport.ftl");
private String label;
private String templateFile;
WordPowerTypeEum(String label,String templateFile ){
this.label = label;
this.templateFile = templateFile;
}
public String getLabel() {
return label;
}
public void setLabel(String label) {
this.label = label;
}
public String getTemplateFile() {
return templateFile;
}
public void setTemplateFile(String templateFile) {
this.templateFile = templateFile;
}
}
\ No newline at end of file
...@@ -21,5 +21,12 @@ public interface CheckResultMapper extends BaseMapper<CheckResult> { ...@@ -21,5 +21,12 @@ public interface CheckResultMapper extends BaseMapper<CheckResult> {
Map getTable(String tableName); Map getTable(String tableName);
List<CheckResultDto> selectStatistion(String batchNo,String amosOrgCode);
List<CheckResultDto> selectDetails(String batchNo,Integer modelId);
String select(String amosOrgCode);
List<CheckResultDto> getOne(String amosOrgCode);
} }
...@@ -24,6 +24,12 @@ public interface CheckResultService extends IService<CheckResult> { ...@@ -24,6 +24,12 @@ public interface CheckResultService extends IService<CheckResult> {
ModelTreeDto treeTwo(String tableId); ModelTreeDto treeTwo(String tableId);
List<CheckResultDto> selectStatistion(String batchNo,String amosOrgCode);
List<CheckResultDto> selectDetails(String batchNo,Integer modelId);
String select(String amosOrgCode);
......
package com.yeejoin.amos.boot.module.tdc.api.utils;
import java.util.UUID;
public class UUIDUtils {
public static String getUUID(){
return UUID.randomUUID().toString().replace("-","");
}
public static Integer getUUIDInOrderId(){
Integer orderId=UUID.randomUUID().toString().hashCode();
orderId = orderId < 0 ? -orderId : orderId; //String.hashCode() 值会为空
return orderId;
}
public static void main(String[] args){
for (int i = 0; i<100; i++) {
System.out.println(UUIDUtils.getUUIDInOrderId());
}
}
}
\ No newline at end of file
package com.yeejoin.amos.boot.module.tdc.api.utils;
import com.aspose.words.License;
import com.aspose.words.SaveFormat;
import com.github.pagehelper.util.StringUtil;
import freemarker.template.Configuration;
import freemarker.template.Template;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import sun.misc.BASE64Encoder;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.util.Map;
import java.util.Properties;
public class WordPowerUtils {
private static String fileUploadDir;
private Configuration configuration;
private static WordPowerUtils wordTemplateUtils;
private WordPowerUtils() {
configuration = new Configuration();
configuration.setDefaultEncoding("utf-8");
}
public static synchronized WordPowerUtils getInstance() {
if (wordTemplateUtils == null) {
//添加你的内容
Properties props;
try {
props = PropertiesLoaderUtils.loadAllProperties("application-dev.properties");
fileUploadDir = (String) props.get("file.uploadUrl");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wordTemplateUtils = new WordPowerUtils();
}
return wordTemplateUtils;
}
public void exportMillCertificateWord(HttpServletRequest request, HttpServletResponse response, Map map,
String title, String ftlFile) throws IOException {
configuration.setClassForTemplateLoading(this.getClass(), "/ftl");
Template freemarkerTemplate = configuration.getTemplate(ftlFile, "UTF-8");
File file = null;
InputStream fin = null;
ServletOutputStream out = null;
try {
// 调用工具类的createDoc方法生成Word文档
file = createDoc(map, freemarkerTemplate);
fin = new FileInputStream(file);
response.setCharacterEncoding("utf-8");
response.setContentType("application/msword");
// 设置浏览器以下载的方式处理该文件名
String fileName = (StringUtil.isNotEmpty(title) ? title : UUIDUtils.getUUID()) + ".doc";
response.setHeader("Content-Disposition",
"attachment;filename=".concat(String.valueOf(URLEncoder.encode(fileName, "UTF-8"))));
out = response.getOutputStream();
// 缓冲区
byte[] buffer = new byte[512];
int bytesToRead = -1;
// 通过循环将读入的Word文件的内容输出到浏览器中
while ((bytesToRead = fin.read(buffer)) != -1) {
out.write(buffer, 0, bytesToRead);
}
} finally {
if (fin != null) {
fin.close();
}
if (out != null) {
out.close();
}
if (file != null) {
file.delete();
}// 删除临时文件
}
}
public File getWordFileItem(Map map, String title, String ftlFile) throws IOException {
configuration.setClassForTemplateLoading(this.getClass(), "/ftl");
Template freemarkerTemplate = configuration.getTemplate(ftlFile, "UTF-8");
File file = null;
File filepdf = new File("sellPlan.pdf");
InputStream fin = null;
OutputStream os = null;
try {
// 调用工具类的createDoc方法生成Word文档
file = createDoc(map, freemarkerTemplate);
fin = new FileInputStream(file);
os = new FileOutputStream(filepdf);
wordTopdfByAspose(fin, os);
return filepdf;
} finally {
if (fin != null) {
fin.close();
}
if (os != null) {
os.close();
}
if (file != null) {
file.delete();
}// 删除临时文件
}
}
private static File createDoc(Map<?, ?> dataMap, Template template) {
String name = "sellPlan.doc";
File f = new File(name);
Template t = template;
try {
// 这个地方不能使用FileWriter因为需要指定编码类型否则生成的Word文档会因为有无法识别的编码而无法打开
Writer w = new OutputStreamWriter(new FileOutputStream(f), "utf-8");
t.process(dataMap, w);
w.close();
} catch (Exception ex) {
ex.printStackTrace();
throw new RuntimeException(ex);
}
return f;
}
public boolean wordTopdfByAspose(InputStream inputStream, OutputStream outputStream) {
// 验证License 若不验证则转化出的pdf文档会有水印产生
if (!getLicense()) {
return false;
}
try {
// 将源文件保存在com.aspose.words.Document中,具体的转换格式依靠里面的save方法
com.aspose.words.Document doc = new com.aspose.words.Document(inputStream);
// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF,EPUB, XPS, SWF 相互转换
doc.save(outputStream, SaveFormat.PDF);
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
if (outputStream != null) {
try {
outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return true;
}
// 官方文档的要求 无需理会
public static boolean getLicense() {
boolean result = false;
try {
String s = "<License><Data><Products><Product>Aspose.Total for Java</Product><Product>Aspose.Words for Java</Product></Products><EditionType>Enterprise</EditionType><SubscriptionExpiry>20991231</SubscriptionExpiry><LicenseExpiry>20991231</LicenseExpiry><SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber></Data><Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature></License>";
ByteArrayInputStream is = new ByteArrayInputStream(s.getBytes());
License aposeLic = new License();
aposeLic.setLicense(is);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
/**
* 获得图片的base64码
* @param src 图片路径
* @return String
*/
@SuppressWarnings("deprecation")
public String getImageBase(String src) {
if (!StringUtil.isNotEmpty(src)) {
return "";
}
src = src.replaceAll("\\.\\.", "");
String fileName = fileUploadDir + src;
File file = new File(fileName);
if (!file.exists()) {
return "";
}
InputStream in = null;
byte[] data = null;
try {
in = new FileInputStream(file);
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
try {
data = new byte[in.available()];
in.read(data);
in.close();
} catch (IOException e) {
e.printStackTrace();
}
BASE64Encoder encoder = new BASE64Encoder();
return encoder.encode(data);
}
}
...@@ -16,4 +16,18 @@ ...@@ -16,4 +16,18 @@
SELECT a.* FROM ${tableName} AS a ORDER BY a.date DESC LIMIT 1 SELECT a.* FROM ${tableName} AS a ORDER BY a.date DESC LIMIT 1
</select> </select>
<select id="selectStatistion" resultType="com.yeejoin.amos.boot.module.tdc.api.dto.CheckResultDto">
SELECT model_id, amos_org_code, amos_org_name,batch_no,model_name, count(1) as `all_total`, COUNT(CASE WHEN (check_item_result=1) THEN check_item_result END) AS `fail_total`
FROM tdc_check_result WHERE batch_no = #{batchNo} and amos_org_code = #{amosOrgCode} GROUP BY model_id;
</select>
<select id="selectDetails" resultType="com.yeejoin.amos.boot.module.tdc.api.dto.CheckResultDto">
select check_item_label,check_item_value,check_explain,model_id,model_name,
case when check_item_result = '0' then '合格' else '不合格' end as is_right from tdc_check_result WHERE batch_no = #{batchNo} and model_id = #{modelId} ;
</select>
<select id="getOne" resultType="com.yeejoin.amos.boot.module.tdc.api.dto.CheckResultDto">
select batch_no,model_id from tdc_check_result where amos_org_code = #{amosOrgCode} group by model_name ORDER BY check_date desc limit 0,1;
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -80,8 +80,30 @@ public class CheckResultController extends BaseController { ...@@ -80,8 +80,30 @@ public class CheckResultController extends BaseController {
@ApiOperation(httpMethod = "GET",value = "查询最后一次校验模型", notes = "查询最后一次校验模型") @ApiOperation(httpMethod = "GET",value = "查询最后一次校验模型", notes = "查询最后一次校验模型")
public ResponseModel<ModelTreeDto> treeTwo(String tableId) { public ResponseModel<ModelTreeDto> treeTwo(String tableId) {
return ResponseHelper.buildResponse(checkResultService.treeTwo(tableId)); return ResponseHelper.buildResponse(checkResultService.treeTwo(tableId));
} }
/**
* cs
*/
@TycloudOperation(ApiLevel = UserType.AGENCY,needAuth = false)
@GetMapping(value = "/selectDetails/")
@ApiOperation(httpMethod = "GET", value = "result", notes = "result")
public ResponseModel<List<CheckResultDto>> selectDetails( String batchNo,int modelId) {
return ResponseHelper.buildResponse(checkResultService.selectDetails(batchNo,modelId));
}
/**
* cs
*/
@TycloudOperation(ApiLevel = UserType.AGENCY,needAuth = false)
@GetMapping(value = "/select")
@ApiOperation(httpMethod = "GET", value = "result", notes = "result")
public ResponseModel<String> select(String amosOrgCode) {
return ResponseHelper.buildResponse(checkResultService.select(amosOrgCode));
}
} }
...@@ -13,20 +13,27 @@ import com.yeejoin.amos.boot.module.tdc.api.dto.ModelTreeDto; ...@@ -13,20 +13,27 @@ import com.yeejoin.amos.boot.module.tdc.api.dto.ModelTreeDto;
import com.yeejoin.amos.boot.module.tdc.api.entity.CheckModel; import com.yeejoin.amos.boot.module.tdc.api.entity.CheckModel;
import com.yeejoin.amos.boot.module.tdc.api.entity.CheckReport; import com.yeejoin.amos.boot.module.tdc.api.entity.CheckReport;
import com.yeejoin.amos.boot.module.tdc.api.entity.CheckResult; import com.yeejoin.amos.boot.module.tdc.api.entity.CheckResult;
import com.yeejoin.amos.boot.module.tdc.api.entity.PowerReportFile;
import com.yeejoin.amos.boot.module.tdc.api.enums.WordPowerTypeEum;
import com.yeejoin.amos.boot.module.tdc.api.feign.IdxFeignService; import com.yeejoin.amos.boot.module.tdc.api.feign.IdxFeignService;
import com.yeejoin.amos.boot.module.tdc.api.mapper.CheckResultMapper; import com.yeejoin.amos.boot.module.tdc.api.mapper.CheckResultMapper;
import com.yeejoin.amos.boot.module.tdc.api.service.CheckResultService; import com.yeejoin.amos.boot.module.tdc.api.service.CheckResultService;
import com.yeejoin.amos.boot.module.tdc.api.utils.WordPowerUtils;
import com.yeejoin.amos.boot.module.tdc.api.vo.SubjectTreeVo; import com.yeejoin.amos.boot.module.tdc.api.vo.SubjectTreeVo;
import com.yeejoin.amos.boot.module.tdc.api.vo.TableColumnsVo; import com.yeejoin.amos.boot.module.tdc.api.vo.TableColumnsVo;
import com.yeejoin.amos.component.feign.model.FeignClientResult;
import com.yeejoin.amos.feign.systemctl.Systemctl;
import org.codehaus.jettison.json.JSONString; import org.codehaus.jettison.json.JSONString;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.util.ArrayList; import java.io.File;
import java.util.HashMap; import java.io.FileInputStream;
import java.util.List; import java.io.IOException;
import java.util.Map; import java.text.SimpleDateFormat;
import java.util.*;
@Service @Service
public class CheckResultImpl extends ServiceImpl<CheckResultMapper, CheckResult> implements CheckResultService { public class CheckResultImpl extends ServiceImpl<CheckResultMapper, CheckResult> implements CheckResultService {
...@@ -109,7 +116,121 @@ public class CheckResultImpl extends ServiceImpl<CheckResultMapper, CheckResult> ...@@ -109,7 +116,121 @@ public class CheckResultImpl extends ServiceImpl<CheckResultMapper, CheckResult>
} }
@Override
public String select(String amosOrgCode) {
Map<String, Object> dataMap = getData(amosOrgCode);
WordPowerUtils instance = WordPowerUtils.getInstance();
String pdfUrlString = "";
File filepdf = null;
try {
filepdf = instance.getWordFileItem(dataMap, null, WordPowerTypeEum.select.getTemplateFile());
filepdf.getAbsolutePath();
MultipartFile multipartFile = new PowerReportFile("file", "file.pdf", "application/pdf", file2byte(filepdf));
FeignClientResult<Map<String, String>> result = Systemctl.fileStorageClient.updateCommonFile(multipartFile);
if (result != null) {
Iterator<String> it = result.getResult().keySet().iterator();
while (it.hasNext()) {
pdfUrlString = it.next();
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (filepdf != null) {
filepdf.delete();
}
}
return pdfUrlString;
}
private Map<String,Object> getData(String amosOrgCode) {
Map<String,Object> map = new HashMap<>();
// JSONObject map=new JSONObject();
//3.统计
ArrayList<Map<String, Object>> list = new ArrayList<>();
List<CheckResultDto> selectBatch = checkResultMapper.getOne(amosOrgCode);
for(CheckResultDto checkResultDto1 : selectBatch){
List<CheckResultDto> systemList = selectStatistion( checkResultDto1.getBatchNo(), amosOrgCode);
for (CheckResultDto system : systemList) {
HashMap<String, Object> data = new HashMap<>();
/*List<Map> collect = (List<Map>) indicatorConfiguration.stream().
filter(item -> item.get("code").equals(String.valueOf(system.getAmosOrgCode())));*/
map.put("station",system.getAmosOrgName());
data.put("modelName",system.getModelName());
System.out.println(system.getModelName()+"----------------------------------------------------------------");
data.put("allTotal",system.getAllTotal());
data.put("failTotal",system.getFailTotal());
list.add(data);
/*for(int i = 0;i<list.size();i++){
map.put(String.valueOf(i),list.get(i));
}*/
map.put("list",list);
}
//1.站名
// List<Map> indicatorConfiguration = JSONObject.parseArray(json, Map.class);
// 2.时间
String date = new SimpleDateFormat("yyyy-MM-dd ").format(Calendar.getInstance().getTime());
map.put("time", date);
//4.校验明细
ArrayList<Map<String,Object>> list2 = new ArrayList<>();
systemList.forEach(checkResultDto -> {
List<CheckResultDto> systemList2 = selectDetails( checkResultDto.getBatchNo(), checkResultDto.getModelId());
HashMap<String,Object> object = new HashMap<>();
ArrayList<Map<String,Object>> maps = new ArrayList<>();
object.put("modelName", checkResultDto.getModelName());
for(CheckResultDto system2: systemList2) {
//HashMap<String,Object> datas = new HashMap<>();
//for(CheckResultDto system3: systemList2){
HashMap<String, Object> item = new HashMap<>();
item.put("checkitemlabel", system2.getCheckItemLabel());
item.put("checkitemvalue", system2.getCheckItemValue());
item.put("isright", system2.getIsRight());
item.put("checkexplain", system2.getCheckExplain());
maps.add(item);
//}
}
object.put("itemList",maps);
list2.add(object);
map.put("list2",list2);
});
}
return map;
}
private static byte[] file2byte(File file) {
try {
FileInputStream in = new FileInputStream(file);
byte[] data = new byte[in.available()];
in.read(data);
in.close();
return data;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
@Override
public List<CheckResultDto> selectStatistion(String batchNo, String amosOrgCode) {
return checkResultMapper.selectStatistion(batchNo, amosOrgCode);
}
@Override
public List<CheckResultDto> selectDetails(String batchNo, Integer modelId) {
return checkResultMapper.selectDetails(batchNo, modelId);
}
} }
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment