release: 新用户邀请获得积分

release-2024-08-08
huangyw 4 months ago
parent c6ef77b8de
commit eca7fad7fa

@ -41,5 +41,19 @@
<artifactId>jedis</artifactId>
<version>3.7.0</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
<version>1.4.2.Final</version> <!-- 替换为最新版本 -->
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.4.2.Final</version> <!-- 替换为最新版本 -->
<scope>provided</scope>
</dependency>
</dependencies>
</project>

@ -203,6 +203,23 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <!-- 替换为最新版本 -->
<configuration>
<source>1.8</source> <!-- 替换为你的Java版本 -->
<target>1.8</target> <!-- 替换为你的Java版本 -->
<annotationProcessorPaths>
<path>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct-processor</artifactId>
<version>1.4.2.Final</version> <!-- 替换为最新版本 -->
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -1,5 +1,6 @@
package com.luoo.user;
import com.luoo.user.listener.JPAEntityListener;
import com.spring4all.mongodb.EnableMongoPlus;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
@ -47,6 +48,10 @@ public class UserApplication {
env.getProperty("server.port"));
}
@Bean
public JPAEntityListener jpaEntityListener() {
return new JPAEntityListener();
}
@Bean
public IdWorker idWorkker(){
return new IdWorker(1, 1);
@ -66,4 +71,5 @@ public class UserApplication {
public RedisLockUtil redisLockUtil() {
return new RedisLockUtil();
}
}

@ -0,0 +1,71 @@
package com.luoo.user.config;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.luoo.user.listener.JPAEntityListener;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Where;
import org.springframework.format.annotation.DateTimeFormat;
import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* @program: luoo_parent
* @description: jpa
* @author: yawei.huang
* @create: 2024-08-08 13:29
**/
@Getter
@Setter
@MappedSuperclass
@EntityListeners(JPAEntityListener.class)
public abstract class JPABasePojo implements Serializable {
private static final long serialVersionUID = -4451172429717455614L;
@Id
@Column(name = "id", nullable = false)
@ApiModelProperty(value = "id")
private String id;
@Size(max = 20)
@Column(name = "create_user", length = 20, updatable = false)
@ApiModelProperty(value = "创建人")
private String createUser;
@Size(max = 20)
@Column(name = "update_user", length = 20)
@ApiModelProperty(value = "更新人")
private String updateUser;
@Column(name = "create_user_name", updatable = false)
@ApiModelProperty(value = "创建人姓名")
private String createUserName;
@Column(name = "update_user_name")
@ApiModelProperty(value = "更新人姓名")
private String updateUserName;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@ApiModelProperty("创建时间")
@Column(name = "create_time", updatable = false)
private LocalDateTime createTime;
@ApiModelProperty("修改时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime updateTime;
@Column(name = "del_flag")
@ApiModelProperty(value = "是否删除 0-未删除 2-已删除")
private Integer delFlag;
}

@ -0,0 +1,68 @@
package com.luoo.user.controller;
import annotation.GlobalInterceptor;
import api.Result;
import com.luoo.user.dto.store.StoreAddDto;
import com.luoo.user.dto.store.StoreUpdateDto;
import com.luoo.user.pojo.Store;
import com.luoo.user.service.StoreService;
import io.swagger.annotations.Api;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
/**
* @program: luoo_parent
* @description:
* @author: yawei.huang
* @create: 2024-08-08 14:28
**/
@Api(tags = "门店模块")
@RestController
@CrossOrigin
@RequestMapping("/store")
public class StoreController {
@Autowired
private StoreService storeService;
@RequestMapping("/list")
@GlobalInterceptor(checkAdminLogin = true)
public Result<List<Store>> getStoreList() {
return Result.success(storeService.findAll());
}
@RequestMapping("/get")
public Result<Store> getStore(String id) {
return Result.success(storeService.getOne(id));
}
@RequestMapping("/add")
@GlobalInterceptor(checkAdminLogin = true)
public Result<Void> addStore(StoreAddDto storeAddDto) {
Store store = new Store();
BeanUtils.copyProperties(storeAddDto, store);
storeService.add(store);
return Result.success();
}
@RequestMapping("/update")
@GlobalInterceptor(checkAdminLogin = true)
public Result<Void> updateStore(StoreUpdateDto storeUpdateDto) {
storeService.update(storeUpdateDto);
return Result.success();
}
@RequestMapping("/delete")
@GlobalInterceptor(checkAdminLogin = true)
public Result<Void> deleteStore(String id) {
storeService.delete(id);
return Result.success();
}
}

@ -0,0 +1,9 @@
package com.luoo.user.dao;
import com.luoo.user.pojo.Store;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
public interface StoreDao extends JpaRepository<Store, String> , JpaSpecificationExecutor<Store> {
}

@ -0,0 +1,57 @@
package com.luoo.user.dto.store;
import io.swagger.annotations.ApiModelProperty;
import lombok.Value;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.validation.constraints.Size;
import java.io.Serializable;
/**
* DTO for {@link com.luoo.user.pojo.Store}
*/
@Value
public class StoreAddDto implements Serializable {
private static final long serialVersionUID = -7780230858811570880L;
@ApiModelProperty(value = "门店名称")
String name;
@ApiModelProperty(value = "区域id")
Integer regionId;
@ApiModelProperty(value = "门店地址")
String address;
@ApiModelProperty(value = "经度")
String lng;
@ApiModelProperty(value = "纬度")
String lat;
@ApiModelProperty(value = "门店联系人")
String contact;
@Column(name = "phone")
@ApiModelProperty(value = "门店电话")
String phone;
@Column(name = "tel")
@ApiModelProperty(value = "门店电话")
String tel;
@Column(name = "opening_hours")
@ApiModelProperty(value = "营业时间")
String openingHours;
@Column(name = "background")
@ApiModelProperty(value = "门店背景图")
String background;
@ApiModelProperty(value = "门店介绍")
String description;
}

@ -0,0 +1,56 @@
package com.luoo.user.dto.store;
import io.swagger.annotations.ApiModelProperty;
import lombok.Value;
import javax.persistence.Column;
import java.io.Serializable;
/**
* DTO for {@link com.luoo.user.pojo.Store}
*/
@Value
public class StoreSearchDto implements Serializable {
private static final long serialVersionUID = -4348467275178028461L;
@ApiModelProperty(value = "id")
String id;
@ApiModelProperty(value = "门店名称")
String name;
@ApiModelProperty(value = "区域id")
Integer regionId;
@ApiModelProperty(value = "门店地址")
String address;
@ApiModelProperty(value = "经度")
String lng;
@ApiModelProperty(value = "纬度")
String lat;
@ApiModelProperty(value = "门店联系人")
String contact;
@Column(name = "phone")
@ApiModelProperty(value = "门店电话")
String phone;
@Column(name = "tel")
@ApiModelProperty(value = "门店电话")
String tel;
@Column(name = "opening_hours")
@ApiModelProperty(value = "营业时间")
String openingHours;
@Column(name = "background")
@ApiModelProperty(value = "门店背景图")
String background;
@ApiModelProperty(value = "门店介绍")
String description;
}

@ -0,0 +1,57 @@
package com.luoo.user.dto.store;
import io.swagger.annotations.ApiModelProperty;
import lombok.Value;
import javax.persistence.Column;
import javax.persistence.Id;
import java.io.Serializable;
/**
* DTO for {@link com.luoo.user.pojo.Store}
*/
@Value
public class StoreUpdateDto implements Serializable {
private static final long serialVersionUID = -4348467275178028461L;
@ApiModelProperty(value = "id")
String id;
@ApiModelProperty(value = "门店名称")
String name;
@ApiModelProperty(value = "区域id")
Integer regionId;
@ApiModelProperty(value = "门店地址")
String address;
@ApiModelProperty(value = "经度")
String lng;
@ApiModelProperty(value = "纬度")
String lat;
@ApiModelProperty(value = "门店联系人")
String contact;
@Column(name = "phone")
@ApiModelProperty(value = "门店电话")
String phone;
@Column(name = "tel")
@ApiModelProperty(value = "门店电话")
String tel;
@Column(name = "opening_hours")
@ApiModelProperty(value = "营业时间")
String openingHours;
@Column(name = "background")
@ApiModelProperty(value = "门店背景图")
String background;
@ApiModelProperty(value = "门店介绍")
String description;
}

@ -0,0 +1,77 @@
package com.luoo.user.listener;
import com.luoo.user.config.JPABasePojo;
import dto.UserLoginDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.stereotype.Component;
import util.IdWorker;
import util.JwtUtil;
import javax.annotation.PostConstruct;
import javax.persistence.PrePersist;
import javax.persistence.PreRemove;
import javax.persistence.PreUpdate;
import java.time.LocalDateTime;
/**
* @program: luoo_parent
* @description: jpa
* @author: yawei.huang
* @create: 2024-08-08 13:35
**/
@Configurable
@Slf4j
public class JPAEntityListener {
private static JwtUtil jwtUtilStatic;
private static IdWorker idWorkerStatic;
@Autowired
private JwtUtil jwtUtil;
@Autowired
private IdWorker idWorker;
@PostConstruct
public void init() {
jwtUtilStatic = this.jwtUtil;
idWorkerStatic = this.idWorker;
}
@PrePersist
public void setCreatedOn(JPABasePojo jpaBasePojo) {
log.info("Setting created on {}", jpaBasePojo);
jpaBasePojo.setCreateUser(getCurrentUser().getUserId());
jpaBasePojo.setUpdateUser(getCurrentUser().getUserId());
jpaBasePojo.setCreateUserName(getCurrentUser().getNickName());
jpaBasePojo.setUpdateUserName(getCurrentUser().getNickName());
jpaBasePojo.setCreateTime(LocalDateTime.now());
jpaBasePojo.setUpdateTime(LocalDateTime.now());
jpaBasePojo.setId(String.valueOf(idWorkerStatic.nextId()));
jpaBasePojo.setDelFlag(0); // 默认未删除
}
@PreUpdate
public void setUpdatedOn(JPABasePojo jpaBasePojo) {
log.info("Setting updated on {}", jpaBasePojo);
jpaBasePojo.setUpdateUser(getCurrentUser().getUserId());
jpaBasePojo.setUpdateUserName(getCurrentUser().getNickName());
jpaBasePojo.setUpdateTime(LocalDateTime.now());
}
@PreRemove
public void setDeletedOn(JPABasePojo jpaBasePojo) {
log.info("Setting deleted on {}", jpaBasePojo);
jpaBasePojo.setUpdateUser(getCurrentUser().getUserId());
jpaBasePojo.setUpdateUserName(getCurrentUser().getNickName());
jpaBasePojo.setUpdateTime(LocalDateTime.now());
jpaBasePojo.setDelFlag(2); // 默认已删除
}
private UserLoginDto getCurrentUser() {
return jwtUtilStatic.getUser();
}
}

@ -0,0 +1,11 @@
package com.luoo.user.mapstruct;
import com.luoo.user.dto.store.StoreUpdateDto;
import com.luoo.user.pojo.Store;
import org.mapstruct.*;
@Mapper(componentModel = "spring")
public interface StoreMapper {
void updateStoreFromDto(StoreUpdateDto dto, @MappingTarget Store entity);
}

@ -0,0 +1,79 @@
package com.luoo.user.pojo;
import com.luoo.user.config.JPABasePojo;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Where;
import javax.persistence.*;
import javax.validation.constraints.Size;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
@DynamicUpdate
@Where(clause = "del_flag = 0")
@Table(name = "tb_store")
public class Store extends JPABasePojo {
private static final long serialVersionUID = 1257837134734167416L;
@Size(max = 255)
@Column(name = "name")
@ApiModelProperty(value = "门店名称")
private String name;
@Column(name = "region_id")
@ApiModelProperty(value = "区域id")
private Integer regionId;
@Size(max = 255)
@Column(name = "address")
@ApiModelProperty(value = "门店地址")
private String address;
@Size(max = 100)
@Column(name = "lng", length = 100)
@ApiModelProperty(value = "经度")
private String lng;
@Size(max = 100)
@Column(name = "lat", length = 100)
@ApiModelProperty(value = "纬度")
private String lat;
@Size(max = 255)
@Column(name = "contact")
@ApiModelProperty(value = "门店联系人")
private String contact;
@Size(max = 255)
@Column(name = "phone")
@ApiModelProperty(value = "门店电话")
private String phone;
@Size(max = 255)
@Column(name = "tel")
@ApiModelProperty(value = "门店电话")
private String tel;
@Size(max = 255)
@Column(name = "opening_hours")
@ApiModelProperty(value = "营业时间")
private String openingHours;
@Size(max = 255)
@Column(name = "background")
@ApiModelProperty(value = "门店背景图")
private String background;
@Lob
@Column(name = "description")
@ApiModelProperty(value = "门店介绍")
private String description;
}

@ -0,0 +1,64 @@
package com.luoo.user.service;
import com.luoo.user.dao.StoreDao;
import com.luoo.user.dto.store.StoreUpdateDto;
import com.luoo.user.mapstruct.StoreMapper;
import com.luoo.user.pojo.Store;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import util.IdWorker;
import java.util.List;
/**
* @program: luoo_parent
* @description:
* @author: yawei.huang
* @create: 2024-08-08 14:20
**/
@Service
@Slf4j
public class StoreService {
private final StoreDao storeDao;
private final StoreMapper storeMapper;
public StoreService(StoreDao storeDao, StoreMapper storeMapper) {
this.storeDao = storeDao;
this.storeMapper = storeMapper;
}
// 增删改查
@Transactional(rollbackFor = Exception.class)
public void add(Store store) {
storeDao.save(store);
}
@Transactional(rollbackFor = Exception.class)
public void delete(String id) {
Store store = storeDao.findById(id).orElse(null);
store.setDelFlag(2);
storeDao.save(store);
}
@Transactional(rollbackFor = Exception.class)
public void update(StoreUpdateDto storeUpdateDto) {
Store oldStore = storeDao.findById(storeUpdateDto.getId()).orElseThrow(() -> new RuntimeException("Store not found"));
storeMapper.updateStoreFromDto(storeUpdateDto, oldStore);
storeDao.save(oldStore);
}
public Store getOne(String id) {
return storeDao.findById(id).orElse(null);
}
// 列表页
public List<Store> findAll() {
return storeDao.findAll();
}
}

@ -0,0 +1,57 @@
package com.luoo.user.vo.store;
import io.swagger.annotations.ApiModelProperty;
import lombok.Value;
import javax.persistence.Column;
import javax.validation.constraints.Size;
import java.io.Serializable;
/**
* DTO for {@link com.luoo.user.pojo.Store}
*/
@Value
public class StoreAppVO implements Serializable {
private static final long serialVersionUID = -8286907101582384522L;
@ApiModelProperty(value = "id")
String id;
@ApiModelProperty(value = "门店名称")
String name;
@ApiModelProperty(value = "区域id")
Integer regionId;
@ApiModelProperty(value = "门店地址")
String address;
@ApiModelProperty(value = "经度")
String lng;
@ApiModelProperty(value = "纬度")
String lat;
@ApiModelProperty(value = "门店联系人")
String contact;
@Column(name = "phone")
@ApiModelProperty(value = "门店电话")
String phone;
@Column(name = "tel")
@ApiModelProperty(value = "门店电话")
String tel;
@Column(name = "opening_hours")
@ApiModelProperty(value = "营业时间")
String openingHours;
@Column(name = "background")
@ApiModelProperty(value = "门店背景图")
String background;
@ApiModelProperty(value = "门店介绍")
String description;
}
Loading…
Cancel
Save