Commit 3c59d26c authored by liuchao's avatar liuchao

no message

parent abdf28c2
package com.qiankun.controller;
import java.io.File;
import java.util.List;
import java.util.ResourceBundle;
import javax.servlet.http.HttpServletRequest;
......@@ -21,6 +22,8 @@ import com.qiankun.annotation.Auth;
import com.qiankun.controller.base.BaseController;
import com.qiankun.entity.Certificate;
import com.qiankun.service.CertificateService;
import com.qiankun.utils.UserUtils;
import com.qiankun.vo.CertificateVo;
@Controller
public class CertificateController extends BaseController<Object>{
......@@ -52,6 +55,21 @@ public class CertificateController extends BaseController<Object>{
return view;
}
@RequestMapping("/certificate/test")
public ModelAndView test(String id) throws Exception {
ModelAndView view = new ModelAndView();
Certificate certificate = certificateService.findById(id);
List<CertificateVo> addTexts = UserUtils.addTexts("志愿者", "0000000", certificate);
String certificatePath = File.separator + "mdp" + File.separator + "certificate" + File.separator + "test" ;
String outputFilePath = rb.getString("file_path") + certificatePath + File.separator + "test.png";
String certificateTemplate = rb.getString("file_path") + certificate.getUploadImage();
UserUtils.generateCertificate(certificateTemplate,outputFilePath,addTexts);
view.getModel().put("certificate", certificate);
view.getModel().put("status", "success");
return view;
}
@RequestMapping(value = "/api/certificate/save", method = RequestMethod.POST)
public ModelAndView save(@RequestParam(value = "file", required = false) MultipartFile file, Certificate certificate, HttpServletResponse response, HttpServletRequest request) throws Exception {
......
......@@ -17,6 +17,7 @@ import com.qiankun.entity.*;
import com.qiankun.pages.IPageList;
import com.qiankun.service.ActivityService;
import com.qiankun.service.BloodService;
import com.qiankun.service.CertificateService;
import com.qiankun.service.UserService;
import com.qiankun.utils.JwtTokenUtil;
import com.qiankun.utils.QRCodeUtil;
......@@ -60,6 +61,9 @@ public class MdpController extends BaseController<Object> {
private ActivityService activityService;
@Autowired
private BloodService bloodService;
@Autowired
private CertificateService certificateService;
private ResourceBundle rb = ResourceBundle.getBundle("system");
private String getAppid(){
return propertis.getConfigs().get(1).getAppid();
......@@ -480,15 +484,17 @@ public class MdpController extends BaseController<Object> {
result.put("certificateImage",user.getCerfificatePath());
return result;
}
private void generateCertificate(User user,String code) throws IOException {
List<CertificateVo> addTexts = Lists.newArrayList();
Calendar now = Calendar.getInstance();
String year = now.get(Calendar.YEAR) + "";
String month = now.get(Calendar.MONTH) + 1 >=10 ? "" + (now.get(Calendar.MONTH) + 1) : "0" + (now.get(Calendar.MONTH) + 1);
String day = now.get(Calendar.DATE) >=10 ? "" + now.get(Calendar.DATE) : "0" + now.get(Calendar.DATE);
List<CertificateVo> addTexts = Lists.newArrayList();
addTexts.add(new CertificateVo(user.getName(),new Font("宋体",Font.BOLD,50),190,570));
addTexts.add(new CertificateVo(code,new Font("宋体",Font.BOLD,30),270,1265));
addTexts.add(new CertificateVo(code,new Font("宋体",Font.PLAIN,30),270,1265));
addTexts.add(new CertificateVo(year,new Font("宋体",Font.PLAIN,30),525,1200));
addTexts.add(new CertificateVo(month,new Font("宋体",Font.PLAIN,30),650,1200));
addTexts.add(new CertificateVo(day,new Font("宋体",Font.PLAIN,30),740,1200));
......
......@@ -17,6 +17,7 @@ import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.PaperSize;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
......@@ -298,8 +299,8 @@ public class RainbowPlanWebController extends BaseController<Object>{
XSSFSheet sheet = wb.createSheet("心愿");
sheet.setMargin(HSSFSheet.TopMargin,( double ) 0.5 ); // 上边距
sheet.setMargin(HSSFSheet.BottomMargin,( double ) 0.5 ); // 下边距
sheet.setMargin(HSSFSheet.LeftMargin,( double ) 0.3 ); // 左边距
sheet.setMargin(HSSFSheet.RightMargin,( double ) 0.2 ); // 右边距
sheet.setMargin(HSSFSheet.LeftMargin,( double ) 0.2 ); // 左边距
sheet.setMargin(HSSFSheet.RightMargin,( double ) 0.0 ); // 右边距
XSSFPrintSetup print = sheet.getPrintSetup();
......@@ -312,17 +313,19 @@ public class RainbowPlanWebController extends BaseController<Object>{
sheet.setColumnWidth(2,3500);
sheet.setColumnWidth(3,1500);
sheet.setColumnWidth(4,3000);
sheet.setColumnWidth(5,4000);
sheet.setColumnWidth(6,8000);
sheet.setColumnWidth(5,2500);
sheet.setColumnWidth(6,6000);
sheet.setColumnWidth(7,3000);
sheet.setColumnWidth(8,3000);
sheet.setColumnWidth(9,6000);
sheet.setColumnWidth(9,4000);
sheet.setColumnWidth(10,6000);
XSSFFont font = wb.createFont();
font.setFontName("宋体");
font.setFontHeightInPoints((short) 12);
font.setBoldweight(Font.BOLDWEIGHT_BOLD);
XSSFFont topfont = wb.createFont();
topfont.setFontName("宋体");
topfont.setFontHeightInPoints((short) 11);
topfont.setBold(true);
//topfont.setBoldweight(Font.BOLDWEIGHT_BOLD);
......@@ -333,7 +336,9 @@ public class RainbowPlanWebController extends BaseController<Object>{
cellTopStyle.setBorderRight(BorderStyle.THIN);//setBorderRight(CellStyle.BORDER_THIN);
cellTopStyle.setBorderTop(BorderStyle.THIN);//setBorderTop(CellStyle.BORDER_THIN);
cellTopStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
cellTopStyle.setFont(font);
cellTopStyle.setFont(topfont);
cellTopStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
XSSFRow row = sheet.createRow(0);
row.setHeightInPoints(30);
......@@ -377,6 +382,9 @@ public class RainbowPlanWebController extends BaseController<Object>{
cell.setCellValue("邮寄地址");
cell.setCellStyle(cellTopStyle);
cell = row.createCell(10);
cell.setCellValue("爱心人士");
cell.setCellStyle(cellTopStyle);
XSSFCellStyle cellStyle=wb.createCellStyle();
cellStyle.setWrapText(true);
......@@ -387,10 +395,15 @@ public class RainbowPlanWebController extends BaseController<Object>{
cellStyle.setBorderRight(BorderStyle.THIN);//setBorderRight(CellStyle.BORDER_THIN);
cellStyle.setBorderTop(BorderStyle.THIN);//setBorderTop(CellStyle.BORDER_THIN);
cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
cellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
XSSFFont cellfont = wb.createFont();
cellfont.setFontName("宋体");
cellfont.setFontHeightInPoints((short) 10);
cellStyle.setFont(cellfont);
IPageList<Wish> wishPage = wishDao.findPages(wishVo.getSearchStr(), wishVo.getActivityId(), wishVo.getStatus(), wishVo.getType(),
wishVo.getOrder(), wishVo.getSort(), new Hints(getStartRow(request), getPageCount(request)));
wishVo.getOrder(), wishVo.getSort(), new Hints(0));
List<Wish> wish = wishPage.getRecords();
XSSFRow rows;
......@@ -398,7 +411,7 @@ public class RainbowPlanWebController extends BaseController<Object>{
for (int i = 0; i < wish.size(); i++) {
// 第三步:在这个sheet页里创建一行
rows = sheet.createRow(i+1);
rows.setHeightInPoints(60);
rows.setHeightInPoints(70);
// 第四步:在该行创建一个单元格
Wish data = wish.get(i);
......@@ -447,6 +460,20 @@ public class RainbowPlanWebController extends BaseController<Object>{
cells = rows.createCell(9);
cells.setCellValue(data.getChildren().getReceiveAddress());
cells.setCellStyle(cellStyle);
cells = rows.createCell(10);
if (data.getVolunteer()!=null) {
String tel = data.getVolunteer().getConnectTel();
tel = tel==null ? "" : "\n" + tel;
String addr = data.getVolunteer().getReceiveAddress();
addr = addr==null ? "" : "\n" + addr;
cells.setCellValue(data.getVolunteer().getName() + tel + addr);
} else {
cells.setCellValue("");
}
cells.setCellStyle(cellStyle);
}
......
package com.qiankun.utils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
import com.qiankun.entity.Certificate;
import com.qiankun.entity.Contacts;
import com.qiankun.entity.User;
import com.qiankun.vo.CertificateVo;
......@@ -101,6 +104,50 @@ public class UserUtils {
return url.openStream();
}
public static List<CertificateVo> addTexts(String userName,String code,Certificate certificate) throws Exception{
ResourceBundle rb = ResourceBundle.getBundle("system");
InputStream templateInput = null;
templateInput = loadTemplateImage(rb.getString("file_path") + certificate.getUploadImage());
Image image = ImageIO.read(templateInput);
int imageWidth = image.getWidth(null);
int imageHeight = image.getHeight(null);
ObjectMapper mapper = new ObjectMapper();
JsonNode request = mapper.readTree(certificate.getPosition());
Calendar now = Calendar.getInstance();
String year = now.get(Calendar.YEAR) + "";
String month = now.get(Calendar.MONTH) + 1 >=10 ? "" + (now.get(Calendar.MONTH) + 1) : "0" + (now.get(Calendar.MONTH) + 1);
String day = now.get(Calendar.DATE) >=10 ? "" + now.get(Calendar.DATE) : "0" + now.get(Calendar.DATE);
Map<String, String> data = new HashMap<>();
data.put("name", userName);
data.put("code", code);
data.put("year", year);
data.put("month", month);
data.put("day", day);
List<CertificateVo> addTexts = Lists.newArrayList();
Iterator<JsonNode> its = request.elements();
while (its.hasNext()) {
JsonNode json = its.next();
String name = json.get("name").asText();
Float x = json.get("x").floatValue()*imageWidth;
Float y = json.get("y").floatValue()*imageHeight;
addTexts.add(new CertificateVo(data.get(name), new Font("宋体",Font.BOLD,50), Math.round(x), Math.round(y)+30));
}
// addTexts.add(new CertificateVo(user.getName(),new Font("宋体",Font.BOLD,50),190,570));
// addTexts.add(new CertificateVo(code,new Font("宋体",Font.PLAIN,30),270,1265));
// addTexts.add(new CertificateVo(year,new Font("宋体",Font.PLAIN,30),525,1200));
// addTexts.add(new CertificateVo(month,new Font("宋体",Font.PLAIN,30),650,1200));
// addTexts.add(new CertificateVo(day,new Font("宋体",Font.PLAIN,30),740,1200));
return addTexts;
}
/*
public static void main(String[] args){
try {
......
#file_path=D:/file/
file_path=D:/file/
#file_path=/Users/liuyang/work/argus_work/tjmdp/udata
file_path=/var/tjmdp/udata
#file_path=/var/tjmdp/udata
account=admin
......
......@@ -97,12 +97,17 @@
<i class="icon-reply bigger-110"></i>
返回
</a>
<c:if test="${certificate.id!=null}">&nbsp; &nbsp; &nbsp;
<a class="btn btn-sm btn-success" href="javascript:;" onclick="certificate.test('${certificate.id}')">
<i class="icon-play bigger-110"></i>
测试
</a></c:if>
</div>
</div>
<div class="col-xs-7">
<c:if test="${certificate.uploadImage!='' && certificate.uploadImage!=null}">
<a href="javascript:;" onclick="certificate.editpic()"><img id="pic" src="<webpath:path/>/wx/rainbowplan/loadResource?imageName=${certificate.uploadImage}" width="300"/></a><br></c:if>
<a href="javascript:;" style="width:300px"><img id="pic" src="<webpath:path/>/wx/rainbowplan/loadResource?imageName=${certificate.uploadImage}" width="300" onclick="certificate.editpic()"/></a><br></c:if>
</div>
</div>
......
......@@ -28,7 +28,9 @@
</div>
<div class="page-content">
</div>
......
......@@ -170,6 +170,30 @@ var certificate = {
}
})
},
test : function(id) {
$.ajax({
url: webPath + '/certificate/test?id='+id,
type: 'GET',
cache: false,
processData: false,
contentType: false,
dataType:"json",
beforeSend: function(){
},
success: function(data){
if ("success" == data.status){
var html = '<img src="'+webPath+'/wx/rainbowplan/loadResource?imageName=\\mdp\\certificate\\test\\test.png" height="100%"/>';
layer.open({
type: 1,
skin: 'layui-layer-rim', //加上边框
area: ['auto', '100%'], //宽高
content: html
});
}
}
})
}
}
......
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