博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
单独管理image
阅读量:5855 次
发布时间:2019-06-19

本文共 8510 字,大约阅读时间需要 28 分钟。

NewsServiceimpl

 

 

@Override	public int addWithImage(KumiaoNewsDO kumiaoNewsDO, String pcImageUrl, String mobileImageUrl) {		this.kumiaoNewsMapper.insert(kumiaoNewsDO);		if (kumiaoNewsDO.getId() <= 0L) {			return -1; // failed		}		if (pcImageUrl != null) {			KumiaoResourceDO pcKumiaoResourceDO = generateKumiaoResourceDO(pcImageUrl, "pc", kumiaoNewsDO);			this.kumiaoResourceService.add(pcKumiaoResourceDO);		}		if (mobileImageUrl != null) {			KumiaoResourceDO mobileKumiaoResourceDO = generateKumiaoResourceDO(mobileImageUrl, "mobile", kumiaoNewsDO);			this.kumiaoResourceService.add(mobileKumiaoResourceDO);		}		return 0;	}		public KumiaoResourceDO generateKumiaoResourceDO(String imageUrl, String clientType, KumiaoNewsDO kumiaoNewsDO) {		KumiaoResourceDO kumiaoResourceDO = new KumiaoResourceDO();    	kumiaoResourceDO.setTitle("");    	kumiaoResourceDO.setGmtCreate(kumiaoNewsDO.getGmtCreate());        kumiaoResourceDO.setGmtModified(kumiaoNewsDO.getGmtModified());        kumiaoResourceDO.setResourceType("image");        kumiaoResourceDO.setPageType("news");        kumiaoResourceDO.setIsDeleted(kumiaoNewsDO.getIsDeleted());        kumiaoResourceDO.setRemark("");        kumiaoResourceDO.setClientType(clientType);        kumiaoResourceDO.setStatus(NewsDataStatusEnum.PUBLISHED.getStoreValue()); // 图片默认是发布状态        kumiaoResourceDO.setImageUrl(imageUrl);        kumiaoResourceDO.setOwnerId(kumiaoNewsDO.getId());        kumiaoResourceDO.setOwnerType("kumiao_news");        kumiaoResourceDO.setIsTest(kumiaoNewsDO.getIsTest());        return kumiaoResourceDO;	}

 

NewsService

 

int addWithImage(KumiaoNewsDO kumiaoNewsDO, String pcImageUrl, String mobileImageUrl);

 

NewsServiceController

 

/*     * 添加单条新闻     */    @RequestMapping(value = "/add", method = RequestMethod.POST)    @ResponseBody    public ResponseVo add(KumiaoNewsDO kumiaoNewsDO,  String pcImageUrl, String mobileImageUrl) throws Exception {        if (kumiaoNewsDO == null || StringUtil.isBlank(kumiaoNewsDO.getTitle())) {            return ResponseUtil.error(MessageCode.PARAMS_NOT_ENOUGH);        }        /*         * 新闻         */        Date now = new Date();        kumiaoNewsDO.setGmtCreate(now);        kumiaoNewsDO.setGmtModified(now);        kumiaoNewsDO.setIsDeleted(NewsDeletedStatusEnum.NOT_DELETED.getStoreValue());        kumiaoNewsDO.setRemark("");        kumiaoNewsDO.setStatus(NewsDataStatusEnum.UNPUBLISHED.getStoreValue());        int result = this.kumiaoNewsService.addWithImage(kumiaoNewsDO, pcImageUrl, mobileImageUrl);                if (result == 0) {            return ResponseUtil.success(MessageCode.SAVE_SUCCESS);        } else {            return ResponseUtil.error(MessageCode.FAILED);        }    }        /*     * 删除单条新闻     */    @RequestMapping(value = "/delete", method = RequestMethod.POST)    public @ResponseBody ResponseVo delete(Long id) throws Exception {        if (id == null || id <= 0L) {            return ResponseUtil.error(MessageCode.PARAMS_NOT_ENOUGH);        }        this.kumiaoNewsService.delete(id);        return ResponseUtil.success(MessageCode.DELETE_SUCCESS);    }        /*     * 发布单条新闻     */    @RequestMapping(value = "/publish", method = RequestMethod.POST)    public @ResponseBody ResponseVo publish(Long id) throws Exception {        if (id == null || id <= 0L) {            return ResponseUtil.error(MessageCode.PARAMS_NOT_ENOUGH);        }        this.kumiaoNewsService.publish(id);        return ResponseUtil.success(MessageCode.PUBLISH_SUCCESS);    }        /*     * 编辑单条新闻-查询     */    @RequestMapping(value = "/edit", method = RequestMethod.GET)    public String edit(Long id, ModelMap model) throws Exception {        if (id == null || id <= 0L) {            return ResponseUtil.error(model, MessageCode.PARAMS_NOT_ENOUGH);        }               KumiaoNewsDO kumiaoNewsDO = this.kumiaoNewsService.getById(id);        if (null == kumiaoNewsDO) {            return ResponseUtil.error(model, MessageCode.OBJ_NOT_EXISTS);        }        model.put("kumiaoNewsDO", kumiaoNewsDO);                KumiaoResourceDO pcImageDO = new KumiaoResourceDO();        KumiaoResourceDO mobileImageDO = new KumiaoResourceDO();        List
kumiaoResourceDOList = this.kumiaoResourceService.getByNewsOwner(kumiaoNewsDO); if (kumiaoResourceDOList != null) { for (int i=0; i
0L) { this.updateImageByNews(pcImageId, pcImageUrl, kumiaoNewsDO); } if (mobileImageId != null && mobileImageId > 0L) { this.updateImageByNews(mobileImageId, mobileImageUrl, kumiaoNewsDO); } this.kumiaoNewsService.update(kumiaoNewsDO); return ResponseUtil.success(MessageCode.SAVE_SUCCESS); } /* * 下线单条新闻 */ @ResponseBody @RequestMapping(value = "/offline", method = RequestMethod.POST) public ResponseVo offline(Long id) throws Exception { if (id == null || id <= 0L) { return ResponseUtil.error(MessageCode.PARAMS_NOT_ENOUGH); } this.kumiaoNewsService.offlineById(id); return ResponseUtil.success(MessageCode.OFFLINE_SUCCESS); } private void fillDefData(ModelMap model) { model.put("newsDataTypeEnum", NewsDataTypeEnum.getMap()); } private void updateImageByNews(Long imageId, String imageUrl, KumiaoNewsDO kumiaoNewsDO) { KumiaoResourceDO kumiaoResourceDO = new KumiaoResourceDO(); kumiaoResourceDO.setId(imageId); kumiaoResourceDO.setImageUrl(imageUrl); kumiaoResourceDO.setIsTest(kumiaoNewsDO.getIsTest()); this.kumiaoResourceService.update(kumiaoResourceDO); }

 

/*     * 添加单条新闻     */    @RequestMapping(value = "/add", method = RequestMethod.POST)    @ResponseBody    public ResponseVo add(KumiaoNewsDO kumiaoNewsDO,  String pcImageUrl, String mobileImageUrl) throws Exception {    	if (kumiaoNewsDO == null || StringUtil.isBlank(kumiaoNewsDO.getTitle())) {    		return ResponseUtil.error(MessageCode.PARAMS_NOT_ENOUGH);    	}    	/*    	 * 新闻    	 */    	Date now = new Date();    	kumiaoNewsDO.setGmtCreate(now);    	kumiaoNewsDO.setGmtModified(now);    	kumiaoNewsDO.setIsDeleted(NewsDeletedStatusEnum.NOT_DELETED.getStoreValue());    	kumiaoNewsDO.setRemark("");    	kumiaoNewsDO.setStatus(NewsDataStatusEnum.UNPUBLISHED.getStoreValue());    	int result = this.kumiaoNewsService.addWithImage(kumiaoNewsDO, pcImageUrl, mobileImageUrl);    	    	if (result == 0) {            return ResponseUtil.success(MessageCode.SAVE_SUCCESS);        } else {            return ResponseUtil.error(MessageCode.FAILED);        }    }

 

 

/*     * 编辑单条新闻-查询     */    @RequestMapping(value = "/edit", method = RequestMethod.GET)    public String edit(Long id, ModelMap model) throws Exception {    	if (id == null || id <= 0L) {            return ResponseUtil.error(model, MessageCode.PARAMS_NOT_ENOUGH);        }               KumiaoNewsDO kumiaoNewsDO = this.kumiaoNewsService.getById(id);        if (null == kumiaoNewsDO) {            return ResponseUtil.error(model, MessageCode.OBJ_NOT_EXISTS);        }        model.put("kumiaoNewsDO", kumiaoNewsDO);                KumiaoResourceDO pcImageDO = new KumiaoResourceDO();        KumiaoResourceDO mobileImageDO = new KumiaoResourceDO();        List
kumiaoResourceDOList = this.kumiaoResourceService.getByNewsOwner(kumiaoNewsDO); if (kumiaoResourceDOList != null) { for (int i=0; i
0L) { this.updateImageByNews(pcImageId, pcImageUrl, kumiaoNewsDO); } if (mobileImageId != null && mobileImageId > 0L) { this.updateImageByNews(mobileImageId, mobileImageUrl, kumiaoNewsDO); } this.kumiaoNewsService.update(kumiaoNewsDO); return ResponseUtil.success(MessageCode.SAVE_SUCCESS); }

 

ResourceService

 

List
getByNewsOwner(KumiaoNewsDO kumiaoNewsDO);

 

 

ResourceServiceImpl

@Override    public List
getByNewsOwner(KumiaoNewsDO kumiaoNewsDO) { KumiaoResourceDOExample example = new KumiaoResourceDOExample(); example.createCriteria().andOwnerIdEqualTo(kumiaoNewsDO.getId()).andOwnerTypeEqualTo("kumiao_news").andIsDeletedEqualTo(KumiaoResourceDeletedStatusEnum.NOT_DELETED.getStoreValue()).andStatusEqualTo(KumiaoResourceStatusEnum.PUBLISHED.getStoreValue()).andIsTestEqualTo(kumiaoNewsDO.getIsTest()); List
result = this.kumiaoResourceMapper.selectByExample(example); return result; }

 

 

 

转载于:https://www.cnblogs.com/iwangzheng/p/6933434.html

你可能感兴趣的文章
如何在ios中集成微信登录功能
查看>>
微软职位内部推荐-Sr SDE
查看>>
设计带有placeHolder的TextView
查看>>
什么是WEBserver? 经常使用的WEBserver有哪些?
查看>>
spring @component的作用
查看>>
2014年,daliu_it 年末文章汇总清单
查看>>
ubuntu12.04上搭建darwin streaming server6.03
查看>>
【高德地图API】汇润做爱地图技术大揭秘
查看>>
Windows系统版本号判定那些事儿
查看>>
【HighCharts系列教程】二、Highcharts结构及API文档
查看>>
Android 自定义对话框使用静态Handler传递参数
查看>>
Hql 执行CRUD
查看>>
[SAP ABAP开发技术总结]日期函数
查看>>
JAVA HTTP请求 常用的代理设置
查看>>
使用Jquery+EasyUI 进行框架项目开发案例解说之二---用户管理源代码分享
查看>>
Forbidden You don't have permission to access / on this server.
查看>>
【转】Gulp入门基础教程
查看>>
WP老杨解迷:如何获得更多的应用评价和解读内容刷新
查看>>
javascript Array对象
查看>>
手游专业名词收集
查看>>