@Override public boolean add(ImageInfo imageInfo) { if (StringUtils.isEmpty(imageInfo.getUrl()) || StringUtils.isEmpty(imageInfo.getRefId())) { log.error("添加图片信息失败!" + imageInfo.toString(), null); return false; } List<ImageInfo> list = queryByComapny(imageInfo.getRefId()); if (list != null && list.size() >= MAX_IMAGE) { log.error("添加图片信息失败!图片总数已经大于等于" + MAX_IMAGE, null); return false; } CompanyInfo companyInfo = companyInfoService.getObjectById(imageInfo.getRefId()); StringBuffer str = new StringBuffer(); str.append("INSERT INTO baiduad.image_info "); str.append("(title,url,order_num,link,create_date,remark,ref_id,company_name) "); str.append("VALUES "); str.append("(?,?,?,?,?,?,?,?) "); imageInfo.setCreateDate(new Date()); return super.add( str.toString(), imageInfo.getTitle(), imageInfo.getUrl(), Integer.valueOf(imageInfo.getOrderNum()), imageInfo.getLink(), imageInfo.getCreateDate(), imageInfo.getRemark(), imageInfo.getRefId(), companyInfo.getCompanyName()); }
@Override public ImageInfo getObjectById(int pkId) { if (pkId <= 0) { log.error("获取单个图片信息失败!pkId=" + pkId, null); return null; } return super.getObject( "SELECT company_name,pk_id,title,ref_id,url,order_num,link,create_date,remark FROM baiduad.image_info where pk_Id = ? ", Integer.valueOf(pkId)); }
@Override public boolean del(int pkId, HttpServletRequest servletRequest) { if (pkId <= 0) { log.error("删除图片信息失败!" + pkId, null); return false; } ImageInfo image = getObjectById(pkId); if (image != null && super.del("DELETE FROM baiduad.image_info WHERE pk_id = ? ", Integer.valueOf(pkId))) { FileUtil.deleteFile(image.getUrl(), "imgs", servletRequest); return true; } return false; }
@Override public boolean update(ImageInfo imageInfo) { if (StringUtils.isEmpty(imageInfo.getUrl()) || StringUtils.isEmpty(imageInfo.getLink()) || imageInfo.getPkId() <= 0) { log.error("更新图片信息失败!" + imageInfo.toString(), null); return false; } StringBuffer str = new StringBuffer(); str.append("UPDATE baiduad.image_info "); str.append("SET "); str.append("title=?,url=?,order_num=?,link=?,remark=? "); str.append("WHERE "); str.append("pk_id=? "); return super.update( str.toString(), imageInfo.getTitle(), imageInfo.getUrl(), Integer.valueOf(imageInfo.getOrderNum()), imageInfo.getLink(), imageInfo.getRemark(), Integer.valueOf(imageInfo.getPkId())); }