test:(角色判断)
parent
75a29531b4
commit
d4678b4dd1
|
@ -7,6 +7,7 @@ import com.muyu.common.system.domain.SysUser;
|
|||
import com.muyu.common.system.remote.factory.RemoteUserFallbackFactory;
|
||||
import com.muyu.common.system.domain.LoginUser;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
|
@ -27,6 +28,11 @@ public interface RemoteUserService {
|
|||
@GetMapping("/user/info/{username}")
|
||||
public Result<LoginUser> getUserInfo (@PathVariable("username") String username, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
|
||||
|
||||
|
||||
|
||||
@PostMapping("/user")
|
||||
public Result add (@Validated @RequestBody SysUser user);
|
||||
|
||||
/**
|
||||
* 注册用户信息
|
||||
*
|
||||
|
|
|
@ -27,6 +27,11 @@ public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserServ
|
|||
return Result.error("获取用户失败:" + throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result add(SysUser user) {
|
||||
return Result.error("获取用户失败:{}", throwable.getMessage());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Boolean> registerUserInfo (SysUser sysUser, String source) {
|
||||
return Result.error("注册用户失败:" + throwable.getMessage());
|
||||
|
|
|
@ -18,6 +18,14 @@
|
|||
</properties>
|
||||
<dependencies>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.docker-java</groupId>
|
||||
<artifactId>docker-java</artifactId>
|
||||
<version>3.2.11</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.muyu</groupId>
|
||||
<artifactId>muyu-networking-common</artifactId>
|
||||
|
|
|
@ -42,7 +42,7 @@ public class InformationController extends BaseController
|
|||
/**
|
||||
* 查询【请填写功能名称】列表
|
||||
*/
|
||||
@RequiresPermissions("system:information:list")
|
||||
|
||||
@GetMapping("/list")
|
||||
public Result<TableDataInfo<Information>> list(Information information)
|
||||
{
|
||||
|
@ -54,7 +54,7 @@ public class InformationController extends BaseController
|
|||
/**
|
||||
* 导出【请填写功能名称】列表
|
||||
*/
|
||||
@RequiresPermissions("system:information:export")
|
||||
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(HttpServletResponse response, Information information)
|
||||
|
@ -67,7 +67,7 @@ public class InformationController extends BaseController
|
|||
/**
|
||||
* 获取【请填写功能名称】详细信息
|
||||
*/
|
||||
@RequiresPermissions("system:information:query")
|
||||
|
||||
@GetMapping(value = "/{id}")
|
||||
public Result getInfo(@PathVariable("id") Long id)
|
||||
{
|
||||
|
@ -77,7 +77,7 @@ public class InformationController extends BaseController
|
|||
/**
|
||||
* 新增【请填写功能名称】
|
||||
*/
|
||||
@RequiresPermissions("system:information:add")
|
||||
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
|
||||
@PostMapping
|
||||
public Result add(@RequestBody Information information)
|
||||
|
@ -88,7 +88,7 @@ public class InformationController extends BaseController
|
|||
/**
|
||||
* 修改【请填写功能名称】
|
||||
*/
|
||||
@RequiresPermissions("system:information:edit")
|
||||
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
|
||||
@PutMapping
|
||||
public Result edit(@RequestBody Information information)
|
||||
|
@ -99,7 +99,7 @@ public class InformationController extends BaseController
|
|||
/**
|
||||
* 删除【请填写功能名称】
|
||||
*/
|
||||
@RequiresPermissions("system:information:remove")
|
||||
|
||||
@Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
|
||||
@DeleteMapping("/{ids}")
|
||||
public Result remove(@PathVariable Long[] ids)
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.springframework.cloud.openfeign.FeignClient;
|
|||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
/**
|
||||
* @ClassDescription:
|
||||
|
@ -16,6 +17,6 @@ import org.springframework.web.bind.annotation.RequestBody;
|
|||
@FeignClient("muyu-system")
|
||||
public interface SysUserNet {
|
||||
|
||||
@PostMapping
|
||||
@PostMapping("/system/user")
|
||||
public Result add (@Validated @RequestBody SysUser user);
|
||||
}
|
||||
|
|
|
@ -1,19 +1,39 @@
|
|||
package com.muyu.networking.service.impl;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import com.muyu.common.core.domain.Result;
|
||||
import com.muyu.common.core.utils.DateUtils;
|
||||
import com.muyu.common.security.utils.SecurityUtils;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
import com.muyu.common.system.remote.RemoteUserService;
|
||||
import com.muyu.domain.Enterprise;
|
||||
import com.muyu.networking.mapper.EnterpriseMapper;
|
||||
import com.muyu.networking.opFen.SysUserNet;
|
||||
import com.muyu.networking.service.EnterpriseService;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.security.SecureRandom;
|
||||
|
||||
|
||||
import com.github.dockerjava.api.DockerClient;
|
||||
import com.github.dockerjava.api.command.CreateContainerCmd;
|
||||
import com.github.dockerjava.api.command.CreateContainerResponse;
|
||||
import com.github.dockerjava.api.command.ExecCreateCmdResponse;
|
||||
import com.github.dockerjava.api.command.InspectContainerResponse;
|
||||
import com.github.dockerjava.core.DefaultDockerClientConfig;
|
||||
import com.github.dockerjava.core.DockerClientBuilder;
|
||||
import com.github.dockerjava.core.command.ExecStartResultCallback;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -53,7 +73,8 @@ public class EnterpriseServiceImpl implements EnterpriseService
|
|||
{
|
||||
return enterpriseMapper.selectEnterpriseList(enterprise);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private RemoteUserService remoteUserService;
|
||||
/**
|
||||
* 新增【请填写功能名称】
|
||||
*
|
||||
|
@ -66,38 +87,17 @@ public class EnterpriseServiceImpl implements EnterpriseService
|
|||
enterprise.setCreateBy(SecurityUtils.getUsername());
|
||||
enterprise.setCreateTime(DateUtils.getNowDate());
|
||||
enterprise.setBusinessLicenseNumber(UUID.randomUUID().toString().replaceAll("-",""));
|
||||
SysUser sysUser = new SysUser();
|
||||
insertUser(sysUser);
|
||||
enterprise.setStatus("1");
|
||||
enterprise.setCertification("1");
|
||||
enterprise.setOpenAdd("0");
|
||||
SysUser sysUser = SysUser.builder().userName(enterprise.getEnterpriseName())
|
||||
.password("admin")
|
||||
.nickName(enterprise.getEnterpriseName()).
|
||||
userType(String.valueOf(enterprise.getId()))
|
||||
.build();
|
||||
Result add = remoteUserService.add(sysUser);
|
||||
return enterpriseMapper.insertEnterprise(enterprise);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private SysUserNet sysUserNet;
|
||||
|
||||
public void insertUser(SysUser user){
|
||||
String alphabet = "abcdefghijklmnopqrstuvwxyz"; // Only lowercase letters
|
||||
SecureRandom random = new SecureRandom();
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
int index = random.nextInt(alphabet.length());
|
||||
stringBuilder.append(alphabet.charAt(index));
|
||||
}
|
||||
user.setUserName(stringBuilder.toString());
|
||||
|
||||
String pwd = "1234567890"; // Only lowercase letters
|
||||
SecureRandom randomPwd = new SecureRandom();
|
||||
StringBuilder stringPwd = new StringBuilder();
|
||||
for (int i = 0; i < 6; i++) {
|
||||
int index = randomPwd.nextInt(pwd.length());
|
||||
stringPwd.append(pwd.charAt(index));
|
||||
}
|
||||
user.setPassword(stringPwd.toString());
|
||||
user.setUserType("enterprise");
|
||||
sysUserNet.add(user);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 修改【请填写功能名称】
|
||||
*
|
||||
|
@ -142,4 +142,74 @@ public class EnterpriseServiceImpl implements EnterpriseService
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// public void DockerMySQLExample() throws IOException {
|
||||
// // 配置Docker客户端
|
||||
// DefaultDockerClientConfig config = DefaultDockerClientConfig.createDefaultConfigBuilder()
|
||||
// .withDockerHost("tcp://115.159.67.205:3306") // 使用Docker守护进程地址
|
||||
// .build();
|
||||
// DockerClient dockerClient = DockerClientBuilder.getInstance(config).build();
|
||||
//
|
||||
// try {
|
||||
// // 创建新的MySQL容器
|
||||
// CreateContainerCmd createContainerCmd = dockerClient.createContainerCmd("mysql:latest")
|
||||
// .withName("my-mysql-container")
|
||||
// .withEnv("MYSQL_ROOT_PASSWORD=my-secret-pw");
|
||||
//
|
||||
// CreateContainerResponse container = createContainerCmd.exec();
|
||||
// System.out.println("Created container " + container.getId());
|
||||
//
|
||||
// // 启动MySQL容器
|
||||
// dockerClient.startContainerCmd(container.getId()).exec();
|
||||
//
|
||||
// // 执行初始化脚本
|
||||
// String initScript = "CREATE DATABASE IF NOT EXISTS mydb;\n" +
|
||||
// "GRANT ALL PRIVILEGES ON mydb.* TO 'myuser' IDENTIFIED BY 'mypass';";
|
||||
//
|
||||
// // 获取容器的进程信息
|
||||
// InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec();
|
||||
// String containerId = inspectContainerResponse.getId();
|
||||
//
|
||||
// // 将初始化脚本通过stdin传递给MySQL
|
||||
// String execId = dockerClient.execCreateCmd(containerId, "/bin/bash", "-c", "mysql -u root -p$MYSQL_ROOT_PASSWORD")
|
||||
// .withAttachStdout(true)
|
||||
// .withAttachStdin(true)
|
||||
// .exec()
|
||||
// .getId();
|
||||
//
|
||||
// try (ExecStartResultCallback callback = new ExecStartResultCallback()) {
|
||||
//
|
||||
// InputStream execStream = dockerClient.execStartCmd(execId).withDetach(false)
|
||||
// .withTty(false)
|
||||
// .withCmd(initScript)
|
||||
// .exec()
|
||||
// .getExecResult()
|
||||
// .getStdout();
|
||||
//
|
||||
// // 读取并打印脚本执行结果
|
||||
// BufferedReader reader = new BufferedReader(new InputStreamReader(execStream));
|
||||
// String line;
|
||||
// while ((line = reader.readLine()) != null) {
|
||||
// System.out.println(line);
|
||||
// }
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// } finally {
|
||||
// // 清理资源,移除容器
|
||||
// dockerClient.close();
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package com.muyu.networking.service.impl;
|
|||
|
||||
import java.util.List;
|
||||
import com.muyu.common.core.utils.DateUtils;
|
||||
import com.muyu.common.system.remote.factory.RemoteUserFallbackFactory;
|
||||
import com.muyu.domain.Information;
|
||||
import com.muyu.networking.mapper.InformationMapper;
|
||||
import com.muyu.networking.service.IInformationService;
|
||||
|
@ -21,6 +22,8 @@ public class InformationServiceImpl implements IInformationService
|
|||
@Autowired
|
||||
private InformationMapper informationMapper;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 查询【请填写功能名称】
|
||||
*
|
||||
|
|
|
@ -18,8 +18,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<result property="status" column="status" />
|
||||
<result property="registrationDate" column="registration_date" />
|
||||
<result property="certification" column="certification" />
|
||||
<result property="openServiceId" column="open_service_id" />
|
||||
<result property="addServiceId" column="add_service_id" />
|
||||
<result property="remark" column="remark" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
|
@ -28,7 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</resultMap>
|
||||
|
||||
<sql id="selectEnterpriseVo">
|
||||
select id, enterprise_name,open_add, legal_person, business_license_number, establishment_date, business_scope, address, contact_phone, email, status, registration_date, certification, open_service_id, add_service_id, remark, create_by, create_time, update_time, update_by from enterprise
|
||||
select id, enterprise_name,open_add, legal_person, business_license_number, establishment_date, business_scope, address, contact_phone, email, status, registration_date, certification, remark, create_by, create_time, update_time, update_by from enterprise
|
||||
</sql>
|
||||
|
||||
<select id="selectEnterpriseList" parameterType="com.muyu.domain.Enterprise" resultMap="EnterpriseResult">
|
||||
|
@ -45,8 +43,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="status != null and status != ''"> and status = #{status}</if>
|
||||
<if test="registrationDate != null "> and registration_date = #{registrationDate}</if>
|
||||
<if test="certification != null "> and certification = #{certification}</if>
|
||||
<if test="openServiceId != null "> and open_service_id = #{openServiceId}</if>
|
||||
<if test="addServiceId != null "> and add_service_id = #{addServiceId}</if>
|
||||
<if test="openAdd != null "> and open_add = #{openAdd}</if>
|
||||
</where>
|
||||
</select>
|
||||
|
@ -70,8 +66,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="status != null">status,</if>
|
||||
<if test="registrationDate != null">registration_date,</if>
|
||||
<if test="certification != null">certification,</if>
|
||||
<if test="openServiceId != null">open_service_id,</if>
|
||||
<if test="addServiceId != null">add_service_id,</if>
|
||||
<if test="remark != null">remark,</if>
|
||||
<if test="createBy != null">create_by,</if>
|
||||
<if test="createTime != null">create_time,</if>
|
||||
|
@ -91,8 +85,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="status != null">#{status},</if>
|
||||
<if test="registrationDate != null">#{registrationDate},</if>
|
||||
<if test="certification != null">#{certification},</if>
|
||||
<if test="openServiceId != null">#{openServiceId},</if>
|
||||
<if test="addServiceId != null">#{addServiceId},</if>
|
||||
<if test="remark != null">#{remark},</if>
|
||||
<if test="createBy != null">#{createBy},</if>
|
||||
<if test="createTime != null">#{createTime},</if>
|
||||
|
@ -116,8 +108,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
<if test="status != null">status = #{status},</if>
|
||||
<if test="registrationDate != null">registration_date = #{registrationDate},</if>
|
||||
<if test="certification != null">certification = #{certification},</if>
|
||||
<if test="openServiceId != null">open_service_id = #{openServiceId},</if>
|
||||
<if test="addServiceId != null">add_service_id = #{addServiceId},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="createBy != null">create_by = #{createBy},</if>
|
||||
<if test="createTime != null">create_time = #{createTime},</if>
|
||||
|
|
Loading…
Reference in New Issue