Commit 9317f90a authored by chenzhao's avatar chenzhao

使用登记表生成

parent 26b8d539
......@@ -747,4 +747,19 @@ public class CommonController extends BaseController {
public ResponseModel<List<EquipmentClassifyDto>> getEquClassifyByCode(@RequestParam(value = "parentCode", required = false) String parentCode) {
return ResponseHelper.buildResponse(commonService.getEquClassifyByCode(parentCode));
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "POST", value = "使用登记表生成", notes = "使用登记表生成")
@PostMapping(value = "/getRegistrationFormUrl")
public ResponseModel<Map<String,Object>> getRegistrationFormUrl(@RequestBody JSONObject map) {
return ResponseHelper.buildResponse(commonService.getRegistrationFormUrl(map));
}
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "POST", value = "pdf流生成", notes = "pdf流生成")
@PostMapping(value = "/getRegistrationFormStream")
public void getRegistrationFormStream(@RequestBody JSONObject map,HttpServletResponse response) {
commonService.getRegistrationFormStream(map,response);
}
}
......@@ -252,4 +252,8 @@ public interface ICommonService {
List<EquipmentCategoryDto> getEquDefineByParentId(String parentId);
List<EquipmentClassifyDto> getEquClassifyByCode(String parentCode);
Map<String,Object> getRegistrationFormUrl(JSONObject map);
void getRegistrationFormStream(JSONObject map,HttpServletResponse response);
}
......@@ -6,6 +6,7 @@ import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.map.MapBuilder;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONException;
......@@ -178,6 +179,9 @@ public class CommonServiceImpl implements ICommonService {
// 业务通用发起——更名变更表单key
private static final String GMBG_PAGE_ID = "jgRegistrationInfo";
private static final String SELECTED_ROLE_SEQS = "selectRoleSeqs";
private static final String VEHICLE = "vehicle";
private static final String UNIT = "unit";
private static final String SET = "set";
@Autowired
EquipmentCategoryMapper equipmentCategoryMapper;
@Autowired
......@@ -2206,6 +2210,76 @@ public class CommonServiceImpl implements ICommonService {
}
@Override
public Map<String,Object> getRegistrationFormUrl(JSONObject map){
JSONObject formData = JSONObject.parseObject(JSONObject.toJSONString(map.get("formData")));
String manageType = JSONObject.toJSONString(map.get("manageType"));
String wordPath ;
String fileName ;
if (UNIT.equals(manageType)){
wordPath = "use-registration-form-unit.ftl";
fileName = "use-registration-form-unit.ftl";
}else if (SET.equals(manageType)){
wordPath = "use-registration-form-set.ftl";
fileName = "use-registration-form-set.ftl";
}else {
wordPath = "use-registration-form-vehicle.ftl";
fileName = "use-registration-form-vehicle.ftl";
}
// word转pdf
File pdfFile = null;
try {
pdfFile = wordToPdf(fileName, wordPath, formData);
return MapBuilder.<String, Object>create().put("url",uploadFile(pdfFile)).build();
} catch (Exception e) {
throw new RuntimeException(e);
}finally {
try {
Files.deleteIfExists(pdfFile.toPath());
} catch (Exception e) {
log.error("文件找不到,删除失败:{}", e);
}
}
}
@Override
public void getRegistrationFormStream(JSONObject map, HttpServletResponse response){
JSONObject formData = JSONObject.parseObject(JSONObject.toJSONString(map.get("formData")));
String manageType = JSONObject.toJSONString(map.get("manageType"));
String wordPath ;
String fileName ;
if (UNIT.equals(manageType)){
wordPath = "use-registration-form-unit.ftl";
fileName = "台套使用登记表_";
}else if (SET.equals(manageType)){
wordPath = "use-registration-form-set.ftl";
fileName = "单位使用登记表_";
}else {
wordPath = "use-registration-form-vehicle.ftl";
fileName = "车用气瓶使用登记表_";
}
// word转pdf
File pdfFile;
try {
pdfFile = wordToPdf(fileName, wordPath, formData);
} catch (Exception e) {
throw new RuntimeException(e);
}
try {
byte[] bytes = CommonServiceImpl.file2byte(pdfFile);
String docTitle = pdfFile.getName();
FileExporter.exportFile(FileExporter.FileType.valueOf("pdf"), docTitle, bytes, response);
} catch (Exception e) {
log.error("pdf文件转换失败:{}", e);
} finally {
try {
Files.deleteIfExists(pdfFile.toPath());
} catch (Exception e) {
log.error("文件找不到,删除失败:{}", e);
}
}
}
@Override
public List<EquipmentClassifyDto> getEquClassifyByCode(String parentCode) {
List<EquipmentClassifyDto> equipmentCategoryDtos = commonMapper.getEquClassifyByCode(parentCode);
if (ValidationUtil.isEmpty(equipmentCategoryDtos)) {
......
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