新增后台门店管理

This commit is contained in:
hupeng
2020-03-04 14:14:04 +08:00
parent 0c1de4e7a1
commit e44cde1bff
10 changed files with 489 additions and 2 deletions

View File

@ -44,6 +44,11 @@ public interface ShopConstants {
*/ */
String YSHOP_DEFAULT_AVATAR = "https://image.dayouqiantu.cn/5dc2c7f3a104c.png"; String YSHOP_DEFAULT_AVATAR = "https://image.dayouqiantu.cn/5dc2c7f3a104c.png";
/**
* 腾讯地图地址解析
*/
String QQ_MAP_URL = "https://apis.map.qq.com/ws/geocoder/v1/";
} }

View File

@ -0,0 +1,101 @@
package co.yixiang.modules.shop.domain;
import lombok.Data;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import javax.persistence.*;
import javax.validation.constraints.*;
import java.io.Serializable;
import java.util.Date;
/**
* @author hupeng
* @date 2020-03-03
*/
@Entity
@Data
@Table(name="yx_system_store")
public class YxSystemStore implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
private Integer id;
/** 门店名称 */
@Column(name = "name",nullable = false)
@NotBlank
private String name;
/** 简介 */
@Column(name = "introduction",nullable = false)
@NotBlank
private String introduction;
/** 手机号码 */
@Column(name = "phone",nullable = false)
@NotBlank
private String phone;
/** 省市区 */
@Column(name = "address",nullable = false)
@NotBlank
private String address;
/** 详细地址 */
@Column(name = "detailed_address",insertable = false)
private String detailedAddress;
/** 门店logo */
@Column(name = "image",nullable = false)
@NotBlank(message = "请上传门店logo")
private String image;
/** 纬度 */
@Column(name = "latitude",nullable = false)
@NotBlank
private String latitude;
/** 经度 */
@Column(name = "longitude",nullable = false)
@NotBlank
private String longitude;
/** 核销有效日期 */
@Column(name = "valid_time",nullable = false)
@NotBlank
private String validTime;
@Column(name = "valid_time_start",nullable = false)
private Date validTimeStart;
@Column(name = "valid_time_end",nullable = false)
private Date validTimeEnd;
/** 每日营业开关时间 */
@Column(name = "day_time",nullable = false)
@NotBlank
private String dayTime;
@Column(name = "day_time_start",nullable = false)
private Date dayTimeStart;
@Column(name = "day_time_end",nullable = false)
private Date dayTimeEnd;
/** 添加时间 */
@Column(name = "add_time",nullable = false)
private Integer addTime;
/** 是否显示 */
@Column(name = "is_show",insertable = false)
private Integer isShow;
/** 是否删除 */
@Column(name = "is_del",insertable = false)
private Integer isDel;
public void copy(YxSystemStore source){
BeanUtil.copyProperties(source,this, CopyOptions.create().setIgnoreNullValue(true));
}
}

View File

@ -0,0 +1,12 @@
package co.yixiang.modules.shop.repository;
import co.yixiang.modules.shop.domain.YxSystemStore;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
/**
* @author hupeng
* @date 2020-03-03
*/
public interface YxSystemStoreRepository extends JpaRepository<YxSystemStore, Integer>, JpaSpecificationExecutor<YxSystemStore> {
}

View File

