private static final String C_ACTION_CREAT_ACTIVITY = "meeting_register_addActivity";
@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.replaceAll("\\\\", "/");
String tempPath;
File dir = new File(path);
if (!dir.exists()) {
dir.mkdirs();
}
String fileName = "";
System.out.println(11);
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 = "附件格式输入有错,请重新输入!(仅支持png)";
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;
if (fileName == null || fileName.equals("")) {
// 文件夹名称为空,不写入
System.out.println("不写入");
} else {
tempPath = path.substring(0, path.length() - 1) + "/"
+ fileName;
System.out.println(tempPath);
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 activity_start_time = activeityVO
.getActivity_start_time();
String activity_end_time = activeityVO.getActivity_end_time();
String activity_validate_mode = activeityVO
.getActivity_validate_mode();
String background_picture = activeityVO.getBackground_picture();
if (background_picture == null || background_picture.equals("")) {
background_picture = null;
} else {
String Path = background_picture;
background_picture = getPinYin.getPY(Path);
}
String seat_picture = activeityVO.getSeat_picture();
if (seat_picture == null || seat_picture.equals("")) {
seat_picture = null;
} else {
String newSeat_picture = seat_picture;
seat_picture = getPinYin.getPY(newSeat_picture);
}
String metting_agenda = activeityVO.getMetting_agenda();
if (metting_agenda == null || metting_agenda.equals("")) {
metting_agenda = null;
} else {
String agenda_newPath = metting_agenda;
metting_agenda = getPinYin.getPY(agenda_newPath);
}
String metting_discipline = activeityVO.getMetting_discipline();
if (metting_discipline == null || metting_discipline.equals("")) {
metting_discipline = null;
} else {
String discipline_newPath =metting_discipline;
metting_discipline = getPinYin.getPY(discipline_newPath);
}
String activity_content = activeityVO.getActivity_content();
//String text = "http://域名/项目名/页面.html?参数id="+id;
//二维码uat访问地址
String text = "http:/域名/项目名/页面?参数id="+id;
int width = 350; // 二维码图片的宽
int height = 350; // 二维码图片的高
String act_name = activity_name;
String py = getPinYin.getPY(act_name); //此方法是将中文变成拼音。该源码贴在下面
String outPutPath = path + py + ".png"; //上传成功
outPutPath = outPutPath.replaceAll("\\\\", "/");
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_code = activeityVO.getTwo_dimension_code();
String two_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_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;
}
//以下是中文转拼音方法
package com.yd.meeting.register.util;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileUploadException;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.apache.log4j.Logger;
import com.yd.common.tool.dbm.StringUtil;
import com.yd.meeting.dongpu.controller.MEETING_dongpu_relationshipController;
public class getPinYin {
private final static Logger log = Logger.getLogger(MEETING_dongpu_relationshipController.class);
/**
* 根据汉字得到对应的拼音
*
* @param source
* @return
*/
public static String getPY(String source) {
if (StringUtil.isBlank(source)) {
return "";
}
char[] t1 = source.toCharArray();
HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();
format.setCaseType(HanyuPinyinCaseType.LOWERCASE);
format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
format.setVCharType(HanyuPinyinVCharType.WITH_V);
StringBuilder result = new StringBuilder();
for (char aT1 : t1) {
if (Character.toString(aT1).matches("[\\u4E00-\\u9FA5]")) {
try {
result.append(PinyinHelper.toHanyuPinyinStringArray(aT1, format)[0]);
} catch (BadHanyuPinyinOutputFormatCombination e) {
log.error("转换汉字拼音错误!", e);
}
} else {
// 非汉字不进行转换,直接添加
result.append(aT1);
}
}
return result.toString();
}
}
原文地址:https://www.cnblogs.com/Darkqueen/p/10449748.html