当前位置: 首页 > 工具软件 > DZMVC 1.0 DWZ > 使用案例 >

dwz服务端代码

茅秦斩
2023-12-01
package com.ketayao.security.service.impl;


import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;


import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import javax.servlet.http.HttpServletRequest;


import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;


import com.ketayao.genericdao.dao.GenericCommonDao;
import com.ketayao.security.MyLoggerFactory;
import com.ketayao.security.dao.AdvertiseinfoDao;
import com.ketayao.security.entity.main.AdvertiseInfo;
import com.ketayao.security.entity.main.AdvertiseType;
import com.ketayao.security.entity.main.FileInfo;
import com.ketayao.security.service.AdvertiseService;
import com.ketayao.util.dwz.DateOperate;
import com.ketayao.util.dwz.EntityOperate;
import com.ketayao.util.dwz.FileTools;
import com.ketayao.util.dwz.Page;
import com.ketayao.util.dwz.springdata.PageUtils;


@Service
@Transactional
public class AdvertiseServiceImpl extends BaseServiceImpl<AdvertiseInfo, Long> implements AdvertiseService{

private static Logger myLogger = MyLoggerFactory.getLogger(AdvertiseServiceImpl.class);

@SuppressWarnings("unused")
@Autowired
private AdvertiseinfoDao advertiseinfoDao;

@Autowired
private GenericCommonDao genericCommonDao;

@PersistenceContext
private EntityManager em;
 
@Autowired
public AdvertiseServiceImpl(AdvertiseinfoDao advertiseinfoDao) {
super((JpaRepository<AdvertiseInfo, Long>)advertiseinfoDao);
this.advertiseinfoDao = advertiseinfoDao;
}
    
/**
* 根据信息查询广告信息表
* @param paramMap
* @return List<TenOpennum>
*/
@SuppressWarnings("unchecked")
@Override
public List<AdvertiseInfo> find(Page page, Map<String, Object> reqMap) {
Pageable pageable =  null;
int cpage = 0;
int pageSize = 0;
if(page != null){
pageable = PageUtils.createPageable(page);
cpage = pageable.getPageNumber();
pageSize = pageable.getPageSize();
}
StringBuffer jpql = new StringBuffer();

jpql.append(" From AdvertiseInfo u where 1=1 ");
boolean isSel = false;
if(reqMap != null){
isSel = true;
}
if(isSel&&StringUtils.isNotEmpty((CharSequence) reqMap.get("advState"))){
jpql.append(" and u.advState = :advState");
}
if(isSel&&StringUtils.isNotEmpty((CharSequence) reqMap.get("advType"))){
jpql.append(" and u.advertisetype.id =:advType");
}
if(isSel&&StringUtils.isNotEmpty((CharSequence) reqMap.get("advTitle"))){
jpql.append(" and u.advTitle like :advTitle");
}
if(isSel&&StringUtils.isNotEmpty((CharSequence) reqMap.get("efectiveTimeSta"))){
jpql.append(" and u.efectiveTimeSta <= :efectiveTimeSta");
}
if(isSel&&StringUtils.isNotEmpty((CharSequence) reqMap.get("efectiveTimeEnd"))){
jpql.append(" and u.efectiveTimeEnd >= :efectiveTimeEnd");
}
jpql.append(" order by u.submitTime desc");
Query q = em.createQuery(jpql.toString());
if(isSel&&StringUtils.isNotEmpty((CharSequence) reqMap.get("advState"))){
q.setParameter("advState", reqMap.get("advState"));
}
if(isSel&&StringUtils.isNotEmpty((CharSequence) reqMap.get("advType"))){
q.setParameter("advType", Long.parseLong((String) reqMap.get("advType")));
}
if(isSel&&StringUtils.isNotEmpty((CharSequence) reqMap.get("advTitle"))){
q.setParameter("advTitle", "%"+reqMap.get("advTitle")+"%");
}
if(isSel&&StringUtils.isNotEmpty((CharSequence) reqMap.get("efectiveTimeSta"))){
q.setParameter("efectiveTimeSta", reqMap.get("efectiveTimeSta"));
}
if(isSel&&StringUtils.isNotEmpty((CharSequence) reqMap.get("efectiveTimeEnd"))){
q.setParameter("efectiveTimeEnd", reqMap.get("efectiveTimeEnd"));
}
if(page != null){
page.setTotalCount(q.getResultList().size());
q.setFirstResult(cpage*pageSize).setMaxResults(pageSize);
}
return q.getResultList();
}

/**
* 根据信息查询广告信息表
* @param paramMap
* @return List<TenOpennum>
* 有三种广告类型
* 1、文字
* 2、图片
* 3、视频
*/
@Override
@Transactional
public Map<String, Object> saveAdvertiseInfo(Map<String, String> paramMap,HttpServletRequest request) {
Map<String, Object> rltMap = new HashMap<String, Object>();
boolean rlt = true;
String msg = "添加广告信息成功!";

String advTitle = paramMap.get("advTitle");
String advType = paramMap.get("advType");
String advFileType = paramMap.get("advFileType");
String advContent = paramMap.get("advContent");
String gradeIds = paramMap.get("gradeIds");
String gradeNames = paramMap.get("gradeNames");
String useDev = paramMap.get("useDev");
String efectiveTimeSta = paramMap.get("efectiveTimeSta");
String efectiveTimeEnd = paramMap.get("efectiveTimeEnd");
String author = paramMap.get("author");

if("1".equals(advFileType)){// 1、文字广告
AdvertiseType advertisetype = em.find(AdvertiseType.class, new Long(advType));
AdvertiseInfo advertiseInfo = new AdvertiseInfo();
advertiseInfo.setAdvTitle(advTitle);
advertiseInfo.setAdvertisetype(advertisetype);
advertiseInfo.setAdvFileType(advFileType);
advertiseInfo.setAdvContent(advContent);
advertiseInfo.setGradeIds(gradeIds);
advertiseInfo.setGradeNames(gradeNames);
advertiseInfo.setUseDev(useDev);
advertiseInfo.setEfectiveTimeSta(efectiveTimeSta);
advertiseInfo.setEfectiveTimeEnd(efectiveTimeEnd); 
advertiseInfo.setAuthor(author);
advertiseInfo.setSubmitTime(DateOperate.getNowDate("yyyy-MM-dd HH:mm:ss"));
advertiseInfo.setAdvState("1");
save(advertiseInfo);
}
if("2".equals(advFileType)||"3".equals(advFileType)){// 2、图片广告,视频广告
List<MultipartFile> uploadFileList = null;
if(rlt){
 //广告信息附件判断
 //图片格式:JPEG、PNG、GIF、BMP 视频格式:AVI、MP4、WMV、MPG
MultipartHttpServletRequest multipartRequest  =  (MultipartHttpServletRequest) request;  
       // (根据前台的name名称得到上传的文件)   
uploadFileList  =    multipartRequest.getFiles("uploadFile");
long softSize = 0;
if(rlt){
//限制soft文件上传大小不超过30k以上
for(int index=0;index<uploadFileList.size();index++){
softSize = uploadFileList.get(index).getSize();
String subName = null;
String appendixName = null;
if(softSize>0){
  subName = uploadFileList.get(index).getOriginalFilename();
  appendixName = subName.substring(subName.indexOf(".")+1);
}
if("2".equals(advFileType)){
if(appendixName!=null&&!
 (appendixName.toUpperCase().equals("JPEG")||
appendixName.toUpperCase().equals("PNG")||
appendixName.toUpperCase().equals("GIF")||
appendixName.toUpperCase().equals("BMP"))){
rlt = false;
msg = "只允许上传PEG、PNG、GIF、BMP格式的文件!";
break;
}
if(softSize > 100*1024){//30*1024
rlt = false;
msg = "图片大小不超过100k以上,请重新选择图!";
break;
}
}
if("3".equals(advFileType)){
if(appendixName!=null&&!
 (appendixName.toUpperCase().equals("AVI")||
appendixName.toUpperCase().equals("MP4")||
appendixName.toUpperCase().equals("WMV")||
appendixName.toUpperCase().equals("MPG"))){
rlt = false;
msg = "只允许上传AVI、MP4、WMV、MPG格式的文件!";
break;
}
if(softSize > 30*1024*1024){//30*1024*1024
rlt = false;
msg = "视频大小不超过30M以上,请重新选择!";
break;
}
}
}
}
}
if(rlt){
AdvertiseType advertisetype = em.find(AdvertiseType.class, new Long(advType));
AdvertiseInfo advertiseInfo = new AdvertiseInfo();
advertiseInfo.setAdvTitle(advTitle);
advertiseInfo.setAdvertisetype(advertisetype);
advertiseInfo.setAdvFileType(advFileType);
advertiseInfo.setAdvContent(advContent);
advertiseInfo.setGradeIds(gradeIds);
advertiseInfo.setGradeNames(gradeNames);
advertiseInfo.setUseDev(useDev);
advertiseInfo.setEfectiveTimeSta(efectiveTimeSta);
advertiseInfo.setEfectiveTimeEnd(efectiveTimeEnd); 
advertiseInfo.setAuthor(author);
advertiseInfo.setSubmitTime(DateOperate.getNowDate("yyyy-MM-dd HH:mm:ss"));
advertiseInfo.setAdvState("1");
save(advertiseInfo);//保存广告信息
if(rlt){
for(int index=0;index<uploadFileList.size();index++){
MultipartFile uploadFile = uploadFileList.get(index);
//上传文件(可能比较耗时,待优化)
   String name = uploadFile.getOriginalFilename();
   String fileName=DateOperate.getNowDate("yyyyMMddHHmmss")+(int)(1+(Math.random())*10000)+name.substring(name.indexOf("."));
String targetfilePath = FileTools.getPushSavePath("2", request) + fileName;
String relativePath = FileTools.getPushSavePath("2", request);
String subFilePath = relativePath.substring(relativePath.lastIndexOf(FileTools.UPLOAD_DIR)-1,relativePath.length());
File file = new File(targetfilePath);
if(!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}

BufferedInputStream bis = null;
BufferedOutputStream bos = null;
FileOutputStream fos = null;
try {
bis = new BufferedInputStream(uploadFile.getInputStream());
fos = new FileOutputStream(file);
bos = new BufferedOutputStream(fos);
byte[] bytes = new byte[4096];
int read = 0;
while((read = bis.read(bytes))!=-1){
bos.write(bytes, 0, read);
}
bos.flush();
fos.flush();
fos.close();
bos.close();
bis.close();

fos = null;
bos = null;
bis = null;
/**
*将文件信息保存到库表中
*/
FileInfo fileinfo = new FileInfo();
fileinfo.setAddTime(DateOperate.formatDateToString(new Date(), "yyyyMMdd HH:mm:ss"));
fileinfo.setAdvertiseInfo(advertiseInfo);
fileinfo.setFileName(fileName);
if("3".equals(advFileType)){
String subOriginalName = uploadFile.getOriginalFilename().substring(0,name.indexOf("."));
if(subOriginalName.length()>50){
subOriginalName = uploadFile.getOriginalFilename().substring(0,50);
}
fileinfo.setOriginalName(subOriginalName+name.substring(name.indexOf(".")));
}
fileinfo.setFilePath(subFilePath);
EntityOperate.saveEntity(em, fileinfo);
EntityOperate.flushEm(em);
} catch (IOException e) {
e.printStackTrace();
rlt = false;
msg = "系统上传文件有误,请联系平台管理员!";
}finally{
if(bis != null){
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
bis = null;
}
if(fos != null){
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
fos = null;
}
if(bos != null){
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
bos = null;
}
}
  }
}
}
}
rltMap.put("rlt", rlt);
rltMap.put("msg", msg);
return rltMap;
}

/**
 * 删除广告信息表中的记录
 * @param id
 * @return Map<String, Object>
 */
@Override
@Transactional
public Map<String, Object> deleteEntity(Long id) {
Map<String, Object> resultMap = new HashMap<String, Object>();
boolean rlt = true;
String msg = "删除广告信息成功!";

if(id <=0 ){
rlt = false;
msg = "请求参数有误!";
}
AdvertiseInfo advertiseInfo = null;
if(rlt){
advertiseInfo = this.get(id);
    if(advertiseInfo == null){
    rlt = false;
msg = "未找到广告信息记录!";
    }
}
if(rlt){
    delete(id);
EntityOperate.flushEm(em);
}
resultMap.put("rlt", rlt);
resultMap.put("msg", msg);
return resultMap;
}

/**
 * 批量删除广告信息表中的记录
 * @param id
 * @return Map<String, Object>
 */
@Override
@Transactional
public Map<String, Object> deleteBatch(String ids){
Map<String, Object> resultMap = new HashMap<String, Object>();
boolean rlt = true;
String msg = "删除广告信息成功!";
if(ids!=null&&!"".equals(ids.trim())){
String[] idsArray = ids.split("\\,");
             for(int index=0;index<idsArray.length;index++){
            delete(new Long(idsArray[index]));
            EntityOperate.flushEm(em);
             }
}else{
rlt = false;
msg = "请选择广告信息!";
}
resultMap.put("rlt", rlt);
resultMap.put("msg", msg);
return resultMap;
}


  @Override
public Map<String, Object> getEntity(Long id) {
Map<String,Object> rltMap = new HashMap<String, Object>();
boolean rlt = true;
String msg = "查找成功";

if(id <= 0){
rlt = false;
msg = "请求信息有误";
}

AdvertiseInfo advertiseInfo = null;
if(rlt){
advertiseInfo = em.find(AdvertiseInfo.class, id);
if(advertiseInfo == null){
rlt = false;
msg = "查询的信息不存在";
}
}
if(rlt){
rltMap.put("advertiseInfo", advertiseInfo);
rltMap.put("useDevNames", convUseDevs(advertiseInfo.getUseDev()));
}
rltMap.put("rlt", rlt);
rltMap.put("msg", msg);
return rltMap;
}

   /**
* 将(1,2,3,4)换算对应的设备信息 (1:管理中心机,2:区口机,3:梯口机 4:家庭机 5:客户端)
*/
private String convUseDevs(String useDevs){
StringBuffer sb = new StringBuffer();
if(useDevs!=null&&!"".equals(useDevs.trim())){
String[] us = useDevs.split(",");
for(int i=0;i<us.length;i++){
if("1".equals(us[i])){
sb.append("管理中心机").append(",");
}else if("2".equals(us[i])){
sb.append("区口机").append(",");
}else if("3".equals(us[i])){
sb.append("梯口机").append(",");
}else if("4".equals(us[i])){
sb.append("家庭机").append(",");
}else if("5".equals(us[i])){
sb.append("客户端").append(",");
}
}
if(sb.length()>0){
sb.deleteCharAt(sb.length()-1);
}
}
return sb.toString();
}

/**
 *修改广告信息表中的记录
 * @param Map<String, String> paramsMap
 * @return Map<String, Object>
 */
@Override
@Transactional
public Map<String, Object> updateEntity(Map<String, String> paramsMap,HttpServletRequest request){
Map<String,Object> rltMap = new HashMap<String, Object>();
boolean rlt = true;
String msg = "修改广告信息成功!";
String id = paramsMap.get("id");
AdvertiseInfo advertiseInfo = get(new Long(id));
if(advertiseInfo == null){
rlt = false;
msg = "修改的广告信息不存在";
}
List<MultipartFile> uploadFileList = null;
String advFileType = request.getParameter("advFileType");
if(rlt){
 //广告信息附件判断
 //图片格式:JPEG、PNG、GIF、BMP 视频格式:AVI、MP4、WMV、MPG
MultipartHttpServletRequest multipartRequest  =  (MultipartHttpServletRequest) request;  
       // (根据前台的name名称得到上传的文件)   
uploadFileList  =    multipartRequest.getFiles("uploadFile");
long softSize = 0;
if(rlt){
//限制soft文件上传大小不超过30k以上
for(int index=0;index<uploadFileList.size();index++){
softSize = uploadFileList.get(index).getSize();
String subName = null;
String appendixName = null;
if(softSize>0){
  subName = uploadFileList.get(index).getOriginalFilename();
  appendixName = subName.substring(subName.indexOf(".")+1);
}
if("2".equals(advFileType)){
if(appendixName!=null&&!
 (appendixName.toUpperCase().equals("JPEG")||
   appendixName.toUpperCase().equals("JPG")||
appendixName.toUpperCase().equals("PNG")||
appendixName.toUpperCase().equals("GIF")||
appendixName.toUpperCase().equals("BMP"))){
rlt = false;
msg = "只允许上传JPEG、PNG、GIF、BMP格式的文件!";
break;
}
if(softSize > 100*1024){//30*1024
rlt = false;
msg = "图片大小不超过100k以上,请重新选择图!";
break;
}
}
if("3".equals(advFileType)){
if(appendixName!=null&&!
 (appendixName.toUpperCase().equals("AVI")||
appendixName.toUpperCase().equals("MP4")||
appendixName.toUpperCase().equals("WMV")||
appendixName.toUpperCase().equals("MPG"))){
rlt = false;
msg = "只允许上传AVI、MP4、WMV、MPG格式的文件!";
break;
}
if(softSize > 30*1024*1024){//30*1024*1024
rlt = false;
msg = "视频大小不超过30M以上,请重新选择!";
break;
}
}
}
}
}
if(rlt){
String oldAdvFileType = advertiseInfo.getAdvFileType();
if(!oldAdvFileType.equals(advFileType)){
      //如果选择的广告表现与原来的不一致则删除原来的附件信息
  Set<FileInfo> advertiseSet = advertiseInfo.getRelativeFiles();
  if(advertiseSet!=null&&advertiseSet.size()>0){
  Iterator<FileInfo> advertiseIter =   advertiseSet.iterator();
  while(advertiseIter.hasNext()){
  genericCommonDao.delete(advertiseIter.next());
  }
  }
    }
String advTitle = request.getParameter("advTitle");
String advType = request.getParameter("advType");
String advContent = request.getParameter("advContent");
String gradeIds = request.getParameter("gradeIds");
String gradeNames = request.getParameter("gradeNames");
String useDev = request.getParameter("useDev");
String efectiveTimeSta = request.getParameter("efectiveTimeSta");
String efectiveTimeEnd = request.getParameter("efectiveTimeEnd");
advertiseInfo.setAdvTitle(advTitle);
advertiseInfo.setAdvertisetype(em.find(AdvertiseType.class, new Long(advType)));
advertiseInfo.setAdvFileType(advFileType);
advertiseInfo.setAdvContent(advContent);
advertiseInfo.setGradeIds(gradeIds);
advertiseInfo.setGradeNames(gradeNames);
advertiseInfo.setUseDev(useDev);
advertiseInfo.setEfectiveTimeSta(efectiveTimeSta);
advertiseInfo.setEfectiveTimeEnd(efectiveTimeEnd);
update(advertiseInfo);
if(rlt){
for(int index=0;index<uploadFileList.size();index++){
MultipartFile uploadFile = uploadFileList.get(index);
//上传文件(可能比较耗时,待优化)
   String name = uploadFile.getOriginalFilename();
       if(uploadFile.getSize()>0){
   String fileName=DateOperate.getNowDate("yyyyMMddHHmmss")+(int)(1+(Math.random())*10000)+name.substring(name.indexOf("."));
String targetfilePath = FileTools.getPushSavePath("2", request) + fileName;
String relativePath = FileTools.getPushSavePath("2", request);
String subFilePath = relativePath.substring(relativePath.lastIndexOf(FileTools.UPLOAD_DIR)-1,relativePath.length());
File file = new File(targetfilePath);
if(!file.exists()){
try {
file.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}

BufferedInputStream bis = null;
BufferedOutputStream bos = null;
FileOutputStream fos = null;
try {
bis = new BufferedInputStream(uploadFile.getInputStream());
fos = new FileOutputStream(file);
bos = new BufferedOutputStream(fos);
byte[] bytes = new byte[4096];
int read = 0;
while((read = bis.read(bytes))!=-1){
bos.write(bytes, 0, read);
}
bos.flush();
fos.flush();
fos.close();
bos.close();
bis.close();

fos = null;
bos = null;
bis = null;
/**
*将文件信息保存到库表中
*/
FileInfo fileinfo = new FileInfo();
fileinfo.setAddTime(DateOperate.formatDateToString(new Date(), "yyyyMMdd HH:mm:ss"));
fileinfo.setAdvertiseInfo(advertiseInfo);
fileinfo.setFileName(fileName);
if("3".equals(advFileType)){
String subOriginalName = uploadFile.getOriginalFilename().substring(0,name.indexOf("."));
if(subOriginalName.length()>50){
subOriginalName = uploadFile.getOriginalFilename().substring(0,50);
}
fileinfo.setOriginalName(subOriginalName+name.substring(name.indexOf(".")));
}
fileinfo.setFilePath(subFilePath);
EntityOperate.saveEntity(em, fileinfo);
EntityOperate.flushEm(em);
} catch (IOException e) {
e.printStackTrace();
rlt = false;
msg = "系统上传文件有误,请联系平台管理员!";
}finally{
if(bis != null){
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
bis = null;
}
if(fos != null){
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
fos = null;
}
if(bos != null){
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
bos = null;
}
}
  }
}
}
}
rltMap.put("rlt", rlt);
rltMap.put("msg", msg);
return rltMap;
  }
/**
 *审核广告信息表中的记录
 * @param Map<String, String> paramsMap
 * @return Map<String, Object>
 */
@Override
@Transactional
public Map<String, Object> auditEntity(Map<String, String> paramsMap){
Map<String,Object> rltMap = new HashMap<String, Object>();
boolean rlt = true;
String msg = "审核广告信息成功!";
String id = paramsMap.get("id");
AdvertiseInfo advertiseInfo = get(new Long(id));
if(advertiseInfo == null){
rlt = false;
msg = "广告信息不存在";
}
if(rlt){
String advState = paramsMap.get("advState");
String adminNote = paramsMap.get("adminNote"); 
String auditor = paramsMap.get("auditor");
advertiseInfo.setAdvState(advState);
advertiseInfo.setAdminNote(adminNote);
advertiseInfo.setAuditor(auditor);
advertiseInfo.setAuditTime(DateOperate.formatDateToString(new Date(), "yyyyMMdd HH:mm:ss"));
update(advertiseInfo);
myLogger.info("广告信息审核成功!");
}
rltMap.put("rlt", rlt);
rltMap.put("msg", msg);
return rltMap;
  }

/**
*批量审核广告信息表中的记录
* @param Map<String, String> paramsMap
* @return Map<String, Object>
*/
@Override
@Transactional
public Map<String, Object> batchAudit(Map<String, String> paramsMap){
Map<String,Object> rltMap = new HashMap<String, Object>();
boolean rlt = true;
String msg = "批量审核广告信息成功!";
String ids = paramsMap.get("ids");
String[] idsArray = ids.split("\\,");
for(int index = 0;index < idsArray.length; index++){
AdvertiseInfo advertiseInfo = get(new Long(idsArray[index]));
if(advertiseInfo == null){
rlt = false;
msg = "第"+index+"广告信息不存在";
break;
}
}
if(rlt){
for(int index = 0;index < idsArray.length; index++){
AdvertiseInfo advertiseInfo = get(new Long(idsArray[index]));
if(rlt){
String adminNote = paramsMap.get("adminNote"); 
String auditor = paramsMap.get("auditor");
advertiseInfo.setAdvState("2");
advertiseInfo.setAdminNote(adminNote);
advertiseInfo.setAuditor(auditor);
advertiseInfo.setAuditTime(DateOperate.formatDateToString(new Date(), "yyyyMMdd HH:mm:ss"));
update(advertiseInfo);
myLogger.info("广告信息审核成功!");
}
}
}
rltMap.put("rlt", rlt);
rltMap.put("msg", msg);
return rltMap;
}
   
/**
 * 获取广告类型列表
 * @return List<AdvertiseType>
 */
@Override
@Transactional
public List<AdvertiseType> getTypeList(){
StringBuffer jpql = new StringBuffer();
jpql.append(" From AdvertiseType u where 1=1 ");
jpql.append(" order by u.id");
Query q = em.createQuery(jpql.toString());
return q.getResultList();
}

/**
 * 删除附件文件信息
 * @return Map<String, Object>
 */
@Override
@Transactional
public Map<String, Object> deleteFileinfo(String id){
Map<String,Object> rltMap = new HashMap<String, Object>();
boolean rlt = true;
String msg = "删除附件成功!";
            FileInfo fileInfo = em.find(FileInfo.class, new Long(id));
            if(fileInfo == null){
rlt = false;
msg = "广告信息不存在";
  }
            if(rlt){
  genericCommonDao.delete(fileInfo);
            }
rltMap.put("rlt", rlt);
rltMap.put("msg", msg);
return rltMap;
}

/**
 * 获取附件文件信息
 * @return Map<String, Object>
 */
@Override
@Transactional
public Map<String, Object> getFiles(Map<String,String> paramsMap){
String advFileType = paramsMap.get("advFileType");
Map<String,Object> rltMap = new HashMap<String, Object>();
StringBuffer jpql = new StringBuffer();
jpql.append(" From FileInfo u where 1=1 ");
if(StringUtils.isNotEmpty((CharSequence) paramsMap.get("advId"))){
jpql.append(" and u.advertiseInfo.id = :advId");
}
if(StringUtils.isNotEmpty((CharSequence) advFileType)){
jpql.append(" and u.advertiseInfo.advFileType = :advFileType ");
}
jpql.append(" order by u.id");
Query q = em.createQuery(jpql.toString());
if(StringUtils.isNotEmpty((CharSequence) paramsMap.get("advId"))){
q.setParameter("advId", new Long(paramsMap.get("advId")));
}
if(StringUtils.isNotEmpty((CharSequence) advFileType)){
q.setParameter("advFileType", advFileType);
}
rltMap.put("relativeFiles",q.getResultList());
return rltMap;
}
}
 类似资料: