提交 e5e0fc25 authored 作者: zgy's avatar zgy

完成标签管理

上级 7c52e83c
package com.platform.controller;
import com.platform.entity.TbCfLabelEntity;
import com.platform.service.TbCfLabelService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
/**
* 商品标签Controller
*
* @author lipengjun
* @date 2020-03-12 16:20:26
*/
@Controller
@RequestMapping("tbcflabel")
public class TbCfLabelController {
@Autowired
private TbCfLabelService tbCfLabelService;
/**
* 查看列表
*/
@RequestMapping("/list")
@RequiresPermissions("tbcflabel:list")
@ResponseBody
public R list(@RequestParam Map<String, Object> params) {
//查询列表数据
Query query = new Query(params);
List<TbCfLabelEntity> tbCfLabelList = tbCfLabelService.queryList(query);
int total = tbCfLabelService.queryTotal(query);
PageUtils pageUtil = new PageUtils(tbCfLabelList, total, query.getLimit(), query.getPage());
return R.ok().put("page", pageUtil);
}
/**
* 查看信息
*/
@RequestMapping("/info/{id}")
@RequiresPermissions("tbcflabel:info")
@ResponseBody
public R info(@PathVariable("id") String id) {
TbCfLabelEntity tbCfLabel = tbCfLabelService.queryObject(id);
return R.ok().put("tbCfLabel", tbCfLabel);
}
/**
* 保存
*/
@RequestMapping("/save")
@RequiresPermissions("tbcflabel:save")
@ResponseBody
public R save(@RequestBody TbCfLabelEntity tbCfLabel) {
tbCfLabelService.save(tbCfLabel);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
@RequiresPermissions("tbcflabel:update")
@ResponseBody
public R update(@RequestBody TbCfLabelEntity tbCfLabel) {
tbCfLabelService.update(tbCfLabel);
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
@RequiresPermissions("tbcflabel:delete")
@ResponseBody
public R delete(@RequestBody String[] ids) {
tbCfLabelService.deleteBatch(ids);
return R.ok();
}
/**
* 查看所有列表
*/
@RequestMapping("/queryAll")
@ResponseBody
public R queryAll(@RequestParam Map<String, Object> params) {
List<TbCfLabelEntity> list = tbCfLabelService.queryList(params);
return R.ok().put("list", list);
}
}
package com.platform.dao;
import com.platform.entity.TbCfLabelEntity;
/**
* 商品标签Dao
*
* @author lipengjun
* @date 2020-03-12 16:20:26
*/
public interface TbCfLabelDao extends BaseDao<TbCfLabelEntity> {
}
package com.platform.entity;
import java.io.Serializable;
import java.util.Date;
/**
* 商品标签实体
* 表名 tb_cf_label
*
* @author lipengjun
* @date 2020-03-12 16:20:26
*/
public class TbCfLabelEntity implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 标签ID
*/
private String id;
/**
* 标签名
*/
private String labelName;
/**
* 是否启用 0:不启用 1:启用
*/
private Integer enableFlag;
/**
* 创建时间
*/
private Date createTime;
/**
* 更新时间
*/
private Date updateTime;
/**
* 设置:标签ID
*/
public void setId(String id) {
this.id = id;
}
/**
* 获取:标签ID
*/
public String getId() {
return id;
}
/**
* 设置:标签名
*/
public void setLabelName(String labelName) {
this.labelName = labelName;
}
/**
* 获取:标签名
*/
public String getLabelName() {
return labelName;
}
/**
* 设置:是否启用 0:不启用 1:启用
*/
public void setEnableFlag(Integer enableFlag) {
this.enableFlag = enableFlag;
}
/**
* 获取:是否启用 0:不启用 1:启用
*/
public Integer getEnableFlag() {
return enableFlag;
}
/**
* 设置:创建时间
*/
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
/**
* 获取:创建时间
*/
public Date getCreateTime() {
return createTime;
}
/**
* 设置:更新时间
*/
public void setUpdateTime(Date updateTime) {
this.updateTime = updateTime;
}
/**
* 获取:更新时间
*/
public Date getUpdateTime() {
return updateTime;
}
}
package com.platform.service;
import com.platform.entity.TbCfLabelEntity;
import java.util.List;
import java.util.Map;
/**
* 商品标签Service接口
*
* @author lipengjun
* @date 2020-03-12 16:20:26
*/
public interface TbCfLabelService {
/**
* 根据主键查询实体
*
* @param id 主键
* @return 实体
*/
TbCfLabelEntity queryObject(String id);
/**
* 分页查询
*
* @param map 参数
* @return list
*/
List<TbCfLabelEntity> queryList(Map<String, Object> map);
/**
* 分页统计总数
*
* @param map 参数
* @return 总数
*/
int queryTotal(Map<String, Object> map);
/**
* 保存实体
*
* @param tbCfLabel 实体
* @return 保存条数
*/
int save(TbCfLabelEntity tbCfLabel);
/**
* 根据主键更新实体
*
* @param tbCfLabel 实体
* @return 更新条数
*/
int update(TbCfLabelEntity tbCfLabel);
/**
* 根据主键删除
*
* @param id
* @return 删除条数
*/
int delete(String id);
/**
* 根据主键批量删除
*
* @param ids
* @return 删除条数
*/
int deleteBatch(String[] ids);
}
package com.platform.service.impl;
import com.platform.dao.TbCfLabelDao;
import com.platform.entity.TbCfLabelEntity;
import com.platform.service.TbCfLabelService;
import com.platform.utils.IdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 商品标签Service实现类
*
* @author lipengjun
* @date 2020-03-12 16:20:26
*/
@Service("tbCfLabelService")
public class TbCfLabelServiceImpl implements TbCfLabelService {
@Autowired
private TbCfLabelDao tbCfLabelDao;
@Override
public TbCfLabelEntity queryObject(String id) {
return tbCfLabelDao.queryObject(id);
}
@Override
public List<TbCfLabelEntity> queryList(Map<String, Object> map) {
return tbCfLabelDao.queryList(map);
}
@Override
public int queryTotal(Map<String, Object> map) {
return tbCfLabelDao.queryTotal(map);
}
@Override
public int save(TbCfLabelEntity tbCfLabel) {
tbCfLabel.setId(IdUtil.createIdbyUUID());
tbCfLabel.setCreateTime(new Date());
tbCfLabel.setUpdateTime(new Date());
return tbCfLabelDao.save(tbCfLabel);
}
@Override
public int update(TbCfLabelEntity tbCfLabel) {
tbCfLabel.setUpdateTime(new Date());
return tbCfLabelDao.update(tbCfLabel);
}
@Override
public int delete(String id) {
return tbCfLabelDao.delete(id);
}
@Override
public int deleteBatch(String[] ids) {
return tbCfLabelDao.deleteBatch(ids);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.platform.dao.TbCfLabelDao">
<resultMap type="com.platform.entity.TbCfLabelEntity" id="tbCfLabelMap">
<result property="id" column="id"/>
<result property="labelName" column="label_name"/>
<result property="enableFlag" column="enable_flag"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
</resultMap>
<select id="queryObject" resultType="com.platform.entity.TbCfLabelEntity">
select
`id`,
`label_name`,
`enable_flag`,
`create_time`,
`update_time`
from tb_cf_label
where id = #{id}
</select>
<select id="queryList" resultType="com.platform.entity.TbCfLabelEntity">
select
`id`,
`label_name`,
`enable_flag`,
`create_time`,
`update_time`
from tb_cf_label
WHERE 1=1
<if test="name != null and name.trim() != ''">
AND name LIKE concat('%',#{name},'%')
</if>
<choose>
<when test="sidx != null and sidx.trim() != ''">
order by ${sidx} ${order}
</when>
<otherwise>
order by id desc
</otherwise>
</choose>
<if test="offset != null and limit != null">
limit #{offset}, #{limit}
</if>
</select>
<select id="queryTotal" resultType="int">
select count(*) from tb_cf_label
WHERE 1=1
<if test="name != null and name.trim() != ''">
AND name LIKE concat('%',#{name},'%')
</if>
</select>
<insert id="save" parameterType="com.platform.entity.TbCfLabelEntity">
insert into tb_cf_label(
`id`,
`label_name`,
`enable_flag`,
`create_time`,
`update_time`)
values(
#{id},
#{labelName},
#{enableFlag},
#{createTime},
#{updateTime})
</insert>
<update id="update" parameterType="com.platform.entity.TbCfLabelEntity">
update tb_cf_label
<set>
<if test="labelName != null">`label_name` = #{labelName}, </if>
<if test="enableFlag != null">`enable_flag` = #{enableFlag}, </if>
<if test="createTime != null">`create_time` = #{createTime}, </if>
<if test="updateTime != null">`update_time` = #{updateTime}</if>
</set>
where id = #{id}
</update>
<delete id="delete">
delete from tb_cf_label where id = #{value}
</delete>
<delete id="deleteBatch">
delete from tb_cf_label where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>
\ No newline at end of file
<!DOCTYPE html>
<html>
<head>
<title>商品标签</title>
#parse("sys/header.html")
</head>
<body>
<div id="rrapp" v-cloak style="height: calc(100% - 15px);">
<div v-show="showList" style="height: 100%;">
<Row :gutter="16">
<div class="search-group">
<i-col span="4">
<i-input v-model="q.name" @on-enter="query" placeholder="名称"/>
</i-col>
<i-button @click="query">查询</i-button>
<i-button @click="reloadSearch">重置</i-button>
</div>
<div class="buttons-group">
#if($shiro.hasPermission("tbcflabel:save"))
<i-button type="info" @click="add"><i class="fa fa-plus"></i>&nbsp;新增</i-button>
#end
#if($shiro.hasPermission("tbcflabel:update"))
<i-button type="warning" @click="update"><i class="fa fa-pencil-square-o"></i>&nbsp;修改</i-button>
#end
#if($shiro.hasPermission("tbcflabel:delete"))
<i-button type="error" @click="del"><i class="fa fa-trash-o"></i>&nbsp;删除</i-button>
#end
</div>
</Row>
<table id="jqGrid"></table>
</div>
<Card v-show="!showList">
<p slot="title">{{title}}</p>
<i-form ref="formValidate" :model="tbCfLabel" :rules="ruleValidate" :label-width="80">
<Form-item label="标签名" prop="labelName">
<i-input v-model="tbCfLabel.labelName" placeholder="标签名"/>
</Form-item>
<Form-item label="是否启用" prop="enableFlag">
<i-input v-model="tbCfLabel.enableFlag" placeholder="是否启用 0:不启用 1:启用"/>
</Form-item>
<Form-item>
<i-button type="primary" @click="handleSubmit('formValidate')">提交</i-button>
<i-button type="warning" @click="reload" style="margin-left: 8px"/>返回</i-button>
<i-button type="ghost" @click="handleReset('formValidate')" style="margin-left: 8px">重置</i-button>
</Form-item>
</i-form>
</Card>
</div>
<script src="${rc.contextPath}/js/sys/tbcflabel.js?_${date.systemTime}"></script>
</body>
</html>
\ No newline at end of file
$(function () {
$("#jqGrid").Grid({
url: '../tbcflabel/list',
colModel: [
{label: 'id', name: 'id', index: 'id', key: true, hidden: true},
{label: '标签名', name: 'labelName', index: 'label_name', width: 80},
{label: '是否启用', name: 'enableFlag', index: 'enable_flag', width: 80, formatter: validFormat},
{label: '创建时间', name: 'createTime', index: 'create_time', width: 80}
]
});
});
let vm = new Vue({
el: '#rrapp',
data: {
showList: true,
title: null,
tbCfLabel: {},
ruleValidate: {
name: [
{required: true, message: '名称不能为空', trigger: 'blur'}
]
},
q: {
name: ''
}
},
methods: {
query: function () {
vm.reload();
},
add: function () {
vm.showList = false;
vm.title = "新增";
vm.tbCfLabel = {};
},
update: function (event) {
let id = getSelectedRow("#jqGrid");
if (id == null) {
return;
}
vm.showList = false;
vm.title = "修改";
vm.getInfo(id);
},
saveOrUpdate: function (event) {
let url = vm.tbCfLabel.id == null ? "../tbcflabel/save" : "../tbcflabel/update";
Ajax.request({
url: url,
params: JSON.stringify(vm.tbCfLabel),
type: "POST",
contentType: "application/json",
successCallback: function (r) {
alert('操作成功', function (index) {
vm.reload();
});
}
});
},
del: function (event) {
let ids = getSelectedRows("#jqGrid");
if (ids == null){
return;
}
confirm('确定要删除选中的记录?', function () {
Ajax.request({
url: "../tbcflabel/delete",
params: JSON.stringify(ids),
type: "POST",
contentType: "application/json",
successCallback: function () {
alert('操作成功', function (index) {
vm.reload();
});
}
});
});
},
getInfo: function(id){
Ajax.request({
url: "../tbcflabel/info/"+id,
async: true,
successCallback: function (r) {
vm.tbCfLabel = r.tbCfLabel;
}
});
},
reload: function (event) {
vm.showList = true;
let page = $("#jqGrid").jqGrid('getGridParam', 'page');
$("#jqGrid").jqGrid('setGridParam', {
postData: {'name': vm.q.name},
page: page
}).trigger("reloadGrid");
vm.handleReset('formValidate');
},
reloadSearch: function() {
vm.q = {
name: ''
};
vm.reload();
},
handleSubmit: function (name) {
handleSubmitValidate(this, name, function () {
vm.saveOrUpdate()
});
},
handleReset: function (name) {
handleResetForm(this, name);
}
}
});
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论