@RequestMapping(value = "/addActivity")
public CIPResponseMsg addActivity(HttpServletRequest request,HttpServletResponse response) throws Exception {
System.out.println("接口进来了");
CIPResponseMsg msg = new CIPResponseMsg();
CIPRuntimeOperator operator = CIPRuntime.getOperateSubject();
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
request.getParameterMap();
String name = request.getParameter("activity_name");
MEETING_register_activeityData activeityData = new MEETING_register_activeityData();
MEETING_register_activeityVO activeityVO = new MEETING_register_activeityVO();
// 文件存放路径
String path = CIPRuntimeConfigure.cip_temp_file_path + File.separator;
String tempPath;
File dir = new File(path);
if (!dir.exists()) {
dir.mkdirs();
}
String fileName ="";
try {
Iterator<FileItem> iter = FileUploadUtil.getFileItemIterator(request, path);
while (iter.hasNext()) {
// item---前端传过来的(实体+表单)的所有数据
FileItem item = iter.next();
String fieldName = item.getFieldName();
Long fileSize = item.getSize();
fileName = item.getName();
// 判断属性是不是普通的表单类型
//将前端数据一一对应塞进对象里面
if (!item.isFormField() && !"".equals(fileName)) {
//截取前端传进来的文件后缀名
String suffix = fileName.substring(fileName.lastIndexOf("."));
// 判断该附件格式是否符合条件
System.out.println("图片类型"+fileName);
if (".png".equalsIgnoreCase(suffix)) {
if("background_picture".equals(fieldName)){
String serverpath = path + "\"+ fileName;
File file = new File(serverpath);
activeityVO.setBackground_picture(serverpath);
}
if("seat_picture".equals(fieldName)){
String serverpath = path + "\"+ fileName;
File file = new File(serverpath);
activeityVO.setSeat_picture(serverpath);
}
if("metting_agenda".equals(fieldName)){
String serverpath = path + "\"+ fileName;
File file = new File(serverpath);
activeityVO.setMetting_agenda(serverpath);
}
if("metting_discipline".equals(fieldName)){
String serverpath = path + "\"+ fileName;
File file = new File(serverpath);
activeityVO.setMetting_discipline(serverpath);
}
} else {
msg.errorCode = 100005;
msg.msg = "附件格式输入有错,请重新输入!(支持doc、docx、jpg、xls、png、zip、rar、pdf、txt)";
return msg;
}
if (fileSize > 10485760) {
msg.errorCode = 100006;
msg.msg = fieldName + "上传图片不得大于10M!";
responseMsg(response, msg);
return msg;
}
} else {
// 表单内除附件外其他表的字段获取(通过映射set获取页面实体值id--name)
ReflectUtil.invokeSetMethod4Field(activeityData, fieldName,new String(item.get(), "UTF-8"));
}
//给图片重新命名+日期(用流重新写进来)--不写进来的结果就是在默认路径下,文件名称发生变化,(码集影响)
//fileName=TimeUtil.format(new Date(), "yyyyMMddHHmmss")+"_"+fileName;
fileName=fileName;
tempPath=path.substring(0, path.length()-1)+"/"+fileName;
File file = new File(tempPath);
file.createNewFile();
file.setExecutable(true);//设置可执行权限
file.setReadable(true);//设置可读权限
file.setWritable(true);//设置可写权限
item.write(file);
}
Integer activity_id = WCM_utils_SequenceUtils.nextItemNo();
activeityVO.setActivity_name(activeityData.getActivity_name());
activeityVO.setActivity_validate_mode(activeityData.getActivity_validate_mode());
activeityVO.setActivity_start_time(activeityData.getActivity_start_time());
activeityVO.setActivity_end_time(activeityData.getActivity_end_time());
activeityVO.setActivity_content(activeityData.getActivity_content());
String activity_name = activeityVO.getActivity_name();
//活动名称不一致
List<MEETING_register_activeityData> ls = activeityService.findName(activity_name);
if(ls.size()>0){
//该任务名称数据库有,请重新命名
msg.errorCode = 1;
msg.msg = "活动名称已存在!请重新重命名";
}else{
//将数据写进对象里面
String metting_discipline = activeityVO.getMetting_discipline();
String activity_content = activeityVO.getActivity_content();
//自动生成二维码接口two_dimension_code
String text = "http://10.20.24.43:8080/meeting/meeting_register_phoneIndex.html"; //二维码生产内容--跳转url
int width = 350; // 二维码图片的宽
int height = 350; // 二维码图片的高
String outPutPath = path+ "\"+activity_name+"二维码"+".png"; //二维码生成保存路径
String imageType = "png"; //二维码生成类型
QRCodeTool.zxingCodeCreate(text, width, height, outPutPath, imageType);
if(outPutPath.equals("")||outPutPath==null){
msg.errorCode = 1;
msg.msg = "二维码生成失败";
}else{
activeityVO.setTwo_dimension_code(outPutPath);
String two_dimension_code = activeityVO.getTwo_dimension_code();
String activity_status="";
activeityService.addActivity(activity_id,activity_name,activity_content,activity_start_time,activity_end_time,activity_validate_mode,background_picture,seat_picture,metting_agenda,metting_discipline,two_dimension_code,activity_status);
msg.errorCode = 0;
msg.msg = CIPErrorCode.CALL_SUCCESS.name;
}
}
} catch (CIPServiceException e) {
CIPErrorCode error = e.getErrorCode();
msg.errorCode = error.code;
msg.msg = error.name;
} catch (CIPDaoException e) {
CIPErrorCode error = e.getErrorCode();
msg.errorCode = error.code;
msg.msg = error.name;
} catch (CIPRuntimeException e) {
CIPErrorCode error = e.getErrorCode();
msg.errorCode = error.code;
msg.msg = error.name;
}
return msg;
}