Skip to content

Commit

Permalink
内容分类管理的编辑的删除功能
Browse files Browse the repository at this point in the history
  • Loading branch information
sdksdk0 committed Nov 7, 2016
1 parent 6809b05 commit 4374309
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
package cn.tf.taotao.service;

import cn.tf.taotao.common.pojo.EUDResult;
import cn.tf.taotao.common.utils.TaotaoResult;
import cn.tf.taotao.po.TbContent;
import cn.tf.taotao.po.TbContentCategory;

public interface ContentService {
/**
* 插入操作
*
* @param content
* @return
*/
TaotaoResult insertContent(TbContent content);

/**
* 列表
* @param page
* @param rows
* @return
*/
EUDResult getContentList(long page, long pageSize);

/**
* 删除
* @param ids
* @return
*/
TaotaoResult deleteContent(String ids);

/**
* 更新操作
*
* @param content
* @return
*/
TaotaoResult updateContent(TbContent content);



}
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
package cn.tf.taotao.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.tf.taotao.common.pojo.EUDResult;
import cn.tf.taotao.common.utils.ExceptionUtil;
import cn.tf.taotao.common.utils.HttpClientUtil;
import cn.tf.taotao.common.utils.TaotaoResult;
import cn.tf.taotao.mapper.TbContentMapper;
import cn.tf.taotao.po.TbContent;
import cn.tf.taotao.po.TbContentExample;
import cn.tf.taotao.po.TbItem;
import cn.tf.taotao.po.TbItemDescExample;
import cn.tf.taotao.po.TbItemExample;
import cn.tf.taotao.po.TbItemExample.Criteria;
import cn.tf.taotao.service.ContentService;

@Service
Expand Down Expand Up @@ -41,4 +53,67 @@ public TaotaoResult insertContent(TbContent content) {
return TaotaoResult.ok();
}

//分页列表显示
@Override
public EUDResult getContentList(long page, long pageSize) {
TbContentExample example = new TbContentExample();
// 开始分页
PageHelper.startPage((int) page, (int) pageSize);
// 获取查询结果
List<TbContent> rows = contentMapper.selectByExample(example);
EUDResult dgr = new EUDResult();
dgr.setRows(rows);
// 获取分页信息 商品总数信息
PageInfo<TbContent> pageInfo = new PageInfo<TbContent>(rows);
dgr.setTotal(pageInfo.getTotal());
return dgr;
}

//删除
@Override
public TaotaoResult deleteContent(String ids) {
try {
String[] idsArray = ids.split(",");
List<Long> values = new ArrayList<Long>();
for(String id : idsArray) {
values.add(Long.parseLong(id));
}
TbContentExample e = new TbContentExample();
TbContentExample.Criteria c = e.createCriteria();
c.andIdIn(values);
contentMapper.deleteByExample(e);


} catch (Exception e) {
e.printStackTrace();
return null;
}
return TaotaoResult.ok();
}

//修改
@Override
public TaotaoResult updateContent(TbContent content) {

try {
//更新商品
TbContentExample e = new TbContentExample();
cn.tf.taotao.po.TbContentExample.Criteria c = e.createCriteria();
c.andIdEqualTo(content.getId());

TbContent tbContent = contentMapper.selectByPrimaryKey(content.getId());

content.setCreated(tbContent.getCreated());
content.setUpdated(new Date());

contentMapper.updateByExample(content, e);

} catch (Exception e) {
e.printStackTrace();
return TaotaoResult.build(500, ExceptionUtil.getStackTrace(e));
}
return TaotaoResult.ok();

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ public TaotaoResult updateItem(TbItem item, TbItemDesc desc, TbItemParamItem ite
TbItemExample e = new TbItemExample();
Criteria c = e.createCriteria();
c.andIdEqualTo(item.getId());
item.setCreated(new Date());

TbItem tbItem = itemMapper.selectByPrimaryKey(item.getId());
item.setCreated(tbItem.getCreated());
item.setUpdated(new Date());
item.setStatus((byte)1);
itemMapper.updateByExample(item, e);
Expand All @@ -202,7 +204,8 @@ public TaotaoResult updateItem(TbItem item, TbItemDesc desc, TbItemParamItem ite
cn.tf.taotao.po.TbItemDescExample.Criteria criteria = de.createCriteria();
criteria.andItemIdEqualTo(item.getId());
desc.setItemId(item.getId());
desc.setCreated(new Date());

desc.setCreated(tbItem.getCreated());
desc.setUpdated(new Date());
itemDescMapper.updateByExample(desc, de);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.tf.taotao.common.pojo.EUDResult;
import cn.tf.taotao.common.utils.TaotaoResult;
import cn.tf.taotao.po.TbContent;
import cn.tf.taotao.po.TbItem;
import cn.tf.taotao.po.TbItemDesc;
import cn.tf.taotao.po.TbItemParamItem;
import cn.tf.taotao.service.ContentService;

@Controller
Expand All @@ -21,5 +25,29 @@ public TaotaoResult insertContent(TbContent content){
TaotaoResult result = contentService.insertContent(content);
return result;
}


//加载列表
@RequestMapping("/content/query/list")
@ResponseBody
public EUDResult getContentList(Long page, Long rows){
EUDResult result = contentService.getContentList(page, rows);
return result;
}

//删除
@RequestMapping("/content/delete")
@ResponseBody
public TaotaoResult deleteContent(String ids){
return contentService.deleteContent(ids);
}

//更新
@RequestMapping("/rest/content/edit")
@ResponseBody
public TaotaoResult updateItem(TbContent content){
TaotaoResult result=contentService.updateContent(content);
return result;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Generated by Maven Integration for Eclipse
#Mon Nov 07 14:40:32 CST 2016
#Mon Nov 07 15:22:41 CST 2016
version=0.0.1-SNAPSHOT
groupId=cn.tf.taotao
m2e.projectName=taotao-manager-web
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<table class="easyui-datagrid" id="contentList" data-options="toolbar:contentListToolbar,singleSelect:false,collapsible:true,pagination:true,method:'get',pageSize:20,url:'/content/query/list',queryParams:{categoryId:0}">
<thead>
<tr>
<th data-options="field:'ck',checkbox:true"></th>
<th data-options="field:'id',width:30">ID</th>
<th data-options="field:'title',width:120">内容标题</th>
<th data-options="field:'subTitle',width:100">内容子标题</th>
Expand Down

0 comments on commit 4374309

Please sign in to comment.