package cn.ksource.web.facade.link;
|
|
import java.io.File;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import com.lowagie.tools.handout_pdf;
|
|
import cn.ksource.core.dao.BaseDao;
|
import cn.ksource.core.dao.SqlParameter;
|
import cn.ksource.core.page.PageInfo;
|
import cn.ksource.core.util.ConvertUtil;
|
import cn.ksource.core.util.FileUtil;
|
import cn.ksource.core.util.MyFileUploadException;
|
import cn.ksource.core.util.StringUtil;
|
import cn.ksource.web.Constants;
|
import cn.ksource.web.entity.link.CmsLink;
|
|
@Service("linkFacade")
|
public class LinkFacadeImpl implements LinkFacade {
|
|
@Autowired
|
private BaseDao baseDao;
|
|
|
/**
|
* 查询指定分类下的列表信息
|
*/
|
@Override
|
public Map queryLinkListJson(String categoryId, int page, int pageSize) {
|
StringBuilder builder = new StringBuilder("SELECT * FROM CMS_LINK WHERE CATEGORY_ID = :categoryId");
|
StringBuilder countBuilder = new StringBuilder("SELECT COUNT(ID) FROM CMS_LINK WHERE CATEGORY_ID = :categoryId");
|
Map paramMap = new HashMap();
|
builder.append(" ORDER BY THETOP ASC,ORDERNUM ASC");
|
builder.append(" LIMIT :begin,:size");
|
page = page==0?1:page;
|
pageSize = pageSize==0?10:pageSize;
|
int begin = (page-1)*pageSize;
|
paramMap.put("begin", begin);
|
paramMap.put("size", pageSize);
|
paramMap.put("categoryId", categoryId);
|
int count = baseDao.queryForInteger(countBuilder.toString(), paramMap);
|
List<Map> resultList = baseDao.queryForList(builder.toString(),paramMap);
|
|
|
Map resultMap = new HashMap();
|
resultMap.put("total", count); //信息总数
|
resultMap.put("rows", resultList);
|
return resultMap;
|
}
|
|
|
|
|
@Override
|
public Map queryLinkCategoryById(String categoryId) {
|
String sql = "SELECT * FROM CMS_LINK_CATEGORY WHERE ID = :id";
|
return baseDao.queryForMap(sql, new SqlParameter().addValue("id", categoryId));
|
}
|
|
|
|
|
@Override
|
public boolean save(CmsLink link, HttpServletRequest request) {
|
String[] allowType = new String[]{"gif","jpg","jpeg","png"};
|
int categoryId = link.getCategoryId();
|
System.out.println("categoryId:"+categoryId);
|
Map linkCategory = queryLinkCategoryById(ConvertUtil.obj2StrBlank(categoryId));
|
//判断是否需要标题图片
|
int titleimage = ConvertUtil.obj2Int(linkCategory.get("TITLEIMAGE"));
|
|
String uploadUrl = new String();
|
if(titleimage==1) {
|
try {
|
uploadUrl = FileUtil.uploadFile4SpringMVC(request, "image" ,"/upload/classify"+categoryId,allowType);
|
//判断是否需要生成缩略图
|
int thumbnail = ConvertUtil.obj2Int(linkCategory.get("THUMBNAIL"));
|
if(thumbnail!=1){
|
//获得生成的缩略图的等比或者强制宽和高
|
String widthStr = ConvertUtil.obj2StrBlank(linkCategory.get("TITLEIMAGE_WIDTH"));
|
String heightStr = ConvertUtil.obj2StrBlank(linkCategory.get("TITLEIMAGE_HEIGHT"));
|
if(!widthStr.equals("") && !heightStr.equals("") && !widthStr.equals("0") && !heightStr.equals("0")) {
|
int width = ConvertUtil.obj2Int(widthStr);
|
int height = ConvertUtil.obj2Int(heightStr);
|
String pathPix = request.getSession().getServletContext().getRealPath("/");
|
boolean b = false;
|
if(thumbnail==3) {
|
b = true;
|
}
|
String newName = FileUtil.resizeForEqualImg(new File(pathPix+uploadUrl), width, height, b);
|
uploadUrl = uploadUrl.replace(uploadUrl.substring(uploadUrl.lastIndexOf("/")+1), newName);
|
}
|
}
|
link.setTitleimage(uploadUrl);
|
|
} catch (MyFileUploadException e) {
|
return false;
|
}
|
}
|
|
//保存信息
|
|
String idSql = "SELECT MAX(ID) FROM CMS_LINK";
|
Integer idObj = baseDao.queryForInteger(idSql);
|
int id = 1;
|
if(null != idObj) {
|
id = idObj;
|
}
|
|
String sql = "INSERT INTO CMS_LINK(ID,CATEGORY_ID,TITLE,TITLEIMAGE,THETOP,SUMMARY,CONTENT,THEURL,ORDERNUM,POSITION_ID,LINK_STATUS) " +
|
"VALUES (:id,:categoryId,:title,:titleimage,:thetop,:summary,:content,:theurl,:ordernum,:positionId,:status)";
|
|
Map paramMap = new HashMap();
|
paramMap.put("id", id+1);
|
paramMap.put("categoryId", link.getCategoryId());
|
paramMap.put("title", link.getTitle());
|
paramMap.put("titleimage", link.getTitleimage());
|
paramMap.put("thetop", link.getThetop());
|
paramMap.put("summary", link.getSummary());
|
paramMap.put("content", link.getContent());
|
paramMap.put("theurl", link.getTheurl());
|
paramMap.put("ordernum", link.getOrdernum());
|
paramMap.put("positionId", link.getPositionId());
|
paramMap.put("status", 1);
|
baseDao.execute(sql, paramMap);
|
return true;
|
}
|
|
|
|
|
@Override
|
public Map queryLinkById(String linkId) {
|
String sql = "SELECT * FROM CMS_LINK WHERE ID = :id";
|
return baseDao.queryForMap(sql, new SqlParameter().addValue("id", linkId));
|
}
|
|
|
|
|
@Override
|
public boolean updateLink(CmsLink link, HttpServletRequest request) {
|
String[] allowType = new String[]{"gif","jpg","jpeg","png"};
|
int categoryId = link.getCategoryId();
|
Map linkCategory = queryLinkCategoryById(ConvertUtil.obj2StrBlank(categoryId));
|
//判断是否需要标题图片
|
int titleimage = ConvertUtil.obj2Int(linkCategory.get("TITLEIMAGE"));
|
|
String uploadUrl = new String();
|
if(titleimage==1) {
|
try {
|
uploadUrl = FileUtil.uploadFile4SpringMVC(request, "image" ,"/upload/classify"+categoryId,allowType);
|
if(null!=uploadUrl) {
|
//判断是否需要生成缩略图
|
int thumbnail = ConvertUtil.obj2Int(linkCategory.get("THUMBNAIL"));
|
if(thumbnail!=1){
|
//获得生成的缩略图的等比或者强制宽和高
|
String widthStr = ConvertUtil.obj2StrBlank(linkCategory.get("TITLEIMAGE_WIDTH"));
|
String heightStr = ConvertUtil.obj2StrBlank(linkCategory.get("TITLEIMAGE_HEIGHT"));
|
if(!widthStr.equals("") && !heightStr.equals("") && !widthStr.equals("0") && !heightStr.equals("0")) {
|
int width = ConvertUtil.obj2Int(widthStr);
|
int height = ConvertUtil.obj2Int(heightStr);
|
String pathPix = request.getSession().getServletContext().getRealPath("/");
|
boolean b = false;
|
if(thumbnail==3) {
|
b = true;
|
}
|
String newName = FileUtil.resizeForEqualImg(new File(pathPix+uploadUrl), width, height, b);
|
uploadUrl = uploadUrl.replace(uploadUrl.substring(uploadUrl.lastIndexOf("/")+1), newName);
|
}
|
}
|
link.setTitleimage(uploadUrl);
|
}
|
|
} catch (MyFileUploadException e) {
|
return false;
|
}
|
}
|
|
String sql = "UPDATE CMS_LINK SET TITLE = :title,TITLEIMAGE = :titleimage,THETOP = :thetop,SUMMARY = :summary,CONTENT = :content,THEURL = :theurl,ORDERNUM = :ordernum,POSITION_ID=:positionId WHERE ID = :id";
|
Map parmaMap = new HashMap();
|
parmaMap.put("title", link.getTitle());
|
parmaMap.put("titleimage", link.getTitleimage());
|
parmaMap.put("thetop", link.getThetop());
|
parmaMap.put("content", link.getContent());
|
parmaMap.put("summary", link.getSummary());
|
parmaMap.put("theurl", link.getTheurl());
|
parmaMap.put("ordernum", link.getOrdernum());
|
parmaMap.put("positionId", link.getPositionId());
|
parmaMap.put("id", link.getId());
|
|
baseDao.execute(sql, parmaMap);
|
return true;
|
|
}
|
|
|
|
|
@Override
|
public void deleteLink(String id,String index) {
|
String sql = "UPDATE CMS_LINK SET LINK_STATUS = :link_status WHERE ID = :id";
|
Map param = new HashMap();
|
param.put("link_status", index);
|
param.put("id", id);
|
baseDao.execute(sql,param);
|
}
|
|
|
|
|
@Override
|
public Boolean queryMsgCountByCategoryId(String categoryId) {
|
String sql = "SELECT COUNT(ID) FROM CMS_LINK WHERE CATEGORY_ID = :categoryId";
|
int count = baseDao.queryForInteger(sql,new SqlParameter("categoryId",categoryId));
|
if(count>0) {
|
return false;
|
}
|
return true;
|
}
|
|
|
|
|
@Override
|
public void updateState(int id, int state) {
|
String sql = "UPDATE CMS_LINK SET LINK_STATUS=:state WHERE ID=:id";
|
|
baseDao.execute(sql, new SqlParameter().addValue("state", state).addValue("id", id));
|
}
|
|
|
|
|
@Override
|
public int querylinkCount(String categoryId) {
|
StringBuilder builder = new StringBuilder("SELECT COUNT(ID) FROM CMS_LINK WHERE CATEGORY_ID = :categoryId ");
|
Map paramMap = new HashMap();
|
paramMap.put("categoryId", categoryId);
|
|
|
int count = baseDao.queryForInteger(builder.toString(), paramMap);
|
|
return count;
|
}
|
|
|
|
|
@Override
|
public PageInfo querylinkData(PageInfo pageInfo,String categoryId) {
|
StringBuilder builder = new StringBuilder("SELECT * FROM CMS_LINK WHERE CATEGORY_ID = :categoryId ");
|
Map paramMap = new HashMap();
|
paramMap.put("categoryId", categoryId);
|
|
builder.append(" ORDER BY THETOP ASC,ORDERNUM ASC ");
|
|
PageInfo info = baseDao.queryforSplitPageInfo(pageInfo, builder.toString(), paramMap);
|
|
return info;
|
}
|
}
|