fix():围栏组+多数据源部分(改)
parent
0d3377c483
commit
6f2496fe9c
|
@ -21,6 +21,12 @@
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.muyu</groupId>
|
||||||
|
<artifactId>muyu-customer-business-server</artifactId>
|
||||||
|
<version>3.6.3</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- SpringCloud Alibaba Nacos -->
|
<!-- SpringCloud Alibaba Nacos -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba.cloud</groupId>
|
<groupId>com.alibaba.cloud</groupId>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package com.muyu.cloud.many.datasource.config;
|
package com.muyu.cloud.many.datasource.config;
|
||||||
|
|
||||||
import com.alibaba.druid.pool.DruidDataSource;
|
import com.alibaba.druid.pool.DruidDataSource;
|
||||||
import com.alibaba.druid.pool.DruidDataSourceFactory;
|
import com.muyu.cloud.many.datasource.config.factory.DruidDataSourceFactory;
|
||||||
import com.muyu.cloud.many.datasource.config.domain.model.DataSourceInfo;
|
import com.muyu.cloud.many.datasource.config.domain.model.DataSourceInfo;
|
||||||
import com.muyu.cloud.many.datasource.config.domain.model.EnterPriseInfo;
|
import com.muyu.cloud.many.datasource.config.domain.model.EnterPriseInfo;
|
||||||
import com.muyu.cloud.many.datasource.config.role.DynamicDataSource;
|
import com.muyu.cloud.many.datasource.config.role.DynamicDataSource;
|
||||||
|
@ -38,8 +38,8 @@ public class ManyDataSource {
|
||||||
DruidDataSourceFactory druidDataSourceFactory= SpringUtils.getBean(DruidDataSourceFactory.class);
|
DruidDataSourceFactory druidDataSourceFactory= SpringUtils.getBean(DruidDataSourceFactory.class);
|
||||||
DynamicDataSource dynamicDataSource= SpringUtils.getBean(DynamicDataSource.class);
|
DynamicDataSource dynamicDataSource= SpringUtils.getBean(DynamicDataSource.class);
|
||||||
EnterPriseInfo enterPriseInfo = EnterPriseInfo.builder()
|
EnterPriseInfo enterPriseInfo = EnterPriseInfo.builder()
|
||||||
.entCode("liu_0603")
|
.entCode("jiang_0604")
|
||||||
.ip("192.168.116.129")
|
.ip("101.34.248.9")
|
||||||
.port(3308)
|
.port(3308)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
@ -54,8 +54,8 @@ public class ManyDataSource {
|
||||||
List<EnterPriseInfo> list = new ArrayList<>();
|
List<EnterPriseInfo> list = new ArrayList<>();
|
||||||
list.add(
|
list.add(
|
||||||
EnterPriseInfo.builder()
|
EnterPriseInfo.builder()
|
||||||
.entCode("liu_0604")
|
.entCode("jiang_0604")
|
||||||
.ip("192.168.116.129")
|
.ip("101.34.248.9")
|
||||||
.port(3307)
|
.port(3307)
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
|
|
|
@ -7,6 +7,8 @@ import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import static com.muyu.cloud.many.datasource.config.DatasourceContent.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author DongZl
|
* @author DongZl
|
||||||
* @description: 数据源实体类
|
* @description: 数据源实体类
|
||||||
|
@ -34,15 +36,14 @@ public class DataSourceInfo {
|
||||||
private String userName;
|
private String userName;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 用户密码
|
* 密码
|
||||||
*/
|
*/
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
|
|
||||||
public static DataSourceInfo hostAndPortBuild(String key,String host, Integer port){
|
public static DataSourceInfo hostAndPortBuild(String key,String host, Integer port){
|
||||||
return DataSourceInfo.builder()
|
return DataSourceInfo.builder()
|
||||||
.key(key)
|
.key(key)
|
||||||
.url(StringUtils.format(DATASOURCE_URL, host, port,port))
|
.url(StringUtils.format(DATASOURCE_URL, host,port))
|
||||||
.password(PASSWORD)
|
.password(PASSWORD)
|
||||||
.userName(USER_NAME)
|
.userName(USER_NAME)
|
||||||
.build();
|
.build();
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package com.muyu.cloud.many.datasource.config.role;
|
||||||
|
|
||||||
|
import com.muyu.cloud.many.datasource.config.holder.DynamicDataSourceHolder;
|
||||||
|
import com.muyu.common.security.utils.SecurityUtils;
|
||||||
|
import org.aspectj.lang.annotation.After;
|
||||||
|
import org.aspectj.lang.annotation.Aspect;
|
||||||
|
import org.aspectj.lang.annotation.Before;
|
||||||
|
import org.aspectj.lang.annotation.Pointcut;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数据源切面
|
||||||
|
*/
|
||||||
|
@Aspect
|
||||||
|
@Component
|
||||||
|
public class DataSourceAsp {
|
||||||
|
|
||||||
|
@Pointcut("execution(public * com.muyu.customer.business.controller.*Controller.*(..))")
|
||||||
|
public void pointcut(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before("pointcut()")
|
||||||
|
public void beforeMethod(){
|
||||||
|
Long storeId = SecurityUtils.getLoginUser().getUserid();
|
||||||
|
DynamicDataSourceHolder.setDynamicDataSourceKey("test_"+storeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@After("pointcut()")
|
||||||
|
public void afterMethod(){
|
||||||
|
DynamicDataSourceHolder.removeDynamicDataSourceKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,36 @@
|
||||||
|
package com.muyu.customer.business.domain;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import com.muyu.common.core.annotation.Excel;
|
||||||
|
import com.muyu.common.core.web.domain.BaseEntity;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.StandardException;
|
||||||
|
import lombok.experimental.SuperBuilder;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@SuperBuilder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@TableName("group")
|
||||||
|
public class Group extends BaseEntity {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 围栏组id
|
||||||
|
*/
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 围栏组名称
|
||||||
|
*/
|
||||||
|
@Excel(name = "围栏组名称")
|
||||||
|
private String groupName;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,86 @@
|
||||||
|
package com.muyu.customer.business.controller;
|
||||||
|
|
||||||
|
import com.muyu.common.core.domain.Result;
|
||||||
|
import com.muyu.common.core.utils.poi.ExcelUtil;
|
||||||
|
import com.muyu.common.core.web.controller.BaseController;
|
||||||
|
import com.muyu.common.core.web.page.TableDataInfo;
|
||||||
|
import com.muyu.common.log.annotation.Log;
|
||||||
|
import com.muyu.common.log.enums.BusinessType;
|
||||||
|
import com.muyu.customer.business.domain.Group;
|
||||||
|
import com.muyu.customer.business.service.GroupService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/group")
|
||||||
|
public class GroupController extends BaseController
|
||||||
|
{
|
||||||
|
@Autowired
|
||||||
|
private GroupService groupService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询围栏组列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
|
public Result<TableDataInfo<Group>> list(Group group)
|
||||||
|
{
|
||||||
|
startPage();
|
||||||
|
List<Group> list = groupService.selectGroupList(group);
|
||||||
|
return getDataTable(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出围栏组列表
|
||||||
|
*/
|
||||||
|
@Log(title = "围栏组", businessType = BusinessType.EXPORT)
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(HttpServletResponse response, Group group)
|
||||||
|
{
|
||||||
|
List<Group> list = groupService.selectGroupList(group);
|
||||||
|
ExcelUtil<Group> util = new ExcelUtil<Group>(Group.class);
|
||||||
|
util.exportExcel(response, list, "围栏组数据");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取围栏组详细信息
|
||||||
|
*/
|
||||||
|
@GetMapping(value = "/{id}")
|
||||||
|
public Result getInfo(@PathVariable("id") Long id)
|
||||||
|
{
|
||||||
|
return success(groupService.selectGroupById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增围栏组
|
||||||
|
*/
|
||||||
|
@Log(title = "围栏组", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping
|
||||||
|
public Result add(@RequestBody Group group)
|
||||||
|
{
|
||||||
|
return toAjax(groupService.insertGroup(group));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改围栏组
|
||||||
|
*/
|
||||||
|
@Log(title = "围栏组", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping
|
||||||
|
public Result edit(@RequestBody Group group)
|
||||||
|
{
|
||||||
|
return toAjax(groupService.updateGroup(group));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除围栏组
|
||||||
|
*/
|
||||||
|
@Log(title = "围栏组", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{ids}")
|
||||||
|
public Result remove(@PathVariable Long[] ids)
|
||||||
|
{
|
||||||
|
return toAjax(groupService.deleteGroupByIds(ids));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
package com.muyu.customer.business.mapper;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.muyu.customer.business.domain.Group;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface GroupMapper extends BaseMapper<Group> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询围栏组
|
||||||
|
*
|
||||||
|
* @param id 围栏组主键
|
||||||
|
* @return 围栏组
|
||||||
|
*/
|
||||||
|
public Group selectGroupById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询围栏组列表
|
||||||
|
*
|
||||||
|
* @param group 围栏组
|
||||||
|
* @return 围栏组集合
|
||||||
|
*/
|
||||||
|
public List<Group> selectGroupList(Group group);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增围栏组
|
||||||
|
*
|
||||||
|
* @param group 围栏组
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int insertGroup(Group group);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改围栏组
|
||||||
|
*
|
||||||
|
* @param group 围栏组
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int updateGroup(Group group);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除围栏组
|
||||||
|
*
|
||||||
|
* @param id 围栏组主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteGroupById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除围栏组
|
||||||
|
*
|
||||||
|
* @param ids 需要删除的数据主键集合
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteGroupByIds(Long[] ids);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
package com.muyu.customer.business.service;
|
||||||
|
|
||||||
|
import com.muyu.customer.business.domain.Group;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface GroupService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询围栏组
|
||||||
|
*
|
||||||
|
* @param id 围栏组主键
|
||||||
|
* @return 围栏组
|
||||||
|
*/
|
||||||
|
public Group selectGroupById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询围栏组列表
|
||||||
|
*
|
||||||
|
* @param group 围栏组
|
||||||
|
* @return 围栏组集合
|
||||||
|
*/
|
||||||
|
public List<Group> selectGroupList(Group group);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增围栏组
|
||||||
|
*
|
||||||
|
* @param group 围栏组
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int insertGroup(Group group);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改围栏组
|
||||||
|
*
|
||||||
|
* @param group 围栏组
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int updateGroup(Group group);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除围栏组
|
||||||
|
*
|
||||||
|
* @param ids 需要删除的围栏组主键集合
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteGroupByIds(Long[] ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除围栏组信息
|
||||||
|
*
|
||||||
|
* @param id 围栏组主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteGroupById(Long id);
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
package com.muyu.customer.business.service.impl;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.muyu.customer.business.domain.Group;
|
||||||
|
import com.muyu.customer.business.mapper.GroupMapper;
|
||||||
|
import com.muyu.customer.business.service.GroupService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class GroupServiceImpl extends ServiceImpl<GroupMapper,Group> implements GroupService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private GroupMapper groupMapper;
|
||||||
|
@Override
|
||||||
|
public Group selectGroupById(Long id) {
|
||||||
|
return groupMapper.selectGroupById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Group> selectGroupList(Group group) {
|
||||||
|
return groupMapper.selectGroupList(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int insertGroup(Group group) {
|
||||||
|
return groupMapper.insertGroup(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int updateGroup(Group group) {
|
||||||
|
return groupMapper.updateGroup(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int deleteGroupByIds(Long[] ids) {
|
||||||
|
return groupMapper.deleteGroupByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int deleteGroupById(Long id) {
|
||||||
|
return groupMapper.deleteGroupById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
<?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.muyu.customer.business.mapper.GroupMapper">
|
||||||
|
|
||||||
|
<resultMap type="com.muyu.customer.business.domain.Group" id="GroupResult">
|
||||||
|
<result property="id" column="id" />
|
||||||
|
<result property="groupName" column="group_name" />
|
||||||
|
<result property="remark" column="remark" />
|
||||||
|
<result property="createBy" column="create_by" />
|
||||||
|
<result property="createTime" column="create_time" />
|
||||||
|
<result property="updateBy" column="update_by" />
|
||||||
|
<result property="updateTime" column="update_time" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="selectGroupVo">
|
||||||
|
select id, group_name, remark, create_by, create_time, update_by, update_time from `group`
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="selectGroupList" parameterType="com.muyu.customer.business.domain.Group" resultMap="GroupResult">
|
||||||
|
<include refid="selectGroupVo"/>
|
||||||
|
<where>
|
||||||
|
<if test="groupName != null and groupName != ''"> and group_name like concat('%', #{groupName}, '%')</if>
|
||||||
|
<if test="updateTime != null "> and update_time = #{updateTime}</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectGroupById" parameterType="Long" resultMap="GroupResult">
|
||||||
|
<include refid="selectGroupVo"/>
|
||||||
|
where id = #{id}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<insert id="insertGroup" parameterType="com.muyu.customer.business.domain.Group" useGeneratedKeys="true" keyProperty="id">
|
||||||
|
insert into `group`
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="groupName != null">group_name,</if>
|
||||||
|
<if test="remark != null">remark,</if>
|
||||||
|
<if test="createBy != null">create_by,</if>
|
||||||
|
<if test="createTime != null">create_time,</if>
|
||||||
|
<if test="updateBy != null">update_by,</if>
|
||||||
|
<if test="updateTime != null">update_time,</if>
|
||||||
|
</trim>
|
||||||
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="groupName != null">#{groupName},</if>
|
||||||
|
<if test="remark != null">#{remark},</if>
|
||||||
|
<if test="createBy != null">#{createBy},</if>
|
||||||
|
<if test="createTime != null">#{createTime},</if>
|
||||||
|
<if test="updateBy != null">#{updateBy},</if>
|
||||||
|
<if test="updateTime != null">#{updateTime},</if>
|
||||||
|
</trim>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="updateGroup" parameterType="com.muyu.customer.business.domain.Group">
|
||||||
|
update `group`
|
||||||
|
<trim prefix="SET" suffixOverrides=",">
|
||||||
|
<if test="groupName != null">group_name = #{groupName},</if>
|
||||||
|
<if test="remark != null">remark = #{remark},</if>
|
||||||
|
<if test="createBy != null">create_by = #{createBy},</if>
|
||||||
|
<if test="createTime != null">create_time = #{createTime},</if>
|
||||||
|
<if test="updateBy != null">update_by = #{updateBy},</if>
|
||||||
|
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||||
|
</trim>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<delete id="deleteGroupById" parameterType="Long">
|
||||||
|
delete from `group` where id = #{id}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<delete id="deleteGroupByIds" parameterType="String">
|
||||||
|
delete from `group` where id in
|
||||||
|
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
</mapper>
|
Loading…
Reference in New Issue