通用文件新项目
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
package com.peanut.modules.common.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.common.entity.BaseAreaEntity;
|
||||
import com.peanut.modules.common.service.BaseAreaService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 国家区域管理
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController("commonBaseArea")
|
||||
@RequestMapping("common/baseArea")
|
||||
public class BaseAreaController {
|
||||
|
||||
@Autowired
|
||||
private BaseAreaService baseAreaService;
|
||||
|
||||
/**
|
||||
* 添加区域
|
||||
* @param baseArea
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/addBaseArea")
|
||||
public R addBaseArea(@RequestBody BaseAreaEntity baseArea){
|
||||
baseAreaService.save(baseArea);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除区域
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/delBaseArea")
|
||||
public R delBaseArea(@RequestBody Map<String,Object> map){
|
||||
Integer areaId = Integer.valueOf(map.get("areaId").toString());
|
||||
baseAreaService.removeById(areaId);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 编辑区域信息
|
||||
* @param baseArea
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/editBaseArea")
|
||||
public R editBaseArea(@RequestBody BaseAreaEntity baseArea){
|
||||
baseAreaService.updateById(baseArea);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取区域列表
|
||||
* @param map
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/getBaseAreas")
|
||||
public R getBaseAreas(@RequestBody Map<String,Object> map){
|
||||
Integer limit = Integer.valueOf(map.get("limit").toString());
|
||||
Integer page = Integer.valueOf(map.get("page").toString());
|
||||
|
||||
Page baseAreas = baseAreaService.getBaseAreas(limit, page);
|
||||
return R.ok().put("page",baseAreas);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部国家领域
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping("/getAllBaseArea")
|
||||
public R getAllBaseArea(){
|
||||
List<BaseAreaEntity> list = baseAreaService.list();
|
||||
return R.ok().put("baseAreas",list);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.peanut.modules.common.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.common.entity.City;
|
||||
import com.peanut.modules.common.entity.County;
|
||||
import com.peanut.modules.common.entity.Province;
|
||||
import com.peanut.modules.common.service.CityService;
|
||||
import com.peanut.modules.common.service.CountyService;
|
||||
import com.peanut.modules.common.service.ProvinceService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 省市区管理
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController("commonProvince")
|
||||
@RequestMapping("common/province")
|
||||
public class ProvinceController {
|
||||
|
||||
@Autowired
|
||||
private ProvinceService provinceService;
|
||||
@Autowired
|
||||
private CityService cityService;
|
||||
@Autowired
|
||||
private CountyService countyService;
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
//获取地址
|
||||
@RequestMapping("/getProvince")
|
||||
public R getProvince() {
|
||||
//优化查询速度 目录放入redis中
|
||||
String s = redisTemplate.opsForValue().get("Province");
|
||||
List<Map<String, Object>> listData = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(s)) {
|
||||
List<Object> redisData = JSONArray.parseArray(s);
|
||||
for (Object object : redisData) {
|
||||
Map<String, Object> ret = (Map<String, Object>) object;//取出list里面的值转为map
|
||||
listData.add(ret);
|
||||
}
|
||||
return R.ok().put("provinceEntity", listData);
|
||||
}
|
||||
List<Province> provinceList = provinceService.getCity();
|
||||
redisTemplate.opsForValue().set("Province", JSON.toJSONString(provinceList));
|
||||
return R.ok().put("provinceEntity", provinceList);
|
||||
}
|
||||
|
||||
//获取省列表
|
||||
@RequestMapping("/getProvinceList")
|
||||
public R getProvinceList() {
|
||||
List<Province> provinceList = provinceService.getBaseMapper().selectList(new QueryWrapper<Province>());
|
||||
return R.ok().put("provinceList", provinceList);
|
||||
}
|
||||
|
||||
//获取市列表
|
||||
@RequestMapping("/getCityList")
|
||||
public R getCityList(@RequestParam("provId") Integer provId) {
|
||||
List<City> prov = cityService.getBaseMapper().selectList(new QueryWrapper<City>()
|
||||
.eq("prov_id", provId));
|
||||
return R.ok().put("prov", prov);
|
||||
}
|
||||
|
||||
//获取区列表
|
||||
@RequestMapping("/getCountyList")
|
||||
public R getCountyList(@RequestParam("cityId") Integer cityId) {
|
||||
List<County> countyList = countyService.getBaseMapper().selectList(new QueryWrapper<County>().eq("city_id", cityId));
|
||||
return R.ok().put("countyList", countyList);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
package com.peanut.modules.common.controller;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.peanut.common.utils.R;
|
||||
import com.peanut.modules.common.entity.UserAddress;
|
||||
import com.peanut.modules.common.service.UserAddressService;
|
||||
import com.peanut.modules.common.vo.UserAddressVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 收货地址管理
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController("commonUserAddress")
|
||||
@RequestMapping("common/userAddress")
|
||||
public class UserAddressController {
|
||||
|
||||
@Autowired
|
||||
private UserAddressService userAddressService;
|
||||
|
||||
/**
|
||||
* 获取地址信息
|
||||
*/
|
||||
@RequestMapping("/info/{addressId}")
|
||||
public R info(@PathVariable("addressId") Integer addressId) {
|
||||
UserAddress userAddress = userAddressService.getById(addressId);
|
||||
UserAddressVo vo = new UserAddressVo();
|
||||
BeanUtil.copyProperties(userAddress, vo);
|
||||
vo = userAddressService.getAddressName(vo, userAddress.getRegionCode());
|
||||
return R.ok().put("result", vo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存
|
||||
*/
|
||||
@RequestMapping("/save")
|
||||
public R save(@RequestBody UserAddress userAddress) {
|
||||
// 判断是否已经有默认的地址了
|
||||
if ((userAddressService.getUserDefaultAddressCount(userAddress.getUserId()) >= 1) && userAddress.getIsDefault() == 1) {
|
||||
return R.error("已经存在默认地址");
|
||||
}
|
||||
if(userAddress.getRegionCode()==null||userAddress.getRegionCode().equals("")){
|
||||
return R.error("地址异常添加失败!");
|
||||
}
|
||||
String str = userAddress.getConsigneeName()+userAddress.getConsigneePhone()+userAddress.getDetailAddress();
|
||||
if(str.contains("+")||str.contains("&")){
|
||||
return R.error("信息中不能含有“+”、“&”符号!");
|
||||
}
|
||||
userAddressService.save(userAddress);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
@RequestMapping("/update")
|
||||
public R update(@RequestBody UserAddress userAddress) {
|
||||
LambdaQueryWrapper<UserAddress> wrapper = new LambdaQueryWrapper();
|
||||
wrapper.eq(UserAddress::getId,userAddress.getId());
|
||||
wrapper.eq(UserAddress::getIsDefault,1);
|
||||
UserAddress ua = userAddressService.getOne(wrapper);
|
||||
if (ua == null){
|
||||
if ((userAddressService.getUserDefaultAddressCount(userAddress.getUserId()) >= 1) && userAddress.getIsDefault() == 1) {
|
||||
return R.error("已经存在默认地址");
|
||||
}
|
||||
}
|
||||
String str = userAddress.getConsigneeName()+userAddress.getConsigneePhone()+userAddress.getDetailAddress();
|
||||
if(str.contains("+")||str.contains("&")){
|
||||
return R.error("信息中不能含有“+”、“&”符号!");
|
||||
}
|
||||
userAddressService.updateById(userAddress);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户地址
|
||||
*/
|
||||
@RequestMapping(value = "/delete", method = RequestMethod.GET)
|
||||
public R delete(@RequestParam("id") Integer id) {
|
||||
userAddressService.removeById(id);
|
||||
return R.ok();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户收货地址列表
|
||||
*/
|
||||
@RequestMapping("/getUserAddress")
|
||||
public R getUserAddress(@RequestParam("userId") Integer userId) {
|
||||
QueryWrapper<UserAddress> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("user_id", userId);
|
||||
queryWrapper.orderByDesc("is_default");
|
||||
List<UserAddress> userAddressList = userAddressService.list(queryWrapper);
|
||||
List<UserAddressVo> result = new ArrayList<>();
|
||||
for (UserAddress userAddress : userAddressList) {
|
||||
UserAddressVo vo = new UserAddressVo();
|
||||
BeanUtil.copyProperties(userAddress, vo);
|
||||
vo = userAddressService.getAddressName(vo, userAddress.getRegionCode());
|
||||
result.add(vo);
|
||||
}
|
||||
return R.ok().put("list", result);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.peanut.modules.common.controller;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alibaba.druid.util.StringUtils;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.peanut.common.utils.MD5Utils;
|
||||
import com.peanut.common.utils.MailUtil;
|
||||
import com.peanut.common.utils.R;
|
||||
@@ -21,8 +19,11 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* 用户登陆注册验证码
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RestController("commonUser")
|
||||
@RequestMapping("common/user")
|
||||
public class UserController {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user