LiTaohong 7 gadi atpakaļ
vecāks
revīzija
7088e073f7

+ 59 - 0
common/common-request-mapping/src/main/java/com/yihu/jw/rm/base/BaseUserRequestMapping.java

@ -0,0 +1,59 @@
package com.yihu.jw.rm.base;
public class BaseUserRequestMapping {
    public static final String api_common = BaseRequestMapping.api_base_common + "/user";
    /**
     * 基础角色
     */
    public static class BaseRole {
        public static final String api_create = "/baseRole";
        public static final String api_update = "/baseRole";
        public static final String api_delete = "/baseRole/{ids}";
        public static final String api_getById = "/baseRole/{id}";
        public static final String api_getList="/baseRole/list";
        public static final String api_getOne="/baseRole/one";
        public static final String api_getListNoPage="/baseRole/listNoPage";
        public static final String message_success_create = "baseRole create success";
        public static final String message_success_update = "baseRole update success";
        public static final String message_success_find = "baseRole find success";
        public static final String message_success_delete = "baseRole delete success";
        public static final String message_fail_name_exist = "baseRole name exist";
        public static final String message_fail_id_is_null = "id is null";
        public static final String message_fail_saasid_is_null = "saasId is null";
        public static final String message_fail_name_is_null = "baseRole name is null";
        public static final String message_fail_id_no_exist = "id no exist";
        public static final String message_fail_saasid_no_exist = "saasId no exist";
        public static final String message_fail_role_no_exist = "baseRole no exist";
        public static final String message_param_id_is_null = "baseRole id param cannot be null";
        public static final String message_param_saasid_is_null = "baseRole saasId param cannot be null";
        public static final String message_param_name_is_null = "baseRole name param cannot be null";
    }
    /**
     * 用户
     */
    public class Employee {
        public static final String api_create = "/employee";
        public static final String api_update = "/employee";
        public static final String api_delete = "/employee/{ids}";
        public static final String api_getById = "/employee/{id}";
        public static final String api_getByUserId = "/employeeById/{userId}";
        public static final String api_getList="/employee/list";
        public static final String api_getListNoPage="/employee/listNoPage";
        public static final String message_success_create="Employee create success";
        public static final String message_success_update="update Employee success";
        public static final String message_success_delete="Employee delete success";
        public static final String message_success_find="Employee find success";
        public static final String message_fail_name_exist = "baseRole name exist";
        public static final String message_fail_name_is_null = "baseRole is null";
        public static final String message_fail_id_is_null = "id is null";
        public static final String message_fail_id_no_exist = "id no exist";
    }
}

+ 106 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/user/contorller/BaseRoleController.java

@ -0,0 +1,106 @@
package com.yihu.jw.business.user.contorller;
import com.yihu.jw.base.user.BaseRoleDO;
import com.yihu.jw.business.user.service.BaseRoleService;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.restmodel.common.Envelop;
import com.yihu.jw.restmodel.common.EnvelopRestController;
import com.yihu.jw.rm.base.BaseUserRequestMapping;
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.http.MediaType;
import org.springframework.web.bind.annotation.*;
/**
 * Created by LiTaohong on 2017/11/28.
 */
