Commit ebb76af1 by zhanghj

V1.0.0--提交字典管理相关接口

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@16326 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent 1063038f
...@@ -35,7 +35,9 @@ import com.glsx.manager.shiro.UserRealm; ...@@ -35,7 +35,9 @@ import com.glsx.manager.shiro.UserRealm;
public class ShiroConfig { public class ShiroConfig {
public static final String PREMISSION_STRING = "perms[\"{0}\"]"; public static final String PREMISSION_STRING = "perms[\"{0}\"]";
// Session超时时间,单位为毫秒(默认30分钟) /**
* Session超时时间,单位为毫秒(默认30分钟)
*/
@Value("${shiro.session.expireTime}") @Value("${shiro.session.expireTime}")
private int expireTime; private int expireTime;
......
package com.glsx.manager.controller;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.validation.groups.Default;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.glsx.common.constants.ResultObject;
import com.glsx.common.utils.Page;
import com.glsx.manager.constants.ResultCodeEnum;
import com.glsx.manager.pojo.GroupA;
import com.glsx.manager.pojo.dictionary.DictionaryType;
import com.glsx.manager.service.DictionaryTypeService;
/**
*
* @Title DictionaryTypeController.java
* @Package com.glsx.manager.controller
* @Description TODO 字典管理控制层
* @author zhanghj
* @date 2019年1月3日 下午6:01:02
* @version 1.0.0
*/
@RestController
@RequestMapping(value="/dictionaryType")
public class DictionaryTypeController extends BaseController{
@Autowired
private DictionaryTypeService dictionaryTypeService;
/**
*
* @author zhanghj
* @Title: save
* @Description: TODO 保存
* @param dictionaryType
* @param bindingResult
* @return
* ResultObject
*
*/
@RequestMapping(value="/save", method=RequestMethod.POST)
public ResultObject save(@Validated(value={Default.class}) DictionaryType dictionaryType, BindingResult bindingResult){
if (bindingResult.hasErrors()) {
Map<String, String> errorMap = getErrors(bindingResult);
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg(), errorMap);
}
//dictionaryType.setCreateBy();
dictionaryType.setCreateTime(new Date());
int num = dictionaryTypeService.save(dictionaryType);
if (num > 0) {
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg());
} else {
return new ResultObject(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getMsg());
}
}
/**
*
* @author zhanghj
* @Title: update
* @Description: TODO 更新
* @param dictionaryType
* @param bindingResult
* @return
* ResultObject
*
*/
@RequestMapping(value="/update", method=RequestMethod.POST)
public ResultObject update(@Validated(value={GroupA.class}) DictionaryType dictionaryType, BindingResult bindingResult){
if (bindingResult.hasErrors()) {
Map<String, String> errorMap = getErrors(bindingResult);
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg(), errorMap);
}
//dictionaryType.setUpdateBy();
dictionaryType.setUpdateTime(new Date());
int num = dictionaryTypeService.update(dictionaryType);
if (num > 0) {
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg());
} else {
return new ResultObject(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getMsg());
}
}
/**
*
* @author zhanghj
* @Title: delete
* @Description: TODO 通过id删除
* @param id
* @return
* ResultObject
*
*/
@RequestMapping(value="/delete", method=RequestMethod.POST)
public ResultObject delete(Integer id) {
if (StringUtils.isEmpty(id)) {
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg());
}
int num = dictionaryTypeService.delete(id);
if (num > 0) {
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg());
} else {
return new ResultObject(ResultCodeEnum.FAIL.getCode(), ResultCodeEnum.FAIL.getMsg());
}
}
/**
*
* @author zhanghj
* @Title: get
* @Description: TODO 通过id获取字典类型
* @param id
* @return
* ResultObject
*
*/
@RequestMapping(value="/get", method=RequestMethod.GET)
public ResultObject get(Integer id) {
if (StringUtils.isEmpty(id)) {
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg());
}
DictionaryType dictionaryType = dictionaryTypeService.get(id);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), dictionaryType);
}
@RequestMapping(value="/list", method=RequestMethod.GET)
public ResultObject list(@RequestParam(defaultValue = "1") int pageIndex, @RequestParam(defaultValue = "10") int pageSize, DictionaryType dictionaryType) {
Map<String, Object> result = new HashMap<String, Object>();
Page page = new Page(pageIndex, pageSize);
List<DictionaryType> list = dictionaryTypeService.list(dictionaryType, page);
com.github.pagehelper.Page<DictionaryType> pages = (com.github.pagehelper.Page<DictionaryType>) list;
page.setTotalCount((int)pages.getTotal());
result.put("page", page);
result.put("items", list);
return new ResultObject(ResultCodeEnum.SUCCESS.getCode(), ResultCodeEnum.SUCCESS.getMsg(), result);
}
}
...@@ -4,10 +4,11 @@ import java.util.HashMap; ...@@ -4,10 +4,11 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.validation.Valid; import javax.validation.groups.Default;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult; import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
...@@ -28,7 +29,7 @@ public class TestController extends BaseController{ ...@@ -28,7 +29,7 @@ public class TestController extends BaseController{
private TestService testService; private TestService testService;
@RequestMapping(value="/get", method={RequestMethod.GET, RequestMethod.POST}) @RequestMapping(value="/get", method={RequestMethod.GET, RequestMethod.POST})
public ResultObject index(@Valid Test test, BindingResult bindingResult){ public ResultObject index(@Validated(value={Default.class}) Test test, BindingResult bindingResult){
if (bindingResult.hasErrors()) { if (bindingResult.hasErrors()) {
Map<String, String> errorMap = getErrors(bindingResult); Map<String, String> errorMap = getErrors(bindingResult);
return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg(), errorMap); return new ResultObject(ResultCodeEnum.PARAM_ERROR.getCode(), ResultCodeEnum.PARAM_ERROR.getMsg(), errorMap);
......
package com.glsx.manager.mapper;
import java.util.List;
import com.glsx.manager.pojo.dictionary.DictionaryType;
/**
*
* @Title DictionaryTypeMapper.java
* @Package com.glsx.manager.mapper
* @Description TODO 字典管理mapper
* @author zhanghj
* @date 2019年1月3日 下午8:27:29
* @version 1.0.0
*/
public interface DictionaryTypeMapper {
/**
*
* @author zhanghj
* @Title: save
* @Description: TODO 保存字典类型
* @param dictionaryType
* @return
* int
*
*/
int save(DictionaryType dictionaryType);
/**
*
* @author zhanghj
* @Title: update
* @Description: TODO 更新字典类型
* @param dictionaryType
* @return
* int
*
*/
int update(DictionaryType dictionaryType);
/**
*
* @author zhanghj
* @Title: delete
* @Description: TODO 通过id删除字典类型
* @param id
* @return
* int
*
*/
int delete(Integer id);
/**
*
* @author zhanghj
* @Title: get
* @Description: TODO 通过id获取字典类型
* @param id
* @return
* DictionaryType
*
*/
DictionaryType get(Integer id);
/**
*
* @author zhanghj
* @Title: list
* @Description: TODO 查询字典类型列表
* @param dictionaryType
* @return
* List<DictionaryType>
*
*/
List<DictionaryType> list(DictionaryType dictionaryType);
}
...@@ -10,10 +10,6 @@ import java.util.Date; ...@@ -10,10 +10,6 @@ import java.util.Date;
public class BaseModel { public class BaseModel {
/** /**
* 主键id
*/
private Integer id;
/**
* 创建人 * 创建人
*/ */
private String createBy; private String createBy;
...@@ -34,14 +30,6 @@ public class BaseModel { ...@@ -34,14 +30,6 @@ public class BaseModel {
*/ */
private String remark; private String remark;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getCreateBy() { public String getCreateBy() {
return createBy; return createBy;
} }
......
package com.glsx.manager.pojo;
/**
*
* @Title GroupA.java
* @Package com.glsx.manager.pojo
* @Description TODO Hibernate-validator的分组
* @author zhanghj
* @date 2019年1月3日 下午7:46:57
* @version 1.0.0
*/
public interface GroupA {
}
package com.glsx.manager.pojo; package com.glsx.manager.pojo;
import javax.validation.constraints.NotNull; import javax.validation.constraints.NotNull;
import javax.validation.groups.Default;
/** /**
* *
...@@ -35,7 +36,7 @@ import javax.validation.constraints.NotNull; ...@@ -35,7 +36,7 @@ import javax.validation.constraints.NotNull;
*/ */
public class Test { public class Test {
@NotNull(message="{param.not.null}") @NotNull(message="{param.not.null}", groups={Default.class, GroupA.class})
private Integer id; private Integer id;
private String username; private String username;
......
package com.glsx.manager.pojo.dictionary;
public class DictionaryData {
/**
* 主键id
*/
private Integer id;
/**
* 字典类型
*/
private String dictType;
/**
* 字典标签
*/
private String dataValue;
/**
* 字典键值
*/
private String dataKey;
/**
* 状态:1:启用,2:停用,3:删除
*/
private Byte dataStatus;
/**
* 顺序
*/
private Integer sort;
public String getDictType() {
return dictType;
}
public void setDictType(String dictType) {
this.dictType = dictType == null ? null : dictType.trim();
}
public String getDataValue() {
return dataValue;
}
public void setDataValue(String dataValue) {
this.dataValue = dataValue == null ? null : dataValue.trim();
}
public String getDataKey() {
return dataKey;
}
public void setDataKey(String dataKey) {
this.dataKey = dataKey == null ? null : dataKey.trim();
}
public Byte getDataStatus() {
return dataStatus;
}
public void setDataStatus(Byte dataStatus) {
this.dataStatus = dataStatus;
}
public Integer getSort() {
return sort;
}
public void setSort(Integer sort) {
this.sort = sort;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
\ No newline at end of file \ No newline at end of file
package com.glsx.manager.pojo.dictionary;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.groups.Default;
import com.glsx.manager.pojo.BaseModel;
import com.glsx.manager.pojo.GroupA;
/**
*
* @Title DictionaryType.java
* @Package com.glsx.manager.pojo.dictionary
* @Description TODO
* @author zhanghj
* @date 2019年1月3日 下午4:24:51
* @version 1.0.0
*/
public class DictionaryType extends BaseModel{
/**
* 主键id
*/
@NotNull(message="{param.not.null}", groups={GroupA.class})
private Integer id;
/**
* 字典名称
*/
@NotBlank(message="{param.not.null}", groups={Default.class, GroupA.class})
private String name;
/**
* 字典类型
*/
@NotBlank(message="{param.not.null}", groups={Default.class, GroupA.class})
private String dictType;
/**
* 状态:1:启用,2:停用,3:注销
*/
@NotNull(message="{param.not.null}", groups={Default.class, GroupA.class})
private Integer dictStatus;
/**
* 查询:开始时间
*/
private String beginDate;
/**
* 查询:结束时间
*/
private String endDate;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name == null ? null : name.trim();
}
public String getDictType() {
return dictType;
}
public void setDictType(String dictType) {
this.dictType = dictType == null ? null : dictType.trim();
}
public Integer getDictStatus() {
return dictStatus;
}
public void setDictStatus(Integer dictStatus) {
this.dictStatus = dictStatus;
}
public String getBeginDate() {
return beginDate;
}
public void setBeginDate(String beginDate) {
this.beginDate = beginDate;
}
public String getEndDate() {
return endDate;
}
public void setEndDate(String endDate) {
this.endDate = endDate;
}
}
\ No newline at end of file \ No newline at end of file
...@@ -7,6 +7,11 @@ import java.util.List; ...@@ -7,6 +7,11 @@ import java.util.List;
public class SysUser extends BaseModel { public class SysUser extends BaseModel {
/**
* 主键id
*/
private Integer id;
private String username; private String username;
private String name; private String name;
...@@ -136,5 +141,13 @@ public class SysUser extends BaseModel { ...@@ -136,5 +141,13 @@ public class SysUser extends BaseModel {
public void setOrgsId(List<Integer> orgsId) { public void setOrgsId(List<Integer> orgsId) {
this.orgsId = orgsId; this.orgsId = orgsId;
} }
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
} }
package com.glsx.manager.service;
import java.util.List;
import com.glsx.common.utils.Page;
import com.glsx.manager.pojo.dictionary.DictionaryType;
/**
*
* @Title DictionaryTypeService.java
* @Package com.glsx.manager.service
* @Description TODO 字典管理service
* @author zhanghj
* @date 2019年1月3日 下午7:57:57
* @version 1.0.0
*/
public interface DictionaryTypeService {
/**
*
* @author zhanghj
* @Title: save
* @Description: TODO 保存字典类型
* @param dictionaryType
* @param a
* @return
* int
*
*/
int save(DictionaryType dictionaryType);
/**
*
* @author zhanghj
* @Title: update
* @Description: TODO 更新字典类型
* @param dictionaryType
* @return
* int
*
*/
int update(DictionaryType dictionaryType);
/**
*
* @author zhanghj
* @Title: delete
* @Description: TODO 通过id删除字典类型
* @param id
* @return
* int
*
*/
int delete(Integer id);
/**
*
* @author zhanghj
* @Title: get 通过id获取字典类型
* @Description: TODO
* @param id
* @return
* DictionaryType
*
*/
DictionaryType get(Integer id);
/**
*
* @author zhanghj
* @Title: list
* @Description: TODO 分页获取列表
* @param dictionaryType
* @param page
* @return
* List<DictionaryType>
*
*/
List<DictionaryType> list(DictionaryType dictionaryType, Page page);
}
package com.glsx.manager.service.impl;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.page.PageMethod;
import com.glsx.common.utils.Page;
import com.glsx.manager.mapper.DictionaryTypeMapper;
import com.glsx.manager.pojo.dictionary.DictionaryType;
import com.glsx.manager.service.DictionaryTypeService;
/**
*
* @Title DictionaryTypeServiceImpl.java
* @Package com.glsx.manager.service.impl
* @Description TODO
* @author zhanghj
* @date 2019年1月3日 下午7:58:39
* @version 1.0.0
*/
@Service
public class DictionaryTypeServiceImpl implements DictionaryTypeService {
@Autowired
private DictionaryTypeMapper dictionaryTypeDao;
@Override
public int save(DictionaryType dictionaryType) {
// TODO Auto-generated method stub
return dictionaryTypeDao.save(dictionaryType);
}
@Override
public int update(DictionaryType dictionaryType) {
// TODO Auto-generated method stub
return dictionaryTypeDao.update(dictionaryType);
}
@Override
public int delete(Integer id) {
// TODO Auto-generated method stub
return dictionaryTypeDao.delete(id);
}
@Override
public DictionaryType get(Integer id) {
// TODO Auto-generated method stub
return dictionaryTypeDao.get(id);
}
@Override
public List<DictionaryType> list(DictionaryType dictionaryType, Page page) {
// TODO Auto-generated method stub
PageMethod.startPage(page.getPageIndex(), page.getPageSize(), true);
return dictionaryTypeDao.list(dictionaryType);
}
}
<?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.glsx.manager.mapper.DictionaryTypeMapper">
<resultMap id="baseResultMap" type="com.glsx.manager.pojo.dictionary.DictionaryType">
<id column="id" jdbcType="INTEGER" property="id" />
<result column="name" jdbcType="VARCHAR" property="name" />
<result column="dict_type" jdbcType="VARCHAR" property="dictType" />
<result column="dict_status" jdbcType="TINYINT" property="dictStatus" />
<result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="create_by" jdbcType="VARCHAR" property="createBy" />
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
<result column="update_by" jdbcType="VARCHAR" property="updateBy" />
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
</resultMap>
<sql id="base_Column">
id, name, dict_type, dict_status, remark, create_by, create_time, update_by, update_time
</sql>
<select id="get" parameterType="java.lang.Integer" resultMap="baseResultMap">
select
<include refid="base_Column" />
from sys_dict_type
where id = #{id,jdbcType=INTEGER}
</select>
<select id="list" parameterType="com.glsx.manager.pojo.dictionary.DictionaryType" resultMap="baseResultMap">
select
<include refid="base_Column" />
from sys_dict_type
<where>
<if test="name != null">
and name = #{name}
</if>
<if test="dictType != null">
and dict_type = #{dictType}
</if>
<if test="dictStatus != null">
and dict_status = #{dictStatus}
</if>
<if test="beginDate != null">
and DATE_FORMAT(create_time, '%Y-%m-%d') &gt;= #{beginDate}
</if>
<if test="endDate != null">
and DATE_FORMAT(create_time, '%Y-%m-%d') &lt;= #{endDate}
</if>
</where>
</select>
<insert id="save" parameterType="com.glsx.manager.pojo.dictionary.DictionaryType" useGeneratedKeys="true">
insert into sys_dict_type
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="name != null">
name,
</if>
<if test="dictType != null">
dict_type,
</if>
<if test="dictStatus != null">
dict_status,
</if>
<if test="remark != null">
remark,
</if>
<if test="createBy != null">
create_by,
</if>
<if test="createTime != null">
create_time,
</if>
<if test="updateBy != null">
update_by,
</if>
<if test="updateTime != null">
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="name != null">
#{name,jdbcType=VARCHAR},
</if>
<if test="dictType != null">
#{dictType,jdbcType=VARCHAR},
</if>
<if test="dictStatus != null">
#{dictStatus,jdbcType=TINYINT},
</if>
<if test="remark != null">
#{remark,jdbcType=VARCHAR},
</if>
<if test="createBy != null">
#{createBy,jdbcType=VARCHAR},
</if>
<if test="createTime != null">
#{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateBy != null">
#{updateBy,jdbcType=VARCHAR},
</if>
<if test="updateTime != null">
#{updateTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
<update id="update" parameterType="com.glsx.manager.pojo.dictionary.DictionaryType">
update sys_dict_type
set name = #{name,jdbcType=VARCHAR},
dict_type = #{dictType,jdbcType=VARCHAR},
dict_status = #{dictStatus,jdbcType=TINYINT},
remark = #{remark,jdbcType=VARCHAR},
update_by = #{updateBy,jdbcType=VARCHAR},
update_time = #{updateTime,jdbcType=TIMESTAMP}
where id = #{id,jdbcType=INTEGER}
</update>
<delete id="delete" parameterType="java.lang.Integer">
delete from sys_dict_type
where id = #{id,jdbcType=INTEGER}
</delete>
</mapper>
\ No newline at end of file \ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!