业务逻辑模块

    /**
     * 接口描述
     * 创建人
     * 创建时间
     */
    public interface IUserService {

        /**
         * 方法描述
         * 创建人
         * 创建时间
         * @param 
         * @return
         */
        UserInfoResponseVmo getUserInfo(Integer userId, List<Integer> userIds, BigDecimal amout, Stringmobile)throws Exception;

        /**
         * 方法描述
         * 创建人
         * 创建时间
         * @param 
         * @return
         */
        UserInfoResponseVmo getUserInfo(UserInfoRequestVmo request)throws Exception;

    }
    /**
     * 接口描述
     * 创建人
     * 创建时间
     */
    @Service
    public class UserServiceImpl implements IUserService {

        @Autowired
        UserDao userDao;
        @Autowired
        UserClint userClint;
        @Autowired
        UserMapper userMapper;

        // 配置中心配置获取: key:默认值
        @Value("${get.user.info.cache.minutes:10}")
        private int getUserinfoCacheMinutes;

         @Override
         public UserInfoResponseVmo getUserInfo(Integer userId, List<Integer> userIds, BigDecimal amout, Stringmobile)throws Exception {
                UserInfoResponseVmo result = new UserInfoResponseVmo();
                // model转换:vmo->bmo->dto...
                // 业务逻辑
                userDao.getUserInfo(userId);
                // Feign调用
                userClint.getUserInfo(userId);
                try {
                     // 数据获取
                     userMapper.selectUserInfoById(userId);
                } catch (Exception e) {
                    LogUtil.logApplicationError(code,message,e);
                }finally{
                    // 资源回收
                    // 队列ack
                    // 业务必要逻辑等
                }
                return result;
            }

    }

接口规范

规范

* 1 依赖注入使用注解:@Autowired,注入时 T t 建议一致,反例:EndUserMapper userMapper;
* 2 禁止在service层进行数据交互和数据输出
* 3 禁止一个方法内,一个大try...catch

建议

* 1 配置中心配置建议给一个默认值
* 2 建议相同逻辑抽取公共方法,提高代码复用率
* 3 复杂的逻辑模块按照功能抽取单独方法,保证每个方法逻辑不超过80行代码
* 4 建议数据层model和输出层model在service进行转换,保证数据安全性
* 5 建议分支语句代码不超过三层,反向判断,快速返回
* 6 代码业务异常处理都在该层

results matching ""

    No results matching ""