diff --git a/.gitignore b/.gitignore index d05cdd4d..7dcfad05 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,5 @@ target build .idea .gradle +hiver-logs +hiver-admin/test-output/spark/ \ No newline at end of file diff --git a/hiver-modules/hiver-app/src/main/java/cc/hiver/app/dao/ShopDao.java b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/dao/ShopDao.java index 41ffd6b9..f8d03131 100644 --- a/hiver-modules/hiver-app/src/main/java/cc/hiver/app/dao/ShopDao.java +++ b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/dao/ShopDao.java @@ -22,6 +22,8 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; import org.springframework.lang.Nullable; +import java.util.List; + /** * @author cc */ @@ -33,5 +35,4 @@ public interface ShopDao extends HiverBaseDao { * @return */ Shop findByShopName(String shopName); - } diff --git a/hiver-modules/hiver-app/src/main/java/cc/hiver/app/dao/mapper/ShopMapper.java b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/dao/mapper/ShopMapper.java new file mode 100644 index 00000000..aae3119b --- /dev/null +++ b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/dao/mapper/ShopMapper.java @@ -0,0 +1,19 @@ +package cc.hiver.app.dao.mapper; + +import cc.hiver.app.entity.Shop; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Param; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Repository +public interface ShopMapper extends BaseMapper { + /** + * 通过用户ID获得管理的所有店铺 + * + * @param userId + * @return + */ + List findByUserId(@Param("userId") String userId); +} diff --git a/hiver-modules/hiver-app/src/main/java/cc/hiver/app/entity/Shop.java b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/entity/Shop.java index 654f5350..ee6261c1 100644 --- a/hiver-modules/hiver-app/src/main/java/cc/hiver/app/entity/Shop.java +++ b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/entity/Shop.java @@ -74,4 +74,6 @@ public class Shop extends HiverBaseEntity { @ApiModelProperty(value = "备注") private String remark; + @ApiModelProperty(value = "是否默认商铺") + private Integer defaulted; } diff --git a/hiver-modules/hiver-app/src/main/java/cc/hiver/app/entity/ShopUser.java b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/entity/ShopUser.java new file mode 100644 index 00000000..72f512c2 --- /dev/null +++ b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/entity/ShopUser.java @@ -0,0 +1,34 @@ +package cc.hiver.app.entity; + +import cc.hiver.core.base.HiverBaseEntity; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.DynamicUpdate; + +import javax.persistence.Entity; +import javax.persistence.Table; + +@Data +@Accessors(chain = true) +@Entity +@DynamicInsert +@DynamicUpdate +@Table(name = "t_shop_user") +@TableName("t_shop_user") +@ApiModel(value = "商铺对应用户表") +public class ShopUser extends HiverBaseEntity { + private static final long serialVersionUID = 1L; + + @ApiModelProperty(value = "用户id") + private String userId; + + @ApiModelProperty(value = "商铺id") + private String shopId; + + @ApiModelProperty(value = "类型 0表示店主 1表示店长 2表示店员") + private Integer type; +} diff --git a/hiver-modules/hiver-app/src/main/java/cc/hiver/app/service/mybatis/IShopService.java b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/service/mybatis/IShopService.java new file mode 100644 index 00000000..1540effc --- /dev/null +++ b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/service/mybatis/IShopService.java @@ -0,0 +1,17 @@ +package cc.hiver.app.service.mybatis; + +import cc.hiver.app.entity.Shop; +import com.baomidou.mybatisplus.extension.service.IService; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +public interface IShopService extends IService { + /** + * 通过用户ID获得管理的所有店铺 + * + * @param userId + * @return + */ + List findByUserId(@Param("userId") String userId); +} diff --git a/hiver-modules/hiver-app/src/main/java/cc/hiver/app/serviceimpl/mybatis/IShopServiceImpl.java b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/serviceimpl/mybatis/IShopServiceImpl.java new file mode 100644 index 00000000..2453c862 --- /dev/null +++ b/hiver-modules/hiver-app/src/main/java/cc/hiver/app/serviceimpl/mybatis/IShopServiceImpl.java @@ -0,0 +1,21 @@ +package cc.hiver.app.serviceimpl.mybatis; + +import cc.hiver.app.dao.mapper.ShopMapper; +import cc.hiver.app.entity.Shop; +import cc.hiver.app.service.mybatis.IShopService; +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class IShopServiceImpl extends ServiceImpl implements IShopService { + @Autowired + private ShopMapper shopMapper; + + @Override + public List findByUserId(String userId) { + return shopMapper.findByUserId(userId); + } +} diff --git a/hiver-modules/hiver-app/src/main/resources/mapper/ShopMapper.xml b/hiver-modules/hiver-app/src/main/resources/mapper/ShopMapper.xml new file mode 100644 index 00000000..ab230ae1 --- /dev/null +++ b/hiver-modules/hiver-app/src/main/resources/mapper/ShopMapper.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/hiver-modules/hiver-mall/pom.xml b/hiver-modules/hiver-mall/pom.xml index ce61ebe5..42e3d0a7 100644 --- a/hiver-modules/hiver-mall/pom.xml +++ b/hiver-modules/hiver-mall/pom.xml @@ -10,4 +10,12 @@ 4.0.0 商城模块 hiver-mall + + + + cc.hiver + hiver-app + 1.0-SNAPSHOT + + \ No newline at end of file diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/CommonController.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/CommonController.java new file mode 100644 index 00000000..7c475c58 --- /dev/null +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/controller/CommonController.java @@ -0,0 +1,60 @@ +package cc.hiver.mall.controller; + +import cc.hiver.app.entity.Shop; +import cc.hiver.app.service.mybatis.IShopService; +import cc.hiver.core.common.utils.ResultUtil; +import cc.hiver.core.common.utils.SecurityUtil; +import cc.hiver.core.common.vo.Result; +import cc.hiver.core.entity.User; +import cc.hiver.mall.pojo.vo.MallUserVo; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import java.util.List; + +@Slf4j +@RestController +@Api(tags = "微信小程序通用接口") +@RequestMapping(value = "/hiver/app/common/") +@Transactional +public class CommonController { + @Autowired + private IShopService shopService; + + @Autowired + private SecurityUtil securityUtil; + + @PersistenceContext + private EntityManager entityManager; + + @RequestMapping(value = "/userInfo", method = RequestMethod.GET) + @ApiOperation(value = "获取当前登录用户接口") + public Result getUserInfo() { + MallUserVo result = new MallUserVo(); + User u = securityUtil.getCurrUser(); + // 清除持久上下文环境 避免后面语句导致持久化 + entityManager.detach(u); + u.setPassword(null); + result.setUser(u); + result.setShops(shopService.findByUserId(u.getId())); + return new ResultUtil().setData(result); + } + + @RequestMapping(value = "/shops", method = RequestMethod.GET) + @ApiOperation(value = "获取当前登录用户对应的所有商铺") + public Result> getShopList() { + User u = securityUtil.getCurrUser(); + // 清除持久上下文环境 避免后面语句导致持久化 + entityManager.detach(u); + List result = shopService.findByUserId(u.getId()); + return new ResultUtil>().setData(result); + } +} diff --git a/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/MallUserVo.java b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/MallUserVo.java new file mode 100644 index 00000000..e8225320 --- /dev/null +++ b/hiver-modules/hiver-mall/src/main/java/cc/hiver/mall/pojo/vo/MallUserVo.java @@ -0,0 +1,22 @@ +package cc.hiver.mall.pojo.vo; + +import cc.hiver.app.entity.Shop; +import cc.hiver.core.entity.User; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.util.List; + +/** + * @author Yazhi Li + */ +@Data +@Accessors(chain = true) +public class MallUserVo { + @ApiModelProperty(value = "登录用户信息") + private User user; + + @ApiModelProperty(value = "用户所属店铺") + private List shops; +}