11 changed files with 198 additions and 1 deletions
@ -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<Shop> { |
||||
|
/** |
||||
|
* 通过用户ID获得管理的所有店铺 |
||||
|
* |
||||
|
* @param userId |
||||
|
* @return |
||||
|
*/ |
||||
|
List<Shop> findByUserId(@Param("userId") String userId); |
||||
|
} |
||||
@ -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; |
||||
|
} |
||||
@ -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<Shop> { |
||||
|
/** |
||||
|
* 通过用户ID获得管理的所有店铺 |
||||
|
* |
||||
|
* @param userId |
||||
|
* @return |
||||
|
*/ |
||||
|
List<Shop> findByUserId(@Param("userId") String userId); |
||||
|
} |
||||
@ -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<ShopMapper, Shop> implements IShopService { |
||||
|
@Autowired |
||||
|
private ShopMapper shopMapper; |
||||
|
|
||||
|
@Override |
||||
|
public List<Shop> findByUserId(String userId) { |
||||
|
return shopMapper.findByUserId(userId); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,11 @@ |
|||||
|
<?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="cc.hiver.app.dao.mapper.ShopMapper"> |
||||
|
<select id="findByUserId" resultType="cc.hiver.app.entity.Shop"> |
||||
|
SELECT DISTINCT m.* |
||||
|
FROM t_shop m |
||||
|
LEFT JOIN t_shop_user um ON m.id = um.shop_id |
||||
|
WHERE um.user_id = #{userId} AND m.status = 0 |
||||
|
ORDER BY m.defaulted DESC |
||||
|
</select> |
||||
|
</mapper> |
||||
@ -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<MallUserVo> 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<MallUserVo>().setData(result); |
||||
|
} |
||||
|
|
||||
|
@RequestMapping(value = "/shops", method = RequestMethod.GET) |
||||
|
@ApiOperation(value = "获取当前登录用户对应的所有商铺") |
||||
|
public Result<List<Shop>> getShopList() { |
||||
|
User u = securityUtil.getCurrUser(); |
||||
|
// 清除持久上下文环境 避免后面语句导致持久化
|
||||
|
entityManager.detach(u); |
||||
|
List<Shop> result = shopService.findByUserId(u.getId()); |
||||
|
return new ResultUtil<List<Shop>>().setData(result); |
||||
|
} |
||||
|
} |
||||
@ -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<Shop> shops; |
||||
|
} |
||||
Loading…
Reference in new issue