新增收货地址管理

This commit is contained in:
kino 2021-01-16 10:35:48 +08:00
parent da9422382a
commit dc35283341
11 changed files with 680 additions and 5 deletions

View File

@ -0,0 +1,128 @@
package com.ruoyi.winery.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.util.List;
import java.util.Arrays;
import com.ruoyi.common.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
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.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.winery.domain.AppUserAddress;
import com.ruoyi.winery.service.IAppUserAddressService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
* 用户收货地址Controller
*
* @author ruoyi
* @date 2021-01-16
*/
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/user/address" )
public class AppUserAddressController extends BaseController {
private final IAppUserAddressService iAppUserAddressService;
/**
* 查询用户收货地址列表
*/
@PreAuthorize("@ss.hasPermi('user:address:list')")
@GetMapping("/list")
public TableDataInfo list(AppUserAddress appUserAddress)
{
startPage();
LambdaQueryWrapper<AppUserAddress> lqw = Wrappers.lambdaQuery(appUserAddress);
if (appUserAddress.getDeptId() != null){
lqw.eq(AppUserAddress::getDeptId ,appUserAddress.getDeptId());
}
if (StringUtils.isNotBlank(appUserAddress.getUserId())){
lqw.eq(AppUserAddress::getUserId ,appUserAddress.getUserId());
}
if (appUserAddress.getIsDefault() != null){
lqw.eq(AppUserAddress::getIsDefault ,appUserAddress.getIsDefault());
}
if (StringUtils.isNotBlank(appUserAddress.getMobile())){
lqw.eq(AppUserAddress::getMobile ,appUserAddress.getMobile());
}
if (StringUtils.isNotBlank(appUserAddress.getName())){
lqw.like(AppUserAddress::getName ,appUserAddress.getName());
}
if (StringUtils.isNotBlank(appUserAddress.getAddress())){
lqw.eq(AppUserAddress::getAddress ,appUserAddress.getAddress());
}
if (StringUtils.isNotBlank(appUserAddress.getRegion())){
lqw.eq(AppUserAddress::getRegion ,appUserAddress.getRegion());
}
List<AppUserAddress> list = iAppUserAddressService.list(lqw);
return getDataTable(list);
}
/**
* 导出用户收货地址列表
*/
@PreAuthorize("@ss.hasPermi('user:address:export')" )
@Log(title = "用户收货地址" , businessType = BusinessType.EXPORT)
@GetMapping("/export" )
public AjaxResult export(AppUserAddress appUserAddress) {
LambdaQueryWrapper<AppUserAddress> lqw = new LambdaQueryWrapper<AppUserAddress>(appUserAddress);
List<AppUserAddress> list = iAppUserAddressService.list(lqw);
ExcelUtil<AppUserAddress> util = new ExcelUtil<AppUserAddress>(AppUserAddress. class);
return util.exportExcel(list, "address" );
}
/**
* 获取用户收货地址详细信息
*/
@PreAuthorize("@ss.hasPermi('user:address:query')" )
@GetMapping(value = "/{id}" )
public AjaxResult getInfo(@PathVariable("id" ) String id) {
return AjaxResult.success(iAppUserAddressService.getById(id));
}
/**
* 新增用户收货地址
*/
@PreAuthorize("@ss.hasPermi('user:address:add')" )
@Log(title = "用户收货地址" , businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody AppUserAddress appUserAddress) {
return toAjax(iAppUserAddressService.save(appUserAddress) ? 1 : 0);
}
/**
* 修改用户收货地址
*/
@PreAuthorize("@ss.hasPermi('user:address:edit')" )
@Log(title = "用户收货地址" , businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody AppUserAddress appUserAddress) {
return toAjax(iAppUserAddressService.updateById(appUserAddress) ? 1 : 0);
}
/**
* 删除用户收货地址
*/
@PreAuthorize("@ss.hasPermi('user:address:remove')" )
@Log(title = "用户收货地址" , businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}" )
public AjaxResult remove(@PathVariable String[] ids) {
return toAjax(iAppUserAddressService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
}
}

View File

@ -0,0 +1,75 @@
package com.ruoyi.winery.domain;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.experimental.Accessors;
import com.ruoyi.common.annotation.Excel;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.IdType;
import java.io.Serializable;
import java.util.Date;
import java.math.BigDecimal;
import com.ruoyi.common.core.domain.BaseEntity;
/**
* 用户收货地址对象 app_user_address
*
* @author ruoyi
* @date 2021-01-16
*/
@Data
@ToString
@EqualsAndHashCode
@NoArgsConstructor
@Accessors(chain = true)
@TableName("app_user_address")
public class AppUserAddress implements Serializable {
private static final long serialVersionUID=1L;
/** ID */
@TableId(value = "id")
private String id;
/** 部门ID */
@Excel(name = "部门ID")
private Long deptId;
/** 用户ID */
@Excel(name = "用户ID")
private String userId;
/** 是否默认 */
@Excel(name = "是否默认")
private Integer isDefault;
/** 手机号 */
@Excel(name = "手机号")
private String mobile;
/** 收货人 */
@Excel(name = "收货人")
private String name;
/** 省市县地址 */
@Excel(name = "省市县地址")
private String address;
/** 省市县地址 */
@Excel(name = "省市县地址")
private String region;
/** 删除标志 */
private String delFlag;
/** 创建时间 */
private Date createTime;
/** 更新时间 */
private Date updateTime;
}

View File

@ -0,0 +1,14 @@
package com.ruoyi.winery.mapper;
import com.ruoyi.winery.domain.AppUserAddress;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
/**
* 用户收货地址Mapper接口
*
* @author ruoyi
* @date 2021-01-16
*/
public interface AppUserAddressMapper extends BaseMapper<AppUserAddress> {
}

View File

@ -0,0 +1,14 @@
package com.ruoyi.winery.service;
import com.ruoyi.winery.domain.AppUserAddress;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* 用户收货地址Service接口
*
* @author ruoyi
* @date 2021-01-16
*/
public interface IAppUserAddressService extends IService<AppUserAddress> {
}

View File

@ -0,0 +1,18 @@
package com.ruoyi.winery.service.impl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.winery.mapper.AppUserAddressMapper;
import com.ruoyi.winery.domain.AppUserAddress;
import com.ruoyi.winery.service.IAppUserAddressService;
/**
* 用户收货地址Service业务层处理
*
* @author ruoyi
* @date 2021-01-16
*/
@Service
public class AppUserAddressServiceImpl extends ServiceImpl<AppUserAddressMapper, AppUserAddress> implements IAppUserAddressService {
}

View File

@ -0,0 +1,22 @@
<?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.ruoyi.winery.mapper.AppUserAddressMapper">
<resultMap type="AppUserAddress" id="AppUserAddressResult">
<result property="id" column="id" />
<result property="deptId" column="dept_id" />
<result property="userId" column="user_id" />
<result property="isDefault" column="is_default" />
<result property="mobile" column="mobile" />
<result property="name" column="name" />
<result property="address" column="address" />
<result property="region" column="region" />
<result property="delFlag" column="del_flag" />
<result property="createTime" column="create_time" />
<result property="updateTime" column="update_time" />
</resultMap>
</mapper>

View File

@ -6,9 +6,9 @@ spring:
druid:
# 主库数据源
master:
url: jdbc:mysql://175.24.17.162:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
url: jdbc:mysql://bj-cdb-ihe0k1z8.sql.tencentcdb.com:61298/wine?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
username: root
password: 26616494
password: Hopesoft!@#123
# 从库数据源
slave:
# 从数据源开关/默认关闭

View File

@ -6,9 +6,9 @@ spring:
druid:
# 主库数据源
master:
url: jdbc:mysql://175.24.17.162:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
url: jdbc:mysql://172.21.0.3:3306/wine?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8&autoReconnect=true
username: root
password: 26616494
password: Hopesoft!@#123
# 从库数据源
slave:
# 从数据源开关/默认关闭

View File

@ -13,7 +13,7 @@ ruoyi:
# 获取ip地址开关
addressEnabled: false
# 验证码类型 math 数组计算 char 字符验证
captchaType: math
captchaType: char
# 开发环境配置
server:

View File

@ -0,0 +1,53 @@
import request from '@/utils/request'
// 查询用户收货地址列表
export function listAddress(query) {
return request({
url: '/user/address/list',
method: 'get',
params: query
})
}
// 查询用户收货地址详细
export function getAddress(id) {
return request({
url: '/user/address/' + id,
method: 'get'
})
}
// 新增用户收货地址
export function addAddress(data) {
return request({
url: '/user/address',
method: 'post',
data: data
})
}
// 修改用户收货地址
export function updateAddress(data) {
return request({
url: '/user/address',
method: 'put',
data: data
})
}
// 删除用户收货地址
export function delAddress(id) {
return request({
url: '/user/address/' + id,
method: 'delete'
})
}
// 导出用户收货地址
export function exportAddress(query) {
return request({
url: '/user/address/export',
method: 'get',
params: query
})
}

View File

@ -0,0 +1,351 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="部门ID" prop="deptId">
<el-input
v-model="queryParams.deptId"
placeholder="请输入部门ID"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="用户ID" prop="userId">
<el-input
v-model="queryParams.userId"
placeholder="请输入用户ID"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="是否默认" prop="isDefault">
<el-input
v-model="queryParams.isDefault"
placeholder="请输入是否默认"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="手机号" prop="mobile">
<el-input
v-model="queryParams.mobile"
placeholder="请输入手机号"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="收货人" prop="name">
<el-input
v-model="queryParams.name"
placeholder="请输入收货人"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="省市县地址" prop="address">
<el-input
v-model="queryParams.address"
placeholder="请输入省市县地址"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="省市县地址" prop="region">
<el-input
v-model="queryParams.region"
placeholder="请输入省市县地址"
clearable
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
type="primary"
icon="el-icon-plus"
size="mini"
@click="handleAdd"
v-hasPermi="['user:address:add']"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['user:address:edit']"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['user:address:remove']"
>删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
icon="el-icon-download"
size="mini"
@click="handleExport"
v-hasPermi="['user:address:export']"
>导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="addressList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column label="ID" align="center" prop="id" v-if="false"/>
<el-table-column label="部门ID" align="center" prop="deptId" />
<el-table-column label="用户ID" align="center" prop="userId" />
<el-table-column label="是否默认" align="center" prop="isDefault" />
<el-table-column label="手机号" align="center" prop="mobile" />
<el-table-column label="收货人" align="center" prop="name" />
<el-table-column label="省市县地址" align="center" prop="address" />
<el-table-column label="省市县地址" align="center" prop="region" />
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope">
<el-button
size="mini"
type="text"
icon="el-icon-edit"
@click="handleUpdate(scope.row)"
v-hasPermi="['user:address:edit']"
>修改</el-button>
<el-button
size="mini"
type="text"
icon="el-icon-delete"
@click="handleDelete(scope.row)"
v-hasPermi="['user:address:remove']"
>删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 添加或修改用户收货地址对话框 -->
<el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
<el-form-item label="部门ID" prop="deptId">
<el-input v-model="form.deptId" placeholder="请输入部门ID" />
</el-form-item>
<el-form-item label="用户ID" prop="userId">
<el-input v-model="form.userId" placeholder="请输入用户ID" />
</el-form-item>
<el-form-item label="是否默认" prop="isDefault">
<el-input v-model="form.isDefault" placeholder="请输入是否默认" />
</el-form-item>
<el-form-item label="手机号" prop="mobile">
<el-input v-model="form.mobile" placeholder="请输入手机号" />
</el-form-item>
<el-form-item label="收货人" prop="name">
<el-input v-model="form.name" placeholder="请输入收货人" />
</el-form-item>
<el-form-item label="省市县地址" prop="address">
<el-input v-model="form.address" placeholder="请输入省市县地址" />
</el-form-item>
<el-form-item label="省市县地址" prop="region">
<el-input v-model="form.region" placeholder="请输入省市县地址" />
</el-form-item>
<el-form-item label="删除标志" prop="delFlag">
<el-input v-model="form.delFlag" placeholder="请输入删除标志" />
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div>
</template>
<script>
import { listAddress, getAddress, delAddress, addAddress, updateAddress, exportAddress } from "@/api/user/address";
export default {
name: "Address",
components: {
},
data() {
return {
//
loading: true,
//
ids: [],
//
single: true,
//
multiple: true,
//
showSearch: true,
//
total: 0,
//
addressList: [],
//
title: "",
//
open: false,
//
queryParams: {
pageNum: 1,
pageSize: 10,
deptId: undefined,
userId: undefined,
isDefault: undefined,
mobile: undefined,
name: undefined,
address: undefined,
region: undefined,
},
//
form: {},
//
rules: {
}
};
},
created() {
this.getList();
},
methods: {
/** 查询用户收货地址列表 */
getList() {
this.loading = true;
listAddress(this.queryParams).then(response => {
this.addressList = response.rows;
this.total = response.total;
this.loading = false;
});
},
//
cancel() {
this.open = false;
this.reset();
},
//
reset() {
this.form = {
id: undefined,
deptId: undefined,
userId: undefined,
isDefault: undefined,
mobile: undefined,
name: undefined,
address: undefined,
region: undefined,
delFlag: undefined,
createTime: undefined,
updateTime: undefined
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.id)
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.open = true;
this.title = "添加用户收货地址";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const id = row.id || this.ids
getAddress(id).then(response => {
this.form = response.data;
this.open = true;
this.title = "修改用户收货地址";
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate(valid => {
if (valid) {
if (this.form.id != null) {
updateAddress(this.form).then(response => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addAddress(this.form).then(response => {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const ids = row.id || this.ids;
this.$confirm('是否确认删除用户收货地址编号为"' + ids + '"的数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return delAddress(ids);
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
})
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm('是否确认导出所有用户收货地址数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return exportAddress(queryParams);
}).then(response => {
this.download(response.msg);
})
}
}
};
</script>