commit
0f65a3cc3b
@ -0,0 +1,86 @@
|
|||||||
|
package com.example.entity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色用户父类
|
||||||
|
*/
|
||||||
|
public class Account {
|
||||||
|
private Integer id;
|
||||||
|
/** 用户名 */
|
||||||
|
private String username;
|
||||||
|
/** 名称 */
|
||||||
|
private String name;
|
||||||
|
/** 密码 */
|
||||||
|
private String password;
|
||||||
|
/** 角色标识 */
|
||||||
|
private String role;
|
||||||
|
/** 新密码 */
|
||||||
|
private String newPassword;
|
||||||
|
/** 头像 */
|
||||||
|
private String avatar;
|
||||||
|
|
||||||
|
private String token;
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRole() {
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRole(String role) {
|
||||||
|
this.role = role;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNewPassword() {
|
||||||
|
return newPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNewPassword(String newPassword) {
|
||||||
|
this.newPassword = newPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAvatar() {
|
||||||
|
return avatar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAvatar(String avatar) {
|
||||||
|
this.avatar = avatar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getToken() {
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setToken(String token) {
|
||||||
|
this.token = token;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
package com.example.entity;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 地址信息表
|
||||||
|
*/
|
||||||
|
public class Address implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
private Integer userId;
|
||||||
|
private String username;
|
||||||
|
private String useraddress;
|
||||||
|
private String phone;
|
||||||
|
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(Integer userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUseraddress() {
|
||||||
|
return useraddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUseraddress(String useraddress) {
|
||||||
|
this.useraddress = useraddress;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPhone() {
|
||||||
|
return phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPhone(String phone) {
|
||||||
|
this.phone = phone;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,87 @@
|
|||||||
|
package com.example.controller;
|
||||||
|
|
||||||
|
import com.example.common.Result;
|
||||||
|
import com.example.entity.Address;
|
||||||
|
import com.example.service.AddressService;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 地址前端操作接口
|
||||||
|
**/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/address")
|
||||||
|
public class AddressController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AddressService addressService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
@PostMapping("/add")
|
||||||
|
public Result add(@RequestBody Address address) {
|
||||||
|
addressService.add(address);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/delete/{id}")
|
||||||
|
public Result deleteById(@PathVariable Integer id) {
|
||||||
|
addressService.deleteById(id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/delete/batch")
|
||||||
|
public Result deleteBatch(@RequestBody List<Integer> ids) {
|
||||||
|
addressService.deleteBatch(ids);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*/
|
||||||
|
@PutMapping("/update")
|
||||||
|
public Result updateById(@RequestBody Address address) {
|
||||||
|
addressService.updateById(address);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
*/
|
||||||
|
@GetMapping("/selectById/{id}")
|
||||||
|
public Result selectById(@PathVariable Integer id) {
|
||||||
|
Address address = addressService.selectById(id);
|
||||||
|
return Result.success(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有
|
||||||
|
*/
|
||||||
|
@GetMapping("/selectAll")
|
||||||
|
public Result selectAll(Address address ) {
|
||||||
|
List<Address> list = addressService.selectAll(address);
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*/
|
||||||
|
@GetMapping("/selectPage")
|
||||||
|
public Result selectPage(Address address,
|
||||||
|
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||||
|
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||||
|
PageInfo<Address> page = addressService.selectPage(address, pageNum, pageSize);
|
||||||
|
return Result.success(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.example.mapper;
|
||||||
|
|
||||||
|
import com.example.entity.Address;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作address相关数据接口
|
||||||
|
*/
|
||||||
|
public interface AddressMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
int insert(Address address);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
int deleteById(Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*/
|
||||||
|
int updateById(Address address);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
*/
|
||||||
|
Address selectById(Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有
|
||||||
|
*/
|
||||||
|
List<Address> selectAll(Address address);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,84 @@
|
|||||||
|
package com.example.service;
|
||||||
|
|
||||||
|
import com.example.common.enums.RoleEnum;
|
||||||
|
import com.example.entity.Account;
|
||||||
|
import com.example.entity.Address;
|
||||||
|
import com.example.mapper.AddressMapper;
|
||||||
|
import com.example.utils.TokenUtils;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 地址业务处理
|
||||||
|
**/
|
||||||
|
@Service
|
||||||
|
public class AddressService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AddressMapper addressMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
public void add(Address address) {
|
||||||
|
addressMapper.insert(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
public void deleteById(Integer id) {
|
||||||
|
addressMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除
|
||||||
|
*/
|
||||||
|
public void deleteBatch(List<Integer> ids) {
|
||||||
|
for (Integer id : ids) {
|
||||||
|
addressMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*/
|
||||||
|
public void updateById(Address address) {
|
||||||
|
addressMapper.updateById(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
*/
|
||||||
|
public Address selectById(Integer id) {
|
||||||
|
return addressMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有
|
||||||
|
*/
|
||||||
|
public List<Address> selectAll(Address address) {
|
||||||
|
Account currentUser = TokenUtils.getCurrentUser();
|
||||||
|
if (RoleEnum.USER.name().equals(currentUser.getRole())) {
|
||||||
|
address.setUserId(currentUser.getId());
|
||||||
|
}
|
||||||
|
return addressMapper.selectAll(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*/
|
||||||
|
public PageInfo<Address> selectPage(Address address, Integer pageNum, Integer pageSize) {
|
||||||
|
Account currentUser = TokenUtils.getCurrentUser();
|
||||||
|
if (RoleEnum.USER.name().equals(currentUser.getRole())) {
|
||||||
|
address.setUserId(currentUser.getId());
|
||||||
|
}
|
||||||
|
PageHelper.startPage(pageNum, pageSize);
|
||||||
|
List<Address> list = addressMapper.selectAll(address);
|
||||||
|
return PageInfo.of(list);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
package com.example.entity;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收藏信息表
|
||||||
|
*/
|
||||||
|
public class Collect implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private Integer id;
|
||||||
|
private Integer userId;
|
||||||
|
private Integer businessId;
|
||||||
|
private Integer goodsId;
|
||||||
|
|
||||||
|
private String businessName;
|
||||||
|
private String goodsName;
|
||||||
|
private String goodsImg;
|
||||||
|
private String goodUnit;
|
||||||
|
private Double goodsPrice;
|
||||||
|
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(Integer userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getBusinessId() {
|
||||||
|
return businessId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBusinessId(Integer businessId) {
|
||||||
|
this.businessId = businessId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getGoodsId() {
|
||||||
|
return goodsId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGoodsId(Integer goodsId) {
|
||||||
|
this.goodsId = goodsId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBusinessName() {
|
||||||
|
return businessName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBusinessName(String businessName) {
|
||||||
|
this.businessName = businessName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGoodsName() {
|
||||||
|
return goodsName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGoodsName(String goodsName) {
|
||||||
|
this.goodsName = goodsName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGoodsImg() {
|
||||||
|
return goodsImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGoodsImg(String goodsImg) {
|
||||||
|
this.goodsImg = goodsImg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGoodUnit() {
|
||||||
|
return goodUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGoodUnit(String goodUnit) {
|
||||||
|
this.goodUnit = goodUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Double getGoodsPrice() {
|
||||||
|
return goodsPrice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGoodsPrice(Double goodsPrice) {
|
||||||
|
this.goodsPrice = goodsPrice;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -0,0 +1,87 @@
|
|||||||
|
package com.example.controller;
|
||||||
|
|
||||||
|
import com.example.common.Result;
|
||||||
|
import com.example.entity.Collect;
|
||||||
|
import com.example.service.CollectService;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收藏前端操作接口
|
||||||
|
**/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/collect")
|
||||||
|
public class CollectController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CollectService collectService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
@PostMapping("/add")
|
||||||
|
public Result add(@RequestBody Collect collect) {
|
||||||
|
collectService.add(collect);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/delete/{id}")
|
||||||
|
public Result deleteById(@PathVariable Integer id) {
|
||||||
|
collectService.deleteById(id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/delete/batch")
|
||||||
|
public Result deleteBatch(@RequestBody List<Integer> ids) {
|
||||||
|
collectService.deleteBatch(ids);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*/
|
||||||
|
@PutMapping("/update")
|
||||||
|
public Result updateById(@RequestBody Collect collect) {
|
||||||
|
collectService.updateById(collect);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
*/
|
||||||
|
@GetMapping("/selectById/{id}")
|
||||||
|
public Result selectById(@PathVariable Integer id) {
|
||||||
|
Collect collect = collectService.selectById(id);
|
||||||
|
return Result.success(collect);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有
|
||||||
|
*/
|
||||||
|
@GetMapping("/selectAll")
|
||||||
|
public Result selectAll(Collect collect ) {
|
||||||
|
List<Collect> list = collectService.selectAll(collect);
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*/
|
||||||
|
@GetMapping("/selectPage")
|
||||||
|
public Result selectPage(Collect collect,
|
||||||
|
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||||
|
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||||
|
PageInfo<Collect> page = collectService.selectPage(collect, pageNum, pageSize);
|
||||||
|
return Result.success(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package com.example.mapper;
|
||||||
|
|
||||||
|
import com.example.entity.Collect;
|
||||||
|
import org.apache.ibatis.annotations.Param;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作collect相关数据接口
|
||||||
|
*/
|
||||||
|
public interface CollectMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
int insert(Collect collect);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
int deleteById(Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*/
|
||||||
|
int updateById(Collect collect);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
*/
|
||||||
|
Collect selectById(Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有
|
||||||
|
*/
|
||||||
|
List<Collect> selectAll(Collect collect);
|
||||||
|
|
||||||
|
@Select("select * from collect where user_id = #{userId} and goods_id = #{goodsId}")
|
||||||
|
Collect selectByUserIdAndGoodsId(@Param("userId") Integer userId, @Param("goodsId") Integer goodsId);
|
||||||
|
}
|
@ -0,0 +1,88 @@
|
|||||||
|
package com.example.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.example.common.enums.ResultCodeEnum;
|
||||||
|
import com.example.common.enums.RoleEnum;
|
||||||
|
import com.example.entity.Account;
|
||||||
|
import com.example.entity.Collect;
|
||||||
|
import com.example.exception.CustomException;
|
||||||
|
import com.example.mapper.CollectMapper;
|
||||||
|
import com.example.utils.TokenUtils;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 收藏业务处理
|
||||||
|
**/
|
||||||
|
@Service
|
||||||
|
public class CollectService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private CollectMapper collectMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
public void add(Collect collect) {
|
||||||
|
// 判断一下该用户有没有收藏过该商品,如果有,就要提示用户不能重复收藏
|
||||||
|
Collect dbCollect = collectMapper.selectByUserIdAndGoodsId(collect.getUserId(), collect.getGoodsId());
|
||||||
|
if (ObjectUtil.isNotEmpty(dbCollect)) {
|
||||||
|
throw new CustomException(ResultCodeEnum.COLLECT_ALREADY_ERROR);
|
||||||
|
}
|
||||||
|
collectMapper.insert(collect);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
public void deleteById(Integer id) {
|
||||||
|
collectMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除
|
||||||
|
*/
|
||||||
|
public void deleteBatch(List<Integer> ids) {
|
||||||
|
for (Integer id : ids) {
|
||||||
|
collectMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*/
|
||||||
|
public void updateById(Collect collect) {
|
||||||
|
collectMapper.updateById(collect);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
*/
|
||||||
|
public Collect selectById(Integer id) {
|
||||||
|
return collectMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有
|
||||||
|
*/
|
||||||
|
public List<Collect> selectAll(Collect collect) {
|
||||||
|
return collectMapper.selectAll(collect);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*/
|
||||||
|
public PageInfo<Collect> selectPage(Collect collect, Integer pageNum, Integer pageSize) {
|
||||||
|
Account currentUser = TokenUtils.getCurrentUser();
|
||||||
|
if (RoleEnum.USER.name().equals(currentUser.getRole())) {
|
||||||
|
collect.setUserId(currentUser.getId());
|
||||||
|
}
|
||||||
|
PageHelper.startPage(pageNum, pageSize);
|
||||||
|
List<Collect> list = collectMapper.selectAll(collect);
|
||||||
|
return PageInfo.of(list);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
package com.example.entity;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公告信息表
|
||||||
|
*/
|
||||||
|
public class Notice implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** ID */
|
||||||
|
private Integer id;
|
||||||
|
/** 标题 */
|
||||||
|
private String title;
|
||||||
|
/** 内容 */
|
||||||
|
private String content;
|
||||||
|
/** 创建时间 */
|
||||||
|
private String time;
|
||||||
|
/** 创建人 */
|
||||||
|
private String user;
|
||||||
|
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setContent(String content) {
|
||||||
|
this.content = content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTime() {
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTime(String time) {
|
||||||
|
this.time = time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(String user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,86 @@
|
|||||||
|
package com.example.controller;
|
||||||
|
|
||||||
|
import com.example.common.Result;
|
||||||
|
import com.example.entity.Notice;
|
||||||
|
import com.example.service.NoticeService;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公告信息表前端操作接口
|
||||||
|
**/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/notice")
|
||||||
|
public class NoticeController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private NoticeService noticeService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
@PostMapping("/add")
|
||||||
|
public Result add(@RequestBody Notice notice) {
|
||||||
|
noticeService.add(notice);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/delete/{id}")
|
||||||
|
public Result deleteById(@PathVariable Integer id) {
|
||||||
|
noticeService.deleteById(id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/delete/batch")
|
||||||
|
public Result deleteBatch(@RequestBody List<Integer> ids) {
|
||||||
|
noticeService.deleteBatch(ids);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*/
|
||||||
|
@PutMapping("/update")
|
||||||
|
public Result updateById(@RequestBody Notice notice) {
|
||||||
|
noticeService.updateById(notice);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
*/
|
||||||
|
@GetMapping("/selectById/{id}")
|
||||||
|
public Result selectById(@PathVariable Integer id) {
|
||||||
|
Notice notice = noticeService.selectById(id);
|
||||||
|
return Result.success(notice);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有
|
||||||
|
*/
|
||||||
|
@GetMapping("/selectAll")
|
||||||
|
public Result selectAll(Notice notice ) {
|
||||||
|
List<Notice> list = noticeService.selectAll(notice);
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*/
|
||||||
|
@GetMapping("/selectPage")
|
||||||
|
public Result selectPage(Notice notice,
|
||||||
|
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||||
|
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||||
|
PageInfo<Notice> page = noticeService.selectPage(notice, pageNum, pageSize);
|
||||||
|
return Result.success(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package com.example.mapper;
|
||||||
|
|
||||||
|
import com.example.entity.Notice;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作notice相关数据接口
|
||||||
|
*/
|
||||||
|
public interface NoticeMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
int insert(Notice notice);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
int deleteById(Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*/
|
||||||
|
int updateById(Notice notice);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
*/
|
||||||
|
Notice selectById(Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有
|
||||||
|
*/
|
||||||
|
List<Notice> selectAll(Notice notice);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
package com.example.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import com.example.entity.Account;
|
||||||
|
import com.example.entity.Notice;
|
||||||
|
import com.example.mapper.NoticeMapper;
|
||||||
|
import com.example.utils.TokenUtils;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 公告信息表业务处理
|
||||||
|
**/
|
||||||
|
@Service
|
||||||
|
public class NoticeService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private NoticeMapper noticeMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
public void add(Notice notice) {
|
||||||
|
notice.setTime(DateUtil.today());
|
||||||
|
Account currentUser = TokenUtils.getCurrentUser();
|
||||||
|
notice.setUser(currentUser.getUsername());
|
||||||
|
noticeMapper.insert(notice);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
public void deleteById(Integer id) {
|
||||||
|
noticeMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除
|
||||||
|
*/
|
||||||
|
public void deleteBatch(List<Integer> ids) {
|
||||||
|
for (Integer id : ids) {
|
||||||
|
noticeMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*/
|
||||||
|
public void updateById(Notice notice) {
|
||||||
|
noticeMapper.updateById(notice);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
*/
|
||||||
|
public Notice selectById(Integer id) {
|
||||||
|
return noticeMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有
|
||||||
|
*/
|
||||||
|
public List<Notice> selectAll(Notice notice) {
|
||||||
|
return noticeMapper.selectAll(notice);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*/
|
||||||
|
public PageInfo<Notice> selectPage(Notice notice, Integer pageNum, Integer pageSize) {
|
||||||
|
PageHelper.startPage(pageNum, pageSize);
|
||||||
|
List<Notice> list = noticeMapper.selectAll(notice);
|
||||||
|
return PageInfo.of(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
package com.example.mapper;
|
||||||
|
|
||||||
|
import com.example.entity.Type;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作type相关数据接口
|
||||||
|
*/
|
||||||
|
public interface TypeMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
int insert(Type type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
int deleteById(Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*/
|
||||||
|
int updateById(Type type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
*/
|
||||||
|
Type selectById(Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有
|
||||||
|
*/
|
||||||
|
List<Type> selectAll(Type type);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,75 @@
|
|||||||
|
package com.example.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.example.entity.Type;
|
||||||
|
import com.example.mapper.TypeMapper;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分类信息表业务处理
|
||||||
|
**/
|
||||||
|
@Service
|
||||||
|
public class TypeService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private TypeMapper typeMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
public void add(Type type) {
|
||||||
|
typeMapper.insert(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
public void deleteById(Integer id) {
|
||||||
|
typeMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除
|
||||||
|
*/
|
||||||
|
public void deleteBatch(List<Integer> ids) {
|
||||||
|
for (Integer id : ids) {
|
||||||
|
typeMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*/
|
||||||
|
public void updateById(Type type) {
|
||||||
|
typeMapper.updateById(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
*/
|
||||||
|
public Type selectById(Integer id) {
|
||||||
|
return typeMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有
|
||||||
|
*/
|
||||||
|
public List<Type> selectAll(Type type) {
|
||||||
|
return typeMapper.selectAll(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*/
|
||||||
|
public PageInfo<Type> selectPage(Type type, Integer pageNum, Integer pageSize) {
|
||||||
|
PageHelper.startPage(pageNum, pageSize);
|
||||||
|
List<Type> list = typeMapper.selectAll(type);
|
||||||
|
return PageInfo.of(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,104 @@
|
|||||||
|
package com.example.entity;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户
|
||||||
|
*/
|
||||||
|
public class User extends Account implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** ID */
|
||||||
|
private Integer id;
|
||||||
|
/** 用户名 */
|
||||||
|
private String username;
|
||||||
|
/** 密码 */
|
||||||
|
private String password;
|
||||||
|
/** 昵称 */
|
||||||
|
private String name;
|
||||||
|
/** 电话 */
|
||||||
|
private String phone;
|
||||||
|
/** 邮箱 */
|
||||||
|
private String email;
|
||||||
|
/** 头像 */
|
||||||
|
private String avatar;
|
||||||
|
/** 角色标识 */
|
||||||
|
private String role;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setId(Integer id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPhone() {
|
||||||
|
return phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPhone(String phone) {
|
||||||
|
this.phone = phone;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getAvatar() {
|
||||||
|
return avatar;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setAvatar(String avatar) {
|
||||||
|
this.avatar = avatar;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getRole() {
|
||||||
|
return role;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRole(String role) {
|
||||||
|
this.role = role;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,89 @@
|
|||||||
|
package com.example.controller;
|
||||||
|
|
||||||
|
import com.example.common.Result;
|
||||||
|
import com.example.entity.Business;
|
||||||
|
import com.example.entity.User;
|
||||||
|
import com.example.service.BusinessService;
|
||||||
|
import com.example.service.UserService;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户前端操作接口
|
||||||
|
**/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/user")
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
@PostMapping("/add")
|
||||||
|
public Result add(@RequestBody User user) {
|
||||||
|
userService.add(user);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/delete/{id}")
|
||||||
|
public Result deleteById(@PathVariable Integer id) {
|
||||||
|
userService.deleteById(id);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/delete/batch")
|
||||||
|
public Result deleteBatch(@RequestBody List<Integer> ids) {
|
||||||
|
userService.deleteBatch(ids);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*/
|
||||||
|
@PutMapping("/update")
|
||||||
|
public Result updateById(@RequestBody User user) {
|
||||||
|
userService.updateById(user);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
*/
|
||||||
|
@GetMapping("/selectById/{id}")
|
||||||
|
public Result selectById(@PathVariable Integer id) {
|
||||||
|
User user = userService.selectById(id);
|
||||||
|
return Result.success(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有
|
||||||
|
*/
|
||||||
|
@GetMapping("/selectAll")
|
||||||
|
public Result selectAll(User user ) {
|
||||||
|
List<User> list = userService.selectAll(user);
|
||||||
|
return Result.success(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*/
|
||||||
|
@GetMapping("/selectPage")
|
||||||
|
public Result selectPage(User user,
|
||||||
|
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||||
|
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||||
|
PageInfo<User> page = userService.selectPage(user, pageNum, pageSize);
|
||||||
|
return Result.success(page);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package com.example.mapper;
|
||||||
|
|
||||||
|
import com.example.entity.User;
|
||||||
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 操作user相关数据接口
|
||||||
|
*/
|
||||||
|
public interface UserMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
int insert(User user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
int deleteById(Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*/
|
||||||
|
int updateById(User user);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
*/
|
||||||
|
User selectById(Integer id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有
|
||||||
|
*/
|
||||||
|
List<User> selectAll(User user);
|
||||||
|
|
||||||
|
@Select("select * from user where username = #{username}")
|
||||||
|
User selectByUsername(String username);
|
||||||
|
}
|
@ -0,0 +1,136 @@
|
|||||||
|
package com.example.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import com.example.common.Constants;
|
||||||
|
import com.example.common.enums.ResultCodeEnum;
|
||||||
|
import com.example.common.enums.RoleEnum;
|
||||||
|
import com.example.common.enums.StatusEnum;
|
||||||
|
import com.example.entity.Account;
|
||||||
|
import com.example.entity.User;
|
||||||
|
import com.example.exception.CustomException;
|
||||||
|
import com.example.mapper.UserMapper;
|
||||||
|
import com.example.utils.TokenUtils;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户业务处理
|
||||||
|
**/
|
||||||
|
@Service
|
||||||
|
public class UserService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private UserMapper userMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增
|
||||||
|
*/
|
||||||
|
public void add(User user) {
|
||||||
|
User dbUser = userMapper.selectByUsername(user.getUsername());
|
||||||
|
if (ObjectUtil.isNotNull(dbUser)) {
|
||||||
|
throw new CustomException(ResultCodeEnum.USER_EXIST_ERROR);
|
||||||
|
}
|
||||||
|
if (ObjectUtil.isEmpty(user.getPassword())) {
|
||||||
|
user.setPassword(Constants.USER_DEFAULT_PASSWORD);
|
||||||
|
}
|
||||||
|
if (ObjectUtil.isEmpty(user.getName())) {
|
||||||
|
user.setName(user.getUsername());
|
||||||
|
}
|
||||||
|
user.setRole(RoleEnum.USER.name());
|
||||||
|
userMapper.insert(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除
|
||||||
|
*/
|
||||||
|
public void deleteById(Integer id) {
|
||||||
|
userMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除
|
||||||
|
*/
|
||||||
|
public void deleteBatch(List<Integer> ids) {
|
||||||
|
for (Integer id : ids) {
|
||||||
|
userMapper.deleteById(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改
|
||||||
|
*/
|
||||||
|
public void updateById(User user) {
|
||||||
|
userMapper.updateById(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据ID查询
|
||||||
|
*/
|
||||||
|
public User selectById(Integer id) {
|
||||||
|
return userMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有
|
||||||
|
*/
|
||||||
|
public List<User> selectAll(User user) {
|
||||||
|
return userMapper.selectAll(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 分页查询
|
||||||
|
*/
|
||||||
|
public PageInfo<User> selectPage(User user, Integer pageNum, Integer pageSize) {
|
||||||
|
PageHelper.startPage(pageNum, pageSize);
|
||||||
|
List<User> list = userMapper.selectAll(user);
|
||||||
|
return PageInfo.of(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录
|
||||||
|
*/
|
||||||
|
public Account login(Account account) {
|
||||||
|
Account dbUser = userMapper.selectByUsername(account.getUsername());
|
||||||
|
if (ObjectUtil.isNull(dbUser)) {
|
||||||
|
throw new CustomException(ResultCodeEnum.USER_NOT_EXIST_ERROR);
|
||||||
|
}
|
||||||
|
if (!account.getPassword().equals(dbUser.getPassword())) {
|
||||||
|
throw new CustomException(ResultCodeEnum.USER_ACCOUNT_ERROR);
|
||||||
|
}
|
||||||
|
// 生成token
|
||||||
|
String tokenData = dbUser.getId() + "-" + RoleEnum.USER.name();
|
||||||
|
String token = TokenUtils.createToken(tokenData, dbUser.getPassword());
|
||||||
|
dbUser.setToken(token);
|
||||||
|
return dbUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册
|
||||||
|
*/
|
||||||
|
public void register(Account account) {
|
||||||
|
User user = new User();
|
||||||
|
BeanUtils.copyProperties(account, user);
|
||||||
|
add(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改密码
|
||||||
|
*/
|
||||||
|
public void updatePassword(Account account) {
|
||||||
|
User dbUser = userMapper.selectByUsername(account.getUsername());
|
||||||
|
if (ObjectUtil.isNull(dbUser)) {
|
||||||
|
throw new CustomException(ResultCodeEnum.USER_NOT_EXIST_ERROR);
|
||||||
|
}
|
||||||
|
if (!account.getPassword().equals(dbUser.getPassword())) {
|
||||||
|
throw new CustomException(ResultCodeEnum.PARAM_PASSWORD_ERROR);
|
||||||
|
}
|
||||||
|
dbUser.setPassword(account.getNewPassword());
|
||||||
|
userMapper.updateById(dbUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,97 @@
|
|||||||
|
package com.example.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.example.common.Result;
|
||||||
|
import com.example.common.enums.ResultCodeEnum;
|
||||||
|
import com.example.common.enums.RoleEnum;
|
||||||
|
import com.example.entity.Account;
|
||||||
|
import com.example.service.AdminService;
|
||||||
|
import com.example.service.BusinessService;
|
||||||
|
import com.example.service.UserService;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 基础前端接口
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
public class WebController {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private AdminService adminService;
|
||||||
|
@Resource
|
||||||
|
private BusinessService businessService;
|
||||||
|
@Resource
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
@GetMapping("/")
|
||||||
|
public Result hello() {
|
||||||
|
return Result.success("访问成功");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录
|
||||||
|
*/
|
||||||
|
@PostMapping("/login")
|
||||||
|
public Result login(@RequestBody Account account) {
|
||||||
|
if (ObjectUtil.isEmpty(account.getUsername()) || ObjectUtil.isEmpty(account.getPassword())
|
||||||
|
|| ObjectUtil.isEmpty(account.getRole())) {
|
||||||
|
return Result.error(ResultCodeEnum.PARAM_LOST_ERROR);
|
||||||
|
}
|
||||||
|
if (RoleEnum.ADMIN.name().equals(account.getRole())) {
|
||||||
|
account = adminService.login(account);
|
||||||
|
}
|
||||||
|
if (RoleEnum.BUSINESS.name().equals(account.getRole())){
|
||||||
|
account = businessService.login(account);
|
||||||
|
}
|
||||||
|
if(RoleEnum.USER.name().equals(account.getRole())){
|
||||||
|
account = userService.login(account);
|
||||||
|
}
|
||||||
|
return Result.success(account);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册
|
||||||
|
*/
|
||||||
|
@PostMapping("/register")
|
||||||
|
public Result register(@RequestBody Account account) {
|
||||||
|
if (StrUtil.isBlank(account.getUsername()) || StrUtil.isBlank(account.getPassword())
|
||||||
|
|| ObjectUtil.isEmpty(account.getRole())) {
|
||||||
|
return Result.error(ResultCodeEnum.PARAM_LOST_ERROR);
|
||||||
|
}
|
||||||
|
if (RoleEnum.ADMIN.name().equals(account.getRole())) {
|
||||||
|
adminService.register(account);
|
||||||
|
}
|
||||||
|
if (RoleEnum.BUSINESS.name().equals(account.getRole())) {
|
||||||
|
businessService.register(account);
|
||||||
|
}
|
||||||
|
if (RoleEnum.USER.name().equals(account.getRole())) {
|
||||||
|
userService.register(account);
|
||||||
|
}
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改密码
|
||||||
|
*/
|
||||||
|
@PutMapping("/updatePassword")
|
||||||
|
public Result updatePassword(@RequestBody Account account) {
|
||||||
|
if (StrUtil.isBlank(account.getUsername()) || StrUtil.isBlank(account.getPassword())
|
||||||
|
|| ObjectUtil.isEmpty(account.getNewPassword())) {
|
||||||
|
return Result.error(ResultCodeEnum.PARAM_LOST_ERROR);
|
||||||
|
}
|
||||||
|
if (RoleEnum.ADMIN.name().equals(account.getRole())) {
|
||||||
|
adminService.updatePassword(account);
|
||||||
|
}
|
||||||
|
if (RoleEnum.BUSINESS.name().equals(account.getRole())) {
|
||||||
|
businessService.updatePassword(account);
|
||||||
|
}
|
||||||
|
if (RoleEnum.USER.name().equals(account.getRole())) {
|
||||||
|
userService.updatePassword(account);
|
||||||
|
}
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue