[name]您好!优蓝网已成功帮您预约了[corpName]的面试,请于[interviewTime]赶到面试点:[interviewAddress],面试联系人:[receiverName][receiverMobile]。有任何问题请联系我,[userName][userMobile]。
select CONCAT(CONCAT(CONCAT(a.name,b.name),c.name),demand.interview_address) as interviewAddress from corp_demand demand LEFT JOIN code_area a on a.code
=demand.interview_province_code LEFT JOIN code_area b on b.code=demand.interview_city_code LEFT JOIN code_area c on c.code=demand.interview_dist_code where demand.id=
SELECT name as corpName from corp_base where id =
Controller层:
/***
* 通过code获取短信模版
* @param code
* @param resumeId
* @param demandId
* @param baseId
* @param timeId
* @return
*/
@ResponseBody
@RequestMapping(value = "/getMessModeByCode", method = RequestMethod.POST)
public SmsModel getMessModeByCode(@RequestParam(value = "code") String code,@RequestParam(value = "resumeId") Long resumeId,
@RequestParam(value = "demandId") Long demandId,@RequestParam(value = "baseId") Long baseId
,@RequestParam(value = "timeId") Long timeId) {
ShiroUser user=(ShiroUser) SecurityUtils.getSubject().getPrincipal();
return smsModelService.getMessModeByCode(resumeId, user.getId(), baseId, demandId, timeId, code, true);
}
Service层实现:
@Override
public SmsModel getMessModeByCode(Long resumeId, Long userId,Long baseId,
Long demandId, Long timeId,String smsCode,boolean isInput) {
Map<String, Object> searchParams=new HashMap<String, Object>();
searchParams.put("isUse", 2);//可用的
searchParams.put("code",smsCode);
SmsModel messModel=smsModelDao.select(searchParams);
if(messModel!=null){
//替换通配符
String content=messModel.getContent();
//正则表达式获取通配符
Pattern p = Pattern.compile("(\\[[^\\]]*\\])");
Matcher m = p.matcher(content);
while(m.find()){
String code=m.group().substring(1, m.group().length()-1);
String valueString=m.group().substring(0, m.group().length());//通配符
CodeDictionary dictionary=codeDictionaryDao.getByCode(code);
if(dictionary!=null){
Map map = new HashMap();
String sql= dictionary.getRemark();//得到Sql
if(sql.contains("sys")){
sql+=userId;
map.put("sql", sql);
List<Map> list = smsModelDao.executeSql(map);
if(list.size()>0){
Object OB=list.get(0);
JSONObject json=JSONObject.fromObject(OB);
if(json==null || json.isNullObject()||("").equals(((String)json.get(code)))){
content=content.replaceAll("\\"+valueString,isInput?"":dictionary.getName());
}else{
content=content.replaceAll("\\"+valueString,(String) json.get(code));
}
messModel.setContent(content);
} else{
content=content.replaceAll("\\"+valueString,isInput?"":dictionary.getName());
messModel.setContent(content);
}
}else if(sql.contains("resume")){
sql+=resumeId;
map.put("sql", sql);
List<Map> list = smsModelDao.executeSql(map);
if(list.size()>0){
Object OB=list.get(0);
JSONObject json=JSONObject.fromObject(OB);
if(json==null ||json.isNullObject()||("").equals(((String)json.get(code)))){
content=content.replaceAll("\\"+valueString,isInput?"":dictionary.getName());
}else{
String name=(String) json.get(code);
content=content.replaceAll("\\"+valueString,name);
}
messModel.setContent(content);
}else{
content=content.replaceAll("\\"+valueString,isInput?"":dictionary.getName());
messModel.setContent(content);
}
}else if(sql.contains("project_scheduling")){
sql+=timeId;
map.put("sql", sql);
List<Map> list = smsModelDao.executeSql(map);
if(list.size()>0){
Object OB=list.get(0);
JSONObject json=JSONObject.fromObject(OB);
if(json==null||json.isNullObject()||("").equals(((String)json.get(code)))){
content=content.replaceAll("\\"+valueString,isInput?"":dictionary.getName());
}else{
content=content.replaceAll("\\"+valueString,(String) json.get(code));
}
messModel.setContent(content);
}else{
content=content.replaceAll("\\"+valueString,isInput?"":dictionary.getName());
messModel.setContent(content);
}
}else if(sql.contains("corp_demand") || sql.contains("project_base")){
sql+=demandId;
map.put("sql", sql);
List<Map> list = smsModelDao.executeSql(map);
if(list.size()>0){
Object OB=list.get(0);
JSONObject json=JSONObject.fromObject(OB);
if(json==null || json.isNullObject()||("").equals(((String)json.get(code)))){
content=content.replaceAll("\\"+valueString,isInput?"":dictionary.getName());
}else{
content=content.replaceAll("\\"+valueString,(String) json.get(code));
}
messModel.setContent(content);
}else{
content=content.replaceAll("\\"+valueString,isInput?"":dictionary.getName());
messModel.setContent(content);
}
}else if(sql.contains("corp_base") || sql.contains("corp_profile")){
sql+=baseId;
map.put("sql", sql);
List<Map> list = smsModelDao.executeSql(map);
if(list.size()>0){
Object OB=list.get(0);
JSONObject json=JSONObject.fromObject(OB);
if(json==null ||json.isNullObject()||("").equals(((String)json.get(code)))){
content=content.replaceAll("\\"+valueString,isInput?"":dictionary.getName());
}else{
content=content.replaceAll("\\"+valueString,(String) json.get(code));
}
}else{
content=content.replaceAll("\\"+valueString,isInput?"":dictionary.getName());
}
messModel.setContent(content);
}
else{//自定义通配符
String html= dictionary.getRemark();
content=content.replaceAll("\\"+valueString,html);
messModel.setContent(content);
}
}
}
}
return messModel;
}
sql:
<select id="executeSql" resultType="map">
${sql}
</select>
通过while(true){}的使用,根据不同的表名匹配不同的信息,简化提高代码质量。