基础管理
This commit is contained in:
parent
af9c62b454
commit
4a9aea54c8
|
|
@ -0,0 +1,37 @@
|
|||
package com.bonus.base.config;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 返回异常枚举类
|
||||
* @Author ma_sh
|
||||
*/
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public enum ExceptionEnum {
|
||||
|
||||
PARAM_NULL(1001, "参数为空"),
|
||||
IOT_CODE_DUPLICATE(1002, "设备编号重复"),
|
||||
IOT_TO_DELETE(1003, "该iot设备绑定相关类型设备,无法删除"),
|
||||
SUCCESS(200, "操作成功"),
|
||||
SAVE_TO_DATABASE(500, "新增保存失败,请联系管理员!!!"),
|
||||
DELETE_TO_DATABASE(500, "删除失败,请联系管理员!!!"),
|
||||
BIND_TO_DATABASE(500, "绑定失败,请联系管理员!!!"),
|
||||
UN_BIND_TO_DATABASE(500, "解绑失败,请联系管理员!!!"),
|
||||
UPDATE_TO_DATABASE(500, "修改失败,请联系管理员!!!"),
|
||||
|
||||
RETURN_DATA_IS_EMPTY(501, "返回数据为空!!"),
|
||||
IOT_ENCODING_ERROR(502, "输入的IOT编码有误,请输入正确的编码!!!");
|
||||
private Integer code;
|
||||
|
||||
private String msg;
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
|
@ -2,15 +2,15 @@ package com.bonus.base.controller;
|
|||
|
||||
import com.bonus.base.domain.TbProDepart;
|
||||
import com.bonus.base.service.TbProDepartService;
|
||||
import com.bonus.common.core.utils.poi.ExcelUtil;
|
||||
import com.bonus.common.core.web.controller.BaseController;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import com.bonus.common.core.web.page.TableDataInfo;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -60,7 +60,7 @@ public class TbProDepartController extends BaseController {
|
|||
*/
|
||||
@PostMapping
|
||||
public AjaxResult add(@RequestBody TbProDepart tbProDepart) {
|
||||
return AjaxResult.success(tbProDepartService.insert(tbProDepart));
|
||||
return tbProDepartService.insert(tbProDepart);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -70,8 +70,8 @@ public class TbProDepartController extends BaseController {
|
|||
* @return 编辑结果
|
||||
*/
|
||||
@PutMapping
|
||||
public ResponseEntity<TbProDepart> edit(TbProDepart tbProDepart) {
|
||||
return ResponseEntity.ok(this.tbProDepartService.update(tbProDepart));
|
||||
public AjaxResult edit(@RequestBody TbProDepart tbProDepart) {
|
||||
return tbProDepartService.update(tbProDepart);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -80,9 +80,20 @@ public class TbProDepartController extends BaseController {
|
|||
* @param id 主键
|
||||
* @return 删除是否成功
|
||||
*/
|
||||
@DeleteMapping
|
||||
public ResponseEntity<Boolean> deleteById(Long id) {
|
||||
return ResponseEntity.ok(this.tbProDepartService.deleteById(id));
|
||||
@DeleteMapping("/{id}")
|
||||
public AjaxResult deleteById(@PathVariable("id") Long id) {
|
||||
return tbProDepartService.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 项目部管理导出
|
||||
*/
|
||||
@ApiOperation("项目部管理导出")
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, TbProDepart tbProDepart) {
|
||||
List<TbProDepart> list = tbProDepartService.queryByPage(tbProDepart);
|
||||
ExcelUtil<TbProDepart> util = new ExcelUtil<>(TbProDepart.class);
|
||||
util.exportExcel(response, list, "项目部管理数据");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
package com.bonus.base.mapper;
|
||||
|
||||
import com.bonus.base.domain.TbProDepart;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
|
@ -21,23 +19,6 @@ public interface TbProDepartMapper {
|
|||
*/
|
||||
TbProDepart queryById(Long id);
|
||||
|
||||
/**
|
||||
* 查询指定行数据
|
||||
*
|
||||
* @param tbProDepart 查询条件
|
||||
* @param pageable 分页对象
|
||||
* @return 对象列表
|
||||
*/
|
||||
List<TbProDepart> queryAllByLimit(TbProDepart tbProDepart, @Param("pageable") Pageable pageable);
|
||||
|
||||
/**
|
||||
* 统计总行数
|
||||
*
|
||||
* @param tbProDepart 查询条件
|
||||
* @return 总行数
|
||||
*/
|
||||
long count(TbProDepart tbProDepart);
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
*
|
||||
|
|
@ -46,23 +27,6 @@ public interface TbProDepartMapper {
|
|||
*/
|
||||
int insert(TbProDepart tbProDepart);
|
||||
|
||||
/**
|
||||
* 批量新增数据(MyBatis原生foreach方法)
|
||||
*
|
||||
* @param entities List<TbProDepart> 实例对象列表
|
||||
* @return 影响行数
|
||||
*/
|
||||
int insertBatch(@Param("entities") List<TbProDepart> entities);
|
||||
|
||||
/**
|
||||
* 批量新增或按主键更新数据(MyBatis原生foreach方法)
|
||||
*
|
||||
* @param entities List<TbProDepart> 实例对象列表
|
||||
* @return 影响行数
|
||||
* @throws org.springframework.jdbc.BadSqlGrammarException 入参是空List的时候会抛SQL语句错误的异常,请自行校验入参
|
||||
*/
|
||||
int insertOrUpdateBatch(@Param("entities") List<TbProDepart> entities);
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package com.bonus.base.service;
|
||||
|
||||
import com.bonus.base.domain.TbProDepart;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
||||
|
|
@ -36,7 +37,7 @@ public interface TbProDepartService {
|
|||
* @param tbProDepart 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
int insert(TbProDepart tbProDepart);
|
||||
AjaxResult insert(TbProDepart tbProDepart);
|
||||
|
||||
/**
|
||||
* 修改数据
|
||||
|
|
@ -44,7 +45,7 @@ public interface TbProDepartService {
|
|||
* @param tbProDepart 实例对象
|
||||
* @return 实例对象
|
||||
*/
|
||||
TbProDepart update(TbProDepart tbProDepart);
|
||||
AjaxResult update(TbProDepart tbProDepart);
|
||||
|
||||
/**
|
||||
* 通过主键删除数据
|
||||
|
|
@ -52,6 +53,6 @@ public interface TbProDepartService {
|
|||
* @param id 主键
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean deleteById(Long id);
|
||||
AjaxResult deleteById(Long id);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
package com.bonus.base.service.impl;
|
||||
|
||||
import com.bonus.base.config.ExceptionEnum;
|
||||
import com.bonus.base.domain.TbProDepart;
|
||||
import com.bonus.base.mapper.TbProDepartMapper;
|
||||
import com.bonus.base.service.TbProDepartService;
|
||||
import com.bonus.common.core.web.domain.AjaxResult;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
|
@ -48,8 +50,12 @@ public class TbProDepartServiceImpl implements TbProDepartService {
|
|||
* @return 实例对象
|
||||
*/
|
||||
@Override
|
||||
public int insert(TbProDepart tbProDepart) {
|
||||
return tbProDepartDao.insert(tbProDepart);
|
||||
public AjaxResult insert(TbProDepart tbProDepart) {
|
||||
int result = tbProDepartDao.insert(tbProDepart);
|
||||
if (result > 0) {
|
||||
return AjaxResult.success(ExceptionEnum.SUCCESS.getMsg(), result);
|
||||
}
|
||||
return AjaxResult.error(ExceptionEnum.SAVE_TO_DATABASE.getCode(), ExceptionEnum.SAVE_TO_DATABASE.getMsg());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -59,9 +65,13 @@ public class TbProDepartServiceImpl implements TbProDepartService {
|
|||
* @return 实例对象
|
||||
*/
|
||||
@Override
|
||||
public TbProDepart update(TbProDepart tbProDepart) {
|
||||
this.tbProDepartDao.update(tbProDepart);
|
||||
return this.queryById(tbProDepart.getId());
|
||||
public AjaxResult update(TbProDepart tbProDepart) {
|
||||
int result = tbProDepartDao.update(tbProDepart);
|
||||
if (result > 0) {
|
||||
return AjaxResult.success(ExceptionEnum.SUCCESS.getMsg(), result);
|
||||
} else {
|
||||
return AjaxResult.error(ExceptionEnum.UPDATE_TO_DATABASE.getCode(), ExceptionEnum.UPDATE_TO_DATABASE.getMsg());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -71,7 +81,12 @@ public class TbProDepartServiceImpl implements TbProDepartService {
|
|||
* @return 是否成功
|
||||
*/
|
||||
@Override
|
||||
public boolean deleteById(Long id) {
|
||||
return this.tbProDepartDao.deleteById(id) > 0;
|
||||
public AjaxResult deleteById(Long id) {
|
||||
int result = tbProDepartDao.deleteById(id);
|
||||
if (result > 0) {
|
||||
return AjaxResult.success(ExceptionEnum.SUCCESS.getMsg(), result);
|
||||
} else {
|
||||
return AjaxResult.error(ExceptionEnum.DELETE_TO_DATABASE.getCode(), ExceptionEnum.DELETE_TO_DATABASE.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,97 +1,10 @@
|
|||
<?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.bonus.base.mapper.TbProDepartMapper">
|
||||
|
||||
<!--查询指定行数据-->
|
||||
<select id="queryAllByLimit" resultMap="TbProDepartMap">
|
||||
select
|
||||
id, depart_name, depart_type, area_id, head_user, head_user_phone, remarks, create_time, create_user,
|
||||
update_time, update_user, del_flag
|
||||
from tb_pro_depart
|
||||
<where>
|
||||
<if test="id != null">
|
||||
and id = #{id}
|
||||
</if>
|
||||
<if test="departName != null and departName != ''">
|
||||
and depart_name = #{departName}
|
||||
</if>
|
||||
<if test="departType != null and departType != ''">
|
||||
and depart_type = #{departType}
|
||||
</if>
|
||||
<if test="areaId != null">
|
||||
and area_id = #{areaId}
|
||||
</if>
|
||||
<if test="headUser != null and headUser != ''">
|
||||
and head_user = #{headUser}
|
||||
</if>
|
||||
<if test="headUserPhone != null and headUserPhone != ''">
|
||||
and head_user_phone = #{headUserPhone}
|
||||
</if>
|
||||
<if test="remarks != null and remarks != ''">
|
||||
and remarks = #{remarks}
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
and create_time = #{createTime}
|
||||
</if>
|
||||
<if test="createUser != null">
|
||||
and create_user = #{createUser}
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
and update_time = #{updateTime}
|
||||
</if>
|
||||
<if test="updateUser != null">
|
||||
and update_user = #{updateUser}
|
||||
</if>
|
||||
<if test="delFlag != null">
|
||||
and del_flag = #{delFlag}
|
||||
</if>
|
||||
</where>
|
||||
limit #{pageable.offset}, #{pageable.pageSize}
|
||||
</select>
|
||||
|
||||
<!--统计总行数-->
|
||||
<select id="count" resultType="java.lang.Long">
|
||||
select count(1)
|
||||
from tb_pro_depart
|
||||
<where>
|
||||
<if test="id != null">
|
||||
and id = #{id}
|
||||
</if>
|
||||
<if test="departName != null and departName != ''">
|
||||
and depart_name = #{departName}
|
||||
</if>
|
||||
<if test="departType != null and departType != ''">
|
||||
and depart_type = #{departType}
|
||||
</if>
|
||||
<if test="areaId != null">
|
||||
and area_id = #{areaId}
|
||||
</if>
|
||||
<if test="headUser != null and headUser != ''">
|
||||
and head_user = #{headUser}
|
||||
</if>
|
||||
<if test="headUserPhone != null and headUserPhone != ''">
|
||||
and head_user_phone = #{headUserPhone}
|
||||
</if>
|
||||
<if test="remarks != null and remarks != ''">
|
||||
and remarks = #{remarks}
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
and create_time = #{createTime}
|
||||
</if>
|
||||
<if test="createUser != null">
|
||||
and create_user = #{createUser}
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
and update_time = #{updateTime}
|
||||
</if>
|
||||
<if test="updateUser != null">
|
||||
and update_user = #{updateUser}
|
||||
</if>
|
||||
<if test="delFlag != null">
|
||||
and del_flag = #{delFlag}
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<delete id="deleteById">
|
||||
update tb_pro_depart set del_flag = 1
|
||||
where id = #{id}
|
||||
</delete>
|
||||
|
||||
<select id="queryByPage" resultType="com.bonus.base.domain.TbProDepart">
|
||||
select
|
||||
|
|
@ -171,30 +84,6 @@
|
|||
</trim>
|
||||
</insert>
|
||||
|
||||
|
||||
<insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
|
||||
insert into tb_pro_depart(depart_name, depart_type, area_id, head_user, head_user_phone, remarks, create_time,
|
||||
create_user, update_time, update_user, del_flag)
|
||||
values
|
||||
<foreach collection="entities" item="entity" separator=",">
|
||||
(#{entity.departName}, #{entity.departType}, #{entity.areaId}, #{entity.headUser}, #{entity.headUserPhone},
|
||||
#{entity.remarks}, #{entity.createTime}, #{entity.createUser}, #{entity.updateTime}, #{entity.updateUser},
|
||||
#{entity.delFlag})
|
||||
</foreach>
|
||||
on duplicate key update
|
||||
depart_name = values(depart_name),
|
||||
depart_type = values(depart_type),
|
||||
area_id = values(area_id),
|
||||
head_user = values(head_user),
|
||||
head_user_phone = values(head_user_phone),
|
||||
remarks = values(remarks),
|
||||
create_time = values(create_time),
|
||||
create_user = values(create_user),
|
||||
update_time = values(update_time),
|
||||
update_user = values(update_user),
|
||||
del_flag = values(del_flag)
|
||||
</insert>
|
||||
|
||||
<!--通过主键修改数据-->
|
||||
<update id="update">
|
||||
update tb_pro_depart
|
||||
|
|
@ -217,15 +106,7 @@
|
|||
<if test="remarks != null and remarks != ''">
|
||||
remarks = #{remarks},
|
||||
</if>
|
||||
<if test="createTime != null">
|
||||
create_time = #{createTime},
|
||||
</if>
|
||||
<if test="createUser != null">
|
||||
create_user = #{createUser},
|
||||
</if>
|
||||
<if test="updateTime != null">
|
||||
update_time = #{updateTime},
|
||||
</if>
|
||||
update_time = NOW(),
|
||||
<if test="updateUser != null">
|
||||
update_user = #{updateUser},
|
||||
</if>
|
||||
|
|
@ -236,12 +117,5 @@
|
|||
where id = #{id}
|
||||
</update>
|
||||
|
||||
<!--通过主键删除-->
|
||||
<delete id="deleteById">
|
||||
delete
|
||||
from tb_pro_depart
|
||||
where id = #{id}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue