领域与用户关系
This commit is contained in:
+44
@@ -0,0 +1,44 @@
|
||||
package com.jero.modules.domain.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.aspect.annotation.AutoLog;
|
||||
import com.jero.modules.domain.service.DomainUserRelService;
|
||||
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.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
/**
|
||||
* 领域与用户关系
|
||||
*@Author: wzj
|
||||
*@Date: 2022/3/2 11:41
|
||||
**/
|
||||
@Slf4j
|
||||
@Api(tags="领域与用户关系")
|
||||
@RestController
|
||||
@RequestMapping("/domain/domainUserRel")
|
||||
public class DomainUserRelController {
|
||||
|
||||
@Autowired
|
||||
private DomainUserRelService domainUserRelService;
|
||||
|
||||
@AutoLog(value = "领域与用户关系-添加")
|
||||
@ApiOperation(value="领域与用户关系-添加", notes="领域与用户关系-添加")
|
||||
@PostMapping(value = "/insert")
|
||||
public Result<?> insert(@RequestBody JSONObject jsonObject){
|
||||
return domainUserRelService.insert(jsonObject);
|
||||
}
|
||||
|
||||
@AutoLog(value = "领域与用户关系-查询")
|
||||
@ApiOperation(value="领域与用户关系-查询", notes="领域与用户关系-查询")
|
||||
@PostMapping(value = "/queryList")
|
||||
public Result<?> queryList(){
|
||||
return domainUserRelService.queryList();
|
||||
}
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
package com.jero.modules.domain.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 领域与用户关系实体
|
||||
*@Author: wzj
|
||||
*@Date: 2022/3/2 11:41
|
||||
**/
|
||||
@Data
|
||||
@TableName("domain_user_rel")
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@ApiModel(value="domain_user_rel对象", description="领域与用户关系表")
|
||||
public class DomainUserRel implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@ApiModelProperty("主键")
|
||||
private String id;
|
||||
|
||||
@ApiModelProperty("创建人")
|
||||
private String createBy;
|
||||
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@ApiModelProperty(value = "创建时间")
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty("领域id")
|
||||
private String domainId;
|
||||
|
||||
@ApiModelProperty("用户id")
|
||||
private String userId;
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package com.jero.modules.domain.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.jero.modules.domain.entity.DomainUserRel;
|
||||
/**
|
||||
* 领域与用户关系
|
||||
*@Author: wzj
|
||||
*@Date: 2022/3/2 11:41
|
||||
**/
|
||||
public interface DomainUserRelMapper extends BaseMapper<DomainUserRel> {
|
||||
}
|
||||
+11
@@ -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="com.jero.modules.domain.mapper.DomainUserRelMapper">
|
||||
<resultMap id="OnlCgformSubscribeResultMap" type="com.jero.modules.domain.entity.DomainUserRel">
|
||||
<id column="id" property="id" />
|
||||
<result column="create_by" property="createBy" />
|
||||
<result column="create_time" property="createTime" />
|
||||
<result column="domain_id" property="domainId" />
|
||||
</resultMap>
|
||||
|
||||
</mapper>
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package com.jero.modules.domain.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.modules.domain.entity.DomainUserRel;
|
||||
/**
|
||||
* 领域与用户关系
|
||||
*@Author: wzj
|
||||
*@Date: 2022/3/2 11:40
|
||||
**/
|
||||
public interface DomainUserRelService extends IService<DomainUserRel> {
|
||||
|
||||
Result<?> insert(JSONObject jsonObject);
|
||||
|
||||
Result<?> queryList();
|
||||
|
||||
}
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
package com.jero.modules.domain.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.modules.domain.entity.DomainUserRel;
|
||||
import com.jero.modules.domain.mapper.DomainUserRelMapper;
|
||||
import com.jero.modules.domain.service.DomainUserRelService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 领域与用户关系
|
||||
*@Author: wzj
|
||||
*@Date: 2022/3/2 11:41
|
||||
**/
|
||||
@Service
|
||||
public class DomainManageServiceImpl extends ServiceImpl<DomainUserRelMapper, DomainUserRel> implements DomainUserRelService {
|
||||
|
||||
@Override
|
||||
public Result<?> insert(JSONObject jsonObject) {
|
||||
try {
|
||||
List<String> domainIdList = jsonObject.getJSONArray("domainIdList").toJavaList(String.class);
|
||||
LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
String userName = currentUser.getUsername();
|
||||
String userId = currentUser.getId();
|
||||
QueryWrapper<DomainUserRel> deleteWrapepr = new QueryWrapper<>();
|
||||
deleteWrapepr.lambda().eq(DomainUserRel::getUserId,userId);
|
||||
super.baseMapper.delete(deleteWrapepr);
|
||||
|
||||
List<DomainUserRel> domainUserRelList = new ArrayList<>();
|
||||
domainIdList.forEach(domainId -> {
|
||||
DomainUserRel domainUserRel = new DomainUserRel();
|
||||
domainUserRel.setCreateBy(userName);
|
||||
domainUserRel.setDomainId(domainId);
|
||||
domainUserRel.setUserId(userId);
|
||||
domainUserRel.setCreateTime(new Date());
|
||||
domainUserRelList.add(domainUserRel);
|
||||
});
|
||||
if (CollectionUtils.isNotEmpty(domainIdList)) {
|
||||
super.saveBatch(domainUserRelList);
|
||||
}
|
||||
}catch (Exception ex){
|
||||
log.error("添加领域与用户关系失败:" + ex.getMessage());
|
||||
throw new JeroBootException("添加失败!");
|
||||
}
|
||||
return Result.OK("添加成功!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<?> queryList() {
|
||||
LoginUser currentUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
||||
String userId = currentUser.getId();
|
||||
QueryWrapper<DomainUserRel> queryWrapper = new QueryWrapper<>();
|
||||
queryWrapper.lambda().eq(DomainUserRel::getUserId,userId);
|
||||
List<DomainUserRel> domainUserRels = super.baseMapper.selectList(queryWrapper);
|
||||
return Result.OK(domainUserRels);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user