parent
3d9ee99090
commit
61e2b33b79
@ -0,0 +1,77 @@
|
||||
package com.cyl.h5.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.cyl.ums.domain.Address;
|
||||
import com.cyl.ums.mapper.AddressMapper;
|
||||
import com.cyl.ums.pojo.dto.AddressDTO;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.core.redis.RedisService;
|
||||
import com.ruoyi.common.utils.OssUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/h5")
|
||||
public class H5CommonController {
|
||||
|
||||
@Autowired
|
||||
private OssUtils ossUtils;
|
||||
@Autowired
|
||||
private AddressMapper addressMapper;
|
||||
@Autowired
|
||||
private RedisService redisService;
|
||||
|
||||
|
||||
@GetMapping("/area")
|
||||
public AjaxResult getAddressList() {
|
||||
String addresses = redisService.getAddressList();
|
||||
if (StringUtils.isNotEmpty(addresses)) {
|
||||
return AjaxResult.success(JSON.parseArray(addresses, AddressDTO.class));
|
||||
}
|
||||
QueryWrapper<Address> addressQueryWrapper = new QueryWrapper<>();
|
||||
addressQueryWrapper.in("level", Arrays.asList(0,1,2));
|
||||
List<Address> addressList = addressMapper.selectList(addressQueryWrapper);
|
||||
Map<Long, List<Address>> cityMap = addressList.stream().filter(it -> it.getLevel() == 1).collect(Collectors.groupingBy(it -> it.getParentCode()));
|
||||
Map<Long, List<Address>> districtMap = addressList.stream().filter(it -> it.getLevel() == 2).collect(Collectors.groupingBy(it -> it.getParentCode()));
|
||||
List<AddressDTO> result = new ArrayList<>();
|
||||
addressList.stream().filter(it -> it.getLevel() == 0).forEach(it -> {
|
||||
AddressDTO dto = new AddressDTO();
|
||||
dto.setId(it.getCode());
|
||||
dto.setLevel("province");
|
||||
dto.setName(it.getName());
|
||||
dto.setPid(0L);
|
||||
//获取城市列表
|
||||
List<AddressDTO> child = new ArrayList<>();
|
||||
if (cityMap.containsKey(it.getCode())) {
|
||||
cityMap.get(it.getCode()).forEach(city -> {
|
||||
AddressDTO cityDto = new AddressDTO();
|
||||
cityDto.setId(city.getCode());
|
||||
cityDto.setLevel("city");
|
||||
cityDto.setName(city.getName());
|
||||
cityDto.setPid(city.getParentCode());
|
||||
cityDto.setChildren(districtMap.containsKey(city.getCode()) ?
|
||||
districtMap.get(city.getCode()).stream().map(district -> {
|
||||
AddressDTO districtDto = new AddressDTO();
|
||||
districtDto.setId(district.getCode());
|
||||
districtDto.setLevel("district");
|
||||
districtDto.setName(district.getName());
|
||||
districtDto.setPid(district.getParentCode());
|
||||
return districtDto;
|
||||
}).collect(Collectors.toList()) : Collections.EMPTY_LIST);
|
||||
child.add(cityDto);
|
||||
});
|
||||
}
|
||||
dto.setChildren(child);
|
||||
result.add(dto);
|
||||
});
|
||||
redisService.setAddressList(JSON.toJSONString(result));
|
||||
return AjaxResult.success(result);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,45 @@
|
||||
package com.cyl.h5.controller;
|
||||
|
||||
import com.cyl.h5.service.H5MemberAddressService;
|
||||
import com.cyl.ums.domain.MemberAddress;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/h5/member/address")
|
||||
public class H5MemberAddressController {
|
||||
|
||||
@Autowired
|
||||
private H5MemberAddressService h5MemberAddressService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public AjaxResult getList(){
|
||||
return AjaxResult.success(h5MemberAddressService.selectList());
|
||||
}
|
||||
|
||||
@GetMapping("/default")
|
||||
public AjaxResult getDefault(){
|
||||
return AjaxResult.success(h5MemberAddressService.getDefault());
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public AjaxResult create(@RequestBody MemberAddress memberAddress){
|
||||
return AjaxResult.success(h5MemberAddressService.insert(memberAddress));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
public AjaxResult update(@RequestBody MemberAddress memberAddress){
|
||||
return AjaxResult.success(h5MemberAddressService.update(memberAddress));
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public AjaxResult getInfo(@PathVariable Long id){
|
||||
return AjaxResult.success(h5MemberAddressService.selectById(id));
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public AjaxResult remove(@PathVariable Long id) {
|
||||
return AjaxResult.success(h5MemberAddressService.deleteById(id));
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,111 @@
|
||||
package com.cyl.h5.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.cyl.ums.domain.Member;
|
||||
import com.cyl.ums.domain.MemberAddress;
|
||||
import com.cyl.ums.mapper.MemberAddressMapper;
|
||||
import com.ruoyi.common.constant.Constants;
|
||||
import com.ruoyi.framework.config.LocalDataUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 会员收货地址Service业务层处理
|
||||
*
|
||||
* @author sjm
|
||||
*/
|
||||
@Service
|
||||
@Transactional
|
||||
public class H5MemberAddressService {
|
||||
@Autowired
|
||||
private MemberAddressMapper memberAddressMapper;
|
||||
|
||||
/**
|
||||
* 查询会员收货地址
|
||||
*
|
||||
* @param id 会员收货地址主键
|
||||
* @return 会员收货地址
|
||||
*/
|
||||
|
||||
public MemberAddress selectById(Long id) {
|
||||
return memberAddressMapper.selectById(id);
|
||||
}
|
||||
|
||||
public List<MemberAddress> selectList() {
|
||||
Member member = (Member) LocalDataUtil.getVar(Constants.MEMBER_INFO);
|
||||
MemberAddress memberAddress = new MemberAddress();
|
||||
memberAddress.setMemberId(member.getId());
|
||||
return memberAddressMapper.selectByEntity(memberAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增会员收货地址
|
||||
*
|
||||
* @param memberAddress 会员收货地址
|
||||
* @return 结果
|
||||
*/
|
||||
public int insert(MemberAddress memberAddress) {
|
||||
Member member = (Member) LocalDataUtil.getVar(Constants.MEMBER_INFO);
|
||||
if (memberAddress.getIsDefault() == 1) {
|
||||
//将别的设置为0
|
||||
memberAddressMapper.updateDefault(0,member.getId());
|
||||
}
|
||||
memberAddress.setMemberId(member.getId());
|
||||
memberAddress.setCreateTime(LocalDateTime.now());
|
||||
return memberAddressMapper.insert(memberAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改会员收货地址
|
||||
*
|
||||
* @param memberAddress 会员收货地址
|
||||
* @return 结果
|
||||
*/
|
||||
|
||||
public int update(MemberAddress memberAddress) {
|
||||
Member member = (Member) LocalDataUtil.getVar(Constants.MEMBER_INFO);
|
||||
if (memberAddress.getIsDefault() == 1) {
|
||||
//将别的设置为0
|
||||
memberAddressMapper.updateDefault(0,member.getId());
|
||||
}
|
||||
memberAddress.setUpdateTime(LocalDateTime.now());
|
||||
return memberAddressMapper.updateById(memberAddress);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量删除会员收货地址
|
||||
*
|
||||
* @param ids 需要删除的会员收货地址主键
|
||||
* @return 结果
|
||||
*/
|
||||
|
||||
public int deleteByIds(Long[] ids) {
|
||||
return memberAddressMapper.deleteBatchIds(Arrays.asList(ids));
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除会员收货地址信息
|
||||
*
|
||||
* @param id 会员收货地址主键
|
||||
* @return 结果
|
||||
*/
|
||||
|
||||
public int deleteById(Long id) {
|
||||
return memberAddressMapper.deleteById(id);
|
||||
}
|
||||
|
||||
public MemberAddress getDefault() {
|
||||
Member member = (Member) LocalDataUtil.getVar(Constants.MEMBER_INFO);
|
||||
QueryWrapper<MemberAddress> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.eq("member_id",member.getId());
|
||||
queryWrapper.eq("is_default",1);
|
||||
List<MemberAddress> list = memberAddressMapper.selectList(queryWrapper);
|
||||
return CollectionUtils.isEmpty(list) ? null : list.get(0);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
package com.cyl.ums.domain;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.ruoyi.common.annotation.Excel;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 地址对象
|
||||
*
|
||||
*/
|
||||
@ApiModel(description="地址对象")
|
||||
@Data
|
||||
@TableName("address")
|
||||
public class Address {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@ApiModelProperty("ID")
|
||||
private Integer id;
|
||||
|
||||
@ApiModelProperty("地区邮编")
|
||||
@Excel(name = "地区邮编")
|
||||
private Long code;
|
||||
|
||||
@ApiModelProperty("父地区邮编")
|
||||
@Excel(name = "父地区邮编")
|
||||
private Long parentCode;
|
||||
|
||||
@ApiModelProperty("地区名")
|
||||
@Excel(name = "地区名")
|
||||
private String name;
|
||||
|
||||
@ApiModelProperty("地区层级")
|
||||
@Excel(name = "地区层级")
|
||||
private Integer level;
|
||||
|
||||
@ApiModelProperty("CREATED_AT")
|
||||
@Excel(name = "CREATED_AT")
|
||||
private String createdAt;
|
||||
|
||||
@ApiModelProperty("UPDATED_AT")
|
||||
@Excel(name = "UPDATED_AT")
|
||||
private String updatedAt;
|
||||
|
||||
@ApiModelProperty("DELETED_AT")
|
||||
@Excel(name = "DELETED_AT")
|
||||
private String deletedAt;
|
||||
|
||||
}
|
||||
@ -0,0 +1,22 @@
|
||||
package com.cyl.ums.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.cyl.ums.domain.Address;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 【请填写功能名称】Mapper接口
|
||||
*
|
||||
* @author sjm
|
||||
*/
|
||||
public interface AddressMapper extends BaseMapper<Address> {
|
||||
/**
|
||||
* 查询【请填写功能名称】列表
|
||||
*
|
||||
* @param address 【请填写功能名称】
|
||||
* @return 【请填写功能名称】集合
|
||||
*/
|
||||
List<Address> selectByEntity(Address address);
|
||||
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
package com.cyl.ums.pojo.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 【请填写功能名称】 DTO 对象
|
||||
*
|
||||
* @author sjm
|
||||
*/
|
||||
@Data
|
||||
public class AddressDTO {
|
||||
private Long id;
|
||||
private Long pid;
|
||||
private String name;
|
||||
private String level;
|
||||
private List<AddressDTO> children;
|
||||
}
|
||||
@ -0,0 +1,34 @@
|
||||
<?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.cyl.ums.mapper.AddressMapper">
|
||||
|
||||
<resultMap type="Address" id="AddressResult">
|
||||
<result property="id" column="id"/>
|
||||
<result property="code" column="code"/>
|
||||
<result property="parentCode" column="parent_code"/>
|
||||
<result property="name" column="name"/>
|
||||
<result property="level" column="level"/>
|
||||
<result property="createdAt" column="created_at"/>
|
||||
<result property="updatedAt" column="updated_at"/>
|
||||
<result property="deletedAt" column="deleted_at"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectAddressVo">
|
||||
select id, code, parent_code, name, level, created_at, updated_at, deleted_at from address
|
||||
</sql>
|
||||
|
||||
<select id="selectByEntity" parameterType="Address" resultMap="AddressResult">
|
||||
<include refid="selectAddressVo"/>
|
||||
<where>
|
||||
<if test="code != null "> and code = #{code}</if>
|
||||
<if test="parentCode != null "> and parent_code = #{parentCode}</if>
|
||||
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
|
||||
<if test="level != null "> and level = #{level}</if>
|
||||
<if test="createdAt != null and createdAt != ''"> and created_at = #{createdAt}</if>
|
||||
<if test="updatedAt != null and updatedAt != ''"> and updated_at = #{updatedAt}</if>
|
||||
<if test="deletedAt != null and deletedAt != ''"> and deleted_at = #{deletedAt}</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
Loading…
Reference in new issue