@ -0,0 +1,95 @@
package co.yixiang.modules.shop.rest;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import co.yixiang.aop.log.Log;
import co.yixiang.constant.ShopConstants;
import co.yixiang.exception.BadRequestException;
import co.yixiang.modules.shop.domain.YxSystemStore;
import co.yixiang.modules.shop.service.YxSystemStoreService;
import co.yixiang.modules.shop.service.dto.YxSystemStoreQueryCriteria;
import co.yixiang.utils.OrderUtil;
import co.yixiang.utils.RedisUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
* @author hupeng
* @date 2020-03-03
*/
@Api(tags = "门店管理")
@RestController
@RequestMapping("/api/yxSystemStore")
public class SystemStoreController {
private final YxSystemStoreService yxSystemStoreService;
public SystemStoreController(YxSystemStoreService yxSystemStoreService) {
this.yxSystemStoreService = yxSystemStoreService;
}
@Log("导出数据")
@ApiOperation("导出数据")
@GetMapping(value = "/download")
@PreAuthorize("@el.check('yxSystemStore:list')")
public void download(HttpServletResponse response, YxSystemStoreQueryCriteria criteria) throws IOException {
yxSystemStoreService.download(yxSystemStoreService.queryAll(criteria), response);
}
@GetMapping
@Log("查询门店")
@ApiOperation("查询门店")
@PreAuthorize("@el.check('yxSystemStore:list')")
public ResponseEntity<Object> getYxSystemStores(YxSystemStoreQueryCriteria criteria, Pageable pageable){
return new ResponseEntity<>(yxSystemStoreService.queryAll(criteria,pageable),HttpStatus.OK);
}
@PostMapping(value = "/getL")
@Log("获取经纬度")
@ApiOperation("获取经纬度")
@PreAuthorize("@el.check('yxSystemStore:getl')")
public ResponseEntity<Object> create(@Validated @RequestBody String jsonStr){
String key = RedisUtil.get("tengxun_map_key");
if(StrUtil.isBlank(key)) throw new BadRequestException("请先配置腾讯地图key");
JSONObject jsonObject = JSON.parseObject(jsonStr);
String addr = jsonObject.getString("addr");
String url = StrUtil.format("?address={}&key={}",addr,key);
String json = HttpUtil.get(ShopConstants.QQ_MAP_URL+url);
return new ResponseEntity<>(json,HttpStatus.CREATED);
}
@PutMapping
@Log("设置门店信息")
@ApiOperation("设置门店信息")
@PreAuthorize("@el.check('yxSystemStore:edit')")
public ResponseEntity<Object> update(@Validated @RequestBody YxSystemStore resources){
if(resources.getId() == null){
resources.setAddTime(OrderUtil.getSecondTimestampTwo());
yxSystemStoreService.create(resources);
}else{
yxSystemStoreService.update(resources);
}
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Log("删除门店")
@ApiOperation("删除门店")
@PreAuthorize("@el.check('yxSystemStore:del')")
@DeleteMapping
public ResponseEntity<Object> deleteAll(@RequestBody Integer[] ids) {
yxSystemStoreService.deleteAll(ids);
return new ResponseEntity<>(HttpStatus.OK);
}
}

View File

@ -0,0 +1,66 @@
package co.yixiang.modules.shop.service;
import co.yixiang.modules.shop.domain.YxSystemStore;
import co.yixiang.modules.shop.service.dto.YxSystemStoreDto;
import co.yixiang.modules.shop.service.dto.YxSystemStoreQueryCriteria;
import org.springframework.data.domain.Pageable;
import java.util.Map;
import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
/**
* @author hupeng
* @date 2020-03-03
*/
public interface YxSystemStoreService {
/**
* 查询数据分页
* @param criteria 条件
* @param pageable 分页参数
* @return Map<String,Object>
*/
Map<String,Object> queryAll(YxSystemStoreQueryCriteria criteria, Pageable pageable);
/**
* 查询所有数据不分页
* @param criteria 条件参数
* @return List<YxSystemStoreDto>
*/
List<YxSystemStoreDto> queryAll(YxSystemStoreQueryCriteria criteria);
/**
* 根据ID查询
* @param id ID
* @return YxSystemStoreDto
*/
YxSystemStoreDto findById(Integer id);
/**
* 创建
* @param resources /
* @return YxSystemStoreDto
*/
YxSystemStoreDto create(YxSystemStore resources);
/**
* 编辑
* @param resources /
*/
void update(YxSystemStore resources);
/**
* 多选删除
* @param ids /
*/
void deleteAll(Integer[] ids);
/**
* 导出数据
* @param all 待导出的数据
* @param response /
* @throws IOException /
*/
void download(List<YxSystemStoreDto> all, HttpServletResponse response) throws IOException;
}

View File

@ -0,0 +1,64 @@
package co.yixiang.modules.shop.service.dto;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
/**
* @author hupeng
* @date 2020-03-03
*/
@Data
public class YxSystemStoreDto implements Serializable {
private Integer id;
/** 门店名称 */
private String name;
/** 简介 */
private String introduction;
/** 手机号码 */
private String phone;
/** 省市区 */
private String address;
/** 详细地址 */
private String detailedAddress;
/** 门店logo */
private String image;
/** 纬度 */
private String latitude;
/** 经度 */
private String longitude;
/** 核销有效日期 */
private String validTime;
/** 每日营业开关时间 */
private String dayTime;
/** 添加时间 */
private Integer addTime;
/** 是否显示 */
private Integer isShow;
/** 是否删除 */
private Integer isDel;
private Date dayTimeStart;
private Date dayTimeEnd;
private Date validTimeStart;
private Date validTimeEnd;
}

View File

@ -0,0 +1,13 @@
package co.yixiang.modules.shop.service.dto;
import lombok.Data;
import java.util.List;
import co.yixiang.annotation.Query;
/**
* @author hupeng
* @date 2020-03-03
*/
@Data
public class YxSystemStoreQueryCriteria{
}

View File

@ -0,0 +1,115 @@
package co.yixiang.modules.shop.service.impl;
import co.yixiang.modules.shop.domain.YxSystemStore;
import co.yixiang.utils.ValidationUtil;
import co.yixiang.utils.FileUtil;
import co.yixiang.modules.shop.repository.YxSystemStoreRepository;
import co.yixiang.modules.shop.service.YxSystemStoreService;
import co.yixiang.modules.shop.service.dto.YxSystemStoreDto;
import co.yixiang.modules.shop.service.dto.YxSystemStoreQueryCriteria;
import co.yixiang.modules.shop.service.mapper.YxSystemStoreMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
// 默认不使用缓存
//import org.springframework.cache.annotation.CacheConfig;
//import org.springframework.cache.annotation.CacheEvict;
//import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import co.yixiang.utils.PageUtil;
import co.yixiang.utils.QueryHelp;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
/**
* @author hupeng
* @date 2020-03-03
*/
@Service
//@CacheConfig(cacheNames = "yxSystemStore")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class YxSystemStoreServiceImpl implements YxSystemStoreService {
private final YxSystemStoreRepository yxSystemStoreRepository;
private final YxSystemStoreMapper yxSystemStoreMapper;
public YxSystemStoreServiceImpl(YxSystemStoreRepository yxSystemStoreRepository, YxSystemStoreMapper yxSystemStoreMapper) {
this.yxSystemStoreRepository = yxSystemStoreRepository;
this.yxSystemStoreMapper = yxSystemStoreMapper;
}
@Override
//@Cacheable
public Map<String,Object> queryAll(YxSystemStoreQueryCriteria criteria, Pageable pageable){
Page<YxSystemStore> page = yxSystemStoreRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder),pageable);
return PageUtil.toPage(page.map(yxSystemStoreMapper::toDto));
}
@Override
//@Cacheable
public List<YxSystemStoreDto> queryAll(YxSystemStoreQueryCriteria criteria){
return yxSystemStoreMapper.toDto(yxSystemStoreRepository.findAll((root, criteriaQuery, criteriaBuilder) -> QueryHelp.getPredicate(root,criteria,criteriaBuilder)));
}
@Override
//@Cacheable(key = "#p0")
public YxSystemStoreDto findById(Integer id) {
YxSystemStore yxSystemStore = yxSystemStoreRepository.findById(id).orElseGet(YxSystemStore::new);
ValidationUtil.isNull(yxSystemStore.getId(),"YxSystemStore","id",id);
return yxSystemStoreMapper.toDto(yxSystemStore);
}
@Override
//@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public YxSystemStoreDto create(YxSystemStore resources) {
return yxSystemStoreMapper.toDto(yxSystemStoreRepository.save(resources));
}
@Override
//@CacheEvict(allEntries = true)
@Transactional(rollbackFor = Exception.class)
public void update(YxSystemStore resources) {
YxSystemStore yxSystemStore = yxSystemStoreRepository.findById(resources.getId()).orElseGet(YxSystemStore::new);
ValidationUtil.isNull( yxSystemStore.getId(),"YxSystemStore","id",resources.getId());
yxSystemStore.copy(resources);
yxSystemStoreRepository.save(yxSystemStore);
}
@Override
//@CacheEvict(allEntries = true)
public void deleteAll(Integer[] ids) {
for (Integer id : ids) {
yxSystemStoreRepository.deleteById(id);
}
}
@Override
public void download(List<YxSystemStoreDto> all, HttpServletResponse response) throws IOException {
List<Map<String, Object>> list = new ArrayList<>();
for (YxSystemStoreDto yxSystemStore : all) {
Map<String,Object> map = new LinkedHashMap<>();
map.put("门店名称", yxSystemStore.getName());
map.put("简介", yxSystemStore.getIntroduction());
map.put("手机号码", yxSystemStore.getPhone());
map.put("省市区", yxSystemStore.getAddress());
map.put("详细地址", yxSystemStore.getDetailedAddress());
map.put("门店logo", yxSystemStore.getImage());
map.put("纬度", yxSystemStore.getLatitude());
map.put("经度", yxSystemStore.getLongitude());
map.put("核销有效日期", yxSystemStore.getValidTime());
map.put("每日营业开关时间", yxSystemStore.getDayTime());
map.put("添加时间", yxSystemStore.getAddTime());
map.put("是否显示", yxSystemStore.getIsShow());
map.put("是否删除", yxSystemStore.getIsDel());
list.add(map);
}
FileUtil.downloadExcel(list, response);
}
}

View File

@ -0,0 +1,16 @@
package co.yixiang.modules.shop.service.mapper;
import co.yixiang.base.BaseMapper;
import co.yixiang.modules.shop.domain.YxSystemStore;
import co.yixiang.modules.shop.service.dto.YxSystemStoreDto;
import org.mapstruct.Mapper;
import org.mapstruct.ReportingPolicy;
/**
* @author hupeng
* @date 2020-03-03
*/
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface YxSystemStoreMapper extends BaseMapper<YxSystemStoreDto, YxSystemStore> {
}

View File

@ -6,7 +6,7 @@ spring:
driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy driverClassName: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
url: jdbc:log4jdbc:mysql://localhost:3306/yshop?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false url: jdbc:log4jdbc:mysql://localhost:3306/yshop?serverTimezone=Asia/Shanghai&characterEncoding=utf8&useSSL=false
username: yshop username: yshop
password: yshoP@2019#yx password:
# 初始化配置 # 初始化配置
initial-size: 3 initial-size: 3
@ -47,7 +47,7 @@ spring:
database: 0 database: 0
host: 127.0.0.1 host: 127.0.0.1
port: 6379 port: 6379
password: yshop2019@yxtw password:
#连接超时时间 #连接超时时间
timeout: 5000 timeout: 5000