Bläddra i källkod

Merge branch 'dev' of yeshijie/jw2.0 into dev

yeshijie 6 år sedan
förälder
incheckning
ec8988ce79

+ 11 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/base/saas/SaasDO.java

@ -52,6 +52,8 @@ public class SaasDO extends UuidIdentityEntityWithOperator {
    List<BaseOrgDO> orgList;
    //业务模块
    List<SaasModuleDO> saasModuleList;
    //主题风格
    List<SaasThemeDO> saasThemeList;
	@Column(name = "name", nullable = false, length = 200)
	public String getName() {
@ -205,4 +207,13 @@ public class SaasDO extends UuidIdentityEntityWithOperator {
    public void setThemeColor(String themeColor) {
        this.themeColor = themeColor;
    }
    @Transient
    public List<SaasThemeDO> getSaasThemeList() {
        return saasThemeList;
    }
    public void setSaasThemeList(List<SaasThemeDO> saasThemeList) {
        this.saasThemeList = saasThemeList;
    }
}

+ 8 - 0
common/common-exception/src/main/java/com/yihu/jw/exception/code/BaseErrorCode.java

@ -47,6 +47,14 @@ public class BaseErrorCode {
         * 该名称已被占用
         */
        public static final String NAME_IS_EXIST = "-101003";
        /**
         * 验证码错误
         */
        public static final String CAPTCHA_IS_ERROR = "-101004";
        /**
         * 该租户已注册过,请直接
         */
        public static final String NAME_IS_EXIST2 = "-101005";
    }
    /**

+ 14 - 1
common/common-request-mapping/src/main/java/com/yihu/jw/rm/base/BaseRequestMapping.java

@ -31,6 +31,18 @@ public class BaseRequestMapping {
        public static final String AUDIT  = "/audit";
    }
    /**
     * 注册saas
     */
    public static class RegisterSaas extends Basic {
        public static final String PREFIX  = "/open/saas";
        public static final String REGISTER  = "/register";
        public static final String SEND_EMAIL  = "/sendEmail";
        public static final String NAME_IS_EXIST  = "/nameIsExist";
        public static final String SAAS_TYPE_DICT  = "/saasTypeDict";
    }
    /**
     * SAAS默认模块
     */
@ -178,6 +190,7 @@ public class BaseRequestMapping {
     */
    public static class ErrorCode extends Basic {
        public static final String PREFIX  = "/error";
        public static final String INIT_WITHOUT_CONDITION  = "/initWithoutCondition";
    }
    /**
@ -199,7 +212,7 @@ public class BaseRequestMapping {
     * 文件上传
     */
    public static class FileUpload extends Basic {
        public static final String PREFIX  = "/fileUpload";
        public static final String PREFIX  = "/open/fileUpload";
        public static final String UPLOAD_STREAM_IMG  = "/upload_stream_img";
        public static final String UPLOAD_STREAM  = "/upload_stream";
        public static final String UPLOAD_STRING  = "/upload_string";

+ 10 - 0
common/common-rest-model/src/main/java/com/yihu/jw/restmodel/base/saas/SaasVO.java

@ -56,6 +56,8 @@ public class SaasVO extends UuidIdentityVOWithOperator {
	List<BaseOrgVO> orgList;
	@ApiModelProperty(value = "业务模块", example = "业务模块")
	List<SaasModuleVO> saasModuleList;
	@ApiModelProperty(value = "主题风格", example = "主题风格")
	List<SaasThemeVO> saasThemeList;
	public String getOrgCode() {
@ -209,4 +211,12 @@ public class SaasVO extends UuidIdentityVOWithOperator {
	public void setThemeColor(String themeColor) {
		this.themeColor = themeColor;
	}
	public List<SaasThemeVO> getSaasThemeList() {
		return saasThemeList;
	}
	public void setSaasThemeList(List<SaasThemeVO> saasThemeList) {
		this.saasThemeList = saasThemeList;
	}
}

+ 12 - 4
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/errorCode/ErrorCodeEndpoint.java

@ -5,6 +5,7 @@ import com.yihu.jw.base.util.ErrorCodeUtil;
import com.yihu.jw.entity.base.dict.ErrorCodeDO;
import com.yihu.jw.exception.code.BaseErrorCode;
import com.yihu.jw.restmodel.base.dict.ErrorCodeVO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ListEnvelop;
import com.yihu.jw.restmodel.web.ObjEnvelop;
import com.yihu.jw.restmodel.web.PageEnvelop;
@ -31,7 +32,7 @@ public class ErrorCodeEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private ErrorCodeUtil errorCodeUtil;
    @PostMapping(value = BaseRequestMapping.Menu.CREATE,consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @PostMapping(value = BaseRequestMapping.ErrorCode.CREATE,consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建")
    public ObjEnvelop<ErrorCodeVO> create (
            @ApiParam(name = "json_data", value = "Json数据", required = true)
@ -44,7 +45,14 @@ public class ErrorCodeEndpoint extends EnvelopRestEndpoint {
        return success(errorCodeDO, ErrorCodeVO.class);
    }
    @PostMapping(value = BaseRequestMapping.Menu.UPDATE)
    @PostMapping(value = BaseRequestMapping.ErrorCode.INIT_WITHOUT_CONDITION,consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "初始化")
    public Envelop initWithoutCondition () throws Exception {
        errorCodeService.initWithoutCondition();
        return success("初始化成功");
    }
    @PostMapping(value = BaseRequestMapping.ErrorCode.UPDATE)
    @ApiOperation(value = "更新")
    public ObjEnvelop<ErrorCodeVO> update (
            @ApiParam(name = "id", value = "id")
@ -59,7 +67,7 @@ public class ErrorCodeEndpoint extends EnvelopRestEndpoint {
        return success(errorCodeDO, ErrorCodeVO.class);
    }
    @GetMapping(value = BaseRequestMapping.Menu.PAGE)
    @GetMapping(value = BaseRequestMapping.ErrorCode.PAGE)
    @ApiOperation(value = "获取分页")
    public PageEnvelop<ErrorCodeVO> page (
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")
@ -77,7 +85,7 @@ public class ErrorCodeEndpoint extends EnvelopRestEndpoint {
        return success(errorCodeDOS, count, page, size, ErrorCodeVO.class);
    }
    @GetMapping(value = BaseRequestMapping.Menu.LIST)
    @GetMapping(value = BaseRequestMapping.ErrorCode.LIST)
    @ApiOperation(value = "获取列表")
    public ListEnvelop<ErrorCodeVO> list (
            @ApiParam(name = "fields", value = "返回的字段,为空返回全部字段")

+ 132 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/open/register/RegisterEndpoint.java

@ -0,0 +1,132 @@
package com.yihu.jw.base.endpoint.open.register;
import com.yihu.jw.base.service.saas.SaasService;
import com.yihu.jw.base.service.saas.SaasTypeDictService;
import com.yihu.jw.base.service.user.UserService;
import com.yihu.jw.base.util.ErrorCodeUtil;
import com.yihu.jw.entity.base.saas.SaasDO;
import com.yihu.jw.entity.base.saas.SaasTypeDictDO;
import com.yihu.jw.entity.base.user.UserDO;
import com.yihu.jw.exception.code.BaseErrorCode;
import com.yihu.jw.restmodel.base.saas.SaasTypeDictVO;
import com.yihu.jw.restmodel.web.Envelop;
import com.yihu.jw.restmodel.web.ListEnvelop;
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
import com.yihu.jw.rm.base.BaseRequestMapping;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.http.MediaType;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
 * @author yeshijie on 2018/10/16.
 */
@RestController
@RequestMapping(value = BaseRequestMapping.RegisterSaas.PREFIX)
@Api(value = "注册Saas管理", description = "注册Saas管理服务接口", tags = {"wlyy基础服务 - 注册Saas管理服务接口"})
public class RegisterEndpoint extends EnvelopRestEndpoint {
    @Autowired
    private SaasService saasService;
    @Autowired
    private UserService userService;
    @Autowired
    private ErrorCodeUtil errorCodeUtil;
    @Autowired
    private JavaMailSender jms;
    @Value("${spring.mail.username}")
    private String username;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private SaasTypeDictService saasTypeDictService;
    /**
     * 验证码redis前缀
     */
    private final String redisPrefix = "verificationCode:";
    @PostMapping(value = BaseRequestMapping.RegisterSaas.REGISTER, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "注册租户")
    public Envelop create (
            @ApiParam(name = "jsonSaas", value = "租户数据", required = true)
            @RequestParam String jsonSaas,
            @ApiParam(name = "captcha", value = "验证码", required = true)
            @RequestParam String captcha) throws Exception {
        SaasDO saasDO = toEntity(jsonSaas, SaasDO.class);
        UserDO userDO = new UserDO();
        userDO.setEmail(saasDO.getEmail());
        userDO.setMobile(saasDO.getMobile());
        userDO.setName(saasDO.getManagerName());
        userDO.setUsername(userDO.getEmail());
        String redisKey = redisPrefix + userDO.getEmail();
        String verificationCode = redisTemplate.opsForValue().get(redisKey);
        if(!captcha.equals(verificationCode)){
            return failed(errorCodeUtil.getErrorMsg(BaseErrorCode.Saas.CAPTCHA_IS_ERROR), Envelop.class);
        }
        if (saasService.search("name=" + saasDO.getName()).size() > 0) {
            return failed(errorCodeUtil.getErrorMsg(BaseErrorCode.Saas.NAME_IS_EXIST), Envelop.class);
        }
        if (userService.search("mobile=" + userDO.getMobile()).size() > 0) {
            return failed(errorCodeUtil.getErrorMsg(BaseErrorCode.Saas.MOBILE_IS_EXIST), Envelop.class);
        }
        if (userService.search("username=" + userDO.getEmail()).size() > 0) {
            return failed(errorCodeUtil.getErrorMsg(BaseErrorCode.Saas.EMAIL_IS_EXIST), Envelop.class);
        }
        saasService.save(saasDO, userDO);
        //注册成功后 吧key删除
        redisTemplate.delete(redisKey);
        return success("注册成功");
    }
    @GetMapping(value = BaseRequestMapping.RegisterSaas.SAAS_TYPE_DICT)
    @ApiOperation(value = "获取列表")
    public ListEnvelop<SaasTypeDictVO> list() throws Exception {
        List<SaasTypeDictDO> saasTypeDictDOS = saasTypeDictService.search(null, "status="+SaasTypeDictDO.Status.effective, null);
        return success(saasTypeDictDOS, SaasTypeDictVO.class);
    }
    @PostMapping(value = BaseRequestMapping.RegisterSaas.NAME_IS_EXIST)
    @ApiOperation(value = "租户名称是否存在")
    public Envelop create (
            @ApiParam(name = "name", value = "租户名称", required = true)
            @RequestParam String name) throws Exception {
        if (saasService.search("name=" + name).size() > 0) {
            return failed(errorCodeUtil.getErrorMsg(BaseErrorCode.Saas.NAME_IS_EXIST2), Envelop.class);
        }
        return success("查询成功");
    }
    @PostMapping(value = BaseRequestMapping.RegisterSaas.SEND_EMAIL)
    @ApiOperation(value = "邮件发送")
    public Envelop send(@ApiParam(name = "email", value = "邮箱地址", required = true)
                         @RequestParam String email) throws Exception {
        //建立邮件消息
        SimpleMailMessage mainMessage = new SimpleMailMessage();
        //发送者
        mainMessage.setFrom(username);
        //接收者
        mainMessage.setTo(email);
        //发送的标题
        mainMessage.setSubject("租户注册-验证码");
        //发送的内容
        StringBuilder content =  new StringBuilder("您好!\n感谢您注册健康之路城市i健康。\n");
        String captcha = String.valueOf(Math.random()).substring(2, 8);
        content.append("您的验证码是:").append(captcha);
        content.append("。 (验证码10分钟内有效)");
        mainMessage.setText(content.toString());
        jms.send(mainMessage);
        redisTemplate.opsForValue().set(redisPrefix + email, captcha, 10, TimeUnit.MINUTES);
        return success("发送成功");
    }
}

+ 9 - 7
svr/svr-base/src/main/java/com/yihu/jw/base/endpoint/saas/SaasEndpoint.java

@ -25,7 +25,6 @@ import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
@ -53,11 +52,15 @@ public class SaasEndpoint extends EnvelopRestEndpoint {
    @PostMapping(value = BaseRequestMapping.Saas.CREATE, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建-基本信息")
    public Envelop create (
            @ApiParam(name = "saasDO", value = "Json数据", required = true)
            @RequestParam(value = "saasDO") SaasDO saasDO,
            @ApiParam(name = "userDO", value = "Json数据", required = true)
            @RequestParam(value = "userDO") UserDO userDO) throws Exception {
        if (saasService.search("name=" + userDO.getName()).size() > 0) {
            @ApiParam(name = "jsonSaas", value = "租户数据", required = true)
            @RequestParam String jsonSaas) throws Exception {
        SaasDO saasDO = toEntity(jsonSaas, SaasDO.class);
        UserDO userDO = new UserDO();
        userDO.setEmail(saasDO.getEmail());
        userDO.setMobile(saasDO.getMobile());
        userDO.setName(saasDO.getManagerName());
        userDO.setUsername(userDO.getEmail());
        if (saasService.search("name=" + saasDO.getName()).size() > 0) {
            return failed(errorCodeUtil.getErrorMsg(BaseErrorCode.Saas.NAME_IS_EXIST), Envelop.class);
        }
        if (userService.search("mobile=" + userDO.getMobile()).size() > 0) {
@ -66,7 +69,6 @@ public class SaasEndpoint extends EnvelopRestEndpoint {
        if (userService.search("username=" + userDO.getEmail()).size() > 0) {
            return failed(errorCodeUtil.getErrorMsg(BaseErrorCode.Saas.EMAIL_IS_EXIST), Envelop.class);
        }
        userDO.setUsername(userDO.getEmail());
        saasService.save(saasDO, userDO);
        return success("创建成功");
    }

+ 10 - 0
svr/svr-base/src/main/java/com/yihu/jw/base/service/errorCode/ErrorCodeService.java

@ -34,6 +34,16 @@ public class ErrorCodeService extends BaseJpaService<ErrorCodeDO, ErrorCodeDao>
        }
    }
    /**
     * 初始化错误码(无条件)
     */
    public void initWithoutCondition(){
        Iterable<ErrorCodeDO> list = errorCodeDao.findAll();
        list.forEach(code->{
            redisTemplate.opsForValue().set(BaseErrorCode.PREFIX + code.getErrorCode(),code.getErrorMsg());
        });
    }
    /**
     * 新增
     * @param errorCodeDO

+ 37 - 17
svr/svr-base/src/main/java/com/yihu/jw/base/service/saas/SaasService.java

@ -16,6 +16,8 @@ import com.yihu.jw.entity.base.module.SaasModuleDO;
import com.yihu.jw.entity.base.org.BaseOrgDO;
import com.yihu.jw.entity.base.role.RoleDO;
import com.yihu.jw.entity.base.saas.SaasDO;
import com.yihu.jw.entity.base.saas.SaasThemeDO;
import com.yihu.jw.entity.base.saas.SaasThemeExtendDO;
import com.yihu.jw.entity.base.system.SystemDictEntryDO;
import com.yihu.jw.entity.base.user.UserDO;
import com.yihu.jw.entity.base.user.UserRoleDO;
@ -82,17 +84,11 @@ public class SaasService extends BaseJpaService<SaasDO, SaasDao> {
     */
    private final String roleCode = "saasAdmin";
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public SaasDO save(SaasDO saas, UserDO user) {
        //初始化租户信息
        String saasId = getCode();
        String userId = getCode();
        saas.setId(saasId);
        saas.setManager(userId);
        //初始化角色
        RoleDO roleDO = roleDao.findByCode(roleCode);
        //初始化租户管理员
        user.setId(userId);
        user.setEnabled(true);
        user.setLocked(false);
        user.setSalt(randomString(5));
@ -104,12 +100,21 @@ public class SaasService extends BaseJpaService<SaasDO, SaasDao> {
        user.setPassword(MD5.md5Hex(password + "{" + user.getSalt() + "}"));
        //初始化管理员角色
        UserRoleDO userRoleDO = new UserRoleDO();
        userRoleDO.setUserId(user.getId());
        userRoleDO.setRoleId(roleDO.getId());
        List<BaseOrgDO> orgDOList = saas.getOrgList();
        orgDOList.forEach(org->{
            org.setSaasid(saasId);
        });
        userDao.save(user);
        userRoleDO.setUserId(user.getId());
        userRoleDao.save(userRoleDO);
        saas.setManager(user.getId());
        saas.setStatus(SaasDO.Status.auditWait);
        saas = saasDao.save(saas);
        String saasId = saas.getId();
        if(orgDOList!=null&&orgDOList.size()>0){
            orgDOList.forEach(org->{
                org.setSaasid(saasId);
            });
        }
        //字典配置(由于需要支持租户对字典的crud,目前考虑直接复制一套字典给租户单独使用)
//        List<SystemDictDO> systemDictDOList = systemDictDao.findBySaasId(defaultSaasId);
@ -216,8 +221,6 @@ public class SaasService extends BaseJpaService<SaasDO, SaasDao> {
        });
        //保存数据
        saas.setStatus(SaasDO.Status.auditWait);
        saas = saasDao.save(saas);
//        systemDictDao.save(dictDOList);
        systemDictEntryDao.save(dictEntryDOList);
        dictMedicineDao.save(medicineDOList);
@ -227,9 +230,7 @@ public class SaasService extends BaseJpaService<SaasDO, SaasDao> {
        dictDiseaseDao.save(diseaseDOList);
        dictHospitalDeptDao.save(hospitalDeptDOList);
        baseOrgDao.save(orgDOList);
        userDao.save(user);
        userRoleDao.save(userRoleDO);
//        roleModuleFunctionDao.save(roleModuleFunctionDOS);
        return saas;
    }
@ -237,7 +238,7 @@ public class SaasService extends BaseJpaService<SaasDO, SaasDao> {
     * 系统配置
     * @param saasDO
     */
    @Transactional
    @Transactional(rollbackFor = Exception.class)
    public void saveSystemConfig(SaasDO saasDO){
        SaasDO oldSaas = saasDao.findById(saasDO.getId());
@ -256,8 +257,27 @@ public class SaasService extends BaseJpaService<SaasDO, SaasDao> {
     * 主题风格
     * @param saasDO
     */
    @Transactional(rollbackFor = Exception.class)
    public void createThemeConfig(SaasDO saasDO){
        SaasDO oldSaas = saasDao.findById(saasDO.getId());
        oldSaas.setThemeColor(saasDO.getThemeColor());
        List<SaasThemeDO> themeDOList = saasDO.getSaasThemeList();
        List<SaasThemeExtendDO> themeExtendDOList = new ArrayList<>(16);
        themeDOList.forEach(saasThemeDO -> {
            String themeId = getCode();
            saasThemeDO.setSaasId(saasDO.getId());
            saasThemeDO.setId(themeId);
            if(saasThemeDO.getThemeExtendList()!=null&&saasThemeDO.getThemeExtendList().size()>0){
                saasThemeDO.getThemeExtendList().forEach(saasThemeExtendDO -> {
                    saasThemeExtendDO.setThemeId(themeId);
                    themeExtendDOList.add(saasThemeExtendDO);
                });
            }
        });
        saasDao.save(oldSaas);
        saasThemeDao.save(themeDOList);
        saasThemeExtendDao.save(themeExtendDOList);
    }
    @Transactional