@RestController
@RequestMapping("/role")
@Api(description = "角色")
public class BaseRoleController extends EnvelopRestController {
    @Autowired
    private BaseRoleService baseRoleService;
    @PostMapping(value = BaseUserRequestMapping.BaseRole.api_create, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "创建角色", notes = "创建单个角色")
    public Envelop createRole(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
        try{
            BaseRoleDO baseRoleDO = toEntity(jsonData,BaseRoleDO.class);
            return Envelop.getSuccess(BaseUserRequestMapping.BaseRole.message_success_create,baseRoleService.createBaseRole(baseRoleDO));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @PostMapping(value = BaseUserRequestMapping.BaseRole.api_update, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "修改角色", notes = "修改角色")
    public Envelop updateBaseRole(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
        try{
            BaseRoleDO baseRoleDO = toEntity(jsonData,BaseRoleDO.class);
            return Envelop.getSuccess(BaseUserRequestMapping.BaseRole.message_success_update,baseRoleService.updateBaseRole(baseRoleDO));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @PostMapping(value = BaseUserRequestMapping.BaseRole.api_getOne, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询单个角色", notes = "根据角色id查询角色信息")
    public Envelop getOneRoleById(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
        try{
            BaseRoleDO baseRoleDO = toEntity(jsonData,BaseRoleDO.class);
            return Envelop.getSuccess(BaseUserRequestMapping.BaseRole.message_success_find,baseRoleService.findById(baseRoleDO.getId()));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @PostMapping(value = BaseUserRequestMapping.BaseRole.api_getOne, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询单个角色", notes = "根据平台和角色名称查询角色信息")
    public Envelop getOneRoleBySaasIdAndName(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
        try{
            BaseRoleDO baseRoleDO = toEntity(jsonData,BaseRoleDO.class);
            return Envelop.getSuccess(BaseUserRequestMapping.BaseRole.message_success_find,baseRoleService.findBySaasIdAndName(baseRoleDO.getName(),baseRoleDO.getSaasId()));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @PostMapping(value = BaseUserRequestMapping.BaseRole.api_getList, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "查询多个角色", notes = "根据平台id查询所有角色信息")
    public Envelop getRoleListBySaasId(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
        try{
            BaseRoleDO baseRoleDO = toEntity(jsonData,BaseRoleDO.class);
            return Envelop.getSuccess(BaseUserRequestMapping.BaseRole.message_success_find,baseRoleService.getRoleListByName(baseRoleDO.getSaasId()));
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @PostMapping(value = BaseUserRequestMapping.BaseRole.api_delete, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "删除角色", notes = "根据角色id删除角色")
    public Envelop deleteRole(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
        try{
            BaseRoleDO baseRoleDO = toEntity(jsonData,BaseRoleDO.class);
            baseRoleService.deleteBaseRole(baseRoleDO);
            return Envelop.getSuccess(BaseUserRequestMapping.BaseRole.message_success_delete);
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
    @PostMapping(value = BaseUserRequestMapping.BaseRole.api_delete, consumes = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ApiOperation(value = "批量删除角色", notes = "删除某一平台下所有角色信息")
    public Envelop deleteRolesBySaasId(@ApiParam(name = "json_data", value = "", defaultValue = "") @RequestBody String jsonData){
        try{
            BaseRoleDO baseRoleDO = toEntity(jsonData,BaseRoleDO.class);
            baseRoleService.deleteBaseRolesBySaasId(baseRoleDO.getSaasId());
            return Envelop.getSuccess(BaseUserRequestMapping.BaseRole.message_success_delete);
        } catch (ApiException e){
            return Envelop.getError(e.getMessage(), e.getErrorCode());
        }
    }
}

+ 0 - 14
svr/svr-base/src/main/java/com/yihu/jw/business/user/contorller/RoleController.java

@ -1,14 +0,0 @@
package com.yihu.jw.business.user.contorller;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * Created by LiTaohong on 2017/11/28.
 */
@RestController
@RequestMapping("/role")
@Api(description = "角色")
public class RoleController {
}

+ 28 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/user/dao/BaseRoleDao.java

@ -0,0 +1,28 @@
package com.yihu.jw.business.user.dao;
import com.yihu.jw.base.user.BaseRoleDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
/**
 * Created by LiTaohong on 2017/11/28.
 */
public interface BaseRoleDao extends PagingAndSortingRepository<BaseRoleDO, String>, JpaSpecificationExecutor<BaseRoleDO> {
    @Query("from BaseRoleDO b where b.id = ?1")
    BaseRoleDO findOneById(String id);
    //角色与saasId为一对多关系
    @Query("from BaseRoleDO b where b.saasId = ?1")
    List<BaseRoleDO> findAllBySaasId(String saasId);
    @Query("from BaseRoleDO b where b.saasId = ?1 and b.name = ?2")
    BaseRoleDO findOneBySaasIdAndName(String saasId,String name);
    @Query("from BaseRoleDO b where b.name like %?1%")
    List<BaseRoleDO> findAllByName(String name);
}

+ 1 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/user/dao/EmployeeDao.java

@ -8,4 +8,5 @@ import org.springframework.data.repository.PagingAndSortingRepository;
 * Created by chenweida on 2017/11/28.
 */
public interface EmployeeDao extends PagingAndSortingRepository<BaseEmployDO, String>, JpaSpecificationExecutor<BaseEmployDO> {
}

+ 2 - 1
svr/svr-base/src/main/java/com/yihu/jw/business/user/dao/RoleDao.java

@ -1,5 +1,6 @@
package com.yihu.jw.business.user.dao;
import com.yihu.jw.base.user.BaseEmployRoleDO;
import com.yihu.jw.base.user.BaseRoleDO;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.repository.PagingAndSortingRepository;
@ -7,5 +8,5 @@ import org.springframework.data.repository.PagingAndSortingRepository;
/**
 * Created by LiTaohong on 2017/11/28.
 */
public interface RoleDao extends PagingAndSortingRepository<BaseRoleDO, String>, JpaSpecificationExecutor<BaseRoleDO> {
public interface EmployeeRoleDao extends PagingAndSortingRepository<BaseEmployRoleDO, String>, JpaSpecificationExecutor<BaseEmployRoleDO> {
}

+ 173 - 0
svr/svr-base/src/main/java/com/yihu/jw/business/user/service/BaseRoleService.java

@ -0,0 +1,173 @@
package com.yihu.jw.business.user.service;
import com.netflix.discovery.converters.Auto;
import com.yihu.base.mysql.query.BaseJpaService;
import com.yihu.jw.base.user.BaseRoleDO;
import com.yihu.jw.business.user.dao.BaseRoleDao;
import com.yihu.jw.exception.ApiException;
import com.yihu.jw.exception.code.ExceptionCode;
import com.yihu.jw.rm.base.BaseUserRequestMapping;
import net.bytebuddy.implementation.bytecode.Throw;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import java.util.List;
/**
 * Created by LiTaohong on 2017/11/28.
 */
@Service
public class BaseRoleService extends BaseJpaService<BaseRoleDO,BaseRoleDao>{
    @Autowired
    private BaseRoleDao baseRoleDao;
    /**
     * 创建role
     * @param baseRoleDO
     * @return
     */
    @Transactional
    public BaseRoleDO createBaseRole(BaseRoleDO baseRoleDO){
        if (StringUtils.isEmpty(baseRoleDO.getId())) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_id_is_null, ExceptionCode.common_error_params_code);
        }
        if (StringUtils.isEmpty(baseRoleDO.getSaasId())) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_saasid_is_null, ExceptionCode.common_error_params_code);
        }
        if (StringUtils.isEmpty(baseRoleDO.getName())) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_name_is_null, ExceptionCode.common_error_params_code);
        }
        return this.baseRoleDao.save(baseRoleDO);
    }
    /**
     * 更新role
     * @param baseRoleDO
     * @return
     */
    @Transactional
    public BaseRoleDO updateBaseRole(BaseRoleDO baseRoleDO){
        if (StringUtils.isEmpty(baseRoleDO.getId())) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_id_is_null, ExceptionCode.common_error_params_code);
        }
        if (StringUtils.isEmpty(baseRoleDO.getSaasId())) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_saasid_is_null, ExceptionCode.common_error_params_code);
        }
        return this.baseRoleDao.save(baseRoleDO);
    }
    /**
     * 根据roleId查询role
     * @param id
     * @return
     */
    public BaseRoleDO findById(String id){
        if (StringUtils.isEmpty(id)) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_id_is_null,ExceptionCode.common_error_params_code);
        }
        BaseRoleDO baseRoleDO = this.baseRoleDao.findOneById(id);
        if (null == baseRoleDO) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_id_no_exist,ExceptionCode.common_error_params_code);
        }
        return baseRoleDO;
    }
    /**
     * 查询某要saasId平台下的所有role
     * @param saasId
     * @return
     */
    public List<BaseRoleDO> findAllBySaasId(String saasId){
        if (StringUtils.isEmpty(saasId)) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_param_saasid_is_null,ExceptionCode.common_error_params_code);
        }
        List<BaseRoleDO> list = this.baseRoleDao.findAllBySaasId(saasId);
        if (null == list || list.size() == 0) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_saasid_no_exist,ExceptionCode.common_error_params_code);
        }
        return list;
    }
    /**
     * 查找某一平台下某一个role
     * @param saasId
     * @param name
     * @return
     */
    public BaseRoleDO findBySaasIdAndName(String saasId,String name){
        if (StringUtils.isEmpty(saasId)) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_param_saasid_is_null,ExceptionCode.common_error_params_code);
        }
        if (StringUtils.isEmpty(name)) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_name_is_null,ExceptionCode.common_error_params_code);
        }
        BaseRoleDO baseRoleDO = this.baseRoleDao.findOneBySaasIdAndName(name,saasId);
        if (null == baseRoleDO) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_role_no_exist,ExceptionCode.common_error_params_code);
        }
        return baseRoleDO;
    }
    /**
     * 根据name查询所有的role,包括不同平台saasid的
     * @param name
     * @return
     */
    public List<BaseRoleDO> getRoleListByName(String name){
        if (StringUtils.isEmpty(name)) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_param_name_is_null,ExceptionCode.common_error_params_code);
        }
        List<BaseRoleDO> list = this.baseRoleDao.findAllByName(name);
        if (null == list || list.size() == 0) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_role_no_exist,ExceptionCode.common_error_params_code);
        }
        return list;
    }
    /**
     * 根据roleId删除role
     * @param baseRoleDO
     */
    @Transactional
    public void deleteBaseRole(BaseRoleDO baseRoleDO){
        if (StringUtils.isEmpty(baseRoleDO.getId())) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_id_is_null, ExceptionCode.common_error_params_code);
        }
        if (StringUtils.isEmpty(baseRoleDO.getSaasId())) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_saasid_is_null, ExceptionCode.common_error_params_code);
        }
        baseRoleDO.setStatus(-1);
        this.baseRoleDao.save(baseRoleDO);
    }
    /**
     * 删除某一saasId相关的所有role
     * @param saasId
     */
    @Transactional
    public void deleteBaseRolesBySaasId(String saasId){
        if (StringUtils.isEmpty(saasId)) {
            throw new ApiException(BaseUserRequestMapping.BaseRole.message_fail_saasid_is_null, ExceptionCode.common_error_params_code);
        }
        List<BaseRoleDO> list = this.baseRoleDao.findAllBySaasId(saasId);
        for(BaseRoleDO baseRoleDO:list){
            baseRoleDO.setStatus(-1);
        }
        this.baseRoleDao.save(list);
    }
    /**
     * 根据saasId和name删除角色
     * @param saasId
     * @param name
     */
    @Transactional
    public void deleteBaseRoleByNameAndSaasId(String saasId,String name){
        BaseRoleDO baseRoleDO = this.findBySaasIdAndName(saasId,name);
        baseRoleDO.setStatus(-1);
        this.baseRoleDao.save(baseRoleDO);
    }
}

+ 0 - 13
svr/svr-base/src/main/java/com/yihu/jw/business/user/service/RoleService.java

@ -1,13 +0,0 @@
package com.yihu.jw.business.user.service;
import com.yihu.base.mysql.query.BaseJpaService;
import com.yihu.jw.base.user.BaseRoleDO;
import com.yihu.jw.business.user.dao.RoleDao;
import org.springframework.stereotype.Service;
/**
 * Created by LiTaohong on 2017/11/28.
 */
@Service
public class RoleService extends BaseJpaService<BaseRoleDO,RoleDao>{
}