Commit 3c59d26c authored by liuchao's avatar liuchao

no message

parent abdf28c2
package com.qiankun.controller; package com.qiankun.controller;
import java.io.File; import java.io.File;
import java.util.List;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -21,6 +22,8 @@ import com.qiankun.annotation.Auth; ...@@ -21,6 +22,8 @@ import com.qiankun.annotation.Auth;
import com.qiankun.controller.base.BaseController; import com.qiankun.controller.base.BaseController;
import com.qiankun.entity.Certificate; import com.qiankun.entity.Certificate;
import com.qiankun.service.CertificateService; import com.qiankun.service.CertificateService;
import com.qiankun.utils.UserUtils;
import com.qiankun.vo.CertificateVo;
@Controller @Controller
public class CertificateController extends BaseController<Object>{ public class CertificateController extends BaseController<Object>{
...@@ -52,6 +55,21 @@ public class CertificateController extends BaseController<Object>{ ...@@ -52,6 +55,21 @@ public class CertificateController extends BaseController<Object>{
return view; 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) @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 { 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.*; ...@@ -17,6 +17,7 @@ import com.qiankun.entity.*;
import com.qiankun.pages.IPageList; import com.qiankun.pages.IPageList;
import com.qiankun.service.ActivityService; import com.qiankun.service.ActivityService;
import com.qiankun.service.BloodService; import com.qiankun.service.BloodService;
import com.qiankun.service.CertificateService;
import com.qiankun.service.UserService; import com.qiankun.service.UserService;
import com.qiankun.utils.JwtTokenUtil; import com.qiankun.utils.JwtTokenUtil;
import com.qiankun.utils.QRCodeUtil; import com.qiankun.utils.QRCodeUtil;
...@@ -59,7 +60,10 @@ public class MdpController extends BaseController<Object> { ...@@ -59,7 +60,10 @@ public class MdpController extends BaseController<Object> {
@Autowired @Autowired
private ActivityService activityService; private ActivityService activityService;
@Autowired @Autowired
private BloodService bloodService; private BloodService bloodService;
@Autowired
private CertificateService certificateService;
private ResourceBundle rb = ResourceBundle.getBundle("system"); private ResourceBundle rb = ResourceBundle.getBundle("system");
private String getAppid(){ private String getAppid(){
return propertis.getConfigs().get(1).getAppid(); return propertis.getConfigs().get(1).getAppid();
...@@ -480,15 +484,17 @@ public class MdpController extends BaseController<Object> { ...@@ -480,15 +484,17 @@ public class MdpController extends BaseController<Object> {
result.put("certificateImage",user.getCerfificatePath()); result.put("certificateImage",user.getCerfificatePath());
return result; return result;
} }
private void generateCertificate(User user,String code) throws IOException { private void generateCertificate(User user,String code) throws IOException {
List<CertificateVo> addTexts = Lists.newArrayList();
Calendar now = Calendar.getInstance(); Calendar now = Calendar.getInstance();
String year = now.get(Calendar.YEAR) + ""; 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 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); 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(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(year,new Font("宋体",Font.PLAIN,30),525,1200));
addTexts.add(new CertificateVo(month,new Font("宋体",Font.PLAIN,30),650,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)); addTexts.add(new CertificateVo(day,new Font("宋体",Font.PLAIN,30),740,1200));
......
...@@ -17,6 +17,7 @@ import org.apache.poi.hssf.usermodel.HSSFSheet; ...@@ -17,6 +17,7 @@ import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.ss.usermodel.BorderStyle; import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font; 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.ss.usermodel.PaperSize;
import org.apache.poi.xssf.usermodel.XSSFCell; import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFCellStyle; import org.apache.poi.xssf.usermodel.XSSFCellStyle;
...@@ -298,8 +299,8 @@ public class RainbowPlanWebController extends BaseController<Object>{ ...@@ -298,8 +299,8 @@ public class RainbowPlanWebController extends BaseController<Object>{
XSSFSheet sheet = wb.createSheet("心愿"); XSSFSheet sheet = wb.createSheet("心愿");
sheet.setMargin(HSSFSheet.TopMargin,( double ) 0.5 ); // 上边距 sheet.setMargin(HSSFSheet.TopMargin,( double ) 0.5 ); // 上边距
sheet.setMargin(HSSFSheet.BottomMargin,( double ) 0.5 ); // 下边距 sheet.setMargin(HSSFSheet.BottomMargin,( double ) 0.5 ); // 下边距
sheet.setMargin(HSSFSheet.LeftMargin,( double ) 0.3 ); // 左边距 sheet.setMargin(HSSFSheet.LeftMargin,( double ) 0.2 ); // 左边距
sheet.setMargin(HSSFSheet.RightMargin,( double ) 0.2 ); // 右边距 sheet.setMargin(HSSFSheet.RightMargin,( double ) 0.0 ); // 右边距
XSSFPrintSetup print = sheet.getPrintSetup(); XSSFPrintSetup print = sheet.getPrintSetup();
...@@ -312,17 +313,19 @@ public class RainbowPlanWebController extends BaseController<Object>{ ...@@ -312,17 +313,19 @@ public class RainbowPlanWebController extends BaseController<Object>{
sheet.setColumnWidth(2,3500); sheet.setColumnWidth(2,3500);
sheet.setColumnWidth(3,1500); sheet.setColumnWidth(3,1500);
sheet.setColumnWidth(4,3000); sheet.setColumnWidth(4,3000);
sheet.setColumnWidth(5,4000); sheet.setColumnWidth(5,2500);
sheet.setColumnWidth(6,8000); sheet.setColumnWidth(6,6000);
sheet.setColumnWidth(7,3000); sheet.setColumnWidth(7,3000);
sheet.setColumnWidth(8,3000); sheet.setColumnWidth(8,3000);
sheet.setColumnWidth(9,6000); sheet.setColumnWidth(9,4000);
sheet.setColumnWidth(10,6000);
XSSFFont font = wb.createFont(); XSSFFont topfont = wb.createFont();
font.setFontName("宋体"); topfont.setFontName("宋体");
font.setFontHeightInPoints((short) 12); topfont.setFontHeightInPoints((short) 11);
font.setBoldweight(Font.BOLDWEIGHT_BOLD); topfont.setBold(true);
//topfont.setBoldweight(Font.BOLDWEIGHT_BOLD);
...@@ -333,7 +336,9 @@ public class RainbowPlanWebController extends BaseController<Object>{ ...@@ -333,7 +336,9 @@ public class RainbowPlanWebController extends BaseController<Object>{
cellTopStyle.setBorderRight(BorderStyle.THIN);//setBorderRight(CellStyle.BORDER_THIN); cellTopStyle.setBorderRight(BorderStyle.THIN);//setBorderRight(CellStyle.BORDER_THIN);
cellTopStyle.setBorderTop(BorderStyle.THIN);//setBorderTop(CellStyle.BORDER_THIN); cellTopStyle.setBorderTop(BorderStyle.THIN);//setBorderTop(CellStyle.BORDER_THIN);
cellTopStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); cellTopStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER);
cellTopStyle.setFont(font); cellTopStyle.setFont(topfont);
cellTopStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
XSSFRow row = sheet.createRow(0); XSSFRow row = sheet.createRow(0);
row.setHeightInPoints(30); row.setHeightInPoints(30);
...@@ -377,6 +382,9 @@ public class RainbowPlanWebController extends BaseController<Object>{ ...@@ -377,6 +382,9 @@ public class RainbowPlanWebController extends BaseController<Object>{
cell.setCellValue("邮寄地址"); cell.setCellValue("邮寄地址");
cell.setCellStyle(cellTopStyle); cell.setCellStyle(cellTopStyle);
cell = row.createCell(10);
cell.setCellValue("爱心人士");
cell.setCellStyle(cellTopStyle);
XSSFCellStyle cellStyle=wb.createCellStyle(); XSSFCellStyle cellStyle=wb.createCellStyle();
cellStyle.setWrapText(true); cellStyle.setWrapText(true);
...@@ -387,10 +395,15 @@ public class RainbowPlanWebController extends BaseController<Object>{ ...@@ -387,10 +395,15 @@ public class RainbowPlanWebController extends BaseController<Object>{
cellStyle.setBorderRight(BorderStyle.THIN);//setBorderRight(CellStyle.BORDER_THIN); cellStyle.setBorderRight(BorderStyle.THIN);//setBorderRight(CellStyle.BORDER_THIN);
cellStyle.setBorderTop(BorderStyle.THIN);//setBorderTop(CellStyle.BORDER_THIN); cellStyle.setBorderTop(BorderStyle.THIN);//setBorderTop(CellStyle.BORDER_THIN);
cellStyle.setVerticalAlignment(XSSFCellStyle.VERTICAL_CENTER); 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(), 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(); List<Wish> wish = wishPage.getRecords();
XSSFRow rows; XSSFRow rows;
...@@ -398,7 +411,7 @@ public class RainbowPlanWebController extends BaseController<Object>{ ...@@ -398,7 +411,7 @@ public class RainbowPlanWebController extends BaseController<Object>{
for (int i = 0; i < wish.size(); i++) { for (int i = 0; i < wish.size(); i++) {
// 第三步:在这个sheet页里创建一行 // 第三步:在这个sheet页里创建一行
rows = sheet.createRow(i+1); rows = sheet.createRow(i+1);
rows.setHeightInPoints(60); rows.setHeightInPoints(70);
// 第四步:在该行创建一个单元格 // 第四步:在该行创建一个单元格
Wish data = wish.get(i); Wish data = wish.get(i);
...@@ -447,6 +460,20 @@ public class RainbowPlanWebController extends BaseController<Object>{ ...@@ -447,6 +460,20 @@ public class RainbowPlanWebController extends BaseController<Object>{
cells = rows.createCell(9); cells = rows.createCell(9);
cells.setCellValue(data.getChildren().getReceiveAddress()); cells.setCellValue(data.getChildren().getReceiveAddress());
cells.setCellStyle(cellStyle); 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; package com.qiankun.utils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.qiankun.entity.Certificate;
import com.qiankun.entity.Contacts; import com.qiankun.entity.Contacts;
import com.qiankun.entity.User; import com.qiankun.entity.User;
import com.qiankun.vo.CertificateVo; import com.qiankun.vo.CertificateVo;
...@@ -100,6 +103,50 @@ public class UserUtils { ...@@ -100,6 +103,50 @@ public class UserUtils {
URL url = ResourceUtils.getURL(imageTemplatePath); URL url = ResourceUtils.getURL(imageTemplatePath);
return url.openStream(); 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){ public static void main(String[] args){
......
#file_path=D:/file/ file_path=D:/file/
#file_path=/Users/liuyang/work/argus_work/tjmdp/udata #file_path=/Users/liuyang/work/argus_work/tjmdp/udata
file_path=/var/tjmdp/udata #file_path=/var/tjmdp/udata
account=admin account=admin
......
...@@ -97,12 +97,17 @@ ...@@ -97,12 +97,17 @@
<i class="icon-reply bigger-110"></i> <i class="icon-reply bigger-110"></i>
返回 返回
</a> </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> </div>
<div class="col-xs-7"> <div class="col-xs-7">
<c:if test="${certificate.uploadImage!='' && certificate.uploadImage!=null}"> <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>
</div> </div>
......
...@@ -28,9 +28,11 @@ ...@@ -28,9 +28,11 @@
</div> </div>
<div class="page-content">
</div>
</div> </div>
...@@ -170,6 +170,30 @@ var certificate = { ...@@ -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