17 changed files with 496 additions and 0 deletions
@ -0,0 +1,45 @@ |
|||||
|
package com.ccsens.yanyuan.api; |
||||
|
|
||||
|
import com.ccsens.cloudutil.annotation.MustLogin; |
||||
|
import com.ccsens.util.JsonResponse; |
||||
|
import com.ccsens.util.bean.dto.QueryDto; |
||||
|
import com.ccsens.yanyuan.bean.dto.ToolDto; |
||||
|
import com.ccsens.yanyuan.bean.po.Tool; |
||||
|
import com.ccsens.yanyuan.bean.vo.ToolVo; |
||||
|
import com.ccsens.yanyuan.bean.vo.UserPowerVo; |
||||
|
import com.ccsens.yanyuan.service.IToolService; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import io.swagger.annotations.ApiParam; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.validation.annotation.Validated; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestMethod; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
|
||||
|
/** |
||||
|
* @author AUSU |
||||
|
*/ |
||||
|
@Api(tags = "工具箱" , description = "工具箱相关接口 | ") |
||||
|
@Slf4j |
||||
|
@RestController |
||||
|
@RequestMapping(value = "/tool") |
||||
|
public class ToolController { |
||||
|
|
||||
|
@Resource |
||||
|
private IToolService toolService; |
||||
|
|
||||
|
@MustLogin |
||||
|
@ApiOperation(value = "绑定工具箱", notes = "绑定工具箱") |
||||
|
@RequestMapping(value = "/bind", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) |
||||
|
public JsonResponse<ToolVo.BindTool> bindTool(@ApiParam @Validated @RequestBody QueryDto<ToolDto.BindTool> params) throws Exception{ |
||||
|
log.info("绑定工具箱:{}",params); |
||||
|
ToolVo.BindTool bindTool = toolService.bindTool(params.getParam(),params.getUserId()); |
||||
|
log.info("绑定工具箱结束{}",bindTool); |
||||
|
return JsonResponse.newInstance().ok(bindTool); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,45 @@ |
|||||
|
package com.ccsens.yanyuan.api; |
||||
|
|
||||
|
import com.ccsens.cloudutil.annotation.MustLogin; |
||||
|
import com.ccsens.common.bean.vo.CProjectVo; |
||||
|
import com.ccsens.util.JsonResponse; |
||||
|
import com.ccsens.util.bean.dto.QueryDto; |
||||
|
import com.ccsens.yanyuan.bean.dto.ProjectDto; |
||||
|
import com.ccsens.yanyuan.bean.vo.ProjectVo; |
||||
|
import com.ccsens.yanyuan.bean.vo.UserPowerVo; |
||||
|
import com.ccsens.yanyuan.service.IUserPowerService; |
||||
|
import io.swagger.annotations.Api; |
||||
|
import io.swagger.annotations.ApiOperation; |
||||
|
import io.swagger.annotations.ApiParam; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.validation.annotation.Validated; |
||||
|
import org.springframework.web.bind.annotation.RequestBody; |
||||
|
import org.springframework.web.bind.annotation.RequestMapping; |
||||
|
import org.springframework.web.bind.annotation.RequestMethod; |
||||
|
import org.springframework.web.bind.annotation.RestController; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
|
||||
|
/** |
||||
|
* @author AUSU |
||||
|
*/ |
||||
|
@Api(tags = "用户身份" , description = "UserPowerController | ") |
||||
|
@Slf4j |
||||
|
@RestController |
||||
|
@RequestMapping("/userPower") |
||||
|
public class UserPowerController { |
||||
|
|
||||
|
@Resource |
||||
|
private IUserPowerService userPowerService; |
||||
|
|
||||
|
@MustLogin |
||||
|
@ApiOperation(value = "用户身份判断", notes = "用户身份判断") |
||||
|
@RequestMapping(value = "/identity", method = RequestMethod.POST, produces = {"application/json;charset=UTF-8"}) |
||||
|
public JsonResponse<UserPowerVo.UserType> findIdentity(@ApiParam @Validated @RequestBody QueryDto params) throws Exception{ |
||||
|
log.info("用户身份判断{}",params); |
||||
|
UserPowerVo.UserType userType = userPowerService.findIdentity(params.getUserId()); |
||||
|
log.info("用户身份判断结束{}",userType); |
||||
|
return JsonResponse.newInstance().ok(userType); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
package com.ccsens.yanyuan.bean.dto; |
||||
|
|
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import javax.validation.constraints.NotBlank; |
||||
|
|
||||
|
public class ToolDto { |
||||
|
|
||||
|
@Data |
||||
|
@ApiModel("绑定工具箱-入参") |
||||
|
public static class BindTool { |
||||
|
@NotBlank |
||||
|
@ApiModelProperty("工具箱code码") |
||||
|
private String toolCode; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,17 @@ |
|||||
|
package com.ccsens.yanyuan.bean.dto; |
||||
|
|
||||
|
import com.ccsens.common.bean.dto.CTaskDto; |
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* @author AUSU |
||||
|
*/ |
||||
|
@Data |
||||
|
public class UserPowerDto { |
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
@ -0,0 +1,40 @@ |
|||||
|
package com.ccsens.yanyuan.bean.vo; |
||||
|
|
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
public class ToolVo { |
||||
|
|
||||
|
@Data |
||||
|
@ApiModel("绑定工具箱-返参") |
||||
|
public static class BindTool{ |
||||
|
@ApiModelProperty("是否绑定") |
||||
|
private Byte isBind; |
||||
|
@ApiModelProperty("用户类型(0:普通用户 1:企业用户)") |
||||
|
private Byte isCompany; |
||||
|
@ApiModelProperty("绑定者是否自己") |
||||
|
private Byte isMine; |
||||
|
@ApiModelProperty("是否满员") |
||||
|
private Byte isMax; |
||||
|
@ApiModelProperty("是否有体验用户") |
||||
|
private Byte isUx; |
||||
|
@ApiModelProperty("体验用户信息") |
||||
|
private List<UxUserInfo> uxUserInfo; |
||||
|
} |
||||
|
|
||||
|
@Data |
||||
|
@ApiModel("体验用户信息-返参") |
||||
|
public static class UxUserInfo{ |
||||
|
@ApiModelProperty("体验者用户实际id") |
||||
|
private Long keyId; |
||||
|
@ApiModelProperty("用户类型(0:体验用户 1:正式用户')") |
||||
|
private Byte useLevel; |
||||
|
@ApiModelProperty("用户名称") |
||||
|
private String userName; |
||||
|
@ApiModelProperty("性别(0-未知,1-男,2-女)") |
||||
|
private Byte sex; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,21 @@ |
|||||
|
package com.ccsens.yanyuan.bean.vo; |
||||
|
|
||||
|
import com.ccsens.common.bean.vo.CTaskVo; |
||||
|
import io.swagger.annotations.ApiModel; |
||||
|
import io.swagger.annotations.ApiModelProperty; |
||||
|
import lombok.Data; |
||||
|
|
||||
|
/** |
||||
|
* @author AUSU |
||||
|
*/ |
||||
|
@Data |
||||
|
public class UserPowerVo { |
||||
|
|
||||
|
@Data |
||||
|
@ApiModel("任务信息") |
||||
|
public static class UserType{ |
||||
|
@ApiModelProperty("用户类型(0:普通用户 1:企业用户)") |
||||
|
private Byte type; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
package com.ccsens.yanyuan.persist.dao; |
||||
|
|
||||
|
import com.ccsens.yanyuan.bean.po.Tool; |
||||
|
import com.ccsens.yanyuan.persist.mapper.ToolMapper; |
||||
|
import org.apache.ibatis.annotations.Param; |
||||
|
import org.springframework.stereotype.Repository; |
||||
|
|
||||
|
/** |
||||
|
* @author AUSU |
||||
|
*/ |
||||
|
@Repository |
||||
|
public interface ToolDao extends ToolMapper { |
||||
|
|
||||
|
/** |
||||
|
* 根据工具箱code查询工具箱信息 |
||||
|
* @param toolCode 工具箱code |
||||
|
* @return 工具箱信息 |
||||
|
*/ |
||||
|
Tool queryByCode(@Param("toolCode") String toolCode); |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
package com.ccsens.yanyuan.persist.dao; |
||||
|
|
||||
|
import org.apache.ibatis.annotations.Param; |
||||
|
import org.springframework.stereotype.Repository; |
||||
|
|
||||
|
/** |
||||
|
* @author AUSU |
||||
|
*/ |
||||
|
@Repository |
||||
|
public interface UserPowerDao { |
||||
|
|
||||
|
/** |
||||
|
* 查询用户身份 |
||||
|
* @param userId 用户id |
||||
|
* @return 是否企业用户 |
||||
|
*/ |
||||
|
Integer findIdentity(@Param("userId") Long userId); |
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
package com.ccsens.yanyuan.persist.dao; |
||||
|
|
||||
|
import com.ccsens.yanyuan.bean.vo.ToolVo; |
||||
|
import com.ccsens.yanyuan.persist.mapper.UserRelationMapper; |
||||
|
import org.apache.ibatis.annotations.Param; |
||||
|
import org.springframework.stereotype.Repository; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
/** |
||||
|
* @author AUSU |
||||
|
*/ |
||||
|
@Repository |
||||
|
public interface UserRelationDao extends UserRelationMapper { |
||||
|
/** |
||||
|
* 查询是否满员 |
||||
|
* @param userId 用户id |
||||
|
* @return 是否满员(0否,1是) |
||||
|
*/ |
||||
|
Byte queryIsMax(@Param("userId") Long userId); |
||||
|
|
||||
|
/** |
||||
|
* 查询绑定人下的体验用户 |
||||
|
* @param userId 用户id |
||||
|
* @return 体验用户列表 |
||||
|
*/ |
||||
|
List<ToolVo.UxUserInfo> queryUxUser(@Param("userId") Long userId); |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
package com.ccsens.yanyuan.service; |
||||
|
|
||||
|
import com.ccsens.yanyuan.bean.dto.ToolDto; |
||||
|
import com.ccsens.yanyuan.bean.vo.ToolVo; |
||||
|
|
||||
|
public interface IToolService { |
||||
|
|
||||
|
/** |
||||
|
* 绑定工具箱 |
||||
|
* @param param 工具箱code |
||||
|
* @param userId 用户id |
||||
|
* @return 工具箱绑定信息 |
||||
|
*/ |
||||
|
ToolVo.BindTool bindTool(ToolDto.BindTool param, Long userId); |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
package com.ccsens.yanyuan.service; |
||||
|
|
||||
|
import com.ccsens.yanyuan.bean.vo.UserPowerVo; |
||||
|
|
||||
|
/** |
||||
|
* @author AUSU |
||||
|
*/ |
||||
|
public interface IUserPowerService { |
||||
|
|
||||
|
/** |
||||
|
* 用户身份判断 |
||||
|
* @param userId 用户id |
||||
|
* @return 是否企业用户 |
||||
|
*/ |
||||
|
UserPowerVo.UserType findIdentity(Long userId); |
||||
|
} |
||||
@ -0,0 +1,103 @@ |
|||||
|
package com.ccsens.yanyuan.service; |
||||
|
|
||||
|
import cn.hutool.core.bean.BeanUtil; |
||||
|
import cn.hutool.core.collection.CollectionUtil; |
||||
|
import cn.hutool.core.util.ObjectUtil; |
||||
|
import com.ccsens.cloudutil.feign.Tall3FeignClient; |
||||
|
import com.ccsens.util.exception.BaseException; |
||||
|
import com.ccsens.yanyuan.bean.dto.ToolDto; |
||||
|
import com.ccsens.yanyuan.bean.po.Tool; |
||||
|
import com.ccsens.yanyuan.bean.vo.ToolVo; |
||||
|
import com.ccsens.yanyuan.bean.vo.UserPowerVo; |
||||
|
import com.ccsens.yanyuan.persist.dao.ToolDao; |
||||
|
import com.ccsens.yanyuan.persist.dao.UserRelationDao; |
||||
|
import com.ccsens.yanyuan.util.BasicsCodeError; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Propagation; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
import java.util.List; |
||||
|
|
||||
|
@Slf4j |
||||
|
@Service |
||||
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) |
||||
|
public class ToolService implements IToolService { |
||||
|
|
||||
|
|
||||
|
@Resource |
||||
|
private ToolDao toolDao; |
||||
|
@Resource |
||||
|
private UserRelationDao userRelationDao; |
||||
|
@Resource |
||||
|
private IUserPowerService userPowerService; |
||||
|
@Resource |
||||
|
private Tall3FeignClient tall3FeignClient; |
||||
|
|
||||
|
@Override |
||||
|
public ToolVo.BindTool bindTool(ToolDto.BindTool param, Long userId) { |
||||
|
ToolVo.BindTool bindTool = new ToolVo.BindTool(); |
||||
|
//查询是否已经绑定
|
||||
|
Tool tool = toolDao.queryByCode(param.getToolCode()); |
||||
|
if (ObjectUtil.isNotNull(tool)) { |
||||
|
if (ObjectUtil.isNotNull(tool.getUserId())) { |
||||
|
//绑定人是否自己
|
||||
|
if (tool.getUserId().equals(userId)) { |
||||
|
return setMyToolInfo(userId); |
||||
|
}else { |
||||
|
bindTool.setIsBind((byte) 1); |
||||
|
bindTool.setIsMine((byte) 0); |
||||
|
return bindTool; |
||||
|
} |
||||
|
}else { |
||||
|
//工具箱未绑定用户
|
||||
|
Tool newTool = new Tool(); |
||||
|
BeanUtil.copyProperties(tool,newTool); |
||||
|
newTool.setUserId(userId); |
||||
|
toolDao.updateByPrimaryKeySelective(newTool); |
||||
|
return setMyToolInfo(userId); |
||||
|
} |
||||
|
}else { |
||||
|
throw new BaseException(BasicsCodeError.TOOL_NOT_FOUND_ERROR); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
private ToolVo.BindTool setMyToolInfo(Long userId) { |
||||
|
ToolVo.BindTool bindTool = new ToolVo.BindTool(); |
||||
|
bindTool.setIsMine((byte) 1); |
||||
|
//是否公司用户
|
||||
|
UserPowerVo.UserType identity = userPowerService.findIdentity(userId); |
||||
|
if (1 == identity.getType()) { |
||||
|
bindTool.setIsBind((byte) 1); |
||||
|
bindTool.setIsCompany((byte) 1); |
||||
|
return bindTool; |
||||
|
} |
||||
|
//普通用户
|
||||
|
Byte isMax = userRelationDao.queryIsMax(userId); |
||||
|
//工具箱 == 老人数
|
||||
|
if (1 == isMax) { |
||||
|
bindTool.setIsBind((byte) 1); |
||||
|
bindTool.setIsCompany((byte) 0); |
||||
|
bindTool.setIsMax(isMax); |
||||
|
return bindTool; |
||||
|
} |
||||
|
//查询体验用户
|
||||
|
List<ToolVo.UxUserInfo> uxUserInfoList = userRelationDao.queryUxUser(userId); |
||||
|
if (CollectionUtil.isEmpty(uxUserInfoList)) { |
||||
|
bindTool.setIsBind((byte) 1); |
||||
|
bindTool.setIsCompany((byte) 0); |
||||
|
bindTool.setIsMax(isMax); |
||||
|
bindTool.setIsUx((byte) 0); |
||||
|
return bindTool; |
||||
|
} |
||||
|
bindTool.setIsBind((byte) 1); |
||||
|
bindTool.setIsCompany((byte) 0); |
||||
|
bindTool.setIsMax(isMax); |
||||
|
bindTool.setIsUx((byte) 1); |
||||
|
bindTool.setUxUserInfo(uxUserInfoList); |
||||
|
return bindTool; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,32 @@ |
|||||
|
package com.ccsens.yanyuan.service; |
||||
|
|
||||
|
import com.ccsens.yanyuan.bean.vo.UserPowerVo; |
||||
|
import com.ccsens.yanyuan.persist.dao.UserPowerDao; |
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.springframework.transaction.annotation.Propagation; |
||||
|
import org.springframework.transaction.annotation.Transactional; |
||||
|
|
||||
|
import javax.annotation.Resource; |
||||
|
|
||||
|
@Slf4j |
||||
|
@Service |
||||
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class) |
||||
|
public class UserPowerService implements IUserPowerService{ |
||||
|
|
||||
|
@Resource |
||||
|
private UserPowerDao userPowerDao; |
||||
|
|
||||
|
@Override |
||||
|
public UserPowerVo.UserType findIdentity(Long userId) { |
||||
|
UserPowerVo.UserType userType = new UserPowerVo.UserType(); |
||||
|
Integer identity = userPowerDao.findIdentity(userId); |
||||
|
if (identity < 1) { |
||||
|
userType.setType((byte) 0); |
||||
|
}else { |
||||
|
userType.setType((byte) 1); |
||||
|
} |
||||
|
return userType; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,19 @@ |
|||||
|
<?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.ccsens.yanyuan.persist.dao.ToolDao"> |
||||
|
|
||||
|
<select id="queryByCode" resultType="com.ccsens.yanyuan.bean.po.Tool"> |
||||
|
SELECT |
||||
|
id, |
||||
|
`code`, |
||||
|
`name`, |
||||
|
description, |
||||
|
user_id |
||||
|
FROM |
||||
|
t_tool |
||||
|
WHERE |
||||
|
rec_status = 0 |
||||
|
AND `code` = #{toolCode} |
||||
|
</select> |
||||
|
|
||||
|
</mapper> |
||||
@ -0,0 +1,16 @@ |
|||||
|
<?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.ccsens.yanyuan.persist.dao.UserPowerDao"> |
||||
|
|
||||
|
<select id="findIdentity" resultType="java.lang.Integer"> |
||||
|
SELECT |
||||
|
COUNT(id) |
||||
|
FROM |
||||
|
u_user_type |
||||
|
WHERE |
||||
|
rec_status = 0 |
||||
|
AND type = 1 |
||||
|
AND user_id = #{userId} |
||||
|
</select> |
||||
|
|
||||
|
</mapper> |
||||
@ -0,0 +1,42 @@ |
|||||
|
<?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.ccsens.yanyuan.persist.dao.UserRelationDao"> |
||||
|
|
||||
|
|
||||
|
<select id="queryIsMax" resultType="java.lang.Byte"> |
||||
|
SELECT |
||||
|
IF(toolnum.number > cre.number,0,1) AS isMax |
||||
|
FROM |
||||
|
( |
||||
|
SELECT |
||||
|
COUNT( ur.id ) AS number |
||||
|
FROM |
||||
|
u_user_relation AS ur |
||||
|
LEFT JOIN u_user AS u ON u.key_id = ur.key_user_id |
||||
|
WHERE |
||||
|
ur.rec_status = 0 |
||||
|
AND u.STATUS = 1 |
||||
|
AND ur.relation_type = 1 |
||||
|
AND u.use_level = 1 |
||||
|
AND ur.user_id = #{userId} |
||||
|
) AS cre, |
||||
|
( SELECT COUNT( id ) AS number FROM t_tool WHERE rec_status = 0 AND user_id = #{userId} ) AS toolnum |
||||
|
</select> |
||||
|
|
||||
|
<select id="queryUxUser" resultType="com.ccsens.yanyuan.bean.vo.ToolVo$UxUserInfo"> |
||||
|
SELECT |
||||
|
u.key_id AS keyId, |
||||
|
u.use_level, |
||||
|
u.user_name, |
||||
|
u.sex |
||||
|
FROM |
||||
|
u_user_relation AS ur |
||||
|
LEFT JOIN u_user AS u ON u.key_id = ur.key_user_id |
||||
|
WHERE |
||||
|
ur.rec_status = 0 |
||||
|
AND u.STATUS = 1 |
||||
|
AND ur.relation_type = 1 |
||||
|
AND u.use_level = 0 |
||||
|
AND ur.user_id = #{userId} |
||||
|
</select> |
||||
|
</mapper> |
||||
Loading…
Reference in new issue