Commit 903d8f40 authored by wangxl's avatar wangxl

1

parent d417aa48
......@@ -123,12 +123,6 @@
<version>2.3.28</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
......@@ -163,6 +157,7 @@
<artifactId>poi-tl</artifactId>
<version>1.10.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
......@@ -180,6 +175,18 @@
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>fr.opensagres.poi.xwpf.converter.core</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>fr.opensagres.poi.xwpf.converter.xhtml</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
......@@ -218,6 +225,17 @@
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.11.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
<version>3.0.11.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.itextpdf/itextpdf -->
<dependency>
<groupId>com.itextpdf</groupId>
......@@ -286,6 +304,28 @@
<scope>compile</scope>
</dependency>
<!-- docx4j for Word processing -->
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-JAXB-Internal</artifactId>
<version>8.3.3</version>
</dependency>
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j-ImportXHTML</artifactId>
<version>8.0.0</version>
</dependency>
<!-- Apache Commons IO -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>com.belerweb</groupId>
<artifactId>pinyin4j</artifactId>
......
......@@ -13,7 +13,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ComExpertSpecDAO extends BaseMapper<ComExpertSpec>, BaseDAO<ComExpertSpecQueryVO, ComExpertSpecDTO,ComExpertSpec> {
public interface ComExpertSpecDAO extends BaseMapper<ComExpertSpec>, BaseDAO<ComExpertSpecQueryVO, ComExpertSpecDTO, ComExpertSpec> {
List<String> getIdListByExpertId(String expertId);
......@@ -23,7 +23,7 @@ public interface ComExpertSpecDAO extends BaseMapper<ComExpertSpec>, BaseDAO<Com
List<ComExpertDTO> getExpertListBySpecIdProjId(@Param("specIds") List<String> SpecList, @Param("porjIds") List<String> ProjList);
List<ComExpertDTO> getExpertListByExpertSpecIds(@Param("specIds") List<String> SpecList, @Param("parentIds") List<String> ParentList, @Param("personName") String personName);
List<ComExpertDTO> getExpertListByExpertSpecIds(@Param("specIds") List<String> specIds, @Param("personName") String personName);
List<ComExpertDTO> getExpertListByExpertSpecIdOrParentId(@Param("specId")String specId, @Param("pkey")String pkey, @Param("ppkey")String ppkey, @Param("personName") String personName);
List<ComExpertDTO> getExpertListByExpertSpecIdOrParentId(@Param("specId") String specId, @Param("pkey") String pkey, @Param("ppkey") String ppkey, @Param("personName") String personName);
}
......@@ -22,4 +22,5 @@ public interface ComProjectGroupDetailDAO extends BaseMapper<ComProjectGroupDeta
Page<ComProjectGroupDetailDTO> getProjectDetailListbyPage(Page<ComProjectGroupDetailQueryVO> page, @Param("ew") Wrapper<ComProjectGroupDetailQueryVO> queryWrapper);
List<ComProjectGroupDetailDTO> getProjectListByGroupIds(@Param("groupIds") List<String> groupList);
List<ComProjectGroupDetailDTO> getMembersListByGroupIds(@Param("groupIds") List<String> groupList);
}
......@@ -16,8 +16,6 @@ import java.util.List;
*/
public interface ComProjectMembersDAO extends BaseMapper<ComProjectMembers>, BaseDAO<ComProjectMembersQueryVO,ComProjectMembersDTO, ComProjectMembers> {
List<ComProjectMembersDTO> getListByObjectId(String objectId);
ComProjectMembersDTO getMemCountById(String objectId);
Integer getMemWorkCountByObjectId(String objectId);
}
\ No newline at end of file
......@@ -53,30 +53,31 @@ public class ComProjectGroupDetailDTO extends BaseDTO {
@ApiModelProperty(value = "学科", position = 6)
private String knowledgeName;
/** 证件号 */
@ApiModelProperty(value = "证件号", position = 2)
private String certId;
/** 申报人Id */
@ApiModelProperty(value = "项目名称", position = 5)
private String appPersonId;
/** 姓名 */
@ApiModelProperty(value = "姓名", position = 4)
private String personName;
/** 证件号 */
@ApiModelProperty(value = "证件号", position = 2)
private String certId;
/** 申报单位Id */
@ApiModelProperty(value = "申报单位Id", position = 6)
@Length(max=36, message = "申报单位Id不能大于36")
private String appUnitId;
/** 申报单位名称 */
@ApiModelProperty(value = "申报单位名称", position = 7)
private String appUnitName;
/** key */
@ApiModelProperty(value = "key", position = 1)
@Length(max=36, message = "key不能大于36")
private String key;
private String title;
private String description;
private String pkey;
private String ppkey;
}
......@@ -5,17 +5,18 @@ import com.yiboshi.arch.base.ResponseDataModel;
import com.yiboshi.science.entity.ComExpertSpec;
import com.yiboshi.science.entity.SelectListItem;
import com.yiboshi.science.param.dto.ComExpertSpecDTO;
import com.yiboshi.science.param.dto.ComProjectGroupDetailDTO;
import com.yiboshi.science.param.query.ComExpertSpecQueryVO;
import com.yiboshi.science.rest.BaseController;
import com.yiboshi.science.service.ComExpertSpecService;
import com.yiboshi.science.service.ComProjectGroupDetailService;
import com.yiboshi.science.service.ComProjectGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.*;
@Api(tags = "com-expert-spec", description = "项目分配表")
......@@ -25,10 +26,14 @@ public class ComExpertSpecController extends BaseController<ComExpertSpecService
@Autowired
private ComExpertSpecService comExpertSpecService;
@ApiOperation(value = "根据类型参数列表", httpMethod = "GET", notes = "根据类型参数列表")
@GetMapping
@RequestMapping("/getExpertListBySpecId")
public ResponseDataModel<List<SelectListItem>> getExpertListBySpecId(@RequestBody Map<String, Object> specId) {
return ResponseDataModel.ok(comExpertSpecService.getExpertListBySpecId(specId));
}
......@@ -51,21 +56,8 @@ public class ComExpertSpecController extends BaseController<ComExpertSpecService
@ApiOperation(value = "根据类型参数列表", httpMethod = "GET", notes = "根据类型参数列表")
@GetMapping
@RequestMapping("/getExpertListByExpertSpecIds")
public ResponseDataModel<List<SelectListItem>> getExpertListByExpertSpecIds(String specIds, String parentIds, String personName) {
String[] split;
List<String> SpecList = null;
if (null != specIds) {
split = specIds.split(",");
SpecList = Arrays.asList(split);
}
List<String> ParentList = null;
if (null != parentIds) {
split = parentIds.split(",");
ParentList = Arrays.asList(split);
}
return ResponseDataModel.ok(comExpertSpecService.getExpertListByExpertSpecIds(SpecList, ParentList, personName));
public ResponseDataModel<List<SelectListItem>> getExpertListByExpertSpecIds(@RequestBody Map<String, Object> params) {
return ResponseDataModel.ok(comExpertSpecService.getExpertListByExpertSpecIds((List<String>) params.get("specIds"),(List<String>) params.get("groupIds"), (String) params.get("personName")));
}
......
......@@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
@Api(tags = "com-project-group", description = "项目分组表")
@RestController
......@@ -164,4 +165,13 @@ public class ComProjectGroupController extends BaseController<ComProjectGroupSer
else
return ResponseDataModel.ok("项目组移除项目失败,请检查!");
}
@ApiOperation(value = "项目信息", httpMethod = "GET", notes = "项目信息")
@GetMapping
@RequestMapping("/getGroupProjectInfo")
public ResponseDataModel<Map<String, Object>> getGroupProjectInfo(@RequestParam String groupIds) {
String[] split = groupIds.split(",");
List<String> groupList = Arrays.asList(split);
return ResponseDataModel.ok(comProjectGroupService.getGroupProjectInfo(groupList));
}
}
......@@ -39,7 +39,6 @@ public class ComProjectGroupDetailController extends BaseController<ComProjectGr
public ResponseDataModel<List<ComProjectGroupDetailDTO>> getProjectListByGroupIds(@RequestParam String groupIds) {
String[] split = groupIds.split(",");
List<String> GroupList = Arrays.asList(split);
List<ComProjectGroupDetailDTO> list = comProjectGroupDetailService.getProjectListByGroupIds(GroupList);
list.forEach(e -> {
e.setKey(e.getId());
......
......@@ -14,19 +14,20 @@ import com.yiboshi.science.param.dto.DataStatisticsDTO;
import com.yiboshi.science.param.query.ComProjectTaskQueryVO;
import com.yiboshi.science.rest.BaseController;
import com.yiboshi.science.service.ComProjectTaskService;
import com.yiboshi.science.utils.StringUtil;
import com.yiboshi.science.utils.TaskInfoToPDFUtil;
import com.yiboshi.science.utils.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import javax.servlet.ServletOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* 功能:任务书表 接口
......@@ -42,6 +43,7 @@ public class ComProjectTaskController extends BaseController<ComProjectTaskServi
@Autowired
private ComProjectTaskService ComProjectTaskService;
/**
* 功能:分页查询
*
......@@ -146,9 +148,15 @@ public class ComProjectTaskController extends BaseController<ComProjectTaskServi
@PostMapping
public void export(@PathVariable String id) throws DocumentException, IOException {
try {
ComProjectTaskDTO dto=ComProjectTaskService.getTaskByProjId(id);
ComProjectTaskDTO dto = ComProjectTaskService.getTaskByProjId(id);
// WordUtils.getHtmlContent(dto, "C:\\Users\\kylin\\Desktop\\导出Pdf\\output.docx");
// 生成PDF文件字节数组
byte[] pdfBytes = TaskInfoToPDFUtil.createContractPdf(ComProjectTaskService.getTaskByProjId(id));
byte[] pdfBytes = TaskToPDF.createContractPdf(dto);
// 设置响应头
response.setContentType("application/pdf");
String fileName = new String((dto.getProjName() + ".pdf").getBytes("UTF-8"), "ISO-8859-1");
......
......@@ -50,9 +50,9 @@ public interface ComExpertSpecService extends BaseService<ComExpertSpecQueryVO,
List<SelectListItem> getExpertListBySpecIdProjId(List<String> SpecList, List<String> ProjList);
/** 根据 项目Id 获取专家列表
*
* @param SpecList
* @param groupIds
*/
List<SelectListItem> getExpertListByExpertSpecIds(List<String> SpecList, List<String> ParentList, String personName);
List<SelectListItem> getExpertListByExpertSpecIds(List<String> specIds,List<String> groupIds, String personName);
/**
* 根据学科Id获取专家列表
......
......@@ -18,5 +18,6 @@ public interface ComProjectGroupDetailService extends BaseService<ComProjectGrou
Pagination<ComProjectGroupDetailDTO> getProjectDetailListbyPage(ComProjectGroupDetailQueryVO vo);
List<ComProjectGroupDetailDTO> getProjectListByGroupIds(@Param("groupIds") List<String> groupList);
List<ComProjectGroupDetailDTO> getProjectListByGroupIds(List<String> groupIds);
List<ComProjectGroupDetailDTO> getMembersListByGroupIds(List<String> groupIds);
}
......@@ -9,6 +9,7 @@ import com.yiboshi.science.param.query.ComProjectAuditQueryVO;
import com.yiboshi.science.param.query.ComProjectGroupQueryVO;
import java.util.List;
import java.util.Map;
public interface ComProjectGroupService extends BaseService<ComProjectGroupQueryVO, ComProjectGroupDTO, ComProjectGroup> {
......@@ -45,4 +46,5 @@ public interface ComProjectGroupService extends BaseService<ComProjectGroupQuery
boolean deleteProjectGroupKnowledge(String groupId, String knowledgeId);
boolean deleteProjectGroupDetail(String groupId, String knowledgeId);
Map<String, Object> getGroupProjectInfo(List<String> groupIds);
}
......@@ -20,6 +20,7 @@ public interface ComProjectMembersService extends BaseService<ComProjectMembersQ
*/
List<ComProjectMembersDTO> getListByObjectId(String objectId);
/**插入项目组成员
*
* @param list
......
......@@ -9,8 +9,11 @@ import com.yiboshi.science.entity.SystemMenu;
import com.yiboshi.science.entity.SelectListItem;
import com.yiboshi.science.param.dto.ComExpertDTO;
import com.yiboshi.science.param.dto.ComExpertSpecDTO;
import com.yiboshi.science.param.dto.ComProjectGroupDetailDTO;
import com.yiboshi.science.param.query.ComExpertSpecQueryVO;
import com.yiboshi.science.service.ComExpertSpecService;
import com.yiboshi.science.service.ComProjectGroupDetailService;
import com.yiboshi.science.service.ComProjectGroupService;
import com.yiboshi.science.utils.AgeUtil;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -31,6 +34,9 @@ public class ComExpertSpecServiceImpl extends BaseServiceImpl<ComExpertSpecDAO,
@Autowired
private ComExpertSpecDAO comExpertSpecDAO;
@Autowired
private ComProjectGroupDetailService comProjectGroupDetailService;
@Override
protected void setCriteriaForQuery(ComExpertSpecQueryVO vo, QueryWrapper<ComExpertSpecQueryVO> criteria) {
if (Objects.nonNull(vo.getExpertId())) {
......@@ -113,17 +119,43 @@ public class ComExpertSpecServiceImpl extends BaseServiceImpl<ComExpertSpecDAO,
return allItem;
}
public List<SelectListItem> getExpertListByExpertSpecIds(List<String> SpecList, List<String> ParentList, String personName) {
List<ComExpertDTO> list = comExpertSpecDAO.getExpertListByExpertSpecIds(SpecList, ParentList, personName);
List<SelectListItem> allItem = new ArrayList<>();
public List<SelectListItem> getExpertListByExpertSpecIds(List<String> specIds, List<String> groupIds, String personName) {
List<ComExpertDTO> list = new ArrayList<>();
if ((specIds != null && specIds.size() > 0) || null != personName)
list = comExpertSpecDAO.getExpertListByExpertSpecIds(specIds, personName);
if (null != list && list.size() > 0) {
List<SelectListItem> array = new ArrayList<>();
List<String> units = new ArrayList<>();
List<ComProjectGroupDetailDTO> project = comProjectGroupDetailService.getProjectListByGroupIds(groupIds);
List<ComProjectGroupDetailDTO> members = comProjectGroupDetailService.getMembersListByGroupIds(groupIds);
if (null == members) {
members = new ArrayList<>();
}
List<ComProjectGroupDetailDTO> finalMembers = members;
project.forEach(e -> {
if (!units.contains(e.getAppUnitId()))
units.add(e.getAppUnitId());
ComProjectGroupDetailDTO dto = new ComProjectGroupDetailDTO();
dto.setPersonName(e.getPersonName());
dto.setCertId(e.getCertId());
dto.setAppUnitName(e.getAppUnitName());
finalMembers.add(dto);
});
List<ComProjectGroupDetailDTO> finalMembers1 = members;
list.forEach((e) -> {
boolean isDisabled = false;
String description = e.getSex() + "/" + AgeUtil.getResidentAge(e.getBirthday()) + "岁/" + e.getWorkUnit();
SelectListItem treeListItem = new SelectListItem(e.getPersonName(), e.getId(), description, false, false, new ArrayList<>());
allItem.add(treeListItem);
isDisabled = units.contains(e.getUnitId());
// 检查专家的证件号是否在 members 列表中
if (!isDisabled)
isDisabled = finalMembers1.stream().anyMatch(member -> Objects.equals(member.getCertId(), e.getCertId()));
SelectListItem treeListItem = new SelectListItem(e.getPersonName(), e.getId(), description, false, isDisabled, new ArrayList<>());
array.add(treeListItem);
});
return array;
}
return allItem;
return new ArrayList<>();
}
public List<SelectListItem> getExpertListByExpertSpecIdOrParentId(String specId, String pkey, String ppkey, String personName) {
......
......@@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
......@@ -63,7 +64,17 @@ public class ComProjectGroupDetailServiceImpl extends BaseServiceImpl<ComProject
return new Pagination<>(dtoList, page.getTotal(), vo.getPageSize());
}
public List<ComProjectGroupDetailDTO> getProjectListByGroupIds(List<String> SpecList) {
return comProjectGroupDetailDAO.getProjectListByGroupIds(SpecList);
public List<ComProjectGroupDetailDTO> getProjectListByGroupIds(List<String> groupIds) {
if (groupIds != null && groupIds.size() > 0)
return comProjectGroupDetailDAO.getProjectListByGroupIds(groupIds);
else
return new ArrayList<>();
}
public List<ComProjectGroupDetailDTO> getMembersListByGroupIds(List<String> groupIds) {
if (groupIds != null && groupIds.size() > 0)
return comProjectGroupDetailDAO.getMembersListByGroupIds(groupIds);
else
return new ArrayList<>();
}
}
......@@ -2,6 +2,7 @@ package com.yiboshi.science.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yiboshi.arch.base.ResponseDataModel;
import com.yiboshi.arch.exception.BusinessException;
import com.yiboshi.science.base.BaseServiceImpl;
import com.yiboshi.science.base.Pagination;
......@@ -17,9 +18,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.*;
@Service
@AllArgsConstructor
......@@ -48,6 +47,9 @@ public class ComProjectGroupServiceImpl extends BaseServiceImpl<ComProjectGroupD
@Autowired
private ComProjectAuditService comProjectAuditService;
@Autowired
private ComProjectMembersService comProjectMembersService;
@Override
protected void setCriteriaForQuery(ComProjectGroupQueryVO vo, QueryWrapper<ComProjectGroupQueryVO> criteria) {
......@@ -149,7 +151,6 @@ public class ComProjectGroupServiceImpl extends BaseServiceImpl<ComProjectGroupD
}
public void CalculateGroupProjectCount(String groupId) {
List<ComProjectGroupDetailDTO> list = comProjectGroupDetailService.getProjectDetailList(groupId);
ComProjectGroup model = new ComProjectGroup();
......@@ -168,8 +169,7 @@ public class ComProjectGroupServiceImpl extends BaseServiceImpl<ComProjectGroupD
if (null == list || list.size() == 0) {
model.setExpertCount(0);
model.setAssignState(0);
}
else {
} else {
model.setExpertCount(list.size());
model.setAssignState(1);
}
......@@ -423,6 +423,7 @@ public class ComProjectGroupServiceImpl extends BaseServiceImpl<ComProjectGroupD
/**
* 项目专家分配
*
* @param groupId
* @return
*/
......@@ -461,6 +462,7 @@ public class ComProjectGroupServiceImpl extends BaseServiceImpl<ComProjectGroupD
/**
* 项目二级学科统计
*
* @param groupId
* @return
*/
......@@ -469,4 +471,25 @@ public class ComProjectGroupServiceImpl extends BaseServiceImpl<ComProjectGroupD
return list;
}
@Transactional
public Map<String, Object> getGroupProjectInfo(List<String> groupIds) {
List<ComProjectGroupDetailDTO> project = comProjectGroupDetailService.getProjectListByGroupIds(groupIds);
List<String> expanded = new ArrayList<>();
List<String> specs = new ArrayList<>();
project.forEach(e -> {
if (!expanded.contains(e.getPpkey()))
expanded.add(e.getPpkey());
if (!expanded.contains(e.getPkey()))
expanded.add(e.getPkey());
if (!specs.contains(e.getKnowledgeId()))
specs.add(e.getKnowledgeId());
});
Map<String, Object> projInfo = new HashMap<String, Object>(4) {
{
put("expanded", expanded);
put("spec", specs);
}
};
return projInfo;
}
}
......@@ -66,10 +66,6 @@ public class ComProjectMembersServiceImpl extends BaseServiceImpl<ComProjectMemb
@Override
public List<ComProjectMembersDTO> getListByObjectId(String objectId) {
List<ComProjectMembersDTO> list = comProjectMembersDAO.getListByObjectId(objectId);
// if (null != list && list.size() > 0)
// list.forEach((e) -> {
// e.setCertId(hideAllIdCardNum(e.getCertId()));
// });
return list;
}
......
......@@ -962,58 +962,6 @@ public class ComProjectServiceImpl extends BaseServiceImpl<ComProjectDAO, ComPro
}
public void export1(@PathVariable String id, HttpServletRequest request, HttpServletResponse response) {
ComProjectDTO p = this.getProjectById(id);
if (null != p) {
String strDateFormat = p.getProjType().equals(1) ? "yyyy-MM-dd HH:mm:ss" : "yyyy-MM-dd";
SimpleDateFormat sdf = new SimpleDateFormat(strDateFormat);
p.getMembers().forEach((e) -> {
// e.setAge(IDCardUtil.getAge(e.getCertId()));
e.setSex(IDCardUtil.getSex(e.getCertId()));
});
final String[] unit = {""};
p.getCooperativeUnits().forEach(e -> {
if (Objects.nonNull(e.getUnitName())) {
unit[0] = unit[0] + " " + e.getUnitName();
}
});
if (null == p.getCooperativeUnits() || p.getCooperativeUnits().size() < 3) {
int count = p.getCooperativeUnits() == null ? 0 : p.getCooperativeUnits().size();
List<ComProjectCooperativeUnitsDTO> item = p.getCooperativeUnits() == null ? new ArrayList<>() : p.getCooperativeUnits();
for (int i = 1; i <= 3 - count; i++) {
item.add(new ComProjectCooperativeUnitsDTO());
}
p.setCooperativeUnits(item);
}
if (null == p.getMembers() || p.getMembers().size() < 6) {
int count = p.getMembers() == null ? 0 : p.getMembers().size();
List<ComProjectMembersDTO> item = p.getMembers() == null ? new ArrayList<>() : p.getMembers();
for (int i = 1; i <= 6 - count; i++) {
item.add(new ComProjectMembersDTO());
}
p.setMembers(item);
}
if (null == p.getBudget() || p.getBudget().size() < 13) {
int count = p.getBudget() == null ? 0 : p.getBudget().size();
List<ComProjectBudgetDTO> item = p.getBudget() == null ? new ArrayList<>() : p.getBudget();
for (int i = 1; i <= 13 - count; i++) {
item.add(new ComProjectBudgetDTO());
}
p.setBudget(item);
}
List<String> str = comProjectResultsService.getNameByObjectId(p.getId());
if (p.getProjType().equals(1)) {
WordUtils utl = new WordUtils();
utl.export(p, response, "word.ftl");
} else {
htmlBuilder.exportWord(p, request, response);
}
}
}
public void export(@PathVariable String id, HttpServletRequest request, HttpServletResponse response) {
String filename = System.currentTimeMillis() + ".pdf";
response.reset();
......
......@@ -156,7 +156,9 @@ public class TaskInfoToPDFUtil {
table.setWidths(new float[]{80f, 80f, 30f, 60f, 60f, 80f, 30f, 100f});
table.setWidthPercentage(100);
// 设置表格默认边框宽度
table.getDefaultCell().setBorderWidth(0.5f);
// table.getDefaultCell().setBorderWidth(0.1f);
table.setSplitLate(false); // 避免拆分时边框异
table.isInline();
// 添加表格内容
addValueCell(table, "单位名称:", null, dto.getAppUnitName(), 7, normalFont, null, null, null);
......@@ -1035,11 +1037,13 @@ public class TaskInfoToPDFUtil {
valueCell.setRowspan(valueRowspan);
if (Objects.nonNull(valueColspan))
valueCell.setColspan(valueColspan);
valueCell.setCellEvent(new UniformBorderEvent());
valueCell.setPadding(5f);
valueCell.setMinimumHeight(height);
valueCell.setVerticalAlignment(vertical);
valueCell.setHorizontalAlignment(horizontal);
valueCell.setBorderWidth(0.5f); // 设置边框宽度
valueCell.setBorderWidth(0.1f); // 设置边框宽度
valueCell.setBorderColor(new BaseColor(0, 0, 0));
table.addCell(valueCell);
}
......
package com.yiboshi.science.utils;
import com.itextpdf.kernel.colors.DeviceRgb;
import com.itextpdf.layout.borders.SolidBorder;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.properties.TextAlignment;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.properties.UnitValue;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.text.pdf.BaseFont;
import com.yiboshi.science.param.dto.*;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.io.font.PdfEncodings;
import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import static com.yiboshi.science.utils.ProjectInfoToPDF.getCurrentOperatingSystem;
public class TaskToPDF {
static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
static SimpleDateFormat sdfM = new SimpleDateFormat("yyyy年MM月");
private static PdfFont createFont(String fontName) {
try {
if ("linux".equals(getCurrentOperatingSystem())) {
if (fontName.toLowerCase().endsWith(".ttc"))
return PdfFontFactory.createFont("/usr/share/fonts/" + fontName + ",0", PdfEncodings.IDENTITY_H);
else
return PdfFontFactory.createFont("/usr/share/fonts/" + fontName, PdfEncodings.IDENTITY_H);
} else {
if (fontName.toLowerCase().endsWith(".ttc"))
return PdfFontFactory.createFont("c:/Windows/Fonts/" + fontName + ",0", PdfEncodings.IDENTITY_H);
else
return PdfFontFactory.createFont("c:/Windows/Fonts/" + fontName, PdfEncodings.IDENTITY_H);
}
} catch (Exception e) {
throw new RuntimeException("加载字体文件失败,请确保系统中存在字体文件 " + fontName + ":" + e.getMessage(), e);
}
}
/**
* 生成项目合同书PDF
*
* @param dto 项目任务信息
* @return PDF文件字节数组
*/
public static byte[] createContractPdf(ComProjectTaskDTO dto) {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(baos));
Document document = new Document(pdfDoc);
// 添加中文字体支持
// 宋体
PdfFont sfChinese = createFont("simsun.ttc");
// 仿宋
PdfFont fsChinese = createFont("simfang.ttf");
document.setFont(sfChinese);
float[] columnWidths = {20f, 20f, 20f, 40f};
Table table = new Table(columnWidths);
table.setWidth(UnitValue.createPercentValue(100));
// 设置单元格样式
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
Cell cell = new Cell();
cell.setHeight(40f);
cell.setBorder(new SolidBorder(new DeviceRgb(0, 0, 0), 0.5f));
cell.setTextAlignment(TextAlignment.CENTER);
// 使用中文测试文本
cell.add(new Paragraph("单元格 " + (i+1) + "-" + (j+1)).setFont(sfChinese));
table.addCell(cell);
}
}
// 添加表格到文档
document.add(table);
// 关闭文档
document.close();
return baos.toByteArray();
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}
package com.yiboshi.science.utils;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfContentByte;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPCellEvent;
import com.itextpdf.text.pdf.PdfPTable;
public class UniformBorderEvent implements PdfPCellEvent {
@Override
public void cellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) {
PdfContentByte canvas = canvases[PdfPTable.LINECANVAS];
canvas.setLineWidth(1f);
canvas.rectangle(position.getLeft(), position.getBottom(), position.getWidth(), position.getHeight());
canvas.stroke();
}
}
\ No newline at end of file
package com.yiboshi.science.utils;
public class WordUtil {
}
......@@ -2,121 +2,32 @@ package com.yiboshi.science.utils;
import freemarker.cache.ClassTemplateLoader;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.InputStreamSource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.Locale;
import freemarker.template.TemplateExceptionHandler;
import java.io.StringWriter;
import java.util.Map;
public class WordUtils {
public void export( Object dataModel,HttpServletResponse response,String templateName) {
Configuration configuration = new Configuration();
configuration.setDefaultEncoding("utf-8");
configuration.setEncoding(Locale.getDefault(), "utf-8");
try {
response.setContentType("application/msword; charset=UTF-8");// application/x-download
response.setHeader("content-disposition", "attachment;filename=document.doc");
response.setHeader("Accept-Ranges", "bytes");
// response.setHeader("Content-Disposition", "attachment; " + encodeFileName(request, fileName + ".doc"));
OutputStream outputStream = response.getOutputStream();
Writer out = new OutputStreamWriter(outputStream);
configuration.setClassicCompatible(true);//处理dataModel中如果为null的情况
//既能保证本地运行找得到模板文件,又能保证jar包运行能找到得到模板文件
configuration.setClassForTemplateLoading(this.getClass(), "/template");
configuration.setTemplateLoader(new ClassTemplateLoader(this.getClass(), "/template"));
Template template = configuration.getTemplate(templateName, "utf-8");
template.process(dataModel, out);
outputStream.close();
out.close();
} catch (IOException | TemplateException e) {
e.printStackTrace();
}
}
public void exportStream(HttpServletResponse response, Object dataModel) {
Configuration configuration = new Configuration();
configuration.setDefaultEncoding("utf-8");
configuration.setEncoding(Locale.getDefault(), "utf-8");
try {
configuration.setClassicCompatible(true);//处理dataModel中如果为null的情况
//既能保证本地运行找得到模板文件,又能保证jar包运行能找到得到模板文件
configuration.setClassForTemplateLoading(this.getClass(), "/template");
configuration.setTemplateLoader(new ClassTemplateLoader(this.getClass(), "/template"));
Template template = configuration.getTemplate("word.ftl", "utf-8");
InputStreamSource file = createDoc(dataModel, template);
InputStream fin = file.getInputStream();
ServletOutputStream out;
response.setContentType("application/x-msdownload");
response.setHeader("content-disposition", "attachment;filename=document.doc");
response.setHeader("Accept-Ranges", "bytes");
out = response.getOutputStream();
// 缓冲区
byte[] buffer = new byte[1024];
int bytesToRead;
while ((bytesToRead = fin.read(buffer)) != -1) {
out.write(buffer, 0, bytesToRead);
}
out.flush();
fin.close();
} catch (IOException | TemplateException e) {
e.printStackTrace();
}
}
public static InputStreamSource createDoc(Object dataModel, Template template) throws TemplateException, IOException, TemplateException {
StringWriter out1 = new StringWriter();
Writer out = new BufferedWriter(out1, 10240);
//将数据输出到模板
template.process(dataModel, out);
out.close();
out1.close();
return new ByteArrayResource(out1.toString().getBytes(StandardCharsets.UTF_8));
}
public String encodeFileName(HttpServletRequest request, String fileName) throws UnsupportedEncodingException {
String new_filename = URLEncoder.encode(fileName, "UTF8").replaceAll("\\+", "%20");
String agent = request.getHeader("USER-AGENT").toLowerCase();
if (null != agent && -1 != agent.indexOf("msie")) {
/**
* IE浏览器,只能采用URLEncoder编码
*/
return "filename=\"" + new_filename + "\"";
} else if (null != agent && -1 != agent.indexOf("applewebkit")) {
/**
* Chrome浏览器,只能采用ISO编码的中文输出
*/
return "filename=\"" + new String(fileName.getBytes("UTF-8"), "ISO8859-1") + "\"";
} else if (null != agent && -1 != agent.indexOf("opera")) {
/**
* Opera浏览器只可以使用filename*的中文输出
* RFC2231规定的标准
* 从模板文件生成Word
*
* @param outputPath 输出文件路径
* @throws Exception 转换异常
*/
return "filename*=" + new_filename;
} else if (null != agent && -1 != agent.indexOf("safari")) {
/**
* Safani浏览器,只能采用iso编码的中文输出
*/
return "filename=\"" + new String(fileName.getBytes("UTF-8"), "ISO8859-1") + "\"";
} else if (null != agent && -1 != agent.indexOf("firefox")) {
/**
* Firfox浏览器,可以使用filename*的中文输出
* RFC2231规定的标准
*/
return "filename*=" + new_filename;
} else {
return "filename=\"" + new_filename + "\"";
}
public static void getHtmlContent(Object obj, String outputPath) throws Exception {
Map<String, Object> data1 = HtmlBuilder.obj2Map(obj);
Configuration cfg = new Configuration(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS);
cfg.setDefaultEncoding("utf-8");
cfg.setClassLoaderForTemplateLoading(PdfUtil.class.getClassLoader(), "template");
cfg.setTemplateLoader(new ClassTemplateLoader(PdfUtil.class.getClassLoader(), "/template"));
cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
// 获取模板
freemarker.template.Template template = cfg.getTemplate("tmp-task.html", "utf-8");
// 处理模板,生成HTML内容
StringWriter tmpText = new StringWriter();
template.process(data1, tmpText);
String htmlContent = tmpText.toString();
}
}
......@@ -50,26 +50,22 @@
</select>
<select id="getExpertListByExpertSpecIds" resultType="com.yiboshi.science.param.dto.ComExpertDTO">
select distinct a.expert_id id,c.person_name,c.cert_id,c.sex,c.birthday,e.unit_name as work_unit
select distinct a.expert_id id,c.person_name,c.cert_id,c.sex,c.birthday,e.id unit_id,
(case when e.unit_name is null then c.work_unit else e.unit_name end) as work_unit
from com_expert_spec a
left join com_expert b on a.expert_id=b.id
left join com_person c on b.person_id=c.id
left join system_parameter d on a.spec_id=d.id
left join com_unit e on c.unit_id = e.id
<if test=' specIds != null '>
where a.spec_id in
where b.id is not null
<if test=' specIds != null and specIds.size() &gt; 0'>
and a.spec_id in
<foreach collection="specIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="parentIds != null">
where d.parent_id in
<foreach collection="parentIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<if test="personName != null">
where c.person_name like CONCAT('%',#{personName},'%')
and c.person_name like CONCAT('%',#{personName},'%')
</if>
</select>
<select id="getExpertListByExpertSpecIdOrParentId" resultType="com.yiboshi.science.param.dto.ComExpertDTO">
......
......@@ -34,10 +34,25 @@
</select>
<select id="getProjectListByGroupIds" resultType="com.yiboshi.science.param.dto.ComProjectGroupDetailDTO">
select a.*, b.proj_no, b.proj_name, d.name as knowledge_name from com_project_group_detail a
select a.id, a.group_id, a.proj_id, a.remark, a.created, a.updated,
g.unit_name app_unit_name,h.person_name person_name,h.cert_id,
b.knowledge_id, b.proj_no, b.proj_name,b.app_unit_id,b.app_person_id, d.name as knowledge_name,
e.id pkey,e.parent_id ppkey
from com_project_group_detail a
left join com_project b on a.proj_id = b.id
left join com_unit g on b.app_unit_id=g.id
left join com_person h on b.app_person_id=h.id
left join system_parameter d on b.knowledge_id = d.id
left join system_parameter e on d.parent_id = e.id
left join system_parameter e on e.id=d.parent_id
where a.group_id in
<foreach collection="groupIds" index="index" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</select>
<select id="getMembersListByGroupIds" resultType="com.yiboshi.science.param.dto.ComProjectGroupDetailDTO">
SELECT b.name personName,b.cert_id,b.work_unit appUnitName
from com_project_group_detail a
left join com_project_members b on a.proj_id = b.object_id
where a.group_id in
<foreach collection="groupIds" index="index" item="item" open="(" separator="," close=")">
#{item}
......
......@@ -10,19 +10,6 @@
margin: 2cm 0;
}
@media print {
.page {
margin: 0;
border: initial;
border-radius: initial;
width: initial;
min-height: initial;
box-shadow: initial;
background: initial;
page-break-after: always;
}
}
* {
box-sizing: border-box;
}
......@@ -40,6 +27,7 @@
background-color: white;
box-shadow: 0 0 1px rgba(0, 0, 0, 0.1);
padding: 0 20mm;
page-break-after: always;
}
table {
......@@ -102,7 +90,7 @@
<span style='font-size:16.0pt;font-weight:normal'>附件<span>4</span></span>
</h1>
<p class="MsoNormal" style='margin-top:7.8pt;line-height:21.0pt'>
<span>&nbsp;</span>
<span></span>
</p>
<p class="MsoNormal" style='line-height:150%'>
<span style='font-size:16.0pt;line-height:100%;'>项目编号:</span>
......@@ -113,22 +101,22 @@
</u>
</p>
<p class="MsoNormal" style='text-align:left;line-height:150%;'>
<span>&nbsp;</span>
<span></span>
</p>
<p class="MsoNormal" style='text-align:left;line-height:150%;'>
<span>&nbsp;</span>
<span></span>
</p>
<p class="MsoNormal" style='text-align:left;line-height:150%;'>
<span>&nbsp;</span>
<span></span>
</p>
<p class="MsoNormal" style='text-align:center;'>
<span style='font-size:22.0pt;'>省级临床医学中心科研项目合同书</span>
</p>
<p class="MsoNormal" style='font-size:16.0pt;text-align:left;line-height:150%;'>
<span>&nbsp;</span>
<span></span>
</p>
<p class="MsoNormal" style='font-size:16.0pt;text-align:left;line-height:150%;'>
<span>&nbsp;</span>
<span></span>
</p>
<table class="head-tab">
<tr>
......@@ -152,11 +140,11 @@
<td colspan="2" class="border-B">${(startDate?string('yyyy年MM月dd日'))!}至 ${(endDate?string('yyyy年MM月dd日'))!}</td>
</tr>
<tr>
<td style="width: 90px;">&nbsp;</td>
<td style="width: 20px;">&nbsp;</td>
<td style="width: 20px;">&nbsp;</td>
<td style="width: 80px;">&nbsp;</td>
<td>&nbsp;</td>
<td style="width: 90px;"></td>
<td style="width: 20px;"></td>
<td style="width: 20px;"></td>
<td style="width: 80px;"></td>
<td></td>
</tr>
</table>
</div>
......
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