当前位置 : 主页 > 编程语言 > java >

userSerivce

来源:互联网 收集:自由互联 发布时间:2021-06-28
user save事物问题 import java.util.List;/** * * @author * @date 2017/7/14 上午9:04 */@Service@Transactional(readOnly = true, rollbackFor = ServiceException.class)public class UserService extends BaseService { @Autowired private UserDa
user save事物问题
import java.util.List;

/**
 *
 * @author 
 * @date 2017/7/14 上午9:04
 */
@Service
@Transactional(readOnly = true, rollbackFor = ServiceException.class)
public class UserService extends BaseService
 
   {

    @Autowired
    private UserDao userDao;

    

    @Transactional(readOnly = false, rollbackFor = ServiceException.class)
    public void save(User user) {
        if (StringUtils.isNotBlank(user.getNewPassword())) {
            user.setPassword(PwdUtils.entryptPassword(user.getNewPassword()));
        }
        if (StringUtils.isBlank(user.getId())) {
            user.preInsert();
            try {
                this.userDao.insert(user);
            } catch (Exception e) {
                e.printStackTrace();
                throw new ServiceException("保存用户失败");
            }

            //创建bbs用户信息
            if(!createBbsUser(user.getMobile())) {
                throw new ServiceException("创建BBS用户信息失败");
            }

        } else {
            user.preUpdate();
            try {
                this.userDao.update(user);
            } catch (Exception e) {
                e.printStackTrace();
                throw new ServiceException("更新用户失败");
            }
        }
        //插入用户角色
        if (user.getRole() == null || StringUtils.isBlank(user.getRole().getId())) {
            throw new ServiceException("缺少角色信息");
        }
        try {
            this.userDao.deleteUserRole(user);
            this.userDao.insertUserRole(user);
        } catch (Exception e) {
            throw new ServiceException("保存角色信息失败");
        }

        if (user.getOffice() == null || StringUtils.isBlank(user.getOffice().getId())) {
            throw new ServiceException("缺少部门信息");
        }
        try {
            this.userDao.deleteUserOffice(user);
            this.userDao.insertUserOffice(user);
        } catch (Exception e) {
            throw new ServiceException("保存部门信息失败");
        }

        UserUtils.clearCache(user);
    }

   
}
 
网友评论