Commit 9a6c9942 authored by liuyang's avatar liuyang

证书增加编号

parent 6620ea92
...@@ -24,6 +24,7 @@ import com.qiankun.utils.UserUtils; ...@@ -24,6 +24,7 @@ import com.qiankun.utils.UserUtils;
import com.qiankun.vo.*; import com.qiankun.vo.*;
import com.sun.mail.imap.ResyncData; import com.sun.mail.imap.ResyncData;
import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.common.error.WxErrorException;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.omg.PortableInterceptor.ServerRequestInfo; import org.omg.PortableInterceptor.ServerRequestInfo;
...@@ -458,9 +459,15 @@ public class MdpController extends BaseController<Object> { ...@@ -458,9 +459,15 @@ public class MdpController extends BaseController<Object> {
result.put("errorMsg","您还未采血,不能生成证书"); result.put("errorMsg","您还未采血,不能生成证书");
return result; return result;
} }
String code = getCollectBloodCode(user);
if (Strings.isNullOrEmpty(code)){
result.put("status","error");
result.put("errorMsg","采血编号不存在");
return result;
}
if (Strings.isNullOrEmpty(user.getCerfificatePath())){ if (Strings.isNullOrEmpty(user.getCerfificatePath())){
try { try {
generateCertificate(user); generateCertificate(user,code);
} catch (IOException e) { } catch (IOException e) {
logger.error(e.getMessage(),e); logger.error(e.getMessage(),e);
result.put("status","error"); result.put("status","error");
...@@ -473,16 +480,27 @@ public class MdpController extends BaseController<Object> { ...@@ -473,16 +480,27 @@ 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) throws IOException { private void generateCertificate(User user,String code) throws IOException {
List<CertificateVo> addTexts = Lists.newArrayList(); List<CertificateVo> addTexts = Lists.newArrayList();
Calendar now = Calendar.getInstance(); Calendar now = Calendar.getInstance();
addTexts.add(new CertificateVo(user.getName(),new Font("微软雅黑",Font.BOLD,50),250,1100)); addTexts.add(new CertificateVo(user.getName(),new Font("宋体",Font.BOLD,50),200,600));
addTexts.add(new CertificateVo(now.get(Calendar.YEAR)+"",new Font("微软雅黑",Font.PLAIN,30),550,1245)); addTexts.add(new CertificateVo(code,new Font("宋体",Font.BOLD,30),280,1310));
addTexts.add(new CertificateVo(now.get(Calendar.MONTH) +1+"",new Font("微软雅黑",Font.PLAIN,30),680,1245)); addTexts.add(new CertificateVo(now.get(Calendar.YEAR)+"",new Font("宋体",Font.PLAIN,30),550,1245));
addTexts.add(new CertificateVo(now.get(Calendar.DATE)+"",new Font("微软雅黑",Font.PLAIN,30),790,1245)); addTexts.add(new CertificateVo(now.get(Calendar.MONTH) +1+"",new Font("宋体",Font.PLAIN,30),680,1245));
addTexts.add(new CertificateVo(now.get(Calendar.DATE)+"",new Font("宋体",Font.PLAIN,30),790,1245));
String outputFilePath = rb.getString("file_path") + this.userCertificatePath + File.separator + user.getId() + ".jpeg"; String outputFilePath = rb.getString("file_path") + this.userCertificatePath + File.separator + user.getId() + ".jpeg";
UserUtils.generateCertificate(this.certificateTemplate,outputFilePath,addTexts); UserUtils.generateCertificate(this.certificateTemplate,outputFilePath,addTexts);
user.setCerfificatePath(this.userCertificatePath + File.separator + user.getId() + ".jpeg"); user.setCerfificatePath(this.userCertificatePath + File.separator + user.getId() + ".jpeg");
} }
private String getCollectBloodCode(User user) {
String code = "";
List<Blood> collectionBloods = bloodService.findByUserId(user);
if (!CollectionUtils.isEmpty(collectionBloods)){
Blood b = collectionBloods.get(0);
code = b.getBloodId();
}
return code;
}
} }
package com.qiankun.dao; package com.qiankun.dao;
import com.qiankun.dao.core.IDao; import com.qiankun.dao.core.IDao;
import com.qiankun.entity.Activity;
import com.qiankun.entity.Blood; import com.qiankun.entity.Blood;
import com.qiankun.entity.User;
import java.util.List;
public interface BloodDao extends IDao<Blood,String> { public interface BloodDao extends IDao<Blood,String> {
long findCountByUserAndActivity(String userId, String activityId); long findCountByUserAndActivity(String userId, String activityId);
List<Blood> findByUserOrderByCreateTime(String userId);
} }
package com.qiankun.dao; package com.qiankun.dao;
import com.qiankun.dao.core.AbsDao; import com.qiankun.dao.core.AbsDao;
import com.qiankun.dao.core.Hints;
import com.qiankun.entity.Activity; import com.qiankun.entity.Activity;
import com.qiankun.entity.Blood; import com.qiankun.entity.Blood;
import com.qiankun.entity.User; import com.qiankun.entity.User;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import java.util.List;
@Repository @Repository
public class BloodDaoImpl extends AbsDao<Blood,String> implements BloodDao { public class BloodDaoImpl extends AbsDao<Blood,String> implements BloodDao {
@Override @Override
public long findCountByUserAndActivity(String userId, String activityId) { public long findCountByUserAndActivity(String userId, String activityId) {
return findCount("select count(*) from Blood where user.id = ? and activity.id = ?",userId,activityId); return findCount("select count(*) from Blood where user.id = ? and activity.id = ?",userId,activityId);
} }
@Override
public List<Blood> findByUserOrderByCreateTime(String userId) {
return find(" from Blood where user.id = ? order by updateTime desc",new Hints(),userId);
}
} }
...@@ -8,6 +8,8 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -8,6 +8,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service @Service
public class BloodService { public class BloodService {
@Autowired @Autowired
...@@ -25,4 +27,7 @@ public class BloodService { ...@@ -25,4 +27,7 @@ public class BloodService {
return false; return false;
} }
} }
public List<Blood> findByUserId(User user){
return bloodDao.findByUserOrderByCreateTime(user.getId());
}
} }
...@@ -101,19 +101,26 @@ public class UserUtils { ...@@ -101,19 +101,26 @@ public class UserUtils {
return url.openStream(); return url.openStream();
} }
/*
// public static void main(String[] args){ public static void main(String[] args){
// try { try {
// List<CertificateVo> addTexts = Lists.newArrayList(); // GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();
// Calendar now = Calendar.getInstance(); // String[] fa=ge.getAvailableFontFamilyNames();
// addTexts.add(new CertificateVo("刘扬",new Font("微软雅黑",Font.BOLD,50),250,1100)); // for (String s:fa) {
// addTexts.add(new CertificateVo(now.get(Calendar.YEAR)+"",new Font("微软雅黑",Font.PLAIN,30),550,1245)); // System.out.println(s);
// addTexts.add(new CertificateVo(now.get(Calendar.MONTH) +1+"",new Font("微软雅黑",Font.PLAIN,30),680,1245));
// addTexts.add(new CertificateVo(now.get(Calendar.DATE)+"",new Font("微软雅黑",Font.PLAIN,30),790,1245));
// UserUtils.generateCertificate("classpath:certificate.jpeg","/Users/liuyang/Pictures/certificate.jpeg",addTexts);
// }catch (IOException e){
// e.printStackTrace();;
// }
//
// } // }
List<CertificateVo> addTexts = Lists.newArrayList();
Calendar now = Calendar.getInstance();
addTexts.add(new CertificateVo("刘扬",new Font("宋体",Font.PLAIN,50),200,600));
addTexts.add(new CertificateVo("0222189765",new Font("宋体",Font.PLAIN,30),280,1310));
addTexts.add(new CertificateVo(now.get(Calendar.YEAR)+"",new Font("宋体",Font.PLAIN,30),550,1245));
addTexts.add(new CertificateVo(now.get(Calendar.MONTH) +1+"",new Font("宋体",Font.PLAIN,30),690,1245));
addTexts.add(new CertificateVo(now.get(Calendar.DATE)+"",new Font("宋体",Font.PLAIN,30),790,1245));
UserUtils.generateCertificate("classpath:certificate.jpeg","/Users/liuyang/Pictures/certificate.jpeg",addTexts);
}catch (IOException e){
e.printStackTrace();;
}
}
*/
} }